From b5ded782a91d04c93912a69aceb095c5b61cfebc Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Tue, 21 Jul 2026 22:20:34 +0100 Subject: [PATCH] Removed old comments from shaders --- .../voxygen/shaders/antialias/fxupscale.glsl | 7 +- assets/voxygen/shaders/antialias/hqx.glsl | 1 - assets/voxygen/shaders/clouds-frag.glsl | 4 +- assets/voxygen/shaders/figure-frag.glsl | 112 +----- assets/voxygen/shaders/figure-vert.glsl | 76 +--- assets/voxygen/shaders/fluid-frag/cheap.glsl | 96 +---- assets/voxygen/shaders/fluid-frag/shiny.glsl | 184 +--------- assets/voxygen/shaders/fluid-vert.glsl | 49 +-- assets/voxygen/shaders/include/light.glsl | 108 +----- assets/voxygen/shaders/include/lod.glsl | 181 ++-------- assets/voxygen/shaders/include/shadows.glsl | 321 ++++------------- assets/voxygen/shaders/include/sky.glsl | 316 +++-------------- assets/voxygen/shaders/include/srgb.glsl | 327 ++---------------- .../shaders/light-shadows-directed-vert.glsl | 14 +- .../shaders/light-shadows-figure-vert.glsl | 11 +- .../voxygen/shaders/light-shadows-frag.glsl | 27 +- .../voxygen/shaders/light-shadows-geom.glsl | 83 +---- .../voxygen/shaders/light-shadows-vert.glsl | 9 +- assets/voxygen/shaders/lod-terrain-frag.glsl | 264 +------------- assets/voxygen/shaders/lod-terrain-vert.glsl | 73 +--- assets/voxygen/shaders/particle-frag.glsl | 8 +- assets/voxygen/shaders/particle-vert.glsl | 8 +- .../voxygen/shaders/player-shadow-frag.glsl | 16 +- .../shaders/point-light-shadows-vert.glsl | 11 +- assets/voxygen/shaders/postprocess-frag.glsl | 149 +------- .../shaders/rain-occlusion-directed-vert.glsl | 7 - .../shaders/rain-occlusion-figure-vert.glsl | 11 +- assets/voxygen/shaders/rope-frag.glsl | 118 +------ assets/voxygen/shaders/skybox-frag.glsl | 17 +- assets/voxygen/shaders/skybox-vert.glsl | 8 +- assets/voxygen/shaders/sprite-frag.glsl | 6 +- assets/voxygen/shaders/sprite-vert.glsl | 5 +- assets/voxygen/shaders/terrain-frag.glsl | 267 +------------- assets/voxygen/shaders/ui-vert.glsl | 4 - 34 files changed, 271 insertions(+), 2627 deletions(-) diff --git a/assets/voxygen/shaders/antialias/fxupscale.glsl b/assets/voxygen/shaders/antialias/fxupscale.glsl index da04051b3d..9745a95dd5 100644 --- a/assets/voxygen/shaders/antialias/fxupscale.glsl +++ b/assets/voxygen/shaders/antialias/fxupscale.glsl @@ -10,8 +10,6 @@ vec4 aa_apply( vec2 sz = textureSize(sampler2D(tex, smplr), 0).xy; - //float center_d = texelFetch(sampler2D(depth_tex, depth_smplr), ivec2(fragCoord / screen_res.xy * sz), 0).x; - float min_depth = 1000; float max_depth = 0; for (uint i = 0u; i < dirs.length(); i ++) { @@ -22,19 +20,16 @@ vec4 aa_apply( vec4 aa_color = fxaa_apply(tex, smplr, fragCoord, resolution, 1.0 + 1.0 / (min_depth * 0 + 0.001 + (max_depth - min_depth) * 500) * 0.001); vec4 lerped = texture(sampler2D(tex, smplr), fragCoord / screen_res.xy); - //aa_color = lerped; vec4 closest = aa_color; float closest_dist = 1000.0; for (uint i = 0u; i < dirs.length(); i ++) { vec4 col_at = texelFetch(sampler2D(tex, smplr), ivec2(fragCoord / screen_res.xy * sz) + dirs[i], 0); - //float depth_at = texelFetch(sampler2D(depth_tex, depth_smplr), ivec2(fragCoord / screen_res.xy * sz) + dirs[i], 0).x; float dist = dot(pow(aa_color.rgb - col_at.rgb, ivec3(2)), vec3(1)); if (dist < closest_dist) { closest = mix(col_at, lerped, min(length(lerped.rgb - col_at.rgb) * 0.25, 1)); closest_dist = dist; } } - //return texelFetch(sampler2D(tex, smplr), ivec2(fragCoord / screen_res.xy * sz), 0); - return closest;//mix(aa_color, closest, clamp(1.0 - sqrt(closest_dist) / length(aa_color.rgb) * 0.75, 0, 1)); + return closest; } diff --git a/assets/voxygen/shaders/antialias/hqx.glsl b/assets/voxygen/shaders/antialias/hqx.glsl index 0eb950877f..bbd250003d 100644 --- a/assets/voxygen/shaders/antialias/hqx.glsl +++ b/assets/voxygen/shaders/antialias/hqx.glsl @@ -39,7 +39,6 @@ vec4 aa_apply( vec2 ip = fragCoord / upscale; //start with nearest pixel as 'background' vec4 s = texelFetch(sampler2D(tex, smplr), ivec2(ip), 0); - //vec4 s = texture(sampler2D(tex, smplr), fragCoord / resolution); float aa_scale = upscale.x * 0.5; diff --git a/assets/voxygen/shaders/clouds-frag.glsl b/assets/voxygen/shaders/clouds-frag.glsl index a6009a6b04..89dd03e7ef 100644 --- a/assets/voxygen/shaders/clouds-frag.glsl +++ b/assets/voxygen/shaders/clouds-frag.glsl @@ -54,7 +54,6 @@ layout(location = 0) out vec4 tgt_color; vec3 wpos_at(vec2 uv) { uvec2 sz = textureSize(sampler2D(t_src_depth, s_src_depth), 0); float buf_depth = texelFetch(sampler2D(t_src_depth, s_src_depth), clamp(ivec2(uv * sz), ivec2(0), ivec2(sz) - 1), 0).x; - //float buf_depth = texture(sampler2D(t_src_depth, s_src_depth), uv).x; vec4 clip_space = vec4((uv * 2.0 - 1.0) * vec2(1, -1), buf_depth, 1.0); vec4 view_space = all_mat_inv * clip_space; view_space /= view_space.w; @@ -207,7 +206,6 @@ void main() { if (d < svpos.z * 0.8 && d > svpos.z * 0.999) { // Don't cast into water! if (texelFetch(sampler2D(t_src_color, s_src_color), clamp(ivec2(suv * col_sz), ivec2(0), ivec2(col_sz) - 1), 0).a >= 1.0) { - /* t -= 1.0 / float(MAIN_ITERS); */ // Do a bit of extra iteration to try to refine the estimate const int ITERS = 8; float diff = 1.0 / float(MAIN_ITERS); @@ -310,7 +308,7 @@ void main() { vec3 rpos = vec3(0.0); float t = 0.0; const float PLANCK = 0.01; - for (int i = 0; i < 14 /* log2(64) * 2 + 2 */; i ++) { + for (int i = 0; i < 14; i ++) { float scale = min(pow(2, ceil(t / 2.0)), 32); vec2 deltas = (step(vec2(0), dir2d) - fract(rpos.xy / scale + 100.0)) / dir2d; float jump = max(min(deltas.x, deltas.y) * scale, PLANCK); diff --git a/assets/voxygen/shaders/figure-frag.glsl b/assets/voxygen/shaders/figure-frag.glsl index ce650d264d..71d742a05b 100644 --- a/assets/voxygen/shaders/figure-frag.glsl +++ b/assets/voxygen/shaders/figure-frag.glsl @@ -30,39 +30,16 @@ #endif layout(location = 0) in vec3 f_pos; -// in float dummy; -// in vec3 f_col; -// in float f_ao; -// flat in uint f_pos_norm; layout(location = 1) flat in vec3 f_norm; -/*centroid */layout(location = 2) in vec2 f_uv_pos; +layout(location = 2) in vec2 f_uv_pos; layout(location = 3) in vec3 m_pos; layout(location = 4) in float scale; -// in float f_alt; -// in vec4 f_shadow; -// in vec3 light_pos[2]; - -// #if (SHADOW_MODE == SHADOW_MODE_MAP) -// in vec4 sun_pos; -// #elif (SHADOW_MODE == SHADOW_MODE_CHEAP || SHADOW_MODE == SHADOW_MODE_NONE) -// const vec4 sun_pos = vec4(0.0); -// #endif layout(set = 2, binding = 0) uniform texture2D t_col_light; layout(set = 2, binding = 1) uniform sampler s_col_light; -//struct ShadowLocals { -// mat4 shadowMatrices; -// mat4 texture_mat; -//}; -// -//layout (std140) -//uniform u_light_shadows { -// ShadowLocals shadowMats[/*MAX_LAYER_FACES*/192]; -//}; - layout (std140, set = 3, binding = 0) uniform u_locals { mat4 model_mat; @@ -113,15 +90,6 @@ void main() { } #endif - // vec2 texSize = textureSize(t_col_light, 0); - // vec4 col_light = texture(t_col_light, (f_uv_pos + 0.5) / texSize); - // vec3 f_col = col_light.rgb; - // float f_ao = col_light.a; - - // vec4 f_col_light = texture(t_col_light, (f_uv_pos + 0.5) / textureSize(t_col_light, 0)); - // vec3 f_col = f_col_light.rgb; - // float f_ao = f_col_light.a; - float f_ao; uint material = 0xFFu; vec3 f_col = greedy_extract_col_light_figure(t_col_light, s_col_light, f_uv_pos, f_ao, material); @@ -130,36 +98,9 @@ void main() { tgt_color = vec4(simple_lighting(f_pos.xyz, f_col, f_ao), 1); #else - // float /*f_light*/f_ao = textureProj(t_col_light, vec3(f_uv_pos, texSize)).a;//1.0;//f_col_light.a * 4.0;// f_light = float(v_col_light & 0x3Fu) / 64.0; - - // vec3 my_chunk_pos = (vec3((uvec3(f_pos_norm) >> uvec3(0, 9, 18)) & uvec3(0x1FFu)) - 256.0) / 2.0; - // tgt_color = vec4(hash(floor(vec4(my_chunk_pos.x, 0, 0, 0))), hash(floor(vec4(0, my_chunk_pos.y, 0, 1))), hash(floor(vec4(0, 0, my_chunk_pos.z, 2))), 1.0); - - // vec3 du = dFdx(f_pos); - // vec3 dv = dFdy(f_pos); - // vec3 f_norm = normalize(cross(du, dv)); - - // vec4 light_pos[2]; -//#if (SHADOW_MODE == SHADOW_MODE_MAP) -// // for (uint i = 0u; i < light_shadow_count.z; ++i) { -// // light_pos[i] = /*vec3(*/shadowMats[i].texture_mat * vec4(f_pos, 1.0)/*)*/; -// // } -// vec4 sun_pos = /*vec3(*/shadowMats[0].texture_mat * vec4(f_pos, 1.0)/*)*/; -//#elif (SHADOW_MODE == SHADOW_MODE_CHEAP || SHADOW_MODE == SHADOW_MODE_NONE) -// vec4 sun_pos = vec4(0.0); -//#endif - vec3 cam_to_frag = normalize(f_pos - cam_pos.xyz); - // vec4 vert_pos4 = view_mat * vec4(f_pos, 1.0); - // vec3 view_dir = normalize(-vec3(vert_pos4)/* / vert_pos4.w*/); vec3 view_dir = -cam_to_frag; - /* vec3 sun_dir = get_sun_dir(time_of_day.x); - vec3 moon_dir = get_moon_dir(time_of_day.x); */ - // float sun_light = get_sun_brightness(sun_dir); - // float moon_light = get_moon_brightness(moon_dir); - /* float sun_shade_frac = horizon_at(f_pos, sun_dir); - float moon_shade_frac = horizon_at(f_pos, moon_dir); */ #if (SHADOW_MODE == SHADOW_MODE_CHEAP || SHADOW_MODE == SHADOW_MODE_MAP || FLUID_MODE >= FLUID_MODE_MEDIUM) float f_alt = alt_at(f_pos.xy); #elif (SHADOW_MODE == SHADOW_MODE_NONE || FLUID_MODE == FLUID_MODE_LOW) @@ -170,18 +111,10 @@ void main() { vec4 f_shadow = textureMaybeBicubic(t_horizon, s_horizon, pos_to_tex(f_pos.xy)); float sun_shade_frac = horizon_at2(f_shadow, f_alt, f_pos, sun_dir); #elif (SHADOW_MODE == SHADOW_MODE_NONE) - float sun_shade_frac = 1.0;//horizon_at2(f_shadow, f_alt, f_pos, sun_dir); + float sun_shade_frac = 1.0; #endif - float moon_shade_frac = 1.0;// horizon_at2(f_shadow, f_alt, f_pos, moon_dir); - // Globbal illumination "estimate" used to light the faces of voxels which are parallel to the sun or moon (which is a very common occurrence). - // Will be attenuated by k_d, which is assumed to carry any additional ambient occlusion information (e.g. about shadowing). - // float ambient_sides = clamp(mix(0.5, 0.0, abs(dot(-f_norm, sun_dir)) * 10000.0), 0.0, 0.5); - // NOTE: current assumption is that moon and sun shouldn't be out at the sae time. - // This assumption is (or can at least easily be) wrong, but if we pretend it's true we avoids having to explicitly pass in a separate shadow - // for the sun and moon (since they have different brightnesses / colors so the shadows shouldn't attenuate equally). - // float shade_frac = /*1.0;*/sun_shade_frac + moon_shade_frac; + float moon_shade_frac = 1.0; - // DirectionalLight sun_info = get_sun_info(sun_dir, sun_shade_frac, light_pos); DirectionalLight sun_info = get_sun_info(sun_dir, sun_shade_frac, /*sun_pos*/f_pos); DirectionalLight moon_info = get_moon_info(moon_dir, moon_shade_frac/*, light_pos*/); @@ -234,25 +167,15 @@ void main() { sun_info.block *= model_light.x; moon_info.block *= model_light.x; - // vec3 light_frac = /*vec3(1.0);*//*vec3(max(dot(f_norm, -sun_dir) * 0.5 + 0.5, 0.0));*/light_reflection_factor(f_norm, view_dir, vec3(0, 0, -1.0), vec3(1.0), vec3(R_s), alpha); - // vec3 point_light = light_at(f_pos, f_norm); - // vec3 light, diffuse_light, ambient_light; - //get_sun_diffuse(f_norm, time_of_day.x, view_dir, k_a * point_shadow * (shade_frac * 0.5 + light_frac * 0.5), k_d * point_shadow * shade_frac, k_s * point_shadow * shade_frac, alpha, emitted_light, reflected_light); float max_light = 0.0; - // reflected_light *= point_shadow * shade_frac; - // emitted_light *= point_shadow * max(shade_frac, MIN_SHADOW); - // max_light *= point_shadow * shade_frac; - // reflected_light *= point_shadow; - // emitted_light *= point_shadow; - // max_light *= point_shadow; vec3 cam_attenuation = vec3(1); float fluid_alt = max(f_pos.z + 1, floor(f_alt + 1)); vec3 mu = medium.x == MEDIUM_WATER ? MU_WATER : vec3(0.0); #if (FLUID_MODE >= FLUID_MODE_MEDIUM) cam_attenuation = - medium.x == MEDIUM_WATER ? compute_attenuation_point(cam_pos.xyz, view_dir, mu, fluid_alt, /*cam_pos.z <= fluid_alt ? cam_pos.xyz : f_pos*/f_pos) - : compute_attenuation_point(f_pos, -view_dir, mu, fluid_alt, /*cam_pos.z <= fluid_alt ? cam_pos.xyz : f_pos*/cam_pos.xyz); + medium.x == MEDIUM_WATER ? compute_attenuation_point(cam_pos.xyz, view_dir, mu, fluid_alt, f_pos) + : compute_attenuation_point(f_pos, -view_dir, mu, fluid_alt, cam_pos.xyz); #endif // Prevent the sky affecting light when underground @@ -270,7 +193,7 @@ void main() { reflected_light += glow * cam_attenuation; // Apply baked AO - float ao = f_ao * sqrt(f_ao);//0.25 + f_ao * 0.75; ///*pow(f_ao, 0.5)*/f_ao * 0.85 + 0.15; + float ao = f_ao * sqrt(f_ao); reflected_light *= ao; emitted_light *= ao; @@ -286,32 +209,9 @@ void main() { apply_cell_material(material, f_pos, f_norm, surf_color, emitted_light, render_alpha, render_mat); } - /* reflected_light *= cloud_shadow(f_pos); */ - /* vec3 point_light = light_at(f_pos, f_norm); - emitted_light += point_light; - reflected_light += point_light; */ - // get_sun_diffuse(f_norm, time_of_day.x, cam_to_frag, surf_color * f_light * point_shadow, 0.5 * surf_color * f_light * point_shadow, 0.5 * surf_color * f_light * point_shadow, 2.0, emitted_light, reflected_light); - - // get_sun_diffuse(f_norm, time_of_day.x, light, diffuse_light, ambient_light, 1.0); - // diffuse_light *= point_shadow; - // ambient_light *= point_shadow; - // vec3 point_light = light_at(f_pos, f_norm); - // light += point_light; - // diffuse_light += point_light; - // reflected_light += point_light; - // vec3 surf_color = illuminate(srgb_to_linear(highlight_col.rgb * f_col), light, diffuse_light, ambient_light); - float reflectance = 0.0; // TODO: Do reflectance properly like this later vec3 reflect_color = vec3(0); - /* - if ((material & (1u << 1u)) > 0u && false) { - vec3 reflect_ray_dir = reflect(cam_to_frag, f_norm); - reflect_color = get_sky_color(reflect_ray_dir, f_pos, vec3(-100000), 0.125, true); - reflect_color = get_cloud_color(reflect_color, reflect_ray_dir, cam_pos.xyz, 100000.0, 0.25); - reflectance = 1.0; - } - */ surf_color = illuminate(max_light, view_dir, mix(surf_color * emitted_light, reflect_color, reflectance), mix(surf_color * reflected_light, reflect_color, reflectance)) * highlight_col.rgb; diff --git a/assets/voxygen/shaders/figure-vert.glsl b/assets/voxygen/shaders/figure-vert.glsl index 320b482622..854f2ef50b 100644 --- a/assets/voxygen/shaders/figure-vert.glsl +++ b/assets/voxygen/shaders/figure-vert.glsl @@ -20,11 +20,6 @@ layout(location = 0) in uint v_pos_norm; layout(location = 1) in uint v_atlas_pos; -// in vec3 v_norm; -/* in uint v_col; -// out vec3 light_pos[2]; -in uint v_ao_bone; */ - layout (std140, set = 3, binding = 0) uniform u_locals { mat4 model_mat; @@ -55,43 +50,18 @@ uniform u_bones { BoneData bones[16]; }; -//struct ShadowLocals { -// mat4 shadowMatrices; -// mat4 texture_mat; -//}; -// -//layout (std140) -//uniform u_light_shadows { -// ShadowLocals shadowMats[/*MAX_LAYER_FACES*/192]; -//}; - layout(location = 0) out vec3 f_pos; -// flat out uint f_pos_norm; layout(location = 1) flat out vec3 f_norm; -// float dummy; -/*centroid */layout(location = 2) out vec2 f_uv_pos; +layout(location = 2) out vec2 f_uv_pos; layout(location = 3) out vec3 m_pos; layout(location = 4) out float scale; -// out vec3 f_col; -// out float f_ao; -// out float f_alt; -// out vec4 f_shadow; - -// #if (SHADOW_MODE == SHADOW_MODE_MAP) -// out vec4 sun_pos; -// #endif void main() { // Pre-calculate bone matrix - /* uint bone_idx = (v_ao_bone >> 2) & 0x3Fu; */ uint bone_idx = (v_pos_norm >> 27) & 0xFu; - // mat4 combined_mat = model_mat * bone_mat; - vec3 pos = (vec3((uvec3(v_pos_norm) >> uvec3(0, 9, 18)) & uvec3(0x1FFu)) - 256.0) / 2.0; - // vec4 bone_pos = bones[bone_idx].bone_mat * vec4(pos, 1); - m_pos = pos; scale = length(bones[bone_idx].bone_mat[0]); @@ -104,55 +74,15 @@ void main() { f_pos.z -= pow(distance(f_pos.xy + focus_off.xy, focus_pos.xy + focus_off.xy) * 0.05, 2); #endif - /* f_pos.z -= 25.0 * pow(distance(focus_pos.xy, f_pos.xy) / view_distance.x, 20.0); */ - f_uv_pos = vec2((uvec2(v_atlas_pos) >> uvec2(2, 17)) & uvec2(0x7FFFu, 0x7FFFu)); - // f_col = srgb_to_linear(vec3((uvec3(v_col) >> uvec3(0, 8, 16)) & uvec3(0xFFu)) / 255.0); - // f_col = vec3(1.0); - - // f_ao = float(v_ao_bone & 0x3u) / 4.0; - // f_ao = 1.0; - /* for (uint i = 0u; i < light_shadow_count.z; ++i) { - light_pos[i] = vec3(shadowMats[i].texture_mat * vec4(f_pos, 1.0)); - } */ - // First 3 normals are negative, next 3 are positive - // uint normal_idx = ((v_atlas_pos & 3u) << 1u) | (v_pos_norm >> 31u); - // const vec3 normals[6] = vec3[](vec3(-1,0,0), vec3(1,0,0), vec3(0,-1,0), vec3(0,1,0), vec3(0,0,-1), vec3(0,0,1)); - // vec3 norm = normals[normal_idx]; uint axis_idx = v_atlas_pos & 3u; vec3 norm = bones[bone_idx].normals_mat[axis_idx].xyz; - // norm = normalize(norm); - // vec3 norm = norm_mat * vec4(uvec3(1 << axis_idx) & uvec3(0x1u, 0x3u, 0x7u), 1); - // // Calculate normal here rather than for each pixel in the fragment shader - // f_norm = normalize(( - // combined_mat * - // vec4(norm, 0) - // ).xyz); + // Calculate normal here rather than for each pixel in the fragment shader f_norm = mix(-norm, norm, v_pos_norm >> 31u); -// #if (SHADOW_MODE == SHADOW_MODE_MAP) -// // for (uint i = 0u; i < light_shadow_count.z; ++i) { -// // light_pos[i] = /*vec3(*/shadowMats[i].texture_mat * vec4(f_pos, 1.0)/*)*/; -// // } -// sun_pos = /*vec3(*/shadowMats[0].texture_mat * vec4(f_pos, 1.0)/*)*/; -// // #elif (SHADOW_MODE == SHADOW_MODE_CHEAP || SHADOW_MODE == SHADOW_MODE_NONE) -// // vec4 sun_pos = vec4(0.0); -// #endif - - // f_pos_norm = v_pos_norm; - - // Also precalculate shadow texture and estimated terrain altitude. - // f_alt = alt_at(f_pos.xy); - // f_shadow = textureMaybeBicubic(t_horizon, pos_to_tex(f_pos.xy)); - - gl_Position = all_mat/*shadowMats[0].shadowMatrices*/ * vec4(f_pos, 1); - // gl_Position.z = -gl_Position.z / 100.0 / gl_Position.w; - // gl_Position.z = -gl_Position.z / 100.0; - // gl_Position.z = gl_Position.z / 100.0; - // gl_Position.z = -gl_Position.z; - // gl_Position.z = -1000.0 / (gl_Position.z + 10000.0); + gl_Position = all_mat * vec4(f_pos, 1); } diff --git a/assets/voxygen/shaders/fluid-frag/cheap.glsl b/assets/voxygen/shaders/fluid-frag/cheap.glsl index 70069c5930..15d0f0b68d 100644 --- a/assets/voxygen/shaders/fluid-frag/cheap.glsl +++ b/assets/voxygen/shaders/fluid-frag/cheap.glsl @@ -24,19 +24,6 @@ layout(location = 0) in vec3 f_pos; layout(location = 1) flat in uint f_pos_norm; layout(location = 2) in vec2 f_vel; -// in vec3 f_col; -// in float f_light; -// in vec3 light_pos[2]; - -// struct ShadowLocals { -// mat4 shadowMatrices; -// mat4 texture_mat; -// }; -// -// layout (std140) -// uniform u_light_shadows { -// ShadowLocals shadowMats[/*MAX_LAYER_FACES*/192]; -// }; layout(std140, set = 2, binding = 0) uniform u_locals { @@ -80,7 +67,6 @@ void main() { tgt_color = vec4(simple_lighting(f_pos.xyz, MU_SCATTER, 1.0), 0.5); #else - // tgt_color = vec4(1.0 - MU_WATER, 1.0); // First 3 normals are negative, next 3 are positive vec3 normals[6] = vec3[](vec3(-1,0,0), vec3(1,0,0), vec3(0,-1,0), vec3(0,1,0), vec3(0,0,-1), vec3(0,0,1)); @@ -91,27 +77,12 @@ void main() { // Use an array to avoid conditional branching vec3 f_norm = normals[norm_axis + norm_dir]; - // vec4 light_pos[2]; -// #if (SHADOW_MODE == SHADOW_MODE_MAP) -// // for (uint i = 0u; i < light_shadow_count.z; ++i) { -// // light_pos[i] = /*vec3(*/shadowMats[i].texture_mat * vec4(f_pos, 1.0)/*)*/; -// // } -// vec4 sun_pos = /*vec3(*/shadowMats[0].texture_mat * vec4(f_pos, 1.0)/*)*/; -// #elif (SHADOW_MODE == SHADOW_MODE_CHEAP || SHADOW_MODE == SHADOW_MODE_NONE) -// vec4 sun_pos = vec4(0.0); -// #endif - vec3 cam_to_frag = normalize(f_pos - cam_pos.xyz); - // vec4 vert_pos4 = view_mat * vec4(f_pos, 1.0); - // vec3 view_dir = normalize(-vec3(vert_pos4)/* / vert_pos4.w*/); vec3 view_dir = -cam_to_frag; - // vec3 surf_color = /*srgb_to_linear*/(vec3(0.4, 0.7, 2.0)); float water_shade = water_col_vel(f_pos.xy); vec3 water_color = (1.0 - mix(MU_WATER, pow(vec3(0.8, 0.9, 0.08), vec3(0.25)), water_shade)) * MU_SCATTER; - /* vec3 sun_dir = get_sun_dir(time_of_day.x); - vec3 moon_dir = get_moon_dir(time_of_day.x); */ #if (SHADOW_MODE == SHADOW_MODE_CHEAP || SHADOW_MODE == SHADOW_MODE_MAP || FLUID_MODE >= FLUID_MODE_MEDIUM) float f_alt = alt_at(f_pos.xy); #elif (SHADOW_MODE == SHADOW_MODE_NONE || FLUID_MODE == FLUID_MODE_LOW) @@ -122,20 +93,16 @@ void main() { vec4 f_shadow = textureMaybeBicubic(t_horizon, s_horizon, pos_to_tex(f_pos.xy)); float sun_shade_frac = horizon_at2(f_shadow, f_alt, f_pos, sun_dir); #elif (SHADOW_MODE == SHADOW_MODE_NONE) - float sun_shade_frac = 1.0;//horizon_at2(f_shadow, f_alt, f_pos, sun_dir); + float sun_shade_frac = 1.0; #endif - float moon_shade_frac = 1.0;//horizon_at2(f_shadow, f_alt, f_pos, moon_dir); - // float sun_shade_frac = horizon_at(/*f_shadow, f_pos.z, */f_pos, sun_dir); - // float moon_shade_frac = horizon_at(/*f_shadow, f_pos.z, */f_pos, moon_dir); - // float shade_frac = /*1.0;*/sun_shade_frac + moon_shade_frac; + float moon_shade_frac = 1.0; - // DirectionalLight sun_info = get_sun_info(sun_dir, sun_shade_frac, light_pos); DirectionalLight sun_info = get_sun_info(sun_dir, sun_shade_frac, /*sun_pos*/f_pos); DirectionalLight moon_info = get_moon_info(moon_dir, moon_shade_frac/*, light_pos*/); - float fluid_alt = f_pos.z;//max(ceil(f_pos.z), floor(f_alt));// f_alt;//max(f_alt - f_pos.z, 0.0); + float fluid_alt = f_pos.z; - const float alpha = 0.255/* / 4.0 / sqrt(2.0)*/; + const float alpha = 0.255; const float n2 = 1.3325; const float R_s2s0 = pow(abs((1.0 - n2) / (1.0 + n2)), 2); const float R_s1s0 = pow(abs((1.3325 - n2) / (1.3325 + n2)), 2); @@ -148,10 +115,10 @@ void main() { vec3 mu = MU_WATER; // NOTE: Default intersection point is camera position, meaning if we fail to intersect we assume the whole camera is in water. - vec3 cam_attenuation = vec3(1.0);//compute_attenuation_point(f_pos, -view_dir, mu, fluid_alt, cam_pos.xyz); + vec3 cam_attenuation = vec3(1.0); // NOTE: Assumes normal is vertical. - vec3 sun_view_dir = cam_pos.z <= fluid_alt ? /*refract(view_dir, -f_norm, 1.0 / n2)*//*reflect(view_dir, -f_norm)*/-view_dir : view_dir;//vec3(view_dir.xy, -view_dir.z) : view_dir; + vec3 sun_view_dir = cam_pos.z <= fluid_alt ? -view_dir : view_dir; vec3 k_a = vec3(1.0); vec3 k_d = vec3(1.0); @@ -170,18 +137,8 @@ void main() { float not_underground = clamp((f_pos.z - f_alt) / 128.0 + 1.0, 0.0, 1.0); reflect_color *= not_underground; - // float point_shadow = shadow_at(f_pos, f_norm); - // vec3 cam_to_frag = normalize(f_pos - cam_pos.xyz); - // vec3 emitted_light, reflected_light; - // vec3 light, diffuse_light, ambient_light; - // Squared to account for prior saturation. - // float f_light = 1.0;// pow(f_light, 1.5); - // float vert_light = f_light; - // vec3 light_frac = /*vec3(1.0);*/light_reflection_factor(f_norm/*vec3(0, 0, 1.0)*/, view_dir, vec3(0, 0, -1.0), vec3(1.0), vec3(R_s), alpha); - - // vec3 surf_color = /*srgb_to_linear*/(vec3(0.4, 0.7, 2.0)); float max_light = 0.0; - max_light += get_sun_diffuse2(sun_info, moon_info, f_norm, /*time_of_day.x*//*-cam_to_frag*/sun_view_dir/*view_dir*/, f_pos, mu, cam_attenuation, fluid_alt, k_a/* * (shade_frac * 0.5 + light_frac * 0.5)*/, /*vec3(0.0)*/k_d, k_s, alpha, f_norm, 1.0, emitted_light, reflected_light); + max_light += get_sun_diffuse2(sun_info, moon_info, f_norm, sun_view_dir, f_pos, mu, cam_attenuation, fluid_alt, k_a, k_d, k_s, alpha, f_norm, 1.0, emitted_light, reflected_light); emitted_light *= not_underground; reflected_light *= not_underground; @@ -193,40 +150,8 @@ void main() { reflected_light *= point_shadow; emitted_light *= point_shadow; - // reflected_light *= f_light * point_shadow * shade_frac; - // emitted_light *= f_light * point_shadow * max(shade_frac, MIN_SHADOW); - // max_light *= f_light * point_shadow * shade_frac; - // reflected_light *= f_light * point_shadow; - // emitted_light *= f_light * point_shadow; - // max_light *= f_light * point_shadow; - // get_sun_diffuse(f_norm, time_of_day.x, light, diffuse_light, ambient_light, 0.0); - // diffuse_light *= f_light * point_shadow; - // ambient_light *= f_light, point_shadow; - // vec3 point_light = light_at(f_pos, f_norm); - // light += point_light; - // diffuse_light += point_light; - // reflected_light += point_light; - // vec3 surf_color = srgb_to_linear(vec3(0.4, 0.7, 2.0)) * light * diffuse_light * ambient_light; - - // lights_at(f_pos, f_norm, cam_to_frag, k_a * f_light * point_shadow, k_d * f_light * point_shadow, k_s * f_light * point_shadow, alpha, emitted_light, reflected_light); - /*vec3 point_light = light_at(f_pos, f_norm); - emitted_light += point_light; - reflected_light += point_light; */ - - max_light += lights_at(f_pos, /*f_norm*/cam_norm, view_dir, mu, cam_attenuation, fluid_alt, k_a, k_d, k_s, alpha, f_norm, 1.0, emitted_light, reflected_light); - // vec3 diffuse_light_point = vec3(0.0); - // max_light += lights_at(f_pos, f_norm, view_dir, k_a, vec3(1.0), k_s, alpha, emitted_light, diffuse_light_point); - - // float reflected_light_point = length(reflected_light);///*length*/(diffuse_light_point.r) + f_light * point_shadow; - // float reflected_light_point = dot(reflected_light, reflected_light) * 0.5;///*length*/(diffuse_light_point.r) + f_light * point_shadow; - // vec3 dump_light = vec3(0.0); - // vec3 specular_light_point = vec3(0.0); - // lights_at(f_pos, f_norm, view_dir, vec3(0.0), vec3(0.0), /*vec3(1.0)*/k_s, alpha, dump_light, specular_light_point); - // diffuse_light_point -= specular_light_point; - - // float reflected_light_point = /*length*/(diffuse_light_point.r) + f_light * point_shadow; - // reflected_light += k_d * (diffuse_light_point + f_light * point_shadow * shade_frac) + specular_light_point; - + max_light += lights_at(f_pos, cam_norm, view_dir, mu, cam_attenuation, fluid_alt, k_a, k_d, k_s, alpha, f_norm, 1.0, emitted_light, reflected_light); + float passthrough = max(dot(cam_norm, -cam_to_frag), 0); float min_refl = 0.0; @@ -236,8 +161,7 @@ void main() { opacity = min(sqrt(max(opacity, clamp((f_pos.z - cam_pos.z) * 0.05, 0.0, 1.0))), 0.99); } - vec3 surf_color = illuminate(max_light, view_dir, water_color * /* fog_color * */emitted_light, /*surf_color * */reflect_color * water_shade + water_color * reflected_light); - // vec4 color = vec4(surf_color, passthrough * 1.0 / (1.0 + min_refl));// * (1.0 - /*log(1.0 + cam_attenuation)*//*cam_attenuation*/1.0 / (2.0 - log_cam))); + vec3 surf_color = illuminate(max_light, view_dir, water_color * emitted_light, reflect_color * water_shade + water_color * reflected_light); vec4 color = vec4(surf_color, opacity); tgt_color = color; diff --git a/assets/voxygen/shaders/fluid-frag/shiny.glsl b/assets/voxygen/shaders/fluid-frag/shiny.glsl index 4474e1bed6..671134d778 100644 --- a/assets/voxygen/shaders/fluid-frag/shiny.glsl +++ b/assets/voxygen/shaders/fluid-frag/shiny.glsl @@ -26,19 +26,6 @@ layout(location = 0) in vec3 f_pos; layout(location = 1) flat in uint f_pos_norm; layout(location = 2) in vec2 f_vel; -// in vec3 f_col; -// in float f_light; -// in vec3 light_pos[2]; - -//struct ShadowLocals { -// mat4 shadowMatrices; -// mat4 texture_mat; -//}; -// -//layout (std140) -//uniform u_light_shadows { -// ShadowLocals shadowMats[/*MAX_LAYER_FACES*/192]; -//}; layout(std140, set = 2, binding = 0) uniform u_locals { @@ -119,7 +106,7 @@ vec4 wave_height(vec4 posx, vec4 posy, float z) { #if (FLUID_MODE == FLUID_MODE_HIGH) for (uint i = 0u; i < light_shadow_count.y; i ++) { Shadow S = shadows[i]; - vec3 shadow_pos = S.shadow_pos_radius.xyz;// + focus_off.xyz; + vec3 shadow_pos = S.shadow_pos_radius.xyz; float radius = S.shadow_pos_radius.w; vec4 dist = vec4( @@ -167,18 +154,6 @@ void main() { vec3 f_norm = vec3(0, 0, 1);//surf_norm; vec3 cam_to_frag = normalize(f_pos - cam_pos.xyz); - // vec4 light_pos[2]; -//#if (SHADOW_MODE == SHADOW_MODE_MAP) -// // for (uint i = 0u; i < light_shadow_count.z; ++i) { -// // light_pos[i] = /*vec3(*/shadowMats[i].texture_mat * vec4(f_pos, 1.0)/*)*/; -// // } -// vec4 sun_pos = /*vec3(*/shadowMats[0].texture_mat * vec4(f_pos, 1.0)/*)*/; -//#elif (SHADOW_MODE == SHADOW_MODE_CHEAP || SHADOW_MODE == SHADOW_MODE_NONE) -// vec4 sun_pos = vec4(0.0); -//#endif - - // vec4 vert_pos4 = view_mat * vec4(f_pos, 1.0); - // vec3 view_dir = normalize(-vec3(vert_pos4)/* / vert_pos4.w*/); vec3 view_dir = -cam_to_frag; float frag_dist = length(f_pos - cam_pos.xyz); @@ -234,10 +209,7 @@ void main() { #endif nmap = mix(f_norm, normalize(nmap), min(1.0 / pow(frag_dist, 0.75), 1)); - - //float suppress_waves = max(dot(), 0); vec3 norm = normalize(f_norm * nmap.z + b_norm * nmap.x + c_norm * nmap.y); - //norm = f_norm; vec3 water_color = (1.0 - MU_WATER) * MU_SCATTER; #if (SHADOW_MODE == SHADOW_MODE_CHEAP || SHADOW_MODE == SHADOW_MODE_MAP || FLUID_MODE >= FLUID_MODE_MEDIUM) @@ -247,7 +219,7 @@ void main() { #endif float fluid_alt = mix(f_pos.z, f_alt, f_norm.z == 0); - const float alpha = 0.255/*/ / 4.0*//* / 4.0 / sqrt(2.0)*/; + const float alpha = 0.255; const float n2 = 1.3325; const float R_s2s0 = pow(abs((1.0 - n2) / (1.0 + n2)), 2); const float R_s1s0 = pow(abs((1.3325 - n2) / (1.3325 + n2)), 2); @@ -257,15 +229,10 @@ void main() { // Water is transparent so both normals are valid. vec3 cam_norm = faceforward(norm, norm, cam_to_frag); - vec3 reflect_ray_dir = reflect(cam_to_frag/*-view_dir*/, norm); - vec3 refract_ray_dir = refract(cam_to_frag/*-view_dir*/, norm, 1.0 / n2); - vec3 sun_view_dir = view_dir;///*sign(cam_pos.z - fluid_alt) * view_dir;*/cam_pos.z <= fluid_alt ? -view_dir : view_dir; - // vec3 sun_view_dir = cam_pos.z <= fluid_alt ? -view_dir : view_dir; - /* vec4 reflect_ray_dir4 = view_mat * vec4(reflect_ray_dir, 1.0); - reflect_ray_dir = normalize(vec3(reflect_ray_dir4) / reflect_ray_dir4.w); */ - // vec3 cam_to_frag = normalize(f_pos - cam_pos.xyz); - // Squared to account for prior saturation. - float f_light = 1.0;// pow(f_light, 1.5); + vec3 reflect_ray_dir = reflect(cam_to_frag, norm); + vec3 refract_ray_dir = refract(cam_to_frag, norm, 1.0 / n2); + vec3 sun_view_dir = view_dir; + float f_light = 1.0; vec3 ray_dir; if (medium.x == MEDIUM_WATER) { ray_dir = refract(cam_to_frag, -norm, 1.33); @@ -274,31 +241,17 @@ void main() { // TODO: Make this more efficient? ray_dir = normalize(max(reflect_ray_dir, vec3(-1.0, -1.0, 0.0))); } - // /*const */vec3 water_color = srgb_to_linear(vec3(0.2, 0.5, 1.0)); - // /*const */vec3 water_color = srgb_to_linear(vec3(0.8, 0.9, 1.0)); - // NOTE: Linear RGB, attenuation coefficients for water at roughly R, G, B wavelengths. - // See https://en.wikipedia.org/wiki/Electromagnetic_absorption_by_water - // /*const */vec3 water_attenuation = MU_WATER;// vec3(0.8, 0.05, 0.01); - // /*const */vec3 water_color = vec3(0.2, 0.95, 0.99); - /* vec3 sun_dir = get_sun_dir(time_of_day.x); - vec3 moon_dir = get_moon_dir(time_of_day.x); */ #if (SHADOW_MODE == SHADOW_MODE_CHEAP || SHADOW_MODE == SHADOW_MODE_MAP) vec4 f_shadow = textureMaybeBicubic(t_horizon, s_horizon, pos_to_tex(f_pos.xy)); float sun_shade_frac = horizon_at2(f_shadow, f_alt, f_pos, sun_dir); #elif (SHADOW_MODE == SHADOW_MODE_NONE) - float sun_shade_frac = 1.0;//horizon_at2(f_shadow, f_alt, f_pos, sun_dir); + float sun_shade_frac = 1.0; #endif - float moon_shade_frac = 1.0;// horizon_at2(f_shadow, f_alt, f_pos, moon_dir); - // float sun_shade_frac = horizon_at(/*f_shadow, f_pos.z, */f_pos, sun_dir); - // float moon_shade_frac = horizon_at(/*f_shadow, f_pos.z, */f_pos, moon_dir); - // float shade_frac = /*1.0;*/sun_shade_frac + moon_shade_frac; + float moon_shade_frac = 1.0; vec3 reflect_color; #if (REFLECTION_MODE >= REFLECTION_MODE_MEDIUM) - // This is now done in the post-process cloud shader - /* reflect_color = get_sky_color(ray_dir, time_of_day.x, f_pos, vec3(-100000), 0.125, true, 1.0, true, sun_shade_frac); */ - /* reflect_color = get_cloud_color(reflect_color, ray_dir, f_pos.xyz, time_of_day.x, 100000.0, 0.1); */ reflect_color = vec3(0); #else reflect_color = get_sky_color(ray_dir, f_pos, vec3(-100000), 0.125, true, 1.0, true, sun_shade_frac); @@ -311,61 +264,23 @@ void main() { float not_underground = clamp((f_pos.z - f_alt) / 32.0 + 1.0, 0.0, 1.0); reflect_color *= not_underground; - // DirectionalLight sun_info = get_sun_info(sun_dir, sun_shade_frac, light_pos); - DirectionalLight sun_info = get_sun_info(sun_dir, sun_shade_frac, /*sun_pos*/f_pos); - DirectionalLight moon_info = get_moon_info(moon_dir, moon_shade_frac/*, light_pos*/); + DirectionalLight sun_info = get_sun_info(sun_dir, sun_shade_frac, f_pos); + DirectionalLight moon_info = get_moon_info(moon_dir, moon_shade_frac); - // Hack to determine water depth: color goes down with distance through water, so - // we assume water color absorption from this point a to some other point b is the distance - // along the the ray from a to b where it intersects with the surface plane; if it doesn't, - // then the whole segment from a to b is considered underwater. - // TODO: Consider doing for point lights. - // vec3 cam_surface_dir = faceforward(vec3(0.0, 0.0, 1.0), cam_to_frag, vec3(0.0, 0.0, 1.0)); - - // vec3 water_intersection_surface_camera = vec3(cam_pos); - // bool _water_intersects_surface_camera = IntersectRayPlane(f_pos, view_dir, vec3(0.0, 0.0, /*f_alt*/f_pos.z + f_light), cam_surface_dir, water_intersection_surface_camera); - // // Should work because we set it up so that if IntersectRayPlane returns false for camera, its default intersection point is cam_pos. - // float water_depth_to_camera = length(water_intersection_surface_camera - f_pos); - - // vec3 water_intersection_surface_light = f_pos; - // bool _light_intersects_surface_water = IntersectRayPlane(f_pos, sun_dir.z <= 0.0 ? sun_dir : moon_dir, vec3(0.0, 0.0, /*f_alt*/f_pos.z + f_light), vec3(0.0, 0.0, 1.0), water_intersection_surface_light); - // // Should work because we set it up so that if IntersectRayPlane returns false for light, its default intersection point is f_pos-- - // // i.e. if a light ray can't hit the water, it shouldn't contribute to coloring at all. - // float water_depth_to_light = length(water_intersection_surface_light - f_pos); - - // // For ambient color, we just take the distance to the surface out of laziness. - // float water_depth_to_vertical = max(/*f_alt - f_pos.z*/f_light, 0.0); - - // // Color goes down with distance... - // // See https://en.wikipedia.org/wiki/Beer%E2%80%93Lambert_law. - // vec3 water_color_direct = exp(-MU_WATER);//exp(-MU_WATER);//vec3(1.0); - // vec3 water_color_direct = exp(-water_attenuation * (water_depth_to_light + water_depth_to_camera)); - // vec3 water_color_ambient = exp(-water_attenuation * (water_depth_to_vertical + water_depth_to_camera)); vec3 mu = MU_WATER; // NOTE: Default intersection point is camera position, meaning if we fail to intersect we assume the whole camera is in water. vec3 cam_attenuation = compute_attenuation_point(f_pos, -view_dir, mu, fluid_alt, cam_pos.xyz); - //reflect_color *= cam_attenuation; - // float water_depth_to_vertical = max(/*f_alt - f_pos.z*/f_light, 0.0); - // For ambient color, we just take the distance to the surface out of laziness. - // See https://en.wikipedia.org/wiki/Beer%E2%80%93Lambert_law. - // float water_depth_to_vertical = max(fluid_alt - cam_pos.z/*f_light*/, 0.0); - // vec3 ambient_attenuation = exp(-mu * water_depth_to_vertical); - - // For ambient reflection, we just take the water - + vec3 k_a = vec3(1.0); - // Oxygen is light blue. vec3 k_d = vec3(1.0); - vec3 k_s = vec3(0.0);//2.0 * reflect_color; + vec3 k_s = vec3(0.0); vec3 emitted_light, reflected_light; - // vec3 light, diffuse_light, ambient_light; - // vec3 light_frac = /*vec3(1.0);*/light_reflection_factor(f_norm/*vec3(0, 0, 1.0)*/, view_dir, vec3(0, 0, -1.0), vec3(1.0), vec3(R_s), alpha); // 0 = 100% reflection, 1 = translucent water float passthrough = max(dot(cam_norm, -cam_to_frag), 0) * 0.75; float max_light = 0.0; - max_light += get_sun_diffuse2(sun_info, moon_info, cam_norm, /*time_of_day.x*/sun_view_dir, f_pos, mu, cam_attenuation, fluid_alt, k_a/* * (shade_frac * 0.5 + light_frac * 0.5)*/, vec3(k_d), /*vec3(f_light * point_shadow)*//*reflect_color*/k_s, alpha, f_norm, 1.0, emitted_light, reflected_light); + max_light += get_sun_diffuse2(sun_info, moon_info, cam_norm, sun_view_dir, f_pos, mu, cam_attenuation, fluid_alt, k_a, vec3(k_d), k_s, alpha, f_norm, 1.0, emitted_light, reflected_light); emitted_light *= not_underground; reflected_light *= not_underground; @@ -374,67 +289,12 @@ void main() { float point_shadow = shadow_at(f_pos, f_norm); reflected_light *= point_shadow; - // Apply cloud layer to sky - // reflected_light *= /*water_color_direct * */reflect_color * f_light * point_shadow * shade_frac; - // emitted_light *= /*water_color_direct*//*ambient_attenuation * */f_light * point_shadow * max(shade_frac, MIN_SHADOW); - // max_light *= f_light * point_shadow * shade_frac; - // reflected_light *= /*water_color_direct * */reflect_color * f_light * point_shadow; - // emitted_light *= /*water_color_direct*//*ambient_attenuation * */f_light * point_shadow; - // max_light *= f_light * point_shadow; + + max_light += lights_at(f_pos, cam_norm, view_dir, mu, cam_attenuation, fluid_alt, k_a, k_d, k_s, alpha, f_norm, 1.0, emitted_light, reflected_light); - // vec3 diffuse_light_point = vec3(0.0); - // max_light += lights_at(f_pos, cam_norm, view_dir, mu, cam_attenuation, fluid_alt, k_a, vec3(1.0), /*vec3(0.0)*/k_s, alpha, emitted_light, diffuse_light_point); - - // vec3 dump_light = vec3(0.0); - // vec3 specular_light_point = vec3(0.0); - // lights_at(f_pos, cam_norm, view_dir, mu, cam_attenuation, fluid_alt, vec3(0.0), vec3(0.0), /*vec3(1.0)*/k_s, alpha, dump_light, specular_light_point); - // diffuse_light_point -= specular_light_point; - // max_light += lights_at(f_pos, cam_norm, view_dir, mu, cam_attenuation, fluid_alt, k_a, /*k_d*/vec3(0.0), /*vec3(0.0)*/k_s, alpha, emitted_light, /*diffuse_light*/reflected_light); - - max_light += lights_at(f_pos, cam_norm, view_dir, mu, cam_attenuation, fluid_alt, k_a, /*k_d*//*vec3(0.0)*/k_d, /*vec3(0.0)*/k_s, alpha, f_norm, 1.0, emitted_light, /*diffuse_light*/reflected_light); - - //float reflected_light_point = length(reflected_light);///*length*/(diffuse_light_point.r) + f_light * point_shadow; - // TODO: See if we can be smarter about this using point light distances. - // reflected_light += k_d * (diffuse_light_point/* + f_light * point_shadow * shade_frac*/) + /*water_color_ambient*/specular_light_point; - - /* vec3 point_light = light_at(f_pos, norm); - emitted_light += point_light; - reflected_light += point_light; */ - - // get_sun_diffuse(norm, time_of_day.x, light, diffuse_light, ambient_light, 0.0); - // diffuse_light *= f_light * point_shadow; - // ambient_light *= f_light * point_shadow; - // vec3 point_light = light_at(f_pos, norm); - // light += point_light; - // diffuse_light += point_light; - // reflected_light += point_light; - // vec3 surf_color = srgb_to_linear(vec3(0.2, 0.5, 1.0)) * light * diffuse_light * ambient_light; const float REFLECTANCE = 1.0; - vec3 surf_color = illuminate(max_light, view_dir, water_color * emitted_light/* * log(1.0 - MU_WATER)*/, /*cam_attenuation * *//*water_color * */reflect_color * REFLECTANCE + water_color * reflected_light/* * log(1.0 - MU_WATER)*/); + vec3 surf_color = illuminate(max_light, view_dir, water_color * emitted_light, reflect_color * REFLECTANCE + water_color * reflected_light); - // passthrough = pow(passthrough, 1.0 / (1.0 + water_depth_to_camera)); - /* surf_color = cam_attenuation.g < 0.5 ? - vec3(1.0, 0.0, 0.0) : - vec3(0.0, 1.0, 1.0) - ; */ - // passthrough = passthrough * length(cam_attenuation); - - // vec3 reflect_ray_dir = reflect(cam_to_frag, norm); - // Hack to prevent the reflection ray dipping below the horizon and creating weird blue spots in the water - // reflect_ray_dir.z = max(reflect_ray_dir.z, 0.01); - - // vec4 _clouds; - // vec3 reflect_color = get_sky_color(reflect_ray_dir, time_of_day.x, f_pos, vec3(-100000), 0.25, false, _clouds) * f_light; - // Tint - // reflect_color = mix(reflect_color, surf_color, 0.6); - - // vec4 color = mix(vec4(reflect_color * 2.0, 1.0), vec4(surf_color, 1.0 / (1.0 + /*diffuse_light*/(f_light * point_shadow + point_light) * 0.25)), passthrough); - // vec4 color = mix(vec4(reflect_color * 2.0, 1.0), vec4(surf_color, 1.0 / (1.0 + /*diffuse_light*/(/*f_light * point_shadow*/f_light * point_shadow + reflected_light_point/* + point_light*//*reflected_light*/) * 0.25)), passthrough); - // vec4 color = mix(vec4(surf_color, 1.0), vec4(surf_color, 0.0), passthrough); - //vec4 color = vec4(surf_color, 1.0); - // vec4 color = mix(vec4(reflect_color, 1.0), vec4(surf_color, 1.0 / (1.0 + /*diffuse_light*/(/*f_light * point_shadow*/reflected_light_point/* + point_light*//*reflected_light*/))), passthrough); - - // float log_cam = log(min(cam_attenuation.r, min(cam_attenuation.g, cam_attenuation.b))); float min_refl = 0.0; float opacity = (1.0 - passthrough) * 0.5 / (1.0 + min_refl); if (medium.x != MEDIUM_WATER) { @@ -448,17 +308,7 @@ void main() { } } - vec4 color = vec4(surf_color, opacity);// * (1.0 - /*log(1.0 + cam_attenuation)*//*cam_attenuation*/1.0 / (2.0 - log_cam))); - // vec4 color = vec4(surf_color, mix(1.0, 1.0 / (1.0 + /*0.25 * *//*diffuse_light*/(/*f_light * point_shadow*/reflected_light_point)), passthrough)); - // vec4 color = vec4(surf_color, mix(1.0, length(cam_attenuation), passthrough)); - - /* reflect_color = reflect_color * 0.5 * (diffuse_light + ambient_light); - // 0 = 100% reflection, 1 = translucent water - float passthrough = dot(faceforward(f_norm, f_norm, cam_to_frag), -cam_to_frag); - - vec4 color = mix(vec4(reflect_color, 1.0), vec4(vec3(0), 1.0 / (1.0 + diffuse_light * 0.25)), passthrough); */ - - tgt_color = color; + tgt_color = vec4(surf_color, opacity); tgt_mat = uvec4(uvec3((norm + 1.0) * 127.0), MAT_WATER); #endif } diff --git a/assets/voxygen/shaders/fluid-vert.glsl b/assets/voxygen/shaders/fluid-vert.glsl index 0ae2b6fd83..d499d5786e 100644 --- a/assets/voxygen/shaders/fluid-vert.glsl +++ b/assets/voxygen/shaders/fluid-vert.glsl @@ -22,7 +22,6 @@ layout(location = 0) in uint v_pos_norm; layout(location = 1) in uint v_vel; -// in uint v_col_light; layout(std140, set = 2, binding = 0) uniform u_locals { @@ -31,24 +30,11 @@ uniform u_locals { float load_time; }; -// struct ShadowLocals { -// mat4 shadowMatrices; -// mat4 texture_mat; -// }; -// -// layout (std140) -// uniform u_light_shadows { -// ShadowLocals shadowMats[/*MAX_LAYER_FACES*/192]; -// }; - layout(location = 0) out vec3 f_pos; layout(location = 1) flat out uint f_pos_norm; layout(location = 2) out vec2 f_vel; -// out vec3 f_col; -// out float f_light; -// out vec3 light_pos[2]; -const float EXTRA_NEG_Z = 65536.0/*65536.1*/; +const float EXTRA_NEG_Z = 65536.0; void main() { vec3 rel_pos = vec3(v_pos_norm & 0x3Fu, (v_pos_norm >> 6) & 0x3Fu, float((v_pos_norm >> 12) & 0x1FFFFu) - EXTRA_NEG_Z); @@ -59,49 +45,18 @@ void main() { (float((v_vel >> 16u) & 0xFFFFu) - 32768.0) / 1000.0 ); - // f_pos.z -= 250.0 * (1.0 - min(1.0001 - 0.02 / pow(tick.x - load_time, 10.0), 1.0)); - // f_pos.z -= min(32.0, 25.0 * pow(distance(focus_pos.xy, f_pos.xy) / view_distance.x, 20.0)); - // Terrain 'pop-in' effect #ifndef EXPERIMENTAL_BAREMINIMUM #ifdef EXPERIMENTAL_TERRAINPOP f_pos.z -= 250.0 * (1.0 - min(1.0001 - 0.02 / pow(time_since(load_time), 10.0), 1.0)); - // f_pos.z -= min(32.0, 25.0 * pow(distance(focus_pos.xy, f_pos.xy) / view_distance.x, 20.0)); #endif #endif - // float pull_down = pow(distance(focus_pos.xy, f_pos.xy) / (view_distance.x * 0.95), 20.0) * 0.7; - //f_pos.z -= pull_down; - #ifdef EXPERIMENTAL_CURVEDWORLD f_pos.z -= pow(distance(f_pos.xy + focus_off.xy, focus_pos.xy + focus_off.xy) * 0.05, 2); #endif - // Small waves - // f_pos.xy += 0.01; // Avoid z-fighting - // f_pos.x += 0.1 * sin(tick.x / 60 * hash(vec4(f_pos.xyz, 1.0))); - // f_pos.y += 0.1 * sin(tick.x / 60 * hash(vec4(f_pos.xyz, 2.0))); -#if (FLUID_MODE >= FLUID_MODE_MEDIUM) - // f_pos.z -= 0.1 + 0.1 * (sin(tick.x/* / 60.0*/* 2.0 + f_pos.x * 2.0 + f_pos.y * 2.0) + 1.0) * 0.5; -#endif - - /* f_col = vec3( - float((v_col_light >> 8) & 0xFFu), - float((v_col_light >> 16) & 0xFFu), - float((v_col_light >> 24) & 0xFFu) - ) / 255.0; - - f_light = float(v_col_light & 0xFFu) / 255.0; */ - /* for (uint i = 0u; i < light_shadow_count.z; ++i) { - light_pos[i] = vec3(shadowMats[i].texture_mat * vec4(f_pos, 1.0)); - } */ - f_pos_norm = v_pos_norm; - gl_Position = - all_mat * - vec4(f_pos, 1); - // gl_Position.z = -gl_Position.z / gl_Position.w; - // gl_Position.z = -gl_Position.z / 100.0; - // gl_Position.z = -1000.0 / (gl_Position.z + 10000.0); + gl_Position = all_mat * vec4(f_pos, 1); } diff --git a/assets/voxygen/shaders/include/light.glsl b/assets/voxygen/shaders/include/light.glsl index a2a619bcef..1a2f790b24 100644 --- a/assets/voxygen/shaders/include/light.glsl +++ b/assets/voxygen/shaders/include/light.glsl @@ -38,37 +38,6 @@ float attenuation_strength_real(vec3 rpos) { return 1.0 / (0.025 + d2); } -// // Compute attenuation due to light passing through a substance that fills an area below a horizontal plane -// // (e.g. in most cases, water below the water surface depth). -// // -// // wpos is the position of the point being hit. -// // ray_dir is the reversed direction of the ray (going "out" of the point being hit). -// // surface_alt is the estimated altitude of the horizontal surface separating the substance from air. -// // defaultpos is the position to use in computing the distance along material at this point if there was a failure. -// // -// // Ideally, defaultpos is set so we can avoid branching on error. -// float compute_attenuation_beam(vec3 wpos, vec3 ray_dir, float surface_alt, vec3 defaultpos, float attenuation_depth) { -// vec3 water_intersection_surface_camera = vec3(cam_pos); -// bool _water_intersects_surface_camera = IntersectRayPlane(f_pos, view_dir, vec3(0.0, 0.0, /*f_alt*/f_pos.z + f_light), cam_surface_dir, water_intersection_surface_camera); -// // Should work because we set it up so that if IntersectRayPlane returns false for camera, its default intersection point is cam_pos. -// float water_depth_to_camera = length(water_intersection_surface_camera - f_pos); -// -// vec3 water_intersection_surface_light = f_pos; -// bool _light_intersects_surface_water = IntersectRayPlane(f_pos, sun_dir.z <= 0.0 ? sun_dir : moon_dir, vec3(0.0, 0.0, /*f_alt*/f_pos.z + f_light), vec3(0.0, 0.0, 1.0), water_intersection_surface_light); -// // Should work because we set it up so that if IntersectRayPlane returns false for light, its default intersection point is f_pos-- -// // i.e. if a light ray can't hit the water, it shouldn't contribute to coloring at all. -// float water_depth_to_light = length(water_intersection_surface_light - f_pos); -// -// // For ambient color, we just take the distance to the surface out of laziness. -// float water_depth_to_vertical = max(/*f_alt - f_pos.z*/f_light, 0.0); -// -// // Color goes down with distance... -// // See https://en.wikipedia.org/wiki/Beer%E2%80%93Lambert_law. -// vec3 water_color_direct = exp(-water_attenuation * (water_depth_to_light + water_depth_to_camera)); -// vec3 water_color_ambient = exp(-water_attenuation * (water_depth_to_vertical + water_depth_to_camera)); -// -// } - vec3 light_at(vec3 wpos, vec3 wnorm) { const float LIGHT_AMBIANCE = 0.025; @@ -113,14 +82,10 @@ float shadow_at(vec3 wpos, vec3 wnorm) { #endif float shade = max(pow(diff.x * diff.x + diff.y * diff.y + diff.z * diff.z, 0.3) / pow(radius * radius * 0.5, 0.5), 0.5); - // float shade = max(pow(dot(diff, diff) / (radius * radius * 0.5), 0.25), 0.5); - // float shade = dot(diff, diff) / (radius * radius * 0.5); shadow = min(shadow, shade); } - // NOTE: Squared to compenate for prior saturation. return min(shadow, 1.0); - // return min(shadow * shadow, 1.0); #else return shadow; #endif @@ -132,15 +97,12 @@ float shadow_at(vec3 wpos, vec3 wnorm) { // cam_attenuation is the total light attenuation due to the substance for beams between the point and the camera. // surface_alt is the altitude of the attenuating surface. float lights_at(vec3 wpos, vec3 wnorm, vec3 /*cam_to_frag*/view_dir, vec3 mu, vec3 cam_attenuation, float surface_alt, vec3 k_a, vec3 k_d, vec3 k_s, float alpha, vec3 voxel_norm, float voxel_lighting, inout vec3 emitted_light, inout vec3 reflected_light/*, out float shadow*/) { - // return 0.0; - // shadow = 0.0; - // vec3 ambient_light = vec3(0.0); vec3 directed_light = vec3(0.0); vec3 max_light = vec3(0.0); - const float LIGHT_AMBIANCE = 0.0;//0.015625; + const float LIGHT_AMBIANCE = 0.0; - for (uint i = 0u; i < /*light_shadow_count.x*//*0u*/light_shadow_count.x/*32u*/; i ++) { + for (uint i = 0u; i < light_shadow_count.x; i ++) { // Only access the array once Light L = lights[i]; @@ -155,7 +117,6 @@ float lights_at(vec3 wpos, vec3 wnorm, vec3 /*cam_to_frag*/view_dir, vec3 mu, ve continue; } - // float strength = attenuation_strength(difference);// pow(attenuation_strength(difference), 0.6); // NOTE: This normalizes strength to 0.25 at the center of the point source. float dist_strength = 3.0 / (5 + distance_2); @@ -166,29 +127,11 @@ float lights_at(vec3 wpos, vec3 wnorm, vec3 /*cam_to_frag*/view_dir, vec3 mu, ve const float PI_2 = 2 * PI; vec3 color = /*srgb_to_linear*/L.light_col.rgb; - // // Only access the array once - // Shadow S = shadows[i]; - - // vec3 shadow_pos = S.shadow_pos_radius.xyz; - // float radius = S.shadow_pos_radius.w; - - // vec3 diff = shadow_pos - wpos; - // if (diff.z >= 0.0) { - // diff.z = -sign(diff.z) * diff.z * 0.1; - // } - - // float shade = max(pow(diff.x * diff.x + diff.y * diff.y + diff.z * diff.z, 0.25) / pow(radius * radius * 0.5, 0.25), /*0.5*/0.0); - - // shadow = min(shadow, shade); - // Compute reflectance. float light_distance = sqrt(distance_2); - vec3 light_dir = -difference / light_distance; // normalize(-difference); - // light_dir = faceforward(light_dir, wnorm, light_dir); - bool is_direct = true;//dot(difference, wnorm) > 0.0; - // reflected_light += color * (distance_2 == 0.0 ? vec3(1.0) : light_reflection_factor(wnorm, cam_to_frag, light_dir, k_d, k_s, alpha)); + vec3 light_dir = -difference / light_distance; + bool is_direct = true; vec3 direct_light_dir = is_direct ? light_dir : -light_dir; - // vec3 direct_norm_dir = is_direct ? wnorm : -wnorm; // Directional light if (L.light_dir.w < 1.0) { @@ -211,11 +154,9 @@ float lights_at(vec3 wpos, vec3 wnorm, vec3 /*cam_to_frag*/view_dir, vec3 mu, ve #if (LIGHTING_TYPE & LIGHTING_TYPE_TRANSMISSION) != 0 is_direct = true; #endif - vec3 lrf = light_reflection_factor(/*direct_norm_dir*/wnorm, /*cam_to_frag*/view_dir, direct_light_dir, k_d, k_s, alpha, voxel_norm, voxel_lighting); + vec3 lrf = light_reflection_factor(wnorm, view_dir, direct_light_dir, k_d, k_s, alpha, voxel_norm, voxel_lighting); vec3 direct_light = PI * color * strength * lrf; - /* is_direct = true; */ - float computed_shadow = ShadowCalculationPoint(i, -difference, wnorm, wpos/*, light_distance*/); - // directed_light += is_direct ? max(computed_shadow, /*LIGHT_AMBIANCE*/0.0) * direct_light : vec3(0.0); + float computed_shadow = ShadowCalculationPoint(i, -difference, wnorm, wpos); float ambiance = 0.0; #ifndef EXPERIMENTAL_PHOTOREALISTIC // Non-physically emulate ambient light nearby @@ -227,45 +168,18 @@ float lights_at(vec3 wpos, vec3 wnorm, vec3 /*cam_to_frag*/view_dir, vec3 mu, ve #endif #endif directed_light += (is_direct ? mix(LIGHT_AMBIANCE, 1.0, computed_shadow) * direct_light : vec3(0.0)) + ambiance * color; - // directed_light += (is_direct ? 1.0 : LIGHT_AMBIANCE) * max(computed_shadow, /*LIGHT_AMBIANCE*/0.0) * direct_light;// : vec3(0.0); - // directed_light += mix(LIGHT_AMBIANCE, 1.0, computed_shadow) * direct_light; - // ambient_light += is_direct ? vec3(0.0) : vec3(0.0); // direct_light * LIGHT_AMBIANCE; - // ambient_light += is_direct ? direct_light * (1.0 - LIGHT_AMBIANCE) : vec3(0.0); vec3 cam_light_diff = light_pos - focus_pos.xyz; - float cam_distance_2 = dot(cam_light_diff, cam_light_diff);// + 0.0001; - float cam_strength = 1.0 / (/*4.0 * *//*PI * *//*1.0 + */cam_distance_2); + float cam_distance_2 = dot(cam_light_diff, cam_light_diff); + float cam_strength = 1.0 / cam_distance_2; - // vec3 cam_pos_diff = cam_to_frag.xyz - wpos; - // float pos_distance_2 = dot(cam_pos_diff, cam_pos_diff);// + 0.0001; - - // float cam_distance = sqrt(cam_distance_2); - // float distance = sqrt(distance_2); - float both_strength = cam_distance_2 == 0.0 ? distance_2 == 0.0 ? 0.0 : strength/* * strength*//*1.0*/ : distance_2 == 0.0 ? cam_strength/* * cam_strength*//*1.0*/ : - // 1.0 / (cam_distance * distance); - // sqrt(cam_strength * strength); + float both_strength = cam_distance_2 == 0.0 ? distance_2 == 0.0 ? 0.0 : strength : distance_2 == 0.0 ? cam_strength : cam_strength + strength; - // (cam_strength * strength); - // max(cam_strength, strength); - // mix(cam_strength, strength, distance_2 / (cam_distance_2 + distance_2)); - // mix(cam_strength, strength, cam_distance_2 / (cam_distance_2 + distance_2)); - // max(cam_strength, strength);//mix(cam_strength, strength, clamp(distance_2 / /*pos_distance_2*/cam_distance_2, 0.0, 1.0)); - // float both_strength = mix(cam_strength, strength, cam_distance_2 / sqrt(cam_distance_2 + distance_2)); - max_light += /*max(1.0, cam_strength)*//*min(cam_strength, 1.0)*//*max*//*max(both_strength, 1.0) * *//*cam_strength*/computed_shadow * both_strength * PI * color; - // max_light += /*max(1.0, cam_strength)*//*min(cam_strength, 1.0)*//*max*/max(cam_strength, 1.0/*, strength*//*1.0*/) * PI * color; - // light += color * (max(0, max(dot(normalize(difference), wnorm), 0.15)) + LIGHT_AMBIANCE); - // Compute emiittance. - // float ambient_sides = clamp(mix(0.15, 0.0, abs(dot(wnorm, light_dir)) * 10000.0), 0.0, 0.15); - // float ambient_sides = 0.0;// max(dot(wnorm, light_dir) - 0.15, 0.15); - // // float ambient_sides = 0.0; - // ambient_light += color * (ambient_sides + LIGHT_AMBIANCE); + max_light += computed_shadow * both_strength * PI * color; } - // shadow = shadow_at(wpos, wnorm); - // float shadow = shadow_at(wpos, wnorm); reflected_light += directed_light; - // emitted_light += k_a * ambient_light/* * shadow*/;// min(shadow, 1.0); - return /*rel_luminance(ambient_light + directed_light)*/rel_luminance(max_light);//ambient_light; + return rel_luminance(max_light); } // Same as lights_at, but with no assumed attenuation due to fluid. diff --git a/assets/voxygen/shaders/include/lod.glsl b/assets/voxygen/shaders/include/lod.glsl index 0f8d6e4e7f..9c6adc0b42 100644 --- a/assets/voxygen/shaders/include/lod.glsl +++ b/assets/voxygen/shaders/include/lod.glsl @@ -39,7 +39,6 @@ vec4 textureBicubic(texture2D tex, sampler sampl, vec2 texCoords) { // TODO: remove all textureSize calls and replace with constants vec2 texSize = textureSize(sampler2D(tex, sampl), 0); vec2 invTexSize = 1.0 / texSize; - /* texCoords.y = texSize.y - texCoords.y; */ texCoords = texCoords/* * texSize */ - 0.5; @@ -51,23 +50,16 @@ vec4 textureBicubic(texture2D tex, sampler sampl, vec2 texCoords) { vec4 ycubic = cubic(fxy.y); vec4 c = texCoords.xxyy + vec2 (-0.5, +1.5).xyxy; - // vec4 c = texCoords.xxyy + vec2 (-1, +1).xyxy; vec4 s = vec4(xcubic.xz + xcubic.yw, ycubic.xz + ycubic.yw); vec4 offset = c + vec4 (xcubic.yw, ycubic.yw) / s; offset *= invTexSize.xxyy; - /* // Correct for map rotaton. - offset.zw = 1.0 - offset.zw; */ vec4 sample0 = texture(sampler2D(tex, sampl), offset.xz); vec4 sample1 = texture(sampler2D(tex, sampl), offset.yz); vec4 sample2 = texture(sampler2D(tex, sampl), offset.xw); vec4 sample3 = texture(sampler2D(tex, sampl), offset.yw); - // vec4 sample0 = texelFetch(sampler, offset.xz, 0); - // vec4 sample1 = texelFetch(sampler, offset.yz, 0); - // vec4 sample2 = texelFetch(sampler, offset.xw, 0); - // vec4 sample3 = texelFetch(sampler, offset.yw, 0); float sx = s.x / (s.x + s.y); float sy = s.z / (s.z + s.w); @@ -92,9 +84,8 @@ vec4 textureMaybeBicubic(texture2D tex, sampler sampl, vec2 texCoords) { vec2 textureBicubic16(texture2D tex, sampler sampl, vec2 texCoords) { vec2 texSize = textureSize(sampler2D(tex, sampl), 0); vec2 invTexSize = 1.0 / texSize; - /* texCoords.y = texSize.y - texCoords.y; */ - texCoords = texCoords/* * texSize */ - 0.5; + texCoords = texCoords - 0.5; vec2 fxy = fract(texCoords); @@ -104,14 +95,11 @@ vec2 textureBicubic16(texture2D tex, sampler sampl, vec2 texCoords) { vec4 ycubic = cubic(fxy.y); vec4 c = texCoords.xxyy + vec2 (-0.5, +1.5).xyxy; - // vec4 c = texCoords.xxyy + vec2 (-1, +1).xyxy; vec4 s = vec4(xcubic.xz + xcubic.yw, ycubic.xz + ycubic.yw); vec4 offset = c + vec4 (xcubic.yw, ycubic.yw) / s; offset *= invTexSize.xxyy; - /* // Correct for map rotaton. - offset.zw = 1.0 - offset.zw; */ vec4 sample0_v4 = textureLod(sampler2D(tex, sampl), offset.xz, 0); vec4 sample1_v4 = textureLod(sampler2D(tex, sampl), offset.yz, 0); @@ -121,142 +109,43 @@ vec2 textureBicubic16(texture2D tex, sampler sampl, vec2 texCoords) { vec2 sample1 = sample1_v4.rb / 256.0 + sample1_v4.ga; vec2 sample2 = sample2_v4.rb / 256.0 + sample2_v4.ga; vec2 sample3 = sample3_v4.rb / 256.0 + sample3_v4.ga; - // vec4 sample0 = texelFetch(sampler, offset.xz, 0); - // vec4 sample1 = texelFetch(sampler, offset.yz, 0); - // vec4 sample2 = texelFetch(sampler, offset.xw, 0); - // vec4 sample3 = texelFetch(sampler, offset.yw, 0); float sx = s.x / (s.x + s.y); float sy = s.z / (s.z + s.w); - return mix( - mix(sample3, sample2, sx), mix(sample1, sample0, sx) - , sy); + return mix(mix(sample3, sample2, sx), mix(sample1, sample0, sx), sy); } // Gets the altitude at a position relative to focus_off. float alt_at(vec2 pos) { - vec4 alt_sample = textureLod/*textureBicubic16*/(sampler2D(t_alt, s_alt), wpos_to_uv(focus_off.xy + pos), 0); - return (/*round*/((alt_sample.r * (1.0 / 256.0) + alt_sample.g) * (/*1300.0*//*1278.7266845703125*/view_distance.w)) + /*140.0*/view_distance.z - focus_off.z); - //+ (texture(t_noise, pos * 0.002).x - 0.5) * 64.0; - - // return 0.0 - // + pow(texture(t_noise, pos * 0.00005).x * 1.4, 3.0) * 1000.0 - // + texture(t_noise, pos * 0.001).x * 100.0 - // + texture(t_noise, pos * 0.003).x * 30.0; + vec4 alt_sample = textureLod(sampler2D(t_alt, s_alt), wpos_to_uv(focus_off.xy + pos), 0); + return (((alt_sample.r * (1.0 / 256.0) + alt_sample.g) * view_distance.w) + view_distance.z - focus_off.z); } float alt_at_real(vec2 pos) { - // Basic idea: only really need the real altitude for an accurate water height estimation, so if we are in the cheap shader take a shortcut. -// #if (FLUID_MODE == FLUID_MODE_LOW) -// return alt_at(pos); -// #elif (FLUID_MODE == FLUID_MODE_SHINY) - return (/*round*/(textureBicubic16(t_alt, s_alt, pos_to_tex(pos)).r * (/*1300.0*//*1278.7266845703125*/view_distance.w)) + /*140.0*/view_distance.z - focus_off.z); -// #endif - //+ (texture(t_noise, pos * 0.002).x - 0.5) * 64.0; - - // return 0.0 - // + pow(texture(t_noise, pos * 0.00005).x * 1.4, 3.0) * 1000.0 - // + texture(t_noise, pos * 0.001).x * 100.0 - // + texture(t_noise, pos * 0.003).x * 30.0; + return ((textureBicubic16(t_alt, s_alt, pos_to_tex(pos)).r * view_distance.w) + view_distance.z - focus_off.z); } float horizon_at2(vec4 f_horizons, float alt, vec3 pos, vec4 light_dir) { const float PI_2 = 3.1415926535897932384626433832795 / 2.0; - const float MIN_LIGHT = 0.0;//0.115/*0.0*/; - - // return 1.0; -/* - - let shade_frac = horizon_map - .and_then(|(angles, heights)| { - chunk_idx - .and_then(|chunk_idx| angles.get(chunk_idx)) - .map(|&e| (e as f64, heights)) - }) - .and_then(|(e, heights)| { - chunk_idx - .and_then(|chunk_idx| heights.get(chunk_idx)) - .map(|&f| (e, f as f64)) - }) - .map(|(angle, height)| { - let w = 0.1; - if angle != 0.0 && light_direction.x != 0.0 { - let deltax = height / angle; - let lighty = (light_direction.y / light_direction.x * deltax).abs(); - let deltay = lighty - height; - let s = (deltay / deltax / w).min(1.0).max(0.0); - // Smoothstep - s * s * (3.0 - 2.0 * s) - } else { - 1.0 - } - }) - .unwrap_or(1.0); -*/ - // vec2 f_horizon; - /* if (light_dir.z >= 0) { - return 0.0; - } */ - /* if (light_dir.x >= 0) { - f_horizon = f_horizons.rg; - // f_horizon = f_horizons.ba; - } else { - f_horizon = f_horizons.ba; - // f_horizon = f_horizons.rg; - } - return 1.0; */ - /* bvec2 f_mode = lessThan(vec2(light_dir.x), vec2(1.0)); - f_horizon = mix(f_horizons.ba, f_horizons.rg, f_mode); */ - // f_horizon = mix(f_horizons.rg, f_horizons.ba, clamp(light_dir.x * 10000.0, 0.0, 1.0)); + const float MIN_LIGHT = 0.0; + vec2 f_horizon = mix(f_horizons.rg, f_horizons.ba, bvec2(light_dir.x < 0.0)); - // vec2 f_horizon = mix(f_horizons.ba, f_horizons.rg, clamp(light_dir.x * 10000.0, 0.0, 1.0)); - // f_horizon = mix(f_horizons.ba, f_horizons.rg, bvec2(lessThan(light_dir.xx, vec2(0.0)))); - /* if (f_horizon.x <= 0) { - return 1.0; - } */ float angle = tan(f_horizon.x * PI_2); - /* if (angle <= 0.0001) { - return 1.0; - } */ - float height = f_horizon.y * /*1300.0*//*1278.7266845703125*/view_distance.w + view_distance.z; + float height = f_horizon.y * view_distance.w + view_distance.z; const float w = 0.1; float deltah = height - alt - focus_off.z; - //if (deltah < 0.0001/* || angle < 0.0001 || abs(light_dir.x) < 0.0001*/) { - // return 1.0; - /*} else */{ - float lighta = /*max*/(-light_dir.z/*, 0.0*/) / max(abs(light_dir.x), 0.0001); - // NOTE: Ideally, deltah <= 0.0 is a sign we have an oblique horizon angle. - float deltax = deltah / max(angle, 0.0001)/*angle*/; - float lighty = lighta * deltax; - float deltay = lighty - deltah + max(pos.z - alt, 0.0); - // NOTE: the "real" deltah should always be >= 0, so we know we're only handling the 0 case with max. - float s = mix(max(min(max(deltay, 0.0) / max(deltax, 0.0001) / w, 1.0), 0.0), 1.0, deltah <= 0); - return max(/*0.2 + 0.8 * */(s * s * (3.0 - 2.0 * s)), MIN_LIGHT); - /* if (lighta >= angle) { - return 1.0; - } else { - return MIN_LIGHT; - } */ - // float deltah = height - alt; - // float deltah = max(height - alt, 0.0); - // float lighty = abs(sun_dir.z / sun_dir.x * deltax); - // float lighty = abs(sun_dir.z / sun_dir.x * deltax); - // float deltay = lighty - /*pos.z*//*deltah*/(deltah + max(pos.z - alt, 0.0))/*deltah*/; - // float s = max(min(max(deltay, 0.0) / deltax / w, 1.0), 0.0); - // Smoothstep - // return max(/*0.2 + 0.8 * */(s * s * (3.0 - 2.0 * s)), MIN_LIGHT); - } + float lighta = -light_dir.z / max(abs(light_dir.x), 0.0001); + // NOTE: Ideally, deltah <= 0.0 is a sign we have an oblique horizon angle. + float deltax = deltah / max(angle, 0.0001); + float lighty = lighta * deltax; + float deltay = lighty - deltah + max(pos.z - alt, 0.0); + // NOTE: the "real" deltah should always be >= 0, so we know we're only handling the 0 case with max. + float s = mix(max(min(max(deltay, 0.0) / max(deltax, 0.0001) / w, 1.0), 0.0), 1.0, deltah <= 0); + return max(s * s * (3.0 - 2.0 * s), MIN_LIGHT); } -// float horizon_at(vec3 pos, /*float time_of_day*/vec3 light_dir) { -// vec4 f_horizons = textureMaybeBicubic(t_horizon, pos_to_tex(pos.xy)); -// // f_horizons.xyz = /*linear_to_srgb*/(f_horizons.xyz); -// float alt = alt_at_real(pos.xy); -// return horizon_at2(f_horizons, alt, pos, light_dir); -// } - vec2 splay(vec2 pos) { vec2 scale = textureSize(sampler2D(t_alt, s_alt), 0) * 32.0; float lod_dist = view_distance.x * 0.95 / max(scale.x, scale.y); @@ -270,44 +159,24 @@ vec2 splay(vec2 pos) { } vec3 lod_norm(vec2 f_pos/*vec3 pos*/, vec4 square) { - // const float SAMPLE_W = 32; - - // vec2 f_pos = pos.xy; - // float altx0 = alt_at_real(f_pos + vec2(-1.0, 0) * SAMPLE_W); - // float altx1 = alt_at_real(f_pos + vec2(1.0, 0) * SAMPLE_W); - // float alty0 = alt_at_real(f_pos + vec2(0, -1.0) * SAMPLE_W); - // float alty1 = alt_at_real(f_pos + vec2(0, 1.0) * SAMPLE_W); float altx0 = alt_at(vec2(square.x, f_pos.y)); float altx1 = alt_at(vec2(square.z, f_pos.y)); float alty0 = alt_at(vec2(f_pos.x, square.y)); float alty1 = alt_at(vec2(f_pos.x, square.w)); float slope = abs(altx1 - altx0) + abs(alty0 - alty1); - // vec3 norm = normalize(cross( - // vec3(/*2.0 * SAMPLE_W*/square.z - square.x, 0.0, altx1 - altx0), - // vec3(0.0, /*2.0 * SAMPLE_W*/square.w - square.y, alty1 - alty0) - // )); vec3 norm = normalize(vec3( (altx0 - altx1) / (square.z - square.x), (alty0 - alty1) / (square.w - square.y), 1.0 - //(abs(square.w - square.y) + abs(square.z - square.x)) / (slope + 0.00001) // Avoid NaN )); - /* vec3 norm = normalize(vec3( - (altx0 - altx1) / (2.0 * SAMPLE_W), - (alty0 - alty1) / (2.0 * SAMPLE_W), - (2.0 * SAMPLE_W) / (slope + 0.00001) // Avoid NaN - )); */ - return faceforward(norm, vec3(0.0, 0.0, -1.0)/*pos - cam_pos.xyz*/, norm); + return faceforward(norm, vec3(0.0, 0.0, -1.0), norm); } -vec3 lod_norm(vec2 f_pos/*vec3 pos*/) { +vec3 lod_norm(vec2 f_pos) { const float SAMPLE_W = 32; - - vec3 norm = lod_norm(f_pos, vec4(f_pos - vec2(SAMPLE_W), f_pos + vec2(SAMPLE_W))); - - return norm; + return lod_norm(f_pos, vec4(f_pos - vec2(SAMPLE_W), f_pos + vec2(SAMPLE_W))); } @@ -317,7 +186,7 @@ vec3 lod_pos(vec2 pos, vec2 focus_pos) { vec2 hpos = focus_pos + delta; vec2 dir = normalize(pos); - float shift = 150.0 * pow(length(pos), 3.0);// min(lod_shift.x, lod_shift.y) * 0.5; + float shift = 150.0 * pow(length(pos), 3.0); for (int i = 1; i < 10; i ++) { hpos -= dir * dot(normalize(lod_norm(hpos)).xy, dir) * shift / float(i); } @@ -347,16 +216,6 @@ vec3 lod_col(vec2 pos) { vec3 col = textureBicubic(t_map, s_map, pos_to_tex(pos)).rgb; - /* - #ifdef EXPERIMENTAL_PROCEDURALLODDETAIL - col *= pow(vec3( - textureLod(sampler2D(t_noise, s_noise), wpos / 40, 0).x - 0.5, - textureLod(sampler2D(t_noise, s_noise), wpos / 50 + 0.5, 0).x - 0.5, - textureLod(sampler2D(t_noise, s_noise), wpos / 45 + 0.75, 0).x - 0.5 - ) + 1.0, vec3(0.5)); - #endif - */ - return col; } #endif diff --git a/assets/voxygen/shaders/include/shadows.glsl b/assets/voxygen/shaders/include/shadows.glsl index 4460c781ce..32a2fc2bdc 100644 --- a/assets/voxygen/shaders/include/shadows.glsl +++ b/assets/voxygen/shaders/include/shadows.glsl @@ -2,271 +2,70 @@ #define SHADOWS_GLSL #ifdef HAS_SHADOW_MAPS - -#if (SHADOW_MODE == SHADOW_MODE_MAP) -layout (std140, set = 0, binding = 9) -uniform u_light_shadows { - mat4 shadowMatrices; - mat4 texture_mat; -}; - -// Use with sampler2DShadow -layout(set = 1, binding = 2) -uniform texture2D t_directed_shadow_maps; -layout(set = 1, binding = 3) -uniform samplerShadow s_directed_shadow_maps; -// uniform sampler2DArrayShadow t_directed_shadow_maps; - -// uniform samplerCubeArrayShadow t_shadow_maps; -// uniform samplerCubeArray t_shadow_maps; -// Use with samplerCubeShadow -layout(set = 1, binding = 0) -uniform textureCube t_point_shadow_maps; -layout(set = 1, binding = 1) -uniform samplerShadow s_point_shadow_maps; -// uniform samplerCube t_shadow_maps; - -// uniform sampler2DArray t_directed_shadow_maps; - -float VectorToDepth (vec3 Vec) -{ - // return length(Vec) / screen_res.w; - vec3 AbsVec = abs(Vec); - float LocalZcomp = max(AbsVec.x, max(AbsVec.y, AbsVec.z)); - // float LocalZcomp = length(Vec); - - // Replace f and n with the far and near plane values you used when - // you drew your cube map. - // const float f = 2048.0; - // const float n = 1.0; - - // float NormZComp = (screen_res.w+screen_res.z) / (screen_res.w-screen_res.z) - (2*screen_res.w*screen_res.z)/(screen_res.w-screen_res.z)/LocalZcomp; - // float NormZComp = 1.0 - shadow_proj_factors.y / shadow_proj_factors.x / LocalZcomp; - // -(1 + 2n/(f-n)) - 2(1 + n/(f-n)) * n/z - // -(1 + n/(f-n)) - (1 + n/(f-n)) * n/z - // f/(f-n) - fn/(f-n)/z - float NormZComp = shadow_proj_factors.x - shadow_proj_factors.y / LocalZcomp; - // NormZComp = -1000.0 / (NormZComp + 10000.0); - // return (NormZComp + 1.0) * 0.5; - return NormZComp; - - // float NormZComp = length(LocalZcomp); - // NormZComp = -NormZComp / screen_res.w; - // // return (NormZComp + 1.0) * 0.5; - // return NormZComp; -} - -const vec3 sampleOffsetDirections[20] = vec3[] -( - vec3( 1, 1, 1), vec3( 1, -1, 1), vec3(-1, -1, 1), vec3(-1, 1, 1), - vec3( 1, 1, -1), vec3( 1, -1, -1), vec3(-1, -1, -1), vec3(-1, 1, -1), - vec3( 1, 1, 0), vec3( 1, -1, 0), vec3(-1, -1, 0), vec3(-1, 1, 0), - vec3( 1, 0, 1), vec3(-1, 0, 1), vec3( 1, 0, -1), vec3(-1, 0, -1), - vec3( 0, 1, 1), vec3( 0, -1, 1), vec3( 0, -1, -1), vec3( 0, 1, -1) - // vec3(0, 0, 0) -); - -float ShadowCalculationPoint(uint lightIndex, vec3 fragToLight, vec3 fragNorm, /*float currentDepth*/vec3 fragPos) -{ - if (lightIndex != 0u) { - return 1.0; - }; - - { - float currentDepth = VectorToDepth(fragToLight);// + bias; - - // currentDepth = -currentDepth * 0.5 + 0.5; - - float visibility = textureGrad(samplerCubeShadow(t_point_shadow_maps, s_point_shadow_maps), vec4(fragToLight, currentDepth), vec3(0), vec3(0));// / (screen_res.w/* - screen_res.z*/)/*1.0 -bias*//*-(currentDepth - bias) / screen_res.w*//*-screen_res.w*/); - /* if (visibility == 1.0 || visibility == 0.0) { - return visibility; - } */ - /* if (visibility >= 0.75) { + #if (SHADOW_MODE == SHADOW_MODE_MAP) + layout (std140, set = 0, binding = 9) + uniform u_light_shadows { + mat4 shadowMatrices; + mat4 texture_mat; + }; + + // Use with sampler2DShadow + layout(set = 1, binding = 2) + uniform texture2D t_directed_shadow_maps; + layout(set = 1, binding = 3) + uniform samplerShadow s_directed_shadow_maps; + + // Use with samplerCubeShadow + layout(set = 1, binding = 0) + uniform textureCube t_point_shadow_maps; + layout(set = 1, binding = 1) + uniform samplerShadow s_point_shadow_maps; + + float VectorToDepth(vec3 Vec) { + vec3 AbsVec = abs(Vec); + float LocalZcomp = max(AbsVec.x, max(AbsVec.y, AbsVec.z)); + + float NormZComp = shadow_proj_factors.x - shadow_proj_factors.y / LocalZcomp; + return NormZComp; + } + + const vec3 sampleOffsetDirections[20] = vec3[]( + vec3( 1, 1, 1), vec3( 1, -1, 1), vec3(-1, -1, 1), vec3(-1, 1, 1), + vec3( 1, 1, -1), vec3( 1, -1, -1), vec3(-1, -1, -1), vec3(-1, 1, -1), + vec3( 1, 1, 0), vec3( 1, -1, 0), vec3(-1, -1, 0), vec3(-1, 1, 0), + vec3( 1, 0, 1), vec3(-1, 0, 1), vec3( 1, 0, -1), vec3(-1, 0, -1), + vec3( 0, 1, 1), vec3( 0, -1, 1), vec3( 0, -1, -1), vec3( 0, 1, -1) + ); + + float ShadowCalculationPoint(uint lightIndex, vec3 fragToLight, vec3 fragNorm, vec3 fragPos) { + if (lightIndex != 0u) { + return 1.0; + }; + + float currentDepth = VectorToDepth(fragToLight); + + return textureGrad(samplerCubeShadow(t_point_shadow_maps, s_point_shadow_maps), vec4(fragToLight, currentDepth), vec3(0), vec3(0)); + } + + float ShadowCalculationDirected(in vec3 fragPos) { + // Don't try to calculate directed shadows if there are no directed light sources + // Applies, for example, in the char select menu + if (light_shadow_count.z < 1) { return 1.0; } + + float bias = 0.0; + float diskRadius = 0.01; + vec4 sun_pos = texture_mat * vec4(fragPos, 1.0); + return textureProj(sampler2DShadow(t_directed_shadow_maps, s_directed_shadow_maps), sun_pos); + } + #elif (SHADOW_MODE == SHADOW_MODE_NONE || SHADOW_MODE == SHADOW_MODE_CHEAP) + float ShadowCalculationPoint(uint lightIndex, vec3 fragToLight, vec3 fragNorm, vec3 fragPos) { return 1.0; } - if (visibility <= 0.25) { - return 0.0; - } */ - /* if (visibility < 1.0) { - return 0.0; - } */ - // return visibility; - /* if (visibility == 1.0) { - return visibility; - } */ - return visibility; - // return visibility == 1.0 ? 1.0 : 0.0; - } - - // float shadow = 0.0; - // float bias = 0.0;//0.003;//-0.003;//-0.005;//0.001;//-1.0;//-0.001;//0.001;//0.003;//-0.05;//-0.1;//0.0;//0.1 - // float viewDistance = length(cam_pos.xyz - fragPos); - // vec3 firstDelta = vec3(0.0);///*min(viewDistance, 5.0) * *//**normalize(cam_pos - fragPos)*/fragNorm * 0.5; - // fragToLight += firstDelta; - // // viewDistance -= length(firstDelta); - // fragPos -= firstDelta; - - // int samples = 20; - // // float lightDistance = length(fragToLight); - // // float diskRadius = 0.00001; - // // float diskRadius = 1.0; - // // float diskRadius = 0.05; - // float diskRadius = 5.0 / screen_res.w;// (1.0 + (/*viewDistance*/viewDistance / screen_res.w)) / 25.0; - // // float diskRadius = lightDistance; - // for(int i = 0; i < samples; ++i) - // { - // float currentDepth = VectorToDepth(fragToLight + sampleOffsetDirections[i] * diskRadius) + bias; - // // float closestDepth = texture(depthMap, fragToLight).r; - // // closestDepth *= far_plane; // Undo mapping [0;1] - // /* if(currentDepth - bias > closestDepth) - // shadow += 1.0;*/ - // float visibility = texture(t_point_shadow_maps, vec4(fragToLight, currentDepth)/*, -2.5*/); - // shadow += visibility; - // // float closestDepth = texture(t_shadow_maps, vec3(fragToLight)/*, -2.5*/).r; - // // shadow += closestDepth > currentDepth ? 1.0 : 0.0; - // } - // shadow /= float(samples); - // // shadow = shadow * shadow * (3.0 - 2.0 * shadow); - - // // use the light to fragment vector to sample from the depth map - // // float bias = 0.0;///*0.05*/0.01;//0.05;// 0.05; - // // float closestDepth = texture(t_shadow_maps, /*vec4*/vec3(fragToLight/*, (lightIndex + 1)*//* * 6*/)/*, 0.0*//*, 0.0*//*, bias*/).r; - // // // // float closestDepth = texture(t_shadow_maps, vec4(fragToLight, lightIndex), bias); - // // // // it is currently in linear range between [0,1]. Re-transform back to original value - // // closestDepth = (closestDepth + 0.0) * screen_res.w; // far plane - // // // // now test for shadows - // // // // float shadow = /*currentDepth*/(screen_res.w - bias) > closestDepth ? 1.0 : 0.0; - // // float shadow = currentDepth - bias < closestDepth ? 1.0 : 0.0; - // // float visibility = textureProj(t_shadow_maps, vec4(fragToLight, lightIndex), bias); - // // float visibility = texture(t_shadow_maps, vec4(fragToLight, lightIndex + 1), -(currentDepth/* + screen_res.z*/) / screen_res.w);// / (screen_res.w/* - screen_res.z*/)/*1.0 -bias*//*-(currentDepth - bias) / screen_res.w*//*-screen_res.w*/); - // // currentDepth += bias; - // // currentDepth = -1000.0 / (currentDepth + 10000.0); - // // currentDepth /= screen_res.w; - // // float currentDepth = VectorToDepth(fragToLight) + bias; - - // // float visibility = texture(t_shadow_maps, vec4(fragToLight, currentDepth));// / (screen_res.w/* - screen_res.z*/)/*1.0 -bias*//*-(currentDepth - bias) / screen_res.w*//*-screen_res.w*/); - // // return visibility == 1.0 ? 1.0 : 0.0; - // return shadow; -} - -float ShadowCalculationDirected(in vec3 fragPos)//in vec4 /*light_pos[2]*/sun_pos, vec3 fragPos) -{ - // Don't try to calculate directed shadows if there are no directed light sources - // Applies, for example, in the char select menu - if (light_shadow_count.z < 1) { return 1.0; } - - float bias = 0.000;//0.0005;//-0.0001;// 0.05 / (2.0 * view_distance.x); - float diskRadius = 0.01; - const vec3 sampleOffsetDirections[20] = vec3[] - ( - vec3( 1, 1, 1), vec3( 1, -1, 1), vec3(-1, -1, 1), vec3(-1, 1, 1), - vec3( 1, 1, -1), vec3( 1, -1, -1), vec3(-1, -1, -1), vec3(-1, 1, -1), - vec3( 1, 1, 0), vec3( 1, -1, 0), vec3(-1, -1, 0), vec3(-1, 1, 0), - vec3( 1, 0, 1), vec3(-1, 0, 1), vec3( 1, 0, -1), vec3(-1, 0, -1), - vec3( 0, 1, 1), vec3( 0, -1, 1), vec3( 0, -1, -1), vec3( 0, 1, -1) - // vec3(0, 0, 0) - ); - /* if (lightIndex >= light_shadow_count.z) { - return 1.0; - } */ - // vec3 fragPos = sun_pos.xyz;// / sun_pos.w;//light_pos[lightIndex].xyz; - // sun_pos.z += sun_pos.w * bias; - vec4 sun_pos = texture_mat/*shadowMatrices*/ * vec4(fragPos, 1.0); - // sun_pos.xy = 0.5 * sun_pos.w + sun_pos.xy * 0.5; - // sun_pos.xy = sun_pos.ww - sun_pos.xy; - // sun_pos.xyz /= abs(sun_pos.w); - // sun_pos.w = sign(sun_pos.w); - // sun_pos.xy = (sun_pos.xy + 1.0) * 0.5; - // vec4 orig_pos = warpViewMat * lightViewMat * vec4(fragPos, 1.0); - // - // vec4 shadow_pos; - // shadow_pos.xyz = (warpProjMat * orig_pos).xyz: - // shadow_pos.w = orig_pos.y; - // - // sun_pos.xy = 0.5 * (shadow_pos.xy + shadow_pos.w) = 0.5 * (shadow_pos.xy + orig_pos.yy); - // sun_pos.z = shadow_pos.z; - // - // sun_pos.w = sign(shadow_pos.w) = sign(orig_pos.y); - // sun_pos.xyz = sun_pos.xyz / shadow_pos.w = vec3(0.5 * shadow_pos.xy / orig_pos.yy + 0.5, shadow_pos.z / orig_pos.y) - // = vec3(0.5 * (2.0 * warp_pos.xy / orig_pos.yy - (max_warp_pos + min_warp_pos).xy) / (max_warp_pos - min_warp_pos).xy + 0.5, - // -(warp_pos.z / orig_pos.y - min_warp_pos.z) / (max_warp_pos - min_warp_pos).z ) - // = vec3((warp_pos.x / orig_pos.y - min_warp_pos.x) / (max_warp_pos - min_warp_pos).x, - // (warp_pos.y / orig_pos.y - min_warp_pos.y) / (max_warp_pos - min_warp_pos).y, - // -(warp_pos.z / orig_pos.y - min_warp_pos.z) / (max_warp_pos - min_warp_pos).z ) - // = vec3((near * orig_pos.x / orig_pos.y - min_warp_pos.x) / (max_warp_pos - min_warp_pos).x, - // (((far+near) - 2.0 * near * far / orig_pos.y)/(far-near) - min_warp_pos.y) / (max_warp_pos - min_warp_pos).y, - // -(near * orig_pos.z / orig_pos.y - min_warp_pos.z) / (max_warp_pos - min_warp_pos).z ) - // = vec3((near * orig_pos.x / orig_pos.y - min_warp_pos.x) / (max_warp_pos - min_warp_pos).x, - // (2.0 * (1.0 - far / orig_pos.y)*near/(far-near) + 1.0 - min_warp_pos.y) / (max_warp_pos - min_warp_pos).y, - // -(near * orig_pos.z / orig_pos.y - min_warp_pos.z) / (max_warp_pos - min_warp_pos).z ) - // = vec3((near * orig_pos.x / orig_pos.y - min_warp_pos.x) / (max_warp_pos - min_warp_pos).x, - // (2.0 * (1.0 - far / orig_pos.y)*near/(far-near) + 1.0 - 0.0) / (1.0 - 0.0), - // -(near * orig_pos.z / orig_pos.y - min_warp_pos.z) / (max_warp_pos - min_warp_pos).z ) - // = vec3((near * orig_pos.x / orig_pos.y - min_warp_pos.x) / (max_warp_pos - min_warp_pos).x, - // 2.0 * (1.0 - far / orig_pos.y)*near/(far-near) + 1.0, - // -(near * orig_pos.z / orig_pos.y - min_warp_pos.z) / (max_warp_pos - min_warp_pos).z ) - // - // orig_pos.y = n: warp_pos.y = 2*(1-f/n)*n/(f-n) + 1 = 2*(n-f)/(f-n) + 1 = 2 * -1 + 1 = -1, sun_pos.y = (-1 - -1) / 2 = 0 - // orig_pos.y = f: warp_pos.y = 2*(1-f/f)*n/(f-n) + 1 = 2*(1-1)*n/(f-n) + 1 = 2 * 0 * n/(f-n) + 1 = 1, sun_pos.y = (1 - -1) / 2 = 1 - // - float visibility = textureProj(sampler2DShadow(t_directed_shadow_maps, s_directed_shadow_maps), sun_pos); - /* float visibilityLeft = textureProj(t_directed_shadow_maps, sun_shadow.texture_mat * vec4(fragPos + vec3(0.0, -diskRadius, 0.0), 1.0)); - float visibilityRight = textureProj(t_directed_shadow_maps, sun_shadow.texture_mat * vec4(fragPos + vec3(0.0, diskRadius, 0.0), 1.0)); */ - // float nearVisibility = textureProj(t_directed_shadow_maps + vec3(0.001, sun_pos)); - // float visibility = textureProj(t_directed_shadow_maps, vec4(fragPos.xy, /*lightIndex, */fragPos.z + bias, sun_pos.w)); - // return visibility; - // return min(visibility, min(visibilityLeft, visibilityRight)); - // return mix(visibility, 0.0, sun_pos.z < -1.0); - // return mix(mix(0.0, 1.0, visibility == 1.0), 1.0, sign(sun_pos.w) * sun_pos.z > /*1.0*/abs(sun_pos.w)); - // return (visibility - 0.5) * (visibility - 0.5) * 2.0 * sign(visibility - 0.5) + 0.5;// visibility > 0.75 ? visibility : 0.0;// visibility > 0.9 ? 1.0 : 0.0; - return visibility; - // return visibility == 1.0 ? 1.0 : 0.0; - // return abs(fragPos.y - round(fragPos.y)) <= 0.1 || abs(fragPos.x - round(fragPos.x)) <= 0.1 ? ( visibility == 1.0 ? 1.0 : 0.0) : visibility; - /* if (visibility == 1.0) { - return 1.0; - } */ - // return visibility; - /* if (fragPos.z > 1.0) { - return 1.0; - } */ - // vec3 snapToZ = abs(fragPos - vec3(ivec3(fragPos))); // fract(abs(fragPos)); - // // snapToZ = min(snapToZ, 1.0 - snapToZ); - // const float EDGE_DIST = 0.01; - // snapToZ = mix(vec3(0.0), vec3(1.0), lessThanEqual(snapToZ, vec3(EDGE_DIST))); - // // float snapToZDist = dot(snapToZ, snapToZ); - // if (visibility <= 0.75 && /*fract(abs(fragPos.xy)), vec2(0.1)))*/ /*snapToZDist <= 0.25*//*all(lessThan(snapToZ, vec3(0.1)))(*/ - // snapToZ.x + snapToZ.y + snapToZ.z >= 2.0) { - // return 0.0; - // } - // int samples = 20; - // float shadow = 0.0; - // // float bias = 0.0001; - // // float viewDistance = length(cam_pos.xyz - fragPos); - // // float diskRadius = 0.2 * (1.0 + (viewDistance / screen_res.w)) / 25.0; - // // float diskRadius = 0.0003;//0.005;// / (2.0 * view_distance.x);//(1.0 + (viewDistance / screen_res.w)) / 25.0; - // fragPos = sun_pos.xyz / sun_pos.w; - // for(int i = 0; i < samples; ++i) - // { - // vec3 currentDepth = fragPos + vec3(sampleOffsetDirections[i].xyz) * diskRadius + bias; - // visibility = texture(t_directed_shadow_maps, currentDepth);//vec4(currentDepth.xy, lightIndex, currentDepth.z)/*, -2.5*/); - // // visibility = texture(t_directed_shadow_maps, vec4(currentDepth.xy, lightIndex, currentDepth.z)/*, -2.5*/); - // shadow += visibility; - // // mix(visibility, 1.0, visibility >= 0.5); - // } - // shadow /= float(samples); - // return shadow; -} - #elif (SHADOW_MODE == SHADOW_MODE_NONE || SHADOW_MODE == SHADOW_MODE_CHEAP) -float ShadowCalculationPoint(uint lightIndex, vec3 fragToLight, vec3 fragNorm, /*float currentDepth*/vec3 fragPos) -{ - return 1.0; -} #endif #else -float ShadowCalculationPoint(uint lightIndex, vec3 fragToLight, vec3 fragNorm, /*float currentDepth*/vec3 fragPos) -{ - return 1.0; -} + float ShadowCalculationPoint(uint lightIndex, vec3 fragToLight, vec3 fragNorm, vec3 fragPos) { + return 1.0; + } #endif #endif diff --git a/assets/voxygen/shaders/include/sky.glsl b/assets/voxygen/shaders/include/sky.glsl index 0c71d64b02..a4aa567ad1 100644 --- a/assets/voxygen/shaders/include/sky.glsl +++ b/assets/voxygen/shaders/include/sky.glsl @@ -9,12 +9,9 @@ // Information about an approximately directional light, like the sun or moon. struct DirectionalLight { - // vec3 dir; float shadow; // Fully blocks all light, including ambience float block; - // vec3 color; - // float brightness; }; const float PI = 3.141592653; @@ -41,19 +38,18 @@ const vec3 SKY_NIGHT_TOP = vec3(0.001, 0.001, 0.0025); const vec3 SKY_NIGHT_MID = vec3(0.001, 0.005, 0.02); const vec3 SKY_NIGHT_BOT = vec3(0.002, 0.004, 0.004); const vec3 NIGHT_LIGHT = vec3(5.0, 0.75, 0.2); -// const vec3 NIGHT_LIGHT = vec3(0.0, 0.0, 0.0); // Linear RGB, scattering coefficients for atmosphere at roughly R, G, B wavelengths. // // See https://en.wikipedia.org/wiki/Diffuse_sky_radiation const vec3 MU_SCATTER = vec3(0.05, 0.10, 0.23); -const float SUN_COLOR_FACTOR = 5.0;//6.0;// * 1.5;//1.8; -const float MOON_COLOR_FACTOR = 5.0;//6.0;// * 1.5;//1.8; +const float SUN_COLOR_FACTOR = 5.0; +const float MOON_COLOR_FACTOR = 5.0; const float UNDERWATER_MIST_DIST = 100.0; -const float PERSISTENT_AMBIANCE = 1.0 / 32.0;// 1.0 / 80; // 1.0 / 512; // 0.00125 // 0.1;// 0.025; // 0.1; +const float PERSISTENT_AMBIANCE = 1.0 / 32.0; // Glow from static light sources // Allowed to be > 1 due to HDR @@ -69,28 +65,6 @@ vec3 glow_light(vec3 pos) { #endif } -//vec3 get_sun_dir(float time_of_day) { -// const float TIME_FACTOR = (PI * 2.0) / (3600.0 * 24.0); -// -// float sun_angle_rad = time_of_day * TIME_FACTOR; -// // return vec3(sin(sun_angle_rad), 0.0, cos(sun_angle_rad)); -// return vec3(sin(sun_angle_rad), 0.0, cos(sun_angle_rad)); -//} -// -//vec3 get_moon_dir(float time_of_day) { -// const float TIME_FACTOR = (PI * 2.0) / (3600.0 * 24.0); -// -// float moon_angle_rad = time_of_day * TIME_FACTOR; -// // -cos((60+60*4)/360*2*pi)-0.5 = 0 -// // -cos((60+60*5)/360*2*pi)-0.5 = -0.5 -// // -cos((60+60*6)/360*2*pi)-0.5 = 0 -// // -// // i.e. moon out from (60*5)/360*24 = 20:00 to (60*7/360*24) = 28:00 = 04:00. -// // -// // Then sun out from 04:00 to 20:00. -// return normalize(-vec3(sin(moon_angle_rad), 0.0, cos(moon_angle_rad) - 0.5)); -//} - float cloud_avg_alt() { return view_distance.z + (view_distance.w - view_distance.z) * 1.25; } const float wind_speed = 0.25; @@ -106,7 +80,7 @@ vec2 wpos_to_uv(vec2 wpos) { // Want: (pixel + 0.5) / W vec2 texSize = textureSize(sampler2D(t_alt, s_alt), 0); vec2 uv_pos = (wpos + 16) / (32.0 * texSize); - return vec2(uv_pos.x, /*1.0 - */uv_pos.y); + return vec2(uv_pos.x, uv_pos.y); } // Weather texture @@ -173,15 +147,15 @@ float emission_br() { #endif -float get_sun_brightness(/*vec3 sun_dir*/) { +float get_sun_brightness() { return max(-sun_dir.z + 0.5, 0.0); } -float get_moon_brightness(/*vec3 moon_dir*/) { +float get_moon_brightness() { return max(sun_dir.z + 0.6, 0.0) * 0.1; } -vec3 get_sun_color(/*vec3 sun_dir*/) { +vec3 get_sun_color() { vec3 light = (sun_dir.x > 0) ? DUSK_LIGHT : DAWN_LIGHT; return mix( @@ -196,7 +170,7 @@ vec3 get_sun_color(/*vec3 sun_dir*/) { } // Average sky colour (i.e: perfectly scattered light from the sky) -vec3 get_sky_color(/*vec3 sun_dir*/) { +vec3 get_sky_color() { return mix( mix( (SKY_DUSK_TOP + SKY_DUSK_MID) / 2 * magnetosphere_tint(), @@ -208,39 +182,27 @@ vec3 get_sky_color(/*vec3 sun_dir*/) { ); } -vec3 get_moon_color(/*vec3 moon_dir*/) { +vec3 get_moon_color() { return vec3(0.5, 0.5, 1.6); } -DirectionalLight get_sun_info(vec4 _dir, float shade_frac/*, vec4 light_pos[2]*/, /*vec4 sun_pos*/vec3 f_pos) { +DirectionalLight get_sun_info(vec4 _dir, float shade_frac, vec3 f_pos) { float shadow = shade_frac; float block = 1.0; #ifdef HAS_SHADOW_MAPS -#if (SHADOW_MODE == SHADOW_MODE_MAP) - if (sun_dir.z < /*0.6*/0.0) { - /* ShadowLocals sun_shadow = shadowMats[0]; - vec4 sun_pos = sun_shadow.texture_mat * vec4(f_pos, 1.0); */ -// #if (SHADOW_MODE == SHADOW_MODE_MAP) -// // for (uint i = 0u; i < light_shadow_count.z; ++i) { -// // light_pos[i] = /*vec3(*/shadowMats[i].texture_mat * vec4(f_pos, 1.0)/*)*/; -// // } -// #elif (SHADOW_MODE == SHADOW_MODE_CHEAP || SHADOW_MODE == SHADOW_MODE_NONE) -// vec4 sun_pos = vec4(0.0); -// #endif - shadow = min(shadow, ShadowCalculationDirected(/*sun_pos, *//*0u*/f_pos)); - } + #if (SHADOW_MODE == SHADOW_MODE_MAP) + if (sun_dir.z < 0.0) { + shadow = min(shadow, ShadowCalculationDirected(f_pos)); + } + #endif #endif -#endif - return DirectionalLight(/*dir, */shadow, block/*, get_sun_color(dir), get_sun_brightness(dir)*/); + return DirectionalLight(shadow, block); } -DirectionalLight get_moon_info(vec4 _dir, float shade_frac/*, vec4 light_pos[2]*/) { +DirectionalLight get_moon_info(vec4 _dir, float shade_frac) { float shadow = shade_frac; float block = 1.0; -// #ifdef HAS_SHADOW_MAPS -// shadow = min(shade_frac, ShadowCalculationDirected(light_pos, 1u)); -// #endif - return DirectionalLight(/*dir, */shadow, block/*, get_moon_color(dir), get_moon_brightness(dir)*/); + return DirectionalLight(shadow, block); } const float LIGHTNING_HEIGHT = 25.0; @@ -271,62 +233,30 @@ vec3 lightning_at(vec3 wpos) { } } -// // Calculates extra emission and reflectance (due to sunlight / moonlight). -// // -// // reflectence = k_a * i_a + i_a,persistent -// // emittence = Σ { m ∈ lights } i_m * shadow_m * get_light_reflected(light_m) -// // -// // Note that any shadowing to be done that would block the sun and moon, aside from heightmap shadowing (that will be -// // implemented sooon), should be implicitly provided via k_a, k_d, and k_s. For instance, shadowing via ambient occlusion. -// // -// // Also note that the emitted light calculation is kind of lame... we probabbly need something a bit nicer if we ever want to do -// // anything interesting here. -// // void get_sun_diffuse(vec3 norm, float time_of_day, out vec3 light, out vec3 diffuse_light, out vec3 ambient_light, float diffusion -// void get_sun_diffuse(vec3 norm, float time_of_day, vec3 dir, vec3 k_a, vec3 k_d, vec3 k_s, float alpha, out vec3 emitted_light, out vec3 reflected_light) { -// const float SUN_AMBIANCE = 0.1 / 2.0;// 0.1 / 3.0; -// -// vec3 sun_dir = get_sun_dir(time_of_day); -// vec3 moon_dir = get_moon_dir(time_of_day); -// -// float sun_light = get_sun_brightness(sun_dir); -// float moon_light = get_moon_brightness(moon_dir); -// -// vec3 sun_color = get_sun_color(sun_dir); -// vec3 moon_color = get_moon_color(moon_dir); -// -// vec3 sun_chroma = sun_color * sun_light; -// vec3 moon_chroma = moon_color * moon_light; -// -// /* float NLsun = max(dot(-norm, sun_dir), 0); -// float NLmoon = max(dot(-norm, moon_dir), 0); -// vec3 E = -dir; */ -// -// // Globbal illumination "estimate" used to light the faces of voxels which are parallel to the sun or moon (which is a very common occurrence). -// // Will be attenuated by k_d, which is assumed to carry any additional ambient occlusion information (e.g. about shadowing). -// float ambient_sides = clamp(mix(0.5, 0.0, abs(dot(-norm, sun_dir)) * mix(0.0, 1.0, abs(sun_dir.z) * 10000.0) * 10000.0), 0.0, 0.5); -// // float ambient_sides = 0.5 - 0.5 * abs(dot(-norm, sun_dir)); -// -// emitted_light = k_a * (ambient_sides + vec3(SUN_AMBIANCE * sun_light + moon_light)) + PERSISTENT_AMBIANCE; -// // TODO: Add shadows. -// reflected_light = -// sun_chroma * light_reflection_factor(norm, dir, sun_dir, k_d, k_s, alpha) + -// moon_chroma * 1.0 * /*4.0 * */light_reflection_factor(norm, dir, moon_dir, k_d, k_s, alpha); -// -// /* light = sun_chroma + moon_chroma + PERSISTENT_AMBIANCE; -// diffuse_light = -// sun_chroma * mix(1.0, max(dot(-norm, sun_dir) * 0.5 + 0.5, 0.0), diffusion) + -// moon_chroma * mix(1.0, pow(dot(-norm, moon_dir) * 2.0, 2.0), diffusion) + -// PERSISTENT_AMBIANCE; -// ambient_light = vec3(SUN_AMBIANCE * sun_light + moon_light); */ -// } - // Returns computed maximum intensity. // // wpos is the position of this fragment. // mu is the attenuation coefficient for any substance on a horizontal plane. // cam_attenuation is the total light attenuation due to the substance for beams between the point and the camera. // surface_alt is the altitude of the attenuating surface. -float get_sun_diffuse2(DirectionalLight sun_info, DirectionalLight moon_info, vec3 norm, vec3 dir, vec3 wpos, vec3 mu, vec3 cam_attenuation, float surface_alt, vec3 k_a, vec3 k_d, vec3 k_s, float alpha, vec3 voxel_norm, float voxel_lighting, out vec3 emitted_light, out vec3 reflected_light) { +float get_sun_diffuse2( + DirectionalLight sun_info, + DirectionalLight moon_info, + vec3 norm, + vec3 dir, + vec3 wpos, + vec3 mu, + vec3 cam_attenuation, + float surface_alt, + vec3 k_a, + vec3 k_d, + vec3 k_s, + float alpha, + vec3 voxel_norm, + float voxel_lighting, + out vec3 emitted_light, + out vec3 reflected_light +) { const vec3 SUN_AMBIANCE = MU_SCATTER; #ifdef EXPERIMENTAL_PHOTOREALISTIC const vec3 MOON_AMBIANCE = MU_SCATTER; @@ -336,19 +266,17 @@ float get_sun_diffuse2(DirectionalLight sun_info, DirectionalLight moon_info, ve const vec3 MOON_AMBIANCE = vec3(0.15, 0.25, 0.23) * 5; #endif - /* vec3 sun_dir = sun_info.dir; - vec3 moon_dir = moon_info.dir; */ vec3 sun_dir = sun_dir.xyz; // TODO: Use real moon dir here and have other ways to light up night. // So this is a hack to just pretend the moon is still opposite to the sun // for this and `get_moon_brightness`. vec3 moon_dir = -sun_dir.xyz; - float sun_light = get_sun_brightness(/*sun_dir*/) * sun_info.block;//sun_info.brightness;; - float moon_light = get_moon_brightness(/*moon_dir*/) * moon_info.block * ambiance;//moon_info.brightness; + float sun_light = get_sun_brightness() * sun_info.block; + float moon_light = get_moon_brightness() * moon_info.block * ambiance; - vec3 sun_color = get_sun_color(/*sun_dir*/) * SUN_COLOR_FACTOR;//sun_info.color * SUN_COLOR_FACTOR; - vec3 moon_color = get_moon_color(/*moon_dir*/) * MOON_COLOR_FACTOR;//moon_info.color; + vec3 sun_color = get_sun_color() * SUN_COLOR_FACTOR; + vec3 moon_color = get_moon_color() * MOON_COLOR_FACTOR; // If the sun is facing the wrong way, we currently just want zero light, hence default point is wpos. vec3 sun_attenuation = compute_attenuation(wpos, -sun_dir, mu, surface_alt, wpos); @@ -357,13 +285,6 @@ float get_sun_diffuse2(DirectionalLight sun_info, DirectionalLight moon_info, ve vec3 sun_chroma = sun_color * sun_light * cam_attenuation * sun_attenuation; vec3 moon_chroma = moon_color * moon_light * cam_attenuation * moon_attenuation; -// #ifdef HAS_SHADOW_MAPS -// float sun_shadow = ShadowCalculationDirected(light_pos, 0u); -// float moon_shadow = ShadowCalculationDirected(light_pos, 1u); -// #else -// float sun_shadow = 1.0; -// float moon_shadow = 1.0; -// #endif float sun_shadow = sun_info.shadow * cloud_shadow(wpos, sun_dir); float moon_shadow = moon_info.shadow * cloud_shadow(wpos, moon_dir); @@ -443,7 +364,7 @@ float get_sun_diffuse2(DirectionalLight sun_info, DirectionalLight moon_info, ve float R_b = sqrt(max(0.0, 1.0 - sin_beta * sin_beta)); // Rough estimate of diffuse reflectance of rest of ground. // NOTE: zeta should be close to 0.7 with snow cover, 0.2 normally? Maybe? - vec3 zeta = max(vec3(0.2), k_d * (1.0 - k_s));//vec3(0.2);// k_d * (1.0 - k_s); + vec3 zeta = max(vec3(0.2), k_d * (1.0 - k_s)); float R_d = (1 + R_b) * 0.5; vec3 R_r = zeta * (1.0 - R_b) * 0.5; // @@ -453,7 +374,6 @@ float get_sun_diffuse2(DirectionalLight sun_info, DirectionalLight moon_info, ve vec3 R_t_b = R_b + R_r; vec3 R_t_r = R_d + R_r; - // vec3 half_vec = normalize(-norm + dir); #ifdef EXPERIMENTAL_PHOTOREALISTIC vec3 lrf = light_reflection_factor(norm, dir, -norm, k_d, vec3(0.0), alpha, voxel_norm, voxel_lighting); #else @@ -462,21 +382,8 @@ float get_sun_diffuse2(DirectionalLight sun_info, DirectionalLight moon_info, ve float lrf = pow(dot(norm, vec3(0, 0, 1)) + 1, 2) * 0.25; #endif vec3 light_frac = R_t_b * (sun_chroma * SUN_AMBIANCE + moon_chroma * MOON_AMBIANCE) * lrf; - // vec3 light_frac = /*vec3(1.0)*//*H_d * */ - // SUN_AMBIANCE * /*sun_light*/sun_chroma * light_reflection_factor(norm, dir, /*vec3(0, 0, -1.0)*/-norm, vec3((1.0 + cos_sun) * 0.5), vec3(k_s * (1.0 - cos_sun) * 0.5), alpha) + - // MOON_AMBIANCE * /*sun_light*/moon_chroma * light_reflection_factor(norm, dir, /*vec3(0, 0, -1.0)*/-norm, vec3((1.0 + cos_moon) * 0.5), vec3(k_s * (1.0 - cos_moon) * 0.5), alpha); - /* float NLsun = max(dot(-norm, sun_dir), 0); - float NLmoon = max(dot(-norm, moon_dir), 0); - vec3 E = -dir; */ - // Globbal illumination "estimate" used to light the faces of voxels which are parallel to the sun or moon (which is a very common occurrence). - // Will be attenuated by k_d, which is assumed to carry any additional ambient occlusion information (e.g. about shadowing). - // float ambient_sides = 0.0; - // float ambient_sides = 0.5 - 0.5 * min(abs(dot(-norm, sun_dir)), abs(dot(-norm, moon_dir))); - // float ambient_sides = clamp(mix(0.5, 0.0, abs(dot(-norm, sun_dir)) * mix(0.0, 1.0, abs(sun_dir.z) * 10000.0) * 10000.0), 0.0, 0.5); - // float ambient_sides = clamp(mix(0.5, 0.0, abs(dot(-norm, sun_dir)) * mix(0.0, 1.0, abs(sun_dir.z) * 10000.0) * 10000.0), 0.0, 0.5); - emitted_light = light_frac;// + k_a * PERSISTENT_AMBIANCE * ambiance * 0.1 * MU_SCATTER; - // emitted_light = k_a * light_frac * (/*ambient_sides + */SUN_AMBIANCE * /*sun_light*/sun_chroma + /*vec3(moon_light)*/MOON_AMBIANCE * moon_chroma) + PERSISTENT_AMBIANCE; + emitted_light = light_frac; vec3 emission = vec3(0); #if (CLOUD_MODE > CLOUD_MODE_FLAT) @@ -492,20 +399,12 @@ float get_sun_diffuse2(DirectionalLight sun_info, DirectionalLight moon_info, ve #endif reflected_light = R_t_r * ( - (1.0 - SUN_AMBIANCE) * sun_chroma * sun_shadow * (light_reflection_factor(norm, dir, sun_dir, k_d, k_s, alpha, voxel_norm, voxel_lighting) /*+ - light_reflection_factor(norm, dir, normalize(sun_dir + vec3(0.0, 0.1, 0.0)), k_d, k_s, alpha) + - light_reflection_factor(norm, dir, normalize(sun_dir - vec3(0.0, 0.1, 0.0)), k_d, k_s, alpha)*/) + - (1.0 - MOON_AMBIANCE) * moon_chroma * moon_shadow * 1.0 * /*4.0 * */light_reflection_factor(norm, dir, moon_dir, k_d, k_s, alpha, voxel_norm, voxel_lighting) + - emission + (1.0 - SUN_AMBIANCE) * sun_chroma * sun_shadow * light_reflection_factor(norm, dir, sun_dir, k_d, k_s, alpha, voxel_norm, voxel_lighting) + + (1.0 - MOON_AMBIANCE) * moon_chroma * moon_shadow * light_reflection_factor(norm, dir, moon_dir, k_d, k_s, alpha, voxel_norm, voxel_lighting) + + emission ) + lightning; - /* light = sun_chroma + moon_chroma + PERSISTENT_AMBIANCE; - diffuse_light = - sun_chroma * mix(1.0, max(dot(-norm, sun_dir) * 0.5 + 0.5, 0.0), diffusion) + - moon_chroma * mix(1.0, pow(dot(-norm, moon_dir) * 2.0, 2.0), diffusion) + - PERSISTENT_AMBIANCE; - ambient_light = vec3(SUN_AMBIANCE * sun_light + moon_light); */ - return rel_luminance(emitted_light + reflected_light);//rel_luminance(emitted_light + reflected_light);//sun_chroma + moon_chroma + PERSISTENT_AMBIANCE; + return rel_luminance(emitted_light + reflected_light); } // This has been extracted into a function to allow quick exit when detecting a star. @@ -521,13 +420,6 @@ float is_star_at(vec3 dir) { // Find distance to fragment float dist = length(pos - dir); - // Star threshold - //if (dist < 0.0015) { - // return 2.5; - //} - - //return 0.0; - #if (CLOUD_MODE == CLOUD_MODE_FLAT) const float power = 5.0; #else @@ -727,123 +619,10 @@ vec3 get_sky_color(vec3 dir, vec3 origin, vec3 f_pos, float quality, bool with_f float fog(vec3 f_pos, vec3 focus_pos, uint medium) { return max(1.0 - 5000.0 / (1.0 + distance(f_pos.xy, focus_pos.xy)), 0.0); - - // float fog_radius = view_distance.x; - // float mist_radius = 10000000.0; - - // float min_fog = 0.5; - // float max_fog = 1.0; - - // if (medium == MEDIUM_WATER) { - // mist_radius = UNDERWATER_MIST_DIST; - // min_fog = 0.0; - // } - - // float fog = distance(f_pos.xy, focus_pos.xy) / fog_radius; - // float mist = distance(f_pos, focus_pos) / mist_radius; - - // return pow(clamp((max(fog, mist) - min_fog) / (max_fog - min_fog), 0.0, 1.0), 1.7); } -/* vec3 illuminate(vec3 color, vec3 light, vec3 diffuse, vec3 ambience) { - float avg_col = (color.r + color.g + color.b) / 3.0; - return ((color - avg_col) * light + (diffuse + ambience) * avg_col) * (diffuse + ambience); -} */ -vec3 illuminate(float max_light, vec3 view_dir, /*vec3 max_light, */vec3 emitted, vec3 reflected) { +vec3 illuminate(float max_light, vec3 view_dir, vec3 emitted, vec3 reflected) { return emitted + reflected; - // const float NIGHT_EXPOSURE = 10.0; - // const float DUSK_EXPOSURE = 2.0;//0.8; - // const float DAY_EXPOSURE = 1.0;//0.7; - -// #if (LIGHTING_ALGORITHM == LIGHTING_ALGORITHM_ASHIKHMIN) -// const float DAY_SATURATION = 1.1; -// #else -// const float DAY_SATURATION = 1.0; -// #endif - // const float DUSK_SATURATION = 0.6; - // const float NIGHT_SATURATION = 0.1; - - // const float gamma = /*0.5*//*1.*0*/1.0;//1.0; - /* float light = length(emitted + reflected); - float color = srgb_to_linear(emitted + reflected); - float avg_col = (color.r + color.g + color.b) / 3.0; - return ((color - avg_col) * light + reflected * avg_col) * (emitted + reflected); */ - // float max_intensity = vec3(1.0); - // vec3 color = emitted + reflected; - // float lum = rel_luminance(color); - // float lum_sky = lum - max_light; - - /* vec3 sun_dir = get_sun_dir(time_of_day.x); - vec3 moon_dir = get_moon_dir(time_of_day.x); */ - // float sky_light = rel_luminance( - // get_sun_color(/*sun_dir*/) * get_sun_brightness(/*sun_dir*/) * SUN_COLOR_FACTOR + - // get_moon_color(/*moon_dir*/) * get_moon_brightness(/*moon_dir*/)); - - // Tone mapped value. - // vec3 T = /*color*//*lum*/color;//normalize(color) * lum / (1.0 + lum); - // float alpha = 0.5;//2.0; - // float alpha = mix( - // mix( - // DUSK_EXPOSURE, - // NIGHT_EXPOSURE, - // max(sun_dir.z, 0) - // ), - // DAY_EXPOSURE, - // max(-sun_dir.z, 0) - // ); - // vec3 now_light = moon_dir.z < 0 ? moon_dir.xyz : sun_dir.xyz; - // float cos_view_light = dot(-now_light, view_dir); - // alpha *= exp(1.0 - cos_view_light); - // sky_light *= 1.0 - log(1.0 + view_dir.z); - // float alph = sky_light > 0.0 && max_light > 0.0 ? mix(1.0 / log(/*1.0*//*1.0 + *//*lum_sky + */1.0 + max_light / (0.0 + sky_light)), 1.0, clamp(max_light - sky_light, 0.0, 1.0)) : 1.0; - // alpha = alpha * min(alph, 1.0);//((max_light > 0.0 && max_light > sky_light /* && sky_light > 0.0*/) ? /*1.0*/1.0 / log(/*1.0*//*1.0 + *//*lum_sky + */1.0 + max_light - (0.0 + sky_light)) : 1.0); - // alpha = alpha * min(1.0, (max_light == 0.0 ? 1.0 : (1.0 + abs(lum_sky)) / /*(1.0 + max_light)*/max_light)); - - // vec3 col_adjusted = lum == 0.0 ? vec3(0.0) : color / lum; - - // float L = lum == 0.0 ? 0.0 : log(lum); - - - // // float B = T; - // // float B = L + log(alpha); - // float B = lum; - - // float D = L - B; - - // float o = 0.0;//log(PERSISTENT_AMBIANCE); - // float scale = /*-alpha*/-alpha;//1.0; - - // float B_ = (B - o) * scale; - - // // float T = lum; - // float O = exp(B_ + D); - - // float T = 1.0 - exp(-alpha * lum);//lum / (1.0 + lum); - // float T = lum; - - // Heuristic desaturation - // const float s = 0.8; - // float s = mix( - // mix( - // DUSK_SATURATION, - // NIGHT_SATURATION, - // max(sun_dir.z, 0) - // ), - // DAY_SATURATION, - // max(-sun_dir.z, 0) - // ); - // s = max(s, (max_light) / (1.0 + s)); - // s = max(s, max_light / (1.0 + max_light)); - - // vec3 c = pow(col_adjusted, vec3(s)) * T; - // vec3 c = col_adjusted * T; - // vec3 c = sqrt(col_adjusted) * T; - // vec3 c = /*col_adjusted * */col_adjusted * T; - - // return color; - // return c; - // float sum_col = color.r + color.g + color.b; - // return /*srgb_to_linear*/(/*0.5*//*0.125 * */vec3(pow(color.x, gamma), pow(color.y, gamma), pow(color.z, gamma))); } vec3 simple_lighting(vec3 pos, vec3 col, float shade) { @@ -862,7 +641,6 @@ float wind_wave(float off, float scaling, float speed, float strength) { return (sin(tick_loop(2.0 * PI, 0.35 * scaling * floor(aspeed), off)) * (1.0 - fract(aspeed)) + sin(tick_loop(2.0 * PI, 0.35 * scaling * ceil(aspeed), off)) * fract(aspeed)) * abs(strength) * 0.25; - //return sin(tick.x * 1.5 * scaling + off) + sin(tick.x * 0.35 * scaling + off); } #endif diff --git a/assets/voxygen/shaders/include/srgb.glsl b/assets/voxygen/shaders/include/srgb.glsl index 7563a9e6d2..e8b91abac0 100644 --- a/assets/voxygen/shaders/include/srgb.glsl +++ b/assets/voxygen/shaders/include/srgb.glsl @@ -7,23 +7,6 @@ // See https://en.wikipedia.org/wiki/Electromagnetic_absorption_by_water const vec3 MU_WATER = vec3(0.6, 0.04, 0.01); -// // NOTE: Automatic in v4.0 -// float -// mip_map_level(in vec2 texture_coordinate) -// { -// // The OpenGL Graphics System: A Specification 4.2 -// // - chapter 3.9.11, equation 3.21 -// -// -// vec2 dx_vtc = dFdx(texture_coordinate); -// vec2 dy_vtc = dFdy(texture_coordinate); -// float delta_max_sqr = max(dot(dx_vtc, dx_vtc), dot(dy_vtc, dy_vtc)); -// -// -// //return max(0.0, 0.5 * log2(delta_max_sqr) - 1.0); // == log2(sqrt(delta_max_sqr)); -// return 0.5 * log2(delta_max_sqr); // == log2(sqrt(delta_max_sqr)); -// } - //https://gamedev.stackexchange.com/questions/92015/optimized-linear-to-srgb-glsl vec3 srgb_to_linear(vec3 srgb) { bvec3 cutoff = lessThan(srgb, vec3(0.04045)); @@ -34,8 +17,6 @@ vec3 srgb_to_linear(vec3 srgb) { } vec3 linear_to_srgb(vec3 col) { - // bvec3 cutoff = lessThan(col, vec3(0.0060)); - // return mix(11.500726 * col, , cutoff); vec3 s1 = vec3(sqrt(col.r), sqrt(col.g), sqrt(col.b)); vec3 s2 = vec3(sqrt(s1.r), sqrt(s1.g), sqrt(s1.b)); vec3 s3 = vec3(sqrt(s2.r), sqrt(s2.g), sqrt(s2.b)); @@ -60,8 +41,6 @@ vec4 pow5(vec4 x) { // Schlick approximation vec3 schlick_fresnel(vec3 Rs, float cosTheta) { - // auto pow5 = [](Float v) { return (v * v) * (v * v) * v; }; - // return Rs + pow5(1 - cosTheta) * (Spectrum(1.) - Rs); return Rs + pow5(1.0 - cosTheta) * (1.0 - Rs); } @@ -77,114 +56,40 @@ float BeckmannDistribution_D(float NdotH, float alpha) { // Voxel Distribution float BeckmannDistribution_D_Voxel(vec3 wh, vec3 voxel_norm, float alpha) { vec3 sides = sign(voxel_norm); - // vec3 cos_sides_i = /*sides * */sides * norm; - // vec3 cos_sides_o = max(sides * view_dir, 0.0); - - vec3 NdotH = wh * sides;//max(wh * sides, 0.0);/*cos_sides_i*///max(sides * wh, 0.0); + + vec3 NdotH = wh * sides; const float PI = 3.1415926535897932384626433832795; vec3 NdotH2 = NdotH * NdotH; vec3 NdotH2m2 = NdotH2 * alpha * alpha; vec3 k_spec = exp((NdotH2 - 1.0) / NdotH2m2) / (PI * NdotH2m2 * NdotH2); - return dot(mix(k_spec, /*cos_sides_o*/vec3(0.0), equal(NdotH, vec3(0.0))), /*cos_sides_i*/abs(voxel_norm)); - // // const float PI = 3.1415926535897932384626433832795; - // const vec3 normals[6] = vec3[](vec3(1,0,0), vec3(0,1,0), vec3(0,0,1), vec3(-1,0,0), vec3(0,-1,0), vec3(0,0,-1)); - - // float voxel_norm = 0.0; - // for (int i = 0; i < 6; i ++) { - // // Light reflecting off the half-angle can shine on up to three sides. - // // So, the idea here is to figure out the ratio of visibility of each of these - // // three sides such that their sum adds to 1, then computing a Beckmann Distribution for each side times - // // the this ratio. - // // - // // The ratio of these normals in each direction should be the sum of their cosines with the light over π, - // // I think. - // // - // // cos (wh, theta) - // // - // // - one normal - // // - // // The ratio of each of the three exposed sides should just be the slope. - // vec3 side = normals[i]; - // float side_share = max(dot(norm, side), 0.0); - // float NdotH = max(dot(wh, side), 0.0); - // voxel_norm += side_share * BeckmannDistribution_D(NdotH, alpha); - // // voxel_norm += normals[i] * side_visible * max(dot(-cam_dir, normals[i]), 0.0); - // // voxel_norm += normals[i] * side_visible * max(dot(-cam_dir, normals[i]), 0.0); - // } - - // /* float NdotH = dot(wh, norm); - // float NdotH2 = NdotH * NdotH; - // float NdotH2m2 = NdotH2 * alpha * alpha; - - // float k_spec = exp((NdotH2 - 1) / NdotH2m2) / (PI * NdotH2m2 * NdotH2); - // return mix(k_spec, 0.0, NdotH == 0.0); */ - // return voxel_norm; + return dot(mix(k_spec, vec3(0.0), equal(NdotH, vec3(0.0))), abs(voxel_norm)); } float TrowbridgeReitzDistribution_D_Voxel(vec3 wh, vec3 voxel_norm, float alpha) { vec3 sides = sign(voxel_norm); - // vec3 cos_sides_i = /*sides * */sides * norm; - // vec3 cos_sides_o = max(sides * view_dir, 0.0); - vec3 NdotH = wh * sides;//max(wh * sides, 0.0);/*cos_sides_i*///max(sides * wh, 0.0); + vec3 NdotH = wh * sides; const float PI = 3.1415926535897932384626433832795; vec3 NdotH2 = NdotH * NdotH; - // vec3 m2 = alpha * alpha; - // vec3 NdotH2m2 = NdotH2 * m2; vec3 NdotH2m2 = NdotH2 * alpha * alpha; - // vec3 Tan2Theta = (1.0 - NdotH2) / NdotH2; - // vec3 e = (NdotH2 / m2 + (1.0 - NdotH2) / m2) * Tan2Theta; - // vec3 e = 1.0 / m2 * (1.0 - NdotH2) / NdotH2; vec3 e = (1.0 - NdotH2) / NdotH2m2; vec3 k_spec = 1.0 / (PI * NdotH2m2 * NdotH2 * (1.0 + e) * (1.0 + e)); - // vec3 k_spec = exp((NdotH2 - 1.0) / NdotH2m2) / (PI * NdotH2m2 * NdotH2); - return dot(mix(k_spec, /*cos_sides_o*/vec3(0.0), equal(NdotH, vec3(0.0))), /*cos_sides_i*/abs(voxel_norm)); + return dot(mix(k_spec, vec3(0.0), equal(NdotH, vec3(0.0))), abs(voxel_norm)); } float BeckmannDistribution_Lambda(vec3 norm, vec3 dir, float alpha) { - float CosTheta = /*max(dot(norm, dir), 0.0);*/dot(norm, dir); - /* if (CosTheta == 0.0) { - return 0.0; - } - float SinTheta = sqrt(1.0 - CosTheta * CosTheta); - float TanTheta = SinTheta / CosTheta; - float absTanTheta = abs(TanTheta); */ - // vec3 w = normalize(dir - dot(dir, norm) * (norm)); - // float CosTheta = w.z; + float CosTheta = dot(norm, dir); float SinTheta = sqrt(1.0 - CosTheta * CosTheta); float TanTheta = SinTheta / CosTheta; float absTanTheta = abs(TanTheta); - /* if (isinf(absTanTheta)) { - return 0.0; - } */ - /* float CosPhi = mix(clamp(projDirNorm.x / sinTheta, -1.0, 1.0), 0.0, sinTheta == 0.0); - float SinPhi = mix(clamp(projDirNorm.y / sinTheta, -1.0, 1.0), 0.0, sinTheta == 0.0); - float alpha = sqrt(CosPhi * CosPhi * alphax * alphax + SinPhi * SinPhi * alphay * alphay); */ - // Float absTanTheta = std::abs(TanTheta(w)); - // if (std::isinf(absTanTheta)) return 0.; - // <> - // Float alpha = std::sqrt(Cos2Phi(w) * alphax * alphax + - // Sin2Phi(w) * alphay * alphay); float a = 1.0 / (alpha * absTanTheta); - /* if (a >= 1.6) { - return 0.0; - } - - return (1.0 - 1.259 * a + 0.396 * a * a) / (3.535 * a + 2.181 * a * a); */ - + return mix(max(0.0, (1.0 - 1.259 * a + 0.396 * a * a) / (3.535 * a + 2.181 * a * a)), 0.0, isinf(absTanTheta) || a >= 1.6); - // Float a = 1 / (alpha * absTanTheta); - // if (a >= 1.6f) - // return 0; - // return (1 - 1.259f * a + 0.396f * a * a) / - // (3.535f * a + 2.181f * a * a); - // return 1 / (1 + Lambda(wo) + Lambda(wi)); } float BeckmannDistribution_G(vec3 norm, vec3 dir, vec3 light_dir, float alpha) { - // return 1 / (1 + Lambda(wo) + Lambda(wi)); return 1.0 / (1.0 + BeckmannDistribution_Lambda(norm, dir, alpha) + BeckmannDistribution_Lambda(norm, -light_dir, alpha)); } @@ -196,18 +101,13 @@ float BeckmannDistribution_G(vec3 norm, vec3 dir, vec3 light_dir, float alpha) { vec3 FresnelBlend_f(vec3 norm, vec3 dir, vec3 light_dir, vec3 R_d, vec3 R_s, float alpha) { const float PI = 3.1415926535897932384626433832795; alpha = alpha * sqrt(2.0); - float cos_wi = /*max(*/dot(-light_dir, norm)/*, 0.0)*/; - float cos_wo = /*max(*/dot(dir, norm)/*, 0.0)*/; + float cos_wi = dot(-light_dir, norm); + float cos_wo = dot(dir, norm); vec3 diffuse = (28.0 / (23.0 * PI)) * R_d * (1.0 - R_s) * (1.0 - pow5(1.0 - 0.5 * abs(cos_wi))) * (1.0 - pow5(1.0 - 0.5 * abs(cos_wo))); - /* Spectrum diffuse = (28.f/(23.f*Pi)) * Rd * - (Spectrum(1.f) - Rs) * - (1 - pow5(1.0 - .5f * AbsCosTheta(wi))) * - (1 - pow5(1.0 - .5f * AbsCosTheta(wo))); */ - // Vector3f wh = wi + wo; vec3 wh = -light_dir + dir; #if (LIGHTING_TYPE & LIGHTING_TYPE_TRANSMISSION) != 0 bool is_blocked = cos_wi == 0.0 || cos_wo == 0.0; @@ -215,29 +115,15 @@ vec3 FresnelBlend_f(vec3 norm, vec3 dir, vec3 light_dir, vec3 R_d, vec3 R_s, flo bool is_blocked = cos_wi <= 0.0 || cos_wo <= 0.0; #endif if (is_blocked) { - return vec3(/*diffuse*/0.0); + return vec3(0.0); } - // if (cos_wo < 0.0) { - // return /*vec3(0.0)*/diffuse; - // } - /* if (cos_wi == 0.0 || cos_wo == 0.0) { - return vec3(0.0); - } */ - /* if (wh.x == 0 && wh.y == 0 && wh.z == 0) { - return vec3(0.0); - // return Spectrum(0); - } */ - wh = normalize(wh);//mix(normalize(wh), vec3(0.0), equal(light_dir, dir)); + wh = normalize(wh); float dot_wi_wh = dot(-light_dir, wh); vec3 specular = dot(norm, dir) > 0.0 ? vec3(0.0) : (BeckmannDistribution_D(dot(wh, norm), alpha) / (4.0 * abs(dot_wi_wh) * max(abs(cos_wi), abs(cos_wo))) * schlick_fresnel(R_s, dot_wi_wh)); - // Spectrum specular = distribution->D(wh) / - // (4.0 * AbsDot(wi, wh) * - // std::max(AbsCosTheta(wi), AbsCosTheta(wo))) * - // SchlickFresnel(Dot(wi, wh)); - return mix(/*diffuse*//* + specular*/diffuse + specular, vec3(0.0), bvec3(all(equal(light_dir, dir)))); + return mix(diffuse + specular, vec3(0.0), bvec3(all(equal(light_dir, dir)))); } // Fresnel blending @@ -248,8 +134,8 @@ vec3 FresnelBlend_f(vec3 norm, vec3 dir, vec3 light_dir, vec3 R_d, vec3 R_s, flo vec3 FresnelBlend_Voxel_f(vec3 norm, vec3 dir, vec3 light_dir, vec3 R_d, vec3 R_s, float alpha, vec3 voxel_norm, float dist) { const float PI = 3.1415926535897932384626433832795; alpha = alpha * sqrt(2.0); - float cos_wi = /*max(*/dot(-light_dir, norm)/*, 0.0)*/; - float cos_wo = /*max(*/dot(dir, norm)/*, 0.0)*/; + float cos_wi = dot(-light_dir, norm); + float cos_wo = dot(dir, norm); #if (LIGHTING_TYPE & LIGHTING_TYPE_TRANSMISSION) != 0 vec4 AbsNdotL = abs(vec4(light_dir, cos_wi)); @@ -260,44 +146,9 @@ vec3 FresnelBlend_Voxel_f(vec3 norm, vec3 dir, vec3 light_dir, vec3 R_d, vec3 R_ vec4 AbsNdotV = vec4(max(dir * sides, 0.0), abs(cos_wo)); #endif - // float R_r = 1.0 - R_s; - // float R_r = 1.0 - schlick_fresnel(R_s, cos_wi); - // // Rs + pow5(1.0 - cosTheta) * (1.0 - Rs) - // vec4 R_r = 1.0 - (R_s + (1.0 - R_s) * schlick_fresnel(R_s, cos_wi)); - // mat4 R_r = 1.0 - (vec4(R_s, 0.0) + vec4(1.0 - R_s, 0.0) * pow5(1.0 - AbsNdotL)); - // vec4 AbsNdotL5 = pow5(1.0 - AbsNdotL); - // vec4 R_s4 = vec4(R_s, 0.0); - // mat4 R_r = - // // mat4(1.0 - (R_s.r + (1.0 - R_s.r) * AbsNdotL5), - // // 1.0 - (R_s.g + (1.0 - R_s.g) * AbsNdotL5), - // // 1.0 - (R_s.b + (1.0 - R_s.b) * AbsNdotL5), - // // vec4(0.0) - // // ); - // mat4(1.0 - (R_s4 + (1.0 - R_s4) * AbsNdotL5.x), - // 1.0 - (R_s4 + (1.0 - R_s4) * AbsNdotL5.y), - // 1.0 - (R_s4 + (1.0 - R_s4) * AbsNdotL5.z), - // 1.0 - (R_s4 + (1.0 - R_s4) * AbsNdotL5.w) - // ); - // * ) (R1.0 - R_s.r) 1.0 - (vec4(R_s, 0.0) + vec4(1.0 - R_s, 0.0) * pow5(1.0 - AbsNdotL)); + vec4 diffuse_factor = (1.0 - pow5(1.0 - 0.5 * AbsNdotL)) * (1.0 - pow5(1.0 - 0.5 * AbsNdotV)); - vec4 diffuse_factor = - // vec4(abs(vec4(-light_dir * sides, cos_wi))) - (1.0 - pow5(1.0 - 0.5 * AbsNdotL)) * - // (1.0 - pow5(1.0 - 0.5 * abs(vec4(-light_dir * sides, cos_wi)))) * - // (1.0 - pow5(1.0 - 0.5 * abs(vec4(dir * sides, cos_wo)))) - (1.0 - pow5(1.0 - 0.5 * AbsNdotV)) - // vec4(1.0) - ; - /* vec4 diffuse_factor = - (1.0 - pow5(1.0 - 0.5 * max(vec4(-light_dir * sides, abs(cos_wi)), 0.0))) * - (1.0 - pow5(1.0 - 0.5 * max(vec4(dir * sides, abs(cos_wo)), 0.0))); */ - - vec3 diffuse = (28.0 / (23.0 * PI))/*(1.0 / PI)*/ * R_d * - (1.0 - R_s) * - //vec3( - dot(diffuse_factor, /*R_r * */vec4(abs(norm) * (1.0 - dist), dist)) - //) - ; + vec3 diffuse = (28.0 / (23.0 * PI)) * R_d * (1.0 - R_s) * dot(diffuse_factor, /*R_r * */vec4(abs(norm) * (1.0 - dist), dist)); vec3 wh = -light_dir + dir; #if (LIGHTING_TYPE & LIGHTING_TYPE_TRANSMISSION) != 0 @@ -306,18 +157,16 @@ vec3 FresnelBlend_Voxel_f(vec3 norm, vec3 dir, vec3 light_dir, vec3 R_d, vec3 R_ bool is_blocked = cos_wi <= 0.0 || cos_wo <= 0.0; #endif if (is_blocked) { - return vec3(/*diffuse*/0.0); + return vec3(0.0); } - wh = normalize(wh);//mix(normalize(wh), vec3(0.0), equal(light_dir, dir)); + wh = normalize(wh); float dot_wi_wh = dot(-light_dir, wh); - // float distr = TrowbridgeReitzDistribution_D_Voxel(wh, voxel_norm, alpha); float distr = BeckmannDistribution_D_Voxel(wh, voxel_norm, alpha); - // float distr = BeckmannDistribution_D(dot(wh, norm), alpha); vec3 specular = distr / (4.0 * abs(dot_wi_wh) * max(abs(cos_wi), abs(cos_wo))) * schlick_fresnel(R_s, dot_wi_wh); - return mix(/*diffuse*//* + specular*/diffuse + specular, vec3(0.0), bvec3(all(equal(light_dir, dir)))); + return mix(diffuse + specular, vec3(0.0), bvec3(all(equal(light_dir, dir)))); } // Phong reflection. @@ -366,25 +215,7 @@ vec3 light_reflection_factor2(vec3 norm, vec3 dir, vec3 light_dir, vec3 k_d, vec // vec3 w_i = // vec3 w_i = vec3(view_mat * vec4(-light_dir, 1.0)); // vec3 w_o = vec3(view_mat * vec4(light_dir, 1.0)); - float g = 1.0;// BeckmannDistribution_G(norm, dir, light_dir, alpha); - return FresnelBlend_f(norm, dir, light_dir, k_d/* * max(dot(norm, -light_dir), 0.0)*/, k_s * g, alpha); - // const float PI = 3.141592; - // alpha = alpha * sqrt(2.0); - // float ndotL = /*max*/(dot(norm, -light_dir)/*, 0.0*/); - - // //if (ndotL > 0.0/* && dot(s_norm, -light_dir) > 0.0*/) { - // vec3 H = normalize(-light_dir + dir); - - // float NdotH = dot(norm, H); - // float NdotH2 = NdotH * NdotH; - // float NdotH2m2 = NdotH2 * alpha * alpha; - // float k_spec = exp((NdotH2 - 1) / NdotH2m2) / (PI * NdotH2m2 * NdotH2); - // return mix(k_s * k_spec, vec3(0.0), bvec3(ndotL <= 0.0 || NdotH == 0.0)); - // // - // // (k_d * (L ⋅ N) + k_s * (R ⋅ V)^α) - // // return k_d * ndotL + mix(k_s * pow(max(dot(norm, H), 0.0), alpha * 4.0), vec3(0.0), bvec3(ndotL == 0.0)); - // // } - // // return vec3(0.0); + return FresnelBlend_f(norm, dir, light_dir, k_d, k_s, alpha); } vec3 light_reflection_factor(vec3 norm, vec3 dir, vec3 light_dir, vec3 k_d, vec3 k_s, float alpha, vec3 voxel_norm, float voxel_lighting) { @@ -440,13 +271,9 @@ vec3 light_reflection_factor(vec3 norm, vec3 dir, vec3 light_dir, vec3 k_d, vec3 return vec3(0.0); #elif (LIGHTING_ALGORITHM == LIGHTING_ALGORITHM_ASHIKHMIN) #if (LIGHTING_DISTRIBUTION_SCHEME == LIGHTING_DISTRIBUTION_SCHEME_VOXEL) - return FresnelBlend_Voxel_f(norm, dir, light_dir, k_d/* * max(dot(norm, -light_dir), 0.0)*/, k_s, alpha, voxel_norm, voxel_lighting); + return FresnelBlend_Voxel_f(norm, dir, light_dir, k_d, k_s, alpha, voxel_norm, voxel_lighting); #elif (LIGHTING_DISTRIBUTION_SCHEME == LIGHTING_DISTRIBUTION_SCHEME_MICROFACET) - //if (voxel_lighting < 1.0) { - return FresnelBlend_f(norm, dir, light_dir, k_d/* * max(dot(norm, -light_dir), 0.0)*/, k_s, alpha); - //} else { - // return FresnelBlend_f(norm, dir, light_dir, k_d/* * max(dot(norm, -light_dir), 0.0)*/, k_s, alpha); - //} + return FresnelBlend_f(norm, dir, light_dir, k_d, k_s, alpha); #endif #endif } @@ -497,17 +324,8 @@ vec3 compute_attenuation(vec3 wpos, vec3 ray_dir, vec3 mu, float surface_alt, ve #if (LIGHTING_TYPE & LIGHTING_TYPE_TRANSMISSION) != 0 return vec3(1.0); #else - // return vec3(1.0); - /*if (mu == vec3(0.0)) { - return vec3(1.0); - }*//* else { - return vec3(0.0); - }*/ - // return vec3(0.0); - // vec3 surface_dir = /*surface_alt < wpos.z ? vec3(0.0, 0.0, -1.0) : vec3(0.0, 0.0, 1.0)*/vec3(0.0, 0.0, sign(surface_alt - wpos.z)); ray_dir = faceforward(ray_dir, vec3(0.0, 0.0, -1.0), ray_dir); vec3 surface_dir = surface_alt < wpos.z ? vec3(0.0, 0.0, -1.0) : vec3(0.0, 0.0, 1.0); - // vec3 surface_dir = faceforward(vec3(0.0, 0.0, 1.0), ray_dir, vec3(0.0, 0.0, 1.0)); bool _intersects_surface = IntersectRayPlane(wpos, ray_dir, vec3(0.0, 0.0, surface_alt), surface_dir, defaultpos); float depth = length(defaultpos - wpos); return exp(-mu * depth); @@ -515,118 +333,19 @@ vec3 compute_attenuation(vec3 wpos, vec3 ray_dir, vec3 mu, float surface_alt, ve #endif } -// vec3 compute_attenuation2(vec3 wpos, vec3 ray_dir, vec3 mu, float surface_alt, vec3 defaultpos) { -// #if (LIGHTING_TRANSPORT_MODE == LIGHTING_TRANSPORT_MODE_IMPORTANCE) -// return vec3(1.0); -// #elif (LIGHTING_TRANSPORT_MODE == LIGHTING_TRANSPORT_MODE_RADIANCE) -// // return vec3(1.0); -// /*if (mu == vec3(0.0)) { -// return vec3(1.0); -// }*//* else { -// return vec3(0.0); -// }*/ -// // return vec3(0.0); -// // vec3 surface_dir = /*surface_alt < wpos.z ? vec3(0.0, 0.0, -1.0) : vec3(0.0, 0.0, 1.0)*/vec3(0.0, 0.0, sign(surface_alt - wpos.z)); -// vec3 surface_dir = surface_alt < wpos.z ? vec3(0.0, 0.0, 1.0) : vec3(0.0, 0.0, -1.0); -// // vec3 surface_dir = faceforward(vec3(0.0, 0.0, 1.0), ray_dir, vec3(0.0, 0.0, 1.0)); -// bool _intersects_surface = IntersectRayPlane(wpos, ray_dir, vec3(0.0, 0.0, surface_alt), surface_dir, defaultpos); -// float depth = length(defaultpos - wpos); -// return exp(-mu * depth); -// #endif -// } - // Same as compute_attenuation but since both point are known, set a maximum to make sure we don't exceed the length // from the default point. vec3 compute_attenuation_point(vec3 wpos, vec3 ray_dir, vec3 mu, float surface_alt, vec3 defaultpos) { #if (LIGHTING_TRANSPORT_MODE == LIGHTING_TRANSPORT_MODE_IMPORTANCE) return pow(1.0 - mu, vec3(3)); #elif (LIGHTING_TRANSPORT_MODE == LIGHTING_TRANSPORT_MODE_RADIANCE) - // return vec3(1.0); - /*if (mu == vec3(0.0)) { - return vec3(1.0); - }*//* else { - return vec3(0.0); - }*/ - // return vec3(0.0); - // vec3 surface_dir = /*surface_alt < wpos.z ? vec3(0.0, 0.0, -1.0) : vec3(0.0, 0.0, 1.0)*/vec3(0.0, 0.0, sign(wpos.z - surface_alt)); - // vec3 surface_dir = surface_alt < wpos.z ? vec3(0.0, 0.0, 1.0) : vec3(0.0, 0.0, -1.0); - // vec3 surface_dir = faceforward(vec3(0.0, 0.0, 1.0), ray_dir, vec3(0.0, 0.0, 1.0)); - // float max_length = dot(defaultpos - wpos, defaultpos - wpos); - // bool _intersects_surface = IntersectRayPlane(wpos, ray_dir, vec3(0.0, 0.0, surface_alt), surface_dir, defaultpos); - // float depth2 = min(max_length, min(0.0, dot(defaultpos - wpos, defaultpos - wpos))); - return vec3(1.0);//exp(-mu * sqrt(depth2)); + return vec3(1.0); #endif } -//#ifdef HAS_SHADOW_MAPS -// #if (SHADOW_MODE == SHADOW_MODE_MAP) -//uniform sampler2DShadow t_directed_shadow_maps; -//// uniform sampler2DArrayShadow t_directed_shadow_maps; -// -//float ShadowCalculationDirected(in vec4 /*light_pos[2]*/sun_pos, uint lightIndex) -//{ -// float bias = 0.0;//-0.0001;// 0.05 / (2.0 * view_distance.x); -// // const vec3 sampleOffsetDirections[20] = vec3[] -// // ( -// // vec3( 1, 1, 1), vec3( 1, -1, 1), vec3(-1, -1, 1), vec3(-1, 1, 1), -// // vec3( 1, 1, -1), vec3( 1, -1, -1), vec3(-1, -1, -1), vec3(-1, 1, -1), -// // vec3( 1, 1, 0), vec3( 1, -1, 0), vec3(-1, -1, 0), vec3(-1, 1, 0), -// // vec3( 1, 0, 1), vec3(-1, 0, 1), vec3( 1, 0, -1), vec3(-1, 0, -1), -// // vec3( 0, 1, 1), vec3( 0, -1, 1), vec3( 0, -1, -1), vec3( 0, 1, -1) -// // // vec3(0, 0, 0) -// // ); -// /* if (lightIndex >= light_shadow_count.z) { -// return 1.0; -// } */ -// // vec3 fragPos = sun_pos.xyz;// / sun_pos.w;//light_pos[lightIndex].xyz; -// float visibility = textureProj(t_directed_shadow_maps, sun_pos); -// // float visibility = textureProj(t_directed_shadow_maps, vec4(fragPos.xy, /*lightIndex, */fragPos.z + bias, sun_pos.w)); -// return visibility; -// // return mix(visibility, 0.0, sun_pos.z < -1.0); -// // return mix(mix(0.0, 1.0, visibility == 1.0), 1.0, sign(sun_pos.w) * sun_pos.z > /*1.0*/abs(sun_pos.w)); -// // return visibility == 1.0 ? 1.0 : 0.0; -// /* if (visibility == 1.0) { -// return 1.0; -// } */ -// // return visibility; -// /* if (fragPos.z > 1.0) { -// return 1.0; -// } */ -// // if (visibility <= 0.75) { -// // return 0.0; -// // } -// // int samples = 20; -// // float shadow = 0.0; -// // // float bias = 0.0001; -// // float viewDistance = length(cam_pos.xyz - fragPos); -// // // float diskRadius = 0.2 * (1.0 + (viewDistance / screen_res.w)) / 25.0; -// // float diskRadius = 0.0008;//0.005;// / (2.0 * view_distance.x);//(1.0 + (viewDistance / screen_res.w)) / 25.0; -// // for(int i = 0; i < samples; ++i) -// // { -// // vec3 currentDepth = fragPos + vec3(sampleOffsetDirections[i].xyz) * diskRadius + bias; -// // visibility = texture(t_directed_shadow_maps, vec4(currentDepth.xy, lightIndex, currentDepth.z)/*, -2.5*/); -// // shadow += mix(visibility, 1.0, visibility >= 0.5); -// // } -// // shadow /= float(samples); -// // return shadow; -//} -// #elif (SHADOW_MODE == SHADOW_MODE_NONE || SHADOW_MODE == SHADOW_MODE_CHEAP) -//float ShadowCalculationDirected(in vec4 light_pos[2], uint lightIndex) -//{ -// return 1.0; -//} -// #endif -//#else -//float ShadowCalculationDirected(in vec4 light_pos[2], uint lightIndex) -//{ -// return 1.0; -//} -//#endif - vec3 greedy_extract_col_light_attr(texture2D t_col_light, sampler s_col_light, vec2 f_uv_pos, out float f_light, out float f_glow, out float f_ao, out uint f_attr, out float f_sky_exposure) { // TODO: Figure out how to use `texture` and modulation to avoid needing to do manual filtering // TODO: Use `texture` instead - //vec2 light = texture(t_col_light, f_uv_pos).xy / 31; uvec4 tex_00 = uvec4(texelFetch(sampler2D(t_col_light, s_col_light), ivec2(f_uv_pos) + ivec2(0, 0), 0) * 255.0); uvec4 tex_10 = uvec4(texelFetch(sampler2D(t_col_light, s_col_light), ivec2(f_uv_pos) + ivec2(1, 0), 0) * 255.0); diff --git a/assets/voxygen/shaders/light-shadows-directed-vert.glsl b/assets/voxygen/shaders/light-shadows-directed-vert.glsl index b68abe98e1..d42759484b 100644 --- a/assets/voxygen/shaders/light-shadows-directed-vert.glsl +++ b/assets/voxygen/shaders/light-shadows-directed-vert.glsl @@ -21,8 +21,6 @@ // Currently, we only need globals for focus_off. #include -// For shadow locals. -// #include layout (std140, set = 0, binding = 9) uniform u_light_shadows { @@ -37,9 +35,6 @@ uniform u_light_shadows { * */ layout(location = 0) in uint v_pos_norm; -// in uint v_col_light; -// in vec4 v_pos; -// layout(location = 1) in uint v_atlas_pos; // Light projection matrices. layout (std140, set = 1, binding = 0) @@ -49,18 +44,11 @@ uniform u_locals { float load_time; }; -// out vec4 shadowMapCoord; - const float EXTRA_NEG_Z = 32768.0; void main() { vec3 f_chunk_pos = vec3(v_pos_norm & 0x3Fu, (v_pos_norm >> 6) & 0x3Fu, float((v_pos_norm >> 12) & 0xFFFFu) - EXTRA_NEG_Z); vec3 f_pos = (model_mat * vec4(f_chunk_pos, 1.0)).xyz - focus_off.xyz; - // f_pos = v_pos; - gl_Position = /*all_mat * */shadowMatrices * vec4(f_pos/*, 1.0*/, /*float(((f_pos_norm >> 29) & 0x7u) ^ 0x1)*//*uintBitsToFloat(v_pos_norm)*/1.0); - // gl_Position.z = -gl_Position.z; - // gl_Position.z = clamp(gl_Position.z, -abs(gl_Position.w), abs(gl_Position.w)); - // shadowMapCoord = lights[gl_InstanceID].light_pos * gl_Vertex; - // vec4(v_pos, 0.0, 1.0); + gl_Position = shadowMatrices * vec4(f_pos, 1.0); } diff --git a/assets/voxygen/shaders/light-shadows-figure-vert.glsl b/assets/voxygen/shaders/light-shadows-figure-vert.glsl index 823cbf8d9e..884fc898eb 100644 --- a/assets/voxygen/shaders/light-shadows-figure-vert.glsl +++ b/assets/voxygen/shaders/light-shadows-figure-vert.glsl @@ -23,8 +23,6 @@ // Currently, we only need globals for focus_off. #include -// For shadow locals. -// #include layout (std140, set = 0, binding = 9) uniform u_light_shadows { @@ -40,8 +38,6 @@ uniform u_light_shadows { layout(location = 0) in uint v_pos_norm; layout(location = 1) in uint v_atlas_pos; -// in uint v_col_light; -// in vec4 v_pos; layout (std140, set = 1, binding = 0) uniform u_locals { @@ -67,16 +63,11 @@ uniform u_bones { BoneData bones[16]; }; -// out vec4 shadowMapCoord; - void main() { uint bone_idx = (v_pos_norm >> 27) & 0xFu; vec3 pos = (vec3((uvec3(v_pos_norm) >> uvec3(0, 9, 18)) & uvec3(0x1FFu)) - 256.0) / 2.0; - vec3 f_pos = ( - bones[bone_idx].bone_mat * - vec4(pos, 1.0) - ).xyz + (model_pos - focus_off.xyz/* + vec3(0.0, 0.0, 0.0001)*/); + vec3 f_pos = (bones[bone_idx].bone_mat * vec4(pos, 1.0)).xyz + (model_pos - focus_off.xyz); gl_Position = shadowMatrices * vec4(f_pos, 1.0); } diff --git a/assets/voxygen/shaders/light-shadows-frag.glsl b/assets/voxygen/shaders/light-shadows-frag.glsl index 0aa94ddb50..0741dd9593 100644 --- a/assets/voxygen/shaders/light-shadows-frag.glsl +++ b/assets/voxygen/shaders/light-shadows-frag.glsl @@ -21,29 +21,4 @@ #define LIGHTING_DISTRIBUTION LIGHTING_DISTRIBUTION_BECKMANN -// Currently, we only need globals for the far plane. -#include -// // Currently, we only need lights for the light position -// #include - -// in vec3 FragPos; // FragPos from GS (output per emitvertex) -// flat in int FragLayer; - -void main() -{ - // Only need to do anything with point lights, since sun and moon should already have nonlinear - // distance. - ///*if (FragLayer > 0) */{ - // // get distance between fragment and light source - // float lightDistance = length(FragPos); - // // float lightDistance = length(FragPos - lights[((/*FragLayer*/1 - 1) & 31)].light_pos.xyz); - - // // // map to [0;1] range by dividing by far_plane - // lightDistance = lightDistance / screen_res.w;//FragPos.w;//screen_res.w; - - // // // write this as modified depth - // // // lightDistance = -1000.0 / (lightDistance + 10000.0); - // // // lightDistance /= screen_res.w; - // gl_FragDepth = lightDistance;// / /*FragPos.w;*/screen_res.w;//-1000.0 / (lightDistance + 1000.0);//lightDistance - //} -} +void main() {} diff --git a/assets/voxygen/shaders/light-shadows-geom.glsl b/assets/voxygen/shaders/light-shadows-geom.glsl index 27db0ef212..cd49445a5b 100644 --- a/assets/voxygen/shaders/light-shadows-geom.glsl +++ b/assets/voxygen/shaders/light-shadows-geom.glsl @@ -27,19 +27,6 @@ // and the far plane (scene_res.z). #include #include -// // Currently, we only need lights for the light position -// #include - -/* struct Light { - vec4 light_pos; - vec4 light_col; - // mat4 light_proj; -}; - -layout (std140) -uniform u_lights { - Light lights[31]; -}; */ // Since our output primitive is a triangle strip, we have to render three vertices // each. @@ -183,87 +170,25 @@ uniform u_lights { layout (triangles/*, invocations = 6*/) in; -layout (triangle_strip, max_vertices = /*MAX_LAYER_VERTICES_PER_FACE*//*96*/18) out; - -//struct ShadowLocals { -// mat4 shadowMatrices; -// mat4 texture_mat; -//}; -// -//layout (std140) -//uniform u_light_shadows { -// ShadowLocals shadowMats[/*MAX_LAYER_FACES*/192]; -//}; - -// NOTE: We choose not to output FragPos currently to save on space limitations -// (see extensive documentation above). However, as these limitations have been -// relaxed (unless the total of all our varying output components can't exceed -// 128, which would mean FragPos would sum to 4 * 3 * 32 = 384; this could be -// remedied only by setting MAX_POINT_LIGHTS to ), we might enable it again soon. -// -// out vec3 FragPos; // FragPos from GS (output per emitvertex) -// flat out int FragLayer; // Current layer - -// const vec3 normals[6] = vec3[](vec3(-1,0,0), vec3(1,0,0), vec3(0,-1,0), vec3(0,1,0), vec3(0,0,-1), vec3(0,0,1)); +layout (triangle_strip, max_vertices = /*MAX_LAYER_VERTICES_PER_FACE*/18) out; void main() { - // NOTE: Assuming that light_shadow_count.x < MAX_POINT_LIGHTS. We could min - // it, but that might make this less optimized, and I'd like to keep this loop as - // optimized as is reasonably possible. - // int face = gl_InvocationID; - - // Part 1: emit directed lights. - /* if (face <= light_shadow_count.z) { - // Directed light. - for(int i = 0; i < VERTICES_PER_FACE; ++i) // for each triangle vertex - { - // NOTE: See above, we don't make FragPos a uniform. - FragPos = gl_in[i].gl_Position; - FragLayer = 0; // 0 is the directed light layer. - // vec4 FragPos = gl_in[i].gl_Position; - gl_Layer = i; // built-in variable that specifies to which face we render. - gl_Position = shadowMats[i].shadowMatrices * FragPos; - EmitVertex(); - } - EndPrimitive(); - } */ - - // Part 2: emit point lights. + // Emit point lights. #if (SHADOW_MODE == SHADOW_MODE_MAP) for (uint layer = 1u; layer <= min(light_shadow_count.x, 1u); ++layer) { int layer_base = int(layer) * FACES_PER_POINT_LIGHT; // We use instancing here in order to increase the number of emitted vertices. - // int face = gl_InvocationID; for(int face = 0; face < FACES_PER_POINT_LIGHT; ++face) { - // int layer_face = layer * FACES_PER_POINT_LIGHT + face; - // int layer_face = layer * FACES_PER_POINT_LIGHT + face; - // for(int i = VERTICES_PER_FACE - 1; i >= 0; --i) // for each triangle vertex for(int i = 0; i < VERTICES_PER_FACE; ++i) // for each triangle vertex { // NOTE: See above, we don't make FragPos a uniform. vec3 fragPos = gl_in[i].gl_Position.xyz; - // FragPos = fragPos - (lights[((/*FragLayer*/layer - 1u) & 31u)].light_pos.xyz - focus_off.xyz); - // FragLayer = layer; - // float lightDistance = length(FragPos - lights[((layer - 1) & 31)].light_pos.xyz); - // lightDistance /= screen_res.w; - - // vec4 FragPos = gl_in[i].gl_Position; - // NOTE: Our normals map to the same thing as cube map normals, *except* that their normal direction is - // swapped; we can fix this by doing normal ^ 0x1u. However, we also want to cull back faces, not front - // faces, so we only care about the shadow cast by the *back* of the triangle, which means we ^ 0x1u - // again and cancel it out. - // int face = int(((floatBitsToUint(gl_Position.w) >> 29) & 0x7u) ^ 0x1u); + int layer_face = layer_base + face; - gl_Layer = face;//layer_face; // built-in variable that specifies to which face we render. + gl_Layer = face; // built-in variable that specifies to which face we render. gl_Position = shadowMats[layer_face].shadowMatrices * vec4(fragPos, 1.0); - // gl_Position.z = -((gl_Position.z + screen_res.z) / (screen_res.w - screen_res.z)) * lightDistance; - // gl_Position.z = gl_Position.z / screen_res.w; - // gl_Position.z = gl_Position.z / gl_Position.w; - // gl_Position.z = -1000.0 / (gl_Position.z + 10000.0); - // lightDistance = -(lightDistance + screen_res.z) / (screen_res.w - screen_res.z); - // gl_Position.z = lightDistance; EmitVertex(); } EndPrimitive(); diff --git a/assets/voxygen/shaders/light-shadows-vert.glsl b/assets/voxygen/shaders/light-shadows-vert.glsl index 28b349b15d..1db7b1c304 100644 --- a/assets/voxygen/shaders/light-shadows-vert.glsl +++ b/assets/voxygen/shaders/light-shadows-vert.glsl @@ -27,8 +27,6 @@ * */ layout(location = 1) in uint v_pos_norm; -// in uint v_col_light; -// in vec4 v_pos; // Light projection matrices. layout (std140, set = 1, binding = 0) @@ -38,16 +36,11 @@ uniform u_locals { float load_time; }; -// out vec4 shadowMapCoord; - const int EXTRA_NEG_Z = 32768; void main() { vec3 f_chunk_pos = vec3(ivec3((uvec3(v_pos_norm) >> uvec3(0, 6, 12)) & uvec3(0x3Fu, 0x3Fu, 0xFFFFu)) - ivec3(0, 0, EXTRA_NEG_Z)); vec3 f_pos = (model_mat * vec4(f_chunk_pos, 1.0)).xyz - focus_off.xyz; - // f_pos = v_pos; - gl_Position = /*all_mat * */vec4(f_pos/*, 1.0*/, /*float(((f_pos_norm >> 29) & 0x7u) ^ 0x1)*//*uintBitsToFloat(v_pos_norm)*/1.0); - // shadowMapCoord = lights[gl_InstanceID].light_pos * gl_Vertex; - // vec4(v_pos, 0.0, 1.0); + gl_Position = vec4(f_pos, 1.0); } diff --git a/assets/voxygen/shaders/lod-terrain-frag.glsl b/assets/voxygen/shaders/lod-terrain-frag.glsl index 6c24da4383..92eea0a0c8 100644 --- a/assets/voxygen/shaders/lod-terrain-frag.glsl +++ b/assets/voxygen/shaders/lod-terrain-frag.glsl @@ -26,93 +26,20 @@ layout(location = 0) in vec3 f_pos; layout(location = 1) in vec3 f_norm; layout(location = 2) in float pull_down; -// in vec2 v_pos_orig; -// in vec4 f_shadow; -// in vec4 f_square; layout(location = 0) out vec4 tgt_color; layout(location = 1) out uvec4 tgt_mat; -/// const vec4 sun_pos = vec4(0); -// const vec4 light_pos[2] = vec4[](vec4(0), vec4(0)/*, vec3(00), vec3(0), vec3(0), vec3(0)*/); - #include void main() { - // tgt_color = vec4(vec3(1.0), 1.0); - // return; - // vec3 f_pos = lod_pos(f_pos.xy); - // vec3 f_col = lod_col(f_pos.xy); - - // vec4 vert_pos4 = view_mat * vec4(f_pos, 1.0); - // vec3 view_dir = normalize(-vec3(vert_pos4)/* / vert_pos4.w*/); - #ifdef EXPERIMENTAL_BAREMINIMUM tgt_color = vec4(simple_lighting(f_pos.xyz, lod_col(f_pos.xy), 1.0), 1); + tgt_mat = uvec4(uvec3((f_norm + 1.0) * 127.0), MAT_LOD); #else - float my_alt = /*f_pos.z;*/alt_at_real(f_pos.xy); - // vec3 f_pos = vec3(f_pos.xy, max(my_alt, f_pos.z)); - /* gl_Position = - proj_mat * - view_mat * - vec4(f_pos, 1); - gl_Position.z = -1000.0 / (gl_Position.z + 10000.0); */ + float my_alt = alt_at_real(f_pos.xy); vec3 f_pos = vec3(f_pos.xy, my_alt); - //vec3 my_norm = lod_norm(f_pos.xy/*, f_square*/); - - //float which_norm = dot(my_norm, normalize(cam_pos.xyz - my_pos)); - // which_norm = 0.5 + which_norm * 0.5; - - // which_norm = pow(max(0.0, which_norm), /*0.03125*/1 / 8.0);// * 0.5; - // smoothstep - //which_norm = which_norm * which_norm * (3 - 2 * abs(which_norm)); - - // which_norm = mix(0.0, 1.0, which_norm > 0.0); - // vec3 normals[6] = vec3[](vec3(-1,0,0), vec3(1,0,0), vec3(0,-1,0), vec3(0,1,0), vec3(0,0,-1), vec3(0,0,1)); - // vec3 f_norm = lod_norm(f_pos.xy);//mix(faceforward(f_norm, cam_pos.xyz - f_pos, -f_norm), my_norm, which_norm); - // vec3 fract_pos = fract(f_pos); - /* if (length(f_pos - cam_pos.xyz) <= view_distance.x + 32.0) { - vec4 new_f_pos; - float depth = 10000000.0; - vec4 old_coord = all_mat * vec4(f_pos.xyz, 1.0); - for (int i = 0; i < 6; i ++) { - // vec4 square = focus_pos.xy + vec4(splay(pos - vec2(1.0, 1.0), splay(pos + vec2(1.0, 1.0)))); - vec3 my_f_norm = normals[i]; - vec3 my_f_tan = normals[(i + 2) % 6]; - vec3 my_f_bitan = normals[(i + 4) % 6]; - mat4 foo = mat4(vec4(my_f_tan, 0), vec4(my_f_bitan, 0), vec4(my_f_norm, 0), vec4(0, 0, 0, 1)); - mat4 invfoo = foo * inverse(foo * all_mat); - vec4 my_f_pos = invfoo * (old_coord);//vec4(f_pos, 1.0); - vec4 my_f_proj = all_mat * my_f_pos; - if (my_f_proj.z <= depth) { - new_f_pos = my_f_pos; - f_norm = my_f_norm; - depth = my_f_proj.z; - } - } - // f_pos = new_f_pos.xyz; - } */ - - // Test for distance to all 6 sides of the enclosing cube. - // if (/*any(lessThan(fract(f_pos.xy), 0.01))*/fract_pos.x <= 0.1) { - // f_norm = faceforward(vec3(-1, 0, 0), f_norm, vec3(1, 0, 0)); - // f_tan = vec3(0, 1, 0); - // } else if (fract_pos.y <= 0.1) { - // f_norm = faceforward(vec3(0, -1, 0), f_norm, vec3(0, 1, 0)); - // f_tan = vec3(0, 0, 1); - // } else { - // f_norm = faceforward(vec3(0, 0, -1), f_norm, vec3(0, 0, 1)); - // f_tan = vec3(1, 0, 0); - // } - // vec3 f_bitan = cross(f_norm, f_tan); - - // mat4 foo = mat4(vec4(f_tan, 0), vec4(f_bitan, 0), vec4(f_norm, 0), vec4(0, 0, 0, 1)); - // mat4 invfoo = foo * inverse(foo * all_mat); - // vec3 old_coord = all_mat * vec4(f_pos.xyz, 1.0); - // vec4 new_f_pos = invfoo * (old_coord);//vec4(f_pos, 1.0); - // tgt_color = vec4(f_col, 1.0); - vec3 cam_to_frag = normalize(f_pos - cam_pos.xyz); vec3 view_dir = -cam_to_frag; @@ -124,131 +51,22 @@ void main() { vec3 f_col_raw = mix(lod_col(f_pos.xy), vec3(0), clamp(pull_down / 30, 0, 1)); - /* vec3 sun_dir = get_sun_dir(time_of_day.x); - vec3 moon_dir = get_moon_dir(time_of_day.x); */ - // voxel_norm = vec3(0.0); - -#if (SHADOW_MODE == SHADOW_MODE_CHEAP || SHADOW_MODE == SHADOW_MODE_MAP || FLUID_MODE >= FLUID_MODE_MEDIUM) - float shadow_alt = /*f_pos.z;*/alt_at(f_pos.xy);//max(alt_at(f_pos.xy), f_pos.z); - // float shadow_alt = f_pos.z; -#elif (SHADOW_MODE == SHADOW_MODE_NONE || FLUID_MODE == FLUID_MODE_LOW) - float shadow_alt = f_pos.z; -#endif + float shadow_alt = my_alt; #if (SHADOW_MODE == SHADOW_MODE_CHEAP || SHADOW_MODE == SHADOW_MODE_MAP) vec4 f_shadow = textureMaybeBicubic(t_horizon, s_horizon, pos_to_tex(f_pos.xy)); float sun_shade_frac = horizon_at2(f_shadow, shadow_alt, f_pos, sun_dir); - // float sun_shade_frac = 1.0; #elif (SHADOW_MODE == SHADOW_MODE_NONE) - float sun_shade_frac = 1.0;//horizon_at2(f_shadow, shadow_alt, f_pos, sun_dir); + float sun_shade_frac = 1.0; #endif - float moon_shade_frac = 1.0;//horizon_at2(f_shadow, shadow_alt, f_pos, moon_dir); + float moon_shade_frac = 1.0; - // Magic stop-gap code without any physical justification. - //vec3 lerpy_norm; - //if (my_norm.z/*f_norm.z*/ > 0.99999) { - // lerpy_norm = vec3(0, 0, 1); - //} else { - // vec3 side_norm = normalize(vec3(my_norm.xy, 0)); - // // lerpy_norm = f_norm; - // float mix_factor = clamp(abs(dot(f_orig_view_dir, side_norm)), 0, 1); - // lerpy_norm = mix( - // mix(my_norm, side_norm, clamp(dot(side_norm, my_norm) + 0.5, 0, 1)), - // my_norm, - // mix_factor - // ); - //} - //const float DIST = 0.07; - /* voxel_norm = normalize(mix(voxel_norm, lerpy_norm, clamp(my_norm.z * my_norm.z - (1.0 - DIST), 0, 1) / DIST)); */ - - //f_pos.xyz += abs(voxel_norm) * delta_sides; - /* voxel_norm = mix(my_norm, voxel_norm == vec3(0.0) ? f_norm : voxel_norm, voxelize_factor); */ - - //vec3 hash_pos = f_pos + focus_off.xyz; - //const float A = 0.055; - //const float W_INV = 1 / (1 + A); - //const float W_2 = W_INV * W_INV;//pow(W_INV, 2.4); - //const float NOISE_FACTOR = 0.02;//pow(0.02, 1.2); - //float noise = hash(vec4(floor(hash_pos * 3.0 - voxel_norm * 0.5), 0));//0.005/* - 0.01*/; - //vec3 noise_delta = (sqrt(f_col_raw) * W_INV + noise * NOISE_FACTOR); - // noise_delta = noise_delta * noise_delta * W_2 - f_col; - // lum = W ⋅ col - // lum + noise = W ⋅ (col + delta) - // W ⋅ col + noise = W ⋅ col + W ⋅ delta - // noise = W ⋅ delta - // delta = noise / W - // vec3 col = (f_col + noise_delta); - // vec3 col = noise_delta * noise_delta * W_2; - - vec3 f_col = f_col_raw;//noise_delta * noise_delta * W_2; - // f_col = /*srgb_to_linear*/(f_col + hash(vec4(floor(hash_pos * 3.0 - voxel_norm * 0.5), 0)) * 0.01/* - 0.01*/); // Small-scale noise - - // f_ao = 1.0; - // f_ao = dot(f_ao_vec, sqrt(1.0 - delta_sides * delta_sides)); - - //f_ao *= dot(f_ao_vec, abs(voxel_norm)); - // f_ao = sqrt(dot(f_ao_vec * abs(voxel_norm), sqrt(1.0 - delta_sides * delta_sides)) / 3.0); - - // vec3 ao_pos2 = min(fract(f_pos), 1.0 - fract(f_pos)); - // f_ao = sqrt(dot(ao_pos2, ao_pos2)); - // // f_ao = dot(abs(voxel_norm), f_ao_vec); - // // voxel_norm = f_norm; - - // Note: because voxels, we reduce the normal for reflections to just its z component, dpendng on distance to camera. - // Idea: the closer we are to facing top-down, the more the norm should tend towards up-z. - // vec3 l_norm; // = vec3(0.0, 0.0, 1.0); - // vec3 l_norm = normalize(vec3(f_norm.x / max(abs(f_norm.x), 0.001), f_norm.y / max(abs(f_norm.y), 0.001), f_norm.z / max(abs(f_norm.z), 0.001))); - // vec3 l_factor = 1.0 / (1.0 + max(abs(/*f_pos - cam_pos.xyz*//*-vec3(vert_pos4) / vert_pos4.w*/vec3(f_pos.xy, 0.0) - vec3(/*cam_pos*/focus_pos.xy, cam_to_frag)) - vec3(view_distance.x, view_distance.x, 0.0), 0.0) / vec3(32.0 * 2.0, 32.0 * 2.0, 1.0)); - // l_factor.z = - // vec4 focus_pos4 = view_mat * vec4(focus_pos.xyz, 1.0); - // vec3 focus_dir = normalize(-vec3(focus_pos4) / focus_pos4.w); - - // float l_factor = 1.0 - pow(clamp(0.5 + 0.5 * dot(/*-view_dir*/-cam_to_frag, l_norm), 0.0, 1.0), 2.0);//1.0 / (1.0 + 0.5 * pow(max(distance(/*focus_pos.xy*/vec3(focus_pos.xy, /*vert_pos4.z / vert_pos4.w*/f_pos.z), vec3(f_pos.xy, f_pos.z))/* - view_distance.x*/ - 32.0, 0.0) / (32.0 * 1.0), /*0.5*/1.0)); - // l_factor = 1.0; - // l_norm = normalize(mix(l_norm, f_norm, l_factor)); - // l_norm = f_norm; - - /* l_norm = normalize(vec3( - mix(l_norm.x, f_norm.x, clamp(pow(f_norm.x * 0.5, 64), 0, 1)), - mix(-1.0, 1.0, clamp(pow(f_norm.y * 0.5, 64), 0, 1)), - mix(-1.0, 1.0, clamp(pow(f_norm.z * 0.5, 64), 0, 1)) - )); */ - // f_norm = mix(l_norm, f_norm, min(1.0 / max(cam_to_frag, 0.001), 1.0)); - /* vec3 l_norm = normalize(vec3( - mix(-1.0, 1.0, clamp(pow(f_norm.x * 0.5, 64), 0, 1)), - mix(-1.0, 1.0, clamp(pow(f_norm.y * 0.5, 64), 0, 1)), - mix(-1.0, 1.0, clamp(pow(f_norm.z * 0.5, 64), 0, 1)) - )); */ - // vec3 view_dir = normalize(f_pos - cam_pos.xyz); - - - // vec3 sun_dir = get_sun_dir(time_of_day.x); - // vec3 moon_dir = get_moon_dir(time_of_day.x); - // // float sun_light = get_sun_brightness(sun_dir); - // // float moon_light = get_moon_brightness(moon_dir); - // // float my_alt = f_pos.z;//alt_at_real(f_pos.xy); - // // vec3 f_norm = my_norm; - // // vec4 f_shadow = textureMaybeBicubic(t_horizon, pos_to_tex(f_pos.xy)); - // // float shadow_alt = /*f_pos.z;*/alt_at(f_pos.xy);//max(alt_at(f_pos.xy), f_pos.z); - // // float my_alt = alt_at(f_pos.xy); - // float sun_shade_frac = horizon_at2(f_shadow, shadow_alt, f_pos, sun_dir); - // float moon_shade_frac = horizon_at2(f_shadow, shadow_alt, f_pos, moon_dir); - // // float sun_shade_frac = horizon_at(/*f_shadow, f_pos.z, */f_pos, sun_dir); - // // float moon_shade_frac = horizon_at(/*f_shadow, f_pos.z, */f_pos, moon_dir); - // // Globbal illumination "estimate" used to light the faces of voxels which are parallel to the sun or moon (which is a very common occurrence). - // // Will be attenuated by k_d, which is assumed to carry any additional ambient occlusion information (e.g. about shadowing). - // // float ambient_sides = clamp(mix(0.5, 0.0, abs(dot(-f_norm, sun_dir)) * 10000.0), 0.0, 0.5); - // // NOTE: current assumption is that moon and sun shouldn't be out at the sae time. - // // This assumption is (or can at least easily be) wrong, but if we pretend it's true we avoids having to explicitly pass in a separate shadow - // // for the sun and moon (since they have different brightnesses / colors so the shadows shouldn't attenuate equally). - // // float shade_frac = sun_shade_frac + moon_shade_frac; - // // float brightness_denominator = (ambient_sides + vec3(SUN_AMBIANCE * sun_light + moon_light); - - // DirectionalLight sun_info = get_sun_info(sun_dir, sun_shade_frac, light_pos); + vec3 f_col = f_col_raw; + DirectionalLight sun_info = get_sun_info(sun_dir, sun_shade_frac, /*sun_pos*/f_pos); DirectionalLight moon_info = get_moon_info(moon_dir, moon_shade_frac/*, light_pos*/); - float alpha = 1.0;//0.1;//0.2;///1.0;//sqrt(2.0); + float alpha = 1.0; const float n2 = 1.5; const float R_s2s0 = pow(abs((1.0 - n2) / (1.0 + n2)), 2); const float R_s1s0 = pow(abs((1.3325 - n2) / (1.3325 + n2)), 2); @@ -262,77 +80,21 @@ void main() { vec3 mu = medium.x == MEDIUM_WATER ? MU_WATER : vec3(0.0); // NOTE: Default intersection point is camera position, meaning if we fail to intersect we assume the whole camera is in water. - vec3 cam_attenuation = compute_attenuation_point(f_pos, view_dir, mu, fluid_alt, /*cam_pos.z <= fluid_alt ? cam_pos.xyz : f_pos*/cam_pos.xyz); - // Use f_norm here for better shadows. - // vec3 light_frac = light_reflection_factor(f_norm/*l_norm*/, view_dir, vec3(0, 0, -1.0), vec3(1.0), vec3(/*1.0*/R_s), alpha); + vec3 cam_attenuation = compute_attenuation_point(f_pos, view_dir, mu, fluid_alt, cam_pos.xyz); - // vec3 light, diffuse_light, ambient_light; - // get_sun_diffuse(f_norm, time_of_day.x, cam_to_frag, (0.25 * shade_frac + 0.25 * light_frac) * f_col, 0.5 * shade_frac * f_col, 0.5 * shade_frac * /*vec3(1.0)*/f_col, 2.0, emitted_light, reflected_light); float max_light = 0.0; vec3 k_a = vec3(1.0); vec3 k_d = vec3(1.0); - max_light += get_sun_diffuse2(sun_info, moon_info, voxel_norm/*l_norm*/, view_dir, f_pos, vec3(0.0), cam_attenuation, fluid_alt, k_a/* * (0.5 * light_frac + vec3(0.5 * shade_frac))*/, k_d, /*0.5 * shade_frac * *//*vec3(1.0)*//*f_col*/vec3(R_s), alpha, voxel_norm, 0.0/*max(distance(focus_pos.xy, f_pos.xyz) - view_distance.x, 0.0) / 1000 < 1.0*/, emitted_light, reflected_light); - // emitted_light = vec3(1.0); - // emitted_light *= max(shade_frac, MIN_SHADOW); - // reflected_light *= shade_frac; - // max_light *= shade_frac; - // reflected_light = vec3(0.0); - - // dot(diffuse_factor, /*R_r * */vec4(abs(norm) * (1.0 - dist), dist)) - - // corner_xy = mix(all(lessThan(corner_xy, 1.0)) ? vec2(0.0) : 0.4 * (), 1.0 - // - // TODO: Handle similar logic for z. - - // So we repeat this for all three sides to find the "next" position on each side. - // vec3 delta_sides = 1.0 + sides * fract(-sides * f_pos); - // Now, we - // Now, all we have to do is find out whether (again, assuming f_pos is positive) next_sides represents a new integer. - // We currently just treat this as "new floor != old floor". - - // So to find the position at the nearest voxel, we just subtract voxel_norm * fract(sides * ) from f_pos.z. - // Then to find out whether we meet a new "block" in 1 voxel, we just - // on the "other" side can be found (according to my temporary theory) as the cross product - // vec3 norm = normalize(cross( - // vec3(/*2.0 * SAMPLE_W*/square.z - square.x, 0.0, altx1 - altx0), - // vec3(0.0, /*2.0 * SAMPLE_W*/square.w - square.y, alty1 - alty0) - // )); - // vec3 norm = normalize(vec3( - // (altx0 - altx1) / (square.z - square.x), - // (alty0 - alty1) / (square.w - square.y), - // 1.0 - // //(abs(square.w - square.y) + abs(square.z - square.x)) / (slope + 0.00001) // Avoid NaN - // )); - // - // If a side coordinate is 0, then it counts as no AO; - // otherwise, it counts as fractional AO. So what we need is to know whether the fractional AO to the next block in that direction pushes us to a new integer. - // - // vec3 ao_pos_z = floor(f_pos + f_norm); - // vec3 ao_pos_z = corner_distance; - // vec3 ao_pos = 0.5 - clamp(min(fract(abs(f_pos)), 1.0 - fract(abs(f_pos))), 0.0, 0.5); - // - // f_ao = /*sqrt*/1.0 - 2.0 * sqrt(dot(ao_pos, ao_pos) / 2.0); - // f_ao = /*sqrt*/1.0 - (dot(ao_pos, ao_pos)/* / 2.0*/); - // f_ao = /*sqrt*/1.0 - 2.0 * (dot(ao_pos, ao_pos)/* / 2.0*/); - // f_ao = /*sqrt*/1.0 - 2.0 * sqrt(dot(ao_pos, ao_pos) / 2.0); - float ao = f_ao;// /*pow(f_ao, 0.5)*/f_ao * 0.9 + 0.1; + max_light += get_sun_diffuse2(sun_info, moon_info, voxel_norm, view_dir, f_pos, vec3(0.0), cam_attenuation, fluid_alt, k_a, k_d, vec3(R_s), alpha, voxel_norm, 0.0, emitted_light, reflected_light); + + float ao = f_ao; emitted_light *= ao; reflected_light *= ao; - // emitted_light += 0.5 * vec3(SUN_AMBIANCE * sun_shade_frac * sun_light + moon_shade_frac * moon_light) * f_col * (ambient_sides + 1.0); - - // Ambient lighting attempt: vertical light. - // reflected_light += /*0.0125*/0.15 * 0.25 * _col * light_reflection_factor(f_norm, cam_to_frag, vec3(0, 0, -1.0), 0.5 * f_col, 0.5 * f_col, 2.0); - // emitted_light += /*0.0125*/0.25 * f_col * ; - // vec3 light, diffuse_light, ambient_light; - // get_sun_diffuse(f_norm, time_of_day.x, light, diffuse_light, ambient_light, 1.0); - // vec3 surf_color = illuminate(f_col, light, diffuse_light, ambient_light); - // f_col = f_col + (hash(vec4(floor(vec3(focus_pos.xy + splay(v_pos_orig), f_pos.z)) * 3.0 - round(f_norm) * 0.5, 0)) - 0.5) * 0.05; // Small-scale noise vec3 surf_color; float surf_alpha = 1.0; uint mat; - // NOTE: On nvidea vulkan drivers a `pow` with negative base results in NaN even if the - // exponent is an integer. + // NOTE: On nvidea vulkan drivers a `pow` with negative base results in NaN even if the exponent is an integer. vec3 water_col_diff = f_col_raw - vec3(0.02, 0.06, 0.22); if (dot(water_col_diff * water_col_diff, vec3(1)) < 0.01 && dot(vec3(0, 0, 1), f_norm) > 0.9) { mat = MAT_WATER; diff --git a/assets/voxygen/shaders/lod-terrain-vert.glsl b/assets/voxygen/shaders/lod-terrain-vert.glsl index ae2810d2c4..39c287b14a 100644 --- a/assets/voxygen/shaders/lod-terrain-vert.glsl +++ b/assets/voxygen/shaders/lod-terrain-vert.glsl @@ -25,10 +25,6 @@ layout(location = 0) in vec2 v_pos; layout(location = 0) out vec3 f_pos; layout(location = 1) out vec3 f_norm; layout(location = 2) out float pull_down; -// out vec2 v_pos_orig; -// out vec4 f_square; -// out vec4 f_shadow; -// out float f_light; void main() { // Find distances between vertices. Pull down a tiny bit more to reduce z fighting near the ocean. @@ -38,18 +34,7 @@ void main() { vec4 f_square = focus_pos.xyxy + vec4(splay(v_pos - dims), splay(v_pos + dims)); f_norm = lod_norm(f_pos.xy, f_square); #endif - // v_pos_orig = v_pos; - - // f_pos = lod_pos(focus_pos.xy + splay(v_pos) * /*1000000.0*/(1 << 20), square); - - // f_norm = lod_norm(f_pos.xy); - - // f_shadow = textureMaybeBicubic(t_horizon, pos_to_tex(f_pos.xy)); - - // TODO: disabled because it isn't designed to work with reverse depth - //float dist = distance(focus_pos.xy, f_pos.xy); - //pull_down = 0.2 / pow(dist / (view_distance.x * 0.9), 20.0); - + pull_down = 1.0 / pow(distance(focus_pos.xy, f_pos.xy) / (view_distance.x * 0.95), 20.0); f_pos.z -= pull_down; @@ -57,59 +42,5 @@ void main() { f_pos.z -= pow(distance(f_pos.xy + focus_off.xy, focus_pos.xy + focus_off.xy) * 0.05, 2); #endif - // f_pos.z -= 100.0 * pow(1.0 + 0.01 / view_distance.x, -pow(distance(focus_pos.xy, f_pos.xy), 2.0)); - // f_pos.z = mix(-f_pos.z, f_pos.z, view_distance.x <= distance(focus_pos.xy, f_pos.xy) + 32.0); - - // bool faces_fluid = false;// bool((f_pos_norm >> 28) & 0x1u); - // // TODO: Measure real water surface altitude here. - // float surfaceAlt = mix(view_distance.z, /*floor*/(min(f_pos.z, floor(alt_at_real(cam_pos.xy)))), medium.x); - // // float surfaceAlt = mix(view_distance.z, floor(max(cam_pos.z, alt_at_real(cam_pos.xy))), medium.x); - // // float surfaceAlt = min(floor(f_pos.z), floor(alt_at_real(cam_pos.xy))); // faces_fluid ? max(ceil(f_pos.z), floor(f_alt)) : floor(f_alt); - - // f_pos.z -= max(sign(view_distance.x - distance(focus_pos.xy, f_pos.xy)), 0.0) * (32.0 * view_distance.z / 255 + 32.0 * max(0.0, f_pos.z - cam_pos.z)); - // f_pos.z -= 0.1 + max(view_distance.x - distance(focus_pos.xy, f_pos.xy), 0.0) * (1.0 + max(1.0, ceil(f_pos.z - focus_pos.z))); - - // vec3 wRayinitial = f_pos; // cam_pos.z < f_pos.z ? f_pos : cam_pos.xyz; - // vec3 wRayfinal = cam_pos.xyz; // cam_pos.z < f_pos.z ? cam_pos.xyz : f_pos; - // wRayfinal = dot(wRayfinal - wRayinitial, focus_pos.xyz - cam_pos.xyz) < 0.0 ? wRayfinal : wRayinitial; - // vec3 wRayNormal = /*surfaceAlt < wRayinitial.z ? vec3(0.0, 0.0, -1.0) : */vec3(0.0, 0.0, 1.0); - // float n_camera = mix(1.0, 1.3325, medium.x); - // float n_vertex = faces_fluid ? 1.3325 : 1.0; - // float n1 = n_vertex; // cam_pos.z < f_pos.z ? n_vertex : n_camera; - // float n2 = n_camera; // cam_pos.z < f_pos.z ? n_camera : n_vertex; - - // float wRayLength0 = length(wRayfinal - wRayinitial); - // vec3 wRayDir = (wRayfinal - wRayinitial) / wRayLength0; - // vec3 wPoint = wRayfinal; - // bool wIntersectsSurface = IntersectRayPlane(wRayinitial, wRayDir, vec3(0.0, 0.0, surfaceAlt), -wRayNormal, wPoint); - // float wRayLength = length(wPoint - wRayinitial); - // wPoint = wRayLength < wRayLength0 ? wPoint : wRayfinal; - // wRayLength = min(wRayLength, wRayLength0); // min(max_length, dot(wRayfinal - wpos, defaultpos - wpos)); - - // // vec3 wRayDir2 = (wRayfinal - wRayinitial) / wRayLength; - - // vec3 wRayDir3 = (dot(wRayDir, wRayNormal) < 0.0 && surfaceAlt < wRayinitial.z && wIntersectsSurface/* && medium.x == 1u*/) ? refract(wRayDir, wRayNormal, n2 / n1) : wRayDir; - // // wPoint -= wRayDir3 * wRayLength * n2 / n1; - - // vec3 newRay = (dot(wRayDir3, focus_pos.xyz - cam_pos.xyz) < 0.0 && /*dot(wRayDir, wRayNormal) > 0.0 && *//*surfaceAlt < wRayinitial.z && */wIntersectsSurface && medium.x == 1u) ? wPoint - wRayDir3 * wRayLength * n2 / n1/*wPoint - wRayDir3 * wRayLength * n2 / n1*/ : f_pos;// - (wRayfinal - wPoint) * n2 / n1; // wPoint + n2 * (wRayfinal - wPoint) - n2 / n1 * wRayLength * wRayDir3; - - // newRay.z -= max(view_distance.x - distance(focus_pos.xy, f_pos.xy), 0.0) * (1.0 + max(0.0, f_pos.z - focus_pos.z)); - - - // f_light = 1.0; - - gl_Position = - /* proj_mat * - view_mat * */ - all_mat * - vec4(f_pos/*newRay*/, 1); - // Pull up the depth to avoid drawing over voxels (biased according to VD) - // TODO: disabled because it isn't designed to work with reverse depth - //gl_Position.z += 0.1 * clamp((view_distance.x * 1.0 - dist) * 0.01, 0, 1); - - // gl_Position.z = -gl_Position.z / gl_Position.w; - // gl_Position.z = -gl_Position.z / gl_Position.w; - // gl_Position.z = -gl_Position.z * gl_Position.w; - // gl_Position.z = -gl_Position.z / 100.0; - // gl_Position.z = -1000.0 / (gl_Position.z + 10000.0); + gl_Position = all_mat * vec4(f_pos, 1); } diff --git a/assets/voxygen/shaders/particle-frag.glsl b/assets/voxygen/shaders/particle-frag.glsl index 6decf513d2..0a76fe87b3 100644 --- a/assets/voxygen/shaders/particle-frag.glsl +++ b/assets/voxygen/shaders/particle-frag.glsl @@ -83,8 +83,8 @@ void main() { const float LIGHT_FADEOUT_OFFSET = 16.0; const float LIGHT_FADEOUT_DIST = 32.0; - sun_info.block *= f_voxel_light.x;//min(f_voxel_light.x, clamp((f_pos.z - f_alt + LIGHT_FADEOUT_OFFSET) / LIGHT_FADEOUT_DIST + 1, 0, 1)); - moon_info.block *= f_voxel_light.x;//min(f_voxel_light.x, clamp((f_pos.z - f_alt + LIGHT_FADEOUT_OFFSET) / LIGHT_FADEOUT_DIST + 1, 0, 1)); + sun_info.block *= f_voxel_light.x; + moon_info.block *= f_voxel_light.x; // To account for prior saturation. float max_light = 0.0; @@ -94,8 +94,8 @@ void main() { vec3 mu = medium.x == MEDIUM_WATER ? MU_WATER : vec3(0.0); #if (FLUID_MODE >= FLUID_MODE_MEDIUM) cam_attenuation = - medium.x == MEDIUM_WATER ? compute_attenuation_point(cam_pos.xyz, view_dir, MU_WATER, fluid_alt, /*cam_pos.z <= fluid_alt ? cam_pos.xyz : f_pos*/f_pos) - : compute_attenuation_point(f_pos, -view_dir, vec3(0), fluid_alt, /*cam_pos.z <= fluid_alt ? cam_pos.xyz : f_pos*/cam_pos.xyz); + medium.x == MEDIUM_WATER ? compute_attenuation_point(cam_pos.xyz, view_dir, MU_WATER, fluid_alt, f_pos) + : compute_attenuation_point(f_pos, -view_dir, vec3(0), fluid_alt, cam_pos.xyz); #endif max_light += get_sun_diffuse2(sun_info, moon_info, f_norm, view_dir, f_pos, mu, cam_attenuation, fluid_alt, k_a, k_d, k_s, alpha, f_norm, 1.0, emitted_light, reflected_light); diff --git a/assets/voxygen/shaders/particle-vert.glsl b/assets/voxygen/shaders/particle-vert.glsl index dfd0caadfa..77155778a5 100644 --- a/assets/voxygen/shaders/particle-vert.glsl +++ b/assets/voxygen/shaders/particle-vert.glsl @@ -18,7 +18,6 @@ #include layout(location = 0) in vec3 v_pos; -// in uint v_col; layout(location = 1) in uint v_norm_ao; layout(location = 2) in float inst_time; layout(location = 3) in float inst_lifespan; @@ -32,8 +31,6 @@ layout(location = 9) in vec2 inst_voxel_light; layout(location = 0) out vec3 f_pos; layout(location = 1) flat out vec3 f_norm; layout(location = 2) out vec4 f_col; -//layout(location = x) out float f_ao; -//layout(location = x) out float f_light; layout(location = 3) out float f_reflect; layout(location = 4) flat out int f_mode; layout(location = 5) out vec2 f_voxel_light; @@ -1367,11 +1364,8 @@ void main() { vec4(0,0,-1,0), vec4(0,0,1,0) ); - f_norm = - // inst_pos * - normalize(((normals[(v_norm_ao >> 0) & 0x7u]) * attr.rot).xyz); + f_norm = normalize(((normals[(v_norm_ao >> 0) & 0x7u]) * attr.rot).xyz); - //vec3 col = vec3((uvec3(v_col) >> uvec3(0, 8, 16)) & uvec3(0xFFu)) / 255.0; f_col = vec4(attr.col.rgb, attr.col.a); f_mode = inst_mode; diff --git a/assets/voxygen/shaders/player-shadow-frag.glsl b/assets/voxygen/shaders/player-shadow-frag.glsl index d64be8f67e..679093a2a9 100644 --- a/assets/voxygen/shaders/player-shadow-frag.glsl +++ b/assets/voxygen/shaders/player-shadow-frag.glsl @@ -20,8 +20,6 @@ in vec3 f_pos; in vec3 f_col; flat in vec3 f_norm; in float f_ao; -// in float f_alt; -// in vec4 f_shadow; layout (std140) uniform u_locals { @@ -51,17 +49,5 @@ uniform u_bones { out vec4 tgt_color; void main() { - // float distance = distance(vec3(cam_pos), focus_pos.xyz) - 2; - - // float opacity = clamp(distance / distance_divider, 0, 1); - - // if(threshold_matrix[int(gl_FragCoord.x) % 4][int(gl_FragCoord.y) % 4] > opacity) { - // discard; - // } - - // if(threshold_matrix[int(gl_FragCoord.x) % 4][int(gl_FragCoord.y) % 4] > shadow_dithering) { - // discard; - // } - - tgt_color = vec4(0.0,0.0,0.0, 1.0); + tgt_color = vec4(0.0, 0.0, 0.0, 1.0); } diff --git a/assets/voxygen/shaders/point-light-shadows-vert.glsl b/assets/voxygen/shaders/point-light-shadows-vert.glsl index 92bd3dbe96..16fa2ab53a 100644 --- a/assets/voxygen/shaders/point-light-shadows-vert.glsl +++ b/assets/voxygen/shaders/point-light-shadows-vert.glsl @@ -27,9 +27,6 @@ * */ layout(location = 0) in uint v_pos_norm; -// layout(location = 1) in uint v_atlas_pos; -// in uint v_col_light; -// in vec4 v_pos; // Light projection matrices. layout (std140, set = 1, binding = 0) @@ -39,8 +36,6 @@ uniform u_locals { float load_time; }; -// out vec4 shadowMapCoord; - const float EXTRA_NEG_Z = 32768.0; layout( push_constant ) uniform PointLightMatrix { @@ -50,10 +45,6 @@ layout( push_constant ) uniform PointLightMatrix { void main() { vec3 f_chunk_pos = vec3(v_pos_norm & 0x3Fu, (v_pos_norm >> 6) & 0x3Fu, float((v_pos_norm >> 12) & 0xFFFFu) - EXTRA_NEG_Z); vec3 f_pos = (model_mat * vec4(f_chunk_pos, 1.0)).xyz - focus_off.xyz; - // f_pos = v_pos; - - // gl_Position = /*all_mat * */vec4(f_pos/*, 1.0*/, /*float(((f_pos_norm >> 29) & 0x7u) ^ 0x1)*//*uintBitsToFloat(v_pos_norm)*/1.0); - // shadowMapCoord = lights[gl_InstanceID].light_pos * gl_Vertex; - // vec4(v_pos, 0.0, 1.0); + gl_Position = lightShadowMatrix * vec4(f_pos, 1.0); } diff --git a/assets/voxygen/shaders/postprocess-frag.glsl b/assets/voxygen/shaders/postprocess-frag.glsl index fa8b9f1e9f..b9b637c636 100644 --- a/assets/voxygen/shaders/postprocess-frag.glsl +++ b/assets/voxygen/shaders/postprocess-frag.glsl @@ -74,35 +74,17 @@ vec3 hsv2rgb(vec3 c) { return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); } -vec3 _illuminate(float max_light, vec3 view_dir, /*vec3 max_light, */vec3 emitted, vec3 reflected) { - const float NIGHT_EXPOSURE = 10.0; - const float DUSK_EXPOSURE = 2.0;//0.8; - const float DAY_EXPOSURE = 1.0;//0.7; - - const float DAY_SATURATION = 1.0; - const float DUSK_SATURATION = 0.6; - const float NIGHT_SATURATION = 0.1; - - const float gamma = /*0.5*//*1.*0*/1.0;//1.0; - /* float light = length(emitted + reflected); - float color = srgb_to_linear(emitted + reflected); - float avg_col = (color.r + color.g + color.b) / 3.0; - return ((color - avg_col) * light + reflected * avg_col) * (emitted + reflected); */ - // float max_intensity = vec3(1.0); +vec3 _illuminate(float max_light, vec3 view_dir, vec3 emitted, vec3 reflected) { + const float gamma = 1.0; vec3 color = emitted + reflected; + float lum = rel_luminance(color); - // float lum_sky = lum - max_light; - - // vec3 sun_dir = get_sun_dir(time_of_day.x); - // vec3 moon_dir = get_moon_dir(time_of_day.x); - // float sky_light = rel_luminance( - // get_sun_color(sun_dir) * get_sun_brightness(sun_dir) * SUN_COLOR_FACTOR + - // get_moon_color(moon_dir) * get_moon_brightness(moon_dir)); float sky_light = lum; // Tone mapped value. - // vec3 T = /*color*//*lum*/color;//normalize(color) * lum / (1.0 + lum); - // float alpha = 0.5;//2.0; + // const float NIGHT_EXPOSURE = 10.0; + // const float DUSK_EXPOSURE = 2.0; + // const float DAY_EXPOSURE = 1.0; // float alpha = mix( // mix( // DUSK_EXPOSURE, @@ -112,40 +94,16 @@ vec3 _illuminate(float max_light, vec3 view_dir, /*vec3 max_light, */vec3 emitte // DAY_EXPOSURE, // max(-sun_dir.z, 0) // ); - float alpha = 1.0;//log(1.0 - lum) / lum; - // vec3 now_light = moon_dir.z < 0 ? moon_dir : sun_dir; - // float cos_view_light = dot(-now_light, view_dir); - // alpha *= exp(1.0 - cos_view_light); - // sky_light *= 1.0 - log(1.0 + view_dir.z); - float alph = sky_light > 0.0 && max_light > 0.0 ? mix(1.0 / log(/*1.0*//*1.0 + *//*lum_sky + */1.0 + max_light / (0.0 + sky_light)), 1.0, clamp(max_light - sky_light, 0.0, 1.0)) : 1.0; - alpha = alpha * alph;// min(alph, 1.0);//((max_light > 0.0 && max_light > sky_light /* && sky_light > 0.0*/) ? /*1.0*/1.0 / log(/*1.0*//*1.0 + *//*lum_sky + */1.0 + max_light - (0.0 + sky_light)) : 1.0); - // alpha = alpha * min(1.0, (max_light == 0.0 ? 1.0 : (1.0 + abs(lum_sky)) / /*(1.0 + max_light)*/max_light)); + float alpha = sky_light > 0.0 && max_light > 0.0 ? mix(1.0 / log(1.0 + max_light / (0.0 + sky_light)), 1.0, clamp(max_light - sky_light, 0.0, 1.0)) : 1.0; vec3 col_adjusted = lum == 0.0 ? vec3(0.0) : color / lum; - // float L = lum == 0.0 ? 0.0 : log(lum); - - - // // float B = T; - // // float B = L + log(alpha); - // float B = lum; - - // float D = L - B; - - // float o = 0.0;//log(PERSISTENT_AMBIANCE); - // float scale = /*-alpha*/-alpha;//1.0; - - // float B_ = (B - o) * scale; - - // // float T = lum; - // float O = exp(B_ + D); - - float T = 1.0 - exp(-alpha * lum);//lum / (1.0 + lum); - // float T = lum; + float T = 1.0 - exp(-alpha * lum); // Heuristic desaturation - // const float s = 0.8; - float s = 1.0; + // const float DAY_SATURATION = 1.0; + // const float DUSK_SATURATION = 0.6; + // const float NIGHT_SATURATION = 0.1; // float s = mix( // mix( // DUSK_SATURATION, @@ -155,18 +113,9 @@ vec3 _illuminate(float max_light, vec3 view_dir, /*vec3 max_light, */vec3 emitte // DAY_SATURATION, // max(-sun_dir.z, 0) // ); - // s = max(s, (max_light) / (1.0 + s)); - // s = max(s, max_light / (1.0 + max_light)); - // s = max_light / (1.0 + max_light); + float s = 1.0; - vec3 c = pow(col_adjusted, vec3(s)) * T; - // vec3 c = col_adjusted * T; - // vec3 c = sqrt(col_adjusted) * T; - // vec3 c = /*col_adjusted * */col_adjusted * T; - - return c; - // float sum_col = color.r + color.g + color.b; - // return /*srgb_to_linear*/(/*0.5*//*0.125 * */vec3(pow(color.x, gamma), pow(color.y, gamma), pow(color.z, gamma))); + return pow(col_adjusted, vec3(s)) * T; } #ifdef EXPERIMENTAL_SOBEL @@ -202,41 +151,9 @@ void main() { tgt_color = vec4(texelFetch(sampler2D(t_src_color, s_src_color), ivec2(uv * textureSize(sampler2D(t_src_color, s_src_color), 0)), 0).rgb, 1); #else - /* if (medium.x == 1u) { - uv = clamp(uv + vec2(sin(uv.y * 16.0 + tick.x), sin(uv.x * 24.0 + tick.x)) * 0.005, 0, 1); - } */ - - vec2 c_uv = vec2(0.5);//uv;//vec2(0.5);//uv; - vec2 delta = /*sqrt*//*sqrt(2.0) / 2.0*//*sqrt(2.0) / 2.0*//*0.5 - */min(uv, 1.0 - uv);//min(uv * (1.0 - uv), 0.25) * 2.0; - // delta = /*sqrt(2.0) / 2.0 - */sqrt(vec2(dot(delta, delta))); - // delta = 0.5 - vec2(min(delta.x, delta.y)); - delta = vec2(0.25);//vec2(dot(/*0.5 - */delta, /*0.5 - */delta));//vec2(min(delta.x, delta.y));//sqrt(2.0) * (0.5 - vec2(min(delta.x, delta.y))); - // delta = vec2(sqrt(dot(delta, delta))); - // vec2 delta = /*sqrt*//*sqrt(2.0) / 2.0*//*sqrt(2.0) / 2.0*/1.0 - vec2(sqrt(dot(uv, 1.0 - uv)));//min(uv * (1.0 - uv), 0.25) * 2.0; - // float delta = /*sqrt*//*sqrt(2.0) / 2.0*//*sqrt(2.0) / 2.0*/1.0 - (dot(uv - 0.5, uv - 0.5));//0.01;//25; - // vec2 delta = /*sqrt*//*sqrt(2.0) / 2.0*//*sqrt(2.0) / 2.0*/sqrt(uv * (1.0 - uv));//min(uv * (1.0 - uv), 0.25) * 2.0; - - // float bright_color0 = rel_luminance(texelFetch/*texture*/(src_color, ivec2(clamp(c_uv + vec2(0.0, 0.0), 0.0, 1.0) * screen_res.xy/* / 50*/)/* * 50*/, 0).rgb); - // float bright_color1 = rel_luminance(texelFetch/*texture*/(src_color, ivec2(clamp(c_uv + vec2(delta.x, delta.y), 0.0, 1.0) * screen_res.xy/* / 50*/)/* * 50*/, 0).rgb); - // float bright_color2 = rel_luminance(texelFetch/*texture*/(src_color, ivec2(clamp(c_uv + vec2(delta.x, -delta.y), 0.0, 1.0) * screen_res.xy/* / 50*/)/* * 50*/, 0).rgb); - // float bright_color3 = rel_luminance(texelFetch/*texture*/(src_color, ivec2(clamp(c_uv + vec2(-delta.x, delta.y), 0.0, 1.0) * screen_res.xy/* / 50*/)/* * 50*/, 0).rgb); - // float bright_color4 = rel_luminance(texelFetch/*texture*/(src_color, ivec2(clamp(c_uv + vec2(-delta.x, -delta.y), 0.0, 1.0) * screen_res.xy/* / 50*/)/* * 50*/, 0).rgb); - - // float bright_color0 = rel_luminance(texture(src_color, /*ivec2*/(clamp(c_uv + vec2(0.0, 0.0), 0.0, 1.0)/* * screen_res.xy*//* / 50*/)/* * 50*/, 0).rgb); - // float bright_color1 = rel_luminance(texture(src_color, /*ivec2*/(clamp(c_uv + vec2(delta, delta), 0.0, 1.0)/* * screen_res.xy*//* / 50*/)/* * 50*/, 0).rgb); - // float bright_color2 = rel_luminance(texture(src_color, /*ivec2*/(clamp(c_uv + vec2(delta, -delta), 0.0, 1.0)/* * screen_res.xy*//* / 50*/)/* * 50*/, 0).rgb); - // float bright_color3 = rel_luminance(texture(src_color, /*ivec2*/(clamp(c_uv + vec2(-delta, delta), 0.0, 1.0)/* * screen_res.xy*//* / 50*/)/* * 50*/, 0).rgb); - // float bright_color4 = rel_luminance(texture(src_color, /*ivec2*/(clamp(c_uv + vec2(-delta, -delta), 0.0, 1.0)/* * screen_res.xy*//* / 50*/)/* * 50*/, 0).rgb); - - // float bright_color = max(bright_color0, max(bright_color1, max(bright_color2, max(bright_color3, bright_color4))));// / 2.0;// / 5.0; - - // float bright_color = (bright_color0 + bright_color1 + bright_color2 + bright_color3 + bright_color4) / 5.0; - - // TODO: this causes flickering when the camera is moving into and out of solid blocks, resolve before uncommenting - // if (medium.x == 2u) { - // tgt_color = vec4(0, 0.005, 0.01, 1) * (1 + hash_fast(uvec3(vec3(uv * screen_res.xy / 32.0, 0)))); - // return; - // } + vec2 c_uv = vec2(0.5); + vec2 delta = min(uv, 1.0 - uv); + delta = vec2(0.25); vec2 sample_uv = uv; #ifdef EXPERIMENTAL_UNDERWARPER @@ -318,40 +235,6 @@ void main() { aa_color.rgb = pow(floor(quant_color + quant_step) * (1.0 / QUANT_STEPS), vec3(4)); #endif - /* - // Apply clouds to `aa_color` - #if (CLOUD_MODE != CLOUD_MODE_FLAT) - vec3 wpos = wpos_at(uv); - float dist = distance(wpos, cam_pos.xyz); - vec3 dir = (wpos - cam_pos.xyz) / dist; - - aa_color.rgb = get_cloud_color(aa_color.rgb, dir, cam_pos.xyz, dist, 1.0); - #endif - */ - - // aa_color.rgb = (wpos + focus_off.xyz) / vec3(32768, 32768, /*view_distance.w*/2048); - // aa_color.rgb = mod((wpos + focus_off.xyz), vec3(32768, 32768, view_distance.w)) / vec3(32768, 32768, view_distance.w);// / vec3(32768, 32768, view_distance.w); - // aa_color.rgb = mod((wpos + focus_off.xyz), vec3(32, 32, 16)) / vec3(32, 32, 16);// / vec3(32768, 32768, view_distance.w); - // aa_color.rgb = focus_off.xyz / vec3(32768, 32768, view_distance.w); - - /* aa_color.rgb = wpos / 10000.0; */ - - /* aa_color.rgb = vec3((texture(src_depth, uv).x - 0.99) * 100.0); */ - - /* aa_color.rgb = vec3((dist - 100000) / 300000.0, 1, 1); */ - - /* vec3 scatter_color = get_sun_color() * get_sun_brightness() + get_moon_color() * get_moon_brightness(); */ - - /* aa_color.rgb += cloud_color.rgb * scatter_color;//mix(aa_color, vec4(cloud_color.rgb * scatter_color, 1), cloud_color.a); */ - - // aa_color.rgb = illuminate(1.0 - 1.0 / (1.0 + bright_color), normalize(cam_pos.xyz - focus_pos.xyz), /*vec3 max_light, */vec3(0.0), aa_color.rgb); - - //vec4 hsva_color = vec4(rgb2hsv(fxaa_color.rgb), fxaa_color.a); - //hsva_color.y *= 1.45; - //hsva_color.z *= 0.85; - //hsva_color.z = 1.0 - 1.0 / (1.0 * hsva_color.z + 1.0); - //vec4 final_color = vec4(hsv2rgb(hsva_color.rgb), hsva_color.a); - vec4 final_color = aa_color * vec4(vec3(screen_fade), 1.0); #if (FLUID_MODE == FLUID_MODE_LOW) diff --git a/assets/voxygen/shaders/rain-occlusion-directed-vert.glsl b/assets/voxygen/shaders/rain-occlusion-directed-vert.glsl index 1f6098c320..e9f8eba754 100644 --- a/assets/voxygen/shaders/rain-occlusion-directed-vert.glsl +++ b/assets/voxygen/shaders/rain-occlusion-directed-vert.glsl @@ -21,8 +21,6 @@ // Currently, we only need globals for focus_off. #include -// For shadow locals. -// #include layout (std140, set = 0, binding = 14) uniform u_rain_occlusion { @@ -41,9 +39,6 @@ uniform u_rain_occlusion { * */ layout(location = 0) in uint v_pos_norm; -// in uint v_col_light; -// in vec4 v_pos; -// layout(location = 1) in uint v_atlas_pos; // Light projection matrices. layout (std140, set = 1, binding = 0) @@ -53,8 +48,6 @@ uniform u_locals { float load_time; }; -// out vec4 shadowMapCoord; - const float EXTRA_NEG_Z = 32768.0; void main() { diff --git a/assets/voxygen/shaders/rain-occlusion-figure-vert.glsl b/assets/voxygen/shaders/rain-occlusion-figure-vert.glsl index 7deec6a392..b23d2a6b18 100644 --- a/assets/voxygen/shaders/rain-occlusion-figure-vert.glsl +++ b/assets/voxygen/shaders/rain-occlusion-figure-vert.glsl @@ -23,8 +23,6 @@ // Currently, we only need globals for focus_off. #include -// For shadow locals. -// #include layout (std140, set = 0, binding = 14) uniform u_rain_occlusion { @@ -44,8 +42,6 @@ uniform u_rain_occlusion { layout(location = 0) in uint v_pos_norm; layout(location = 1) in uint v_atlas_pos; -// in uint v_col_light; -// in vec4 v_pos; layout (std140, set = 1, binding = 0) uniform u_locals { @@ -71,16 +67,11 @@ uniform u_bones { BoneData bones[16]; }; -// out vec4 shadowMapCoord; - void main() { uint bone_idx = (v_pos_norm >> 27) & 0xFu; vec3 pos = (vec3((uvec3(v_pos_norm) >> uvec3(0, 9, 18)) & uvec3(0x1FFu)) - 256.0) / 2.0; - vec3 f_pos = ( - bones[bone_idx].bone_mat * - vec4(pos, 1.0) - ).xyz + (model_pos - focus_off.xyz/* + vec3(0.0, 0.0, 0.0001)*/); + vec3 f_pos = (bones[bone_idx].bone_mat * vec4(pos, 1.0)).xyz + (model_pos - focus_off.xyz); gl_Position = rainOcclusionMatrices * vec4(f_pos, 1.0); } diff --git a/assets/voxygen/shaders/rope-frag.glsl b/assets/voxygen/shaders/rope-frag.glsl index 6a95299fb7..e7df2c114d 100644 --- a/assets/voxygen/shaders/rope-frag.glsl +++ b/assets/voxygen/shaders/rope-frag.glsl @@ -26,31 +26,8 @@ #include layout(location = 0) in vec3 f_pos; -// in float dummy; -// in vec3 f_col; -// in float f_ao; -// flat in uint f_pos_norm; layout(location = 1) in vec3 f_norm; layout(location = 2) in vec3 m_pos; -// in float f_alt; -// in vec4 f_shadow; -// in vec3 light_pos[2]; - -// #if (SHADOW_MODE == SHADOW_MODE_MAP) -// in vec4 sun_pos; -// #elif (SHADOW_MODE == SHADOW_MODE_CHEAP || SHADOW_MODE == SHADOW_MODE_NONE) -// const vec4 sun_pos = vec4(0.0); -// #endif - -//struct ShadowLocals { -// mat4 shadowMatrices; -// mat4 texture_mat; -//}; -// -//layout (std140) -//uniform u_light_shadows { -// ShadowLocals shadowMats[/*MAX_LAYER_FACES*/192]; -//}; layout (std140, set = 2, binding = 0) uniform u_locals { @@ -63,15 +40,6 @@ layout(location = 0) out vec4 tgt_color; layout(location = 1) out uvec4 tgt_mat; void main() { - // vec2 texSize = textureSize(t_col_light, 0); - // vec4 col_light = texture(t_col_light, (f_uv_pos + 0.5) / texSize); - // vec3 f_col = col_light.rgb; - // float f_ao = col_light.a; - - // vec4 f_col_light = texture(t_col_light, (f_uv_pos + 0.5) / textureSize(t_col_light, 0)); - // vec3 f_col = f_col_light.rgb; - // float f_ao = f_col_light.a; - float f_ao = 1.0; vec3 f_col = mix( vec3(0.05, 0.03, 0.01), @@ -83,40 +51,9 @@ void main() { tgt_color = vec4(simple_lighting(f_pos.xyz, f_col, f_ao), 1); #else - // float /*f_light*/f_ao = textureProj(t_col_light, vec3(f_uv_pos, texSize)).a;//1.0;//f_col_light.a * 4.0;// f_light = float(v_col_light & 0x3Fu) / 64.0; - - // vec3 my_chunk_pos = (vec3((uvec3(f_pos_norm) >> uvec3(0, 9, 18)) & uvec3(0x1FFu)) - 256.0) / 2.0; - // tgt_color = vec4(hash(floor(vec4(my_chunk_pos.x, 0, 0, 0))), hash(floor(vec4(0, my_chunk_pos.y, 0, 1))), hash(floor(vec4(0, 0, my_chunk_pos.z, 2))), 1.0); - // float f_ao = 0; - // tgt_color = vec4(vec3(f_ao), 1.0); - // tgt_color = vec4(f_col, 1.0); - // return; - - // vec3 du = dFdx(f_pos); - // vec3 dv = dFdy(f_pos); - // vec3 f_norm = normalize(cross(du, dv)); - - // vec4 light_pos[2]; -//#if (SHADOW_MODE == SHADOW_MODE_MAP) -// // for (uint i = 0u; i < light_shadow_count.z; ++i) { -// // light_pos[i] = /*vec3(*/shadowMats[i].texture_mat * vec4(f_pos, 1.0)/*)*/; -// // } -// vec4 sun_pos = /*vec3(*/shadowMats[0].texture_mat * vec4(f_pos, 1.0)/*)*/; -//#elif (SHADOW_MODE == SHADOW_MODE_CHEAP || SHADOW_MODE == SHADOW_MODE_NONE) -// vec4 sun_pos = vec4(0.0); -//#endif - vec3 cam_to_frag = normalize(f_pos - cam_pos.xyz); - // vec4 vert_pos4 = view_mat * vec4(f_pos, 1.0); - // vec3 view_dir = normalize(-vec3(vert_pos4)/* / vert_pos4.w*/); vec3 view_dir = -cam_to_frag; - /* vec3 sun_dir = get_sun_dir(time_of_day.x); - vec3 moon_dir = get_moon_dir(time_of_day.x); */ - // float sun_light = get_sun_brightness(sun_dir); - // float moon_light = get_moon_brightness(moon_dir); - /* float sun_shade_frac = horizon_at(f_pos, sun_dir); - float moon_shade_frac = horizon_at(f_pos, moon_dir); */ #if (SHADOW_MODE == SHADOW_MODE_CHEAP || SHADOW_MODE == SHADOW_MODE_MAP || FLUID_MODE >= FLUID_MODE_MEDIUM) float f_alt = alt_at(f_pos.xy); #elif (SHADOW_MODE == SHADOW_MODE_NONE || FLUID_MODE == FLUID_MODE_LOW) @@ -127,18 +64,10 @@ void main() { vec4 f_shadow = textureBicubic(t_horizon, s_horizon, pos_to_tex(f_pos.xy)); float sun_shade_frac = horizon_at2(f_shadow, f_alt, f_pos, sun_dir); #elif (SHADOW_MODE == SHADOW_MODE_NONE) - float sun_shade_frac = 1.0;//horizon_at2(f_shadow, f_alt, f_pos, sun_dir); + float sun_shade_frac = 1.0; #endif - float moon_shade_frac = 1.0;// horizon_at2(f_shadow, f_alt, f_pos, moon_dir); - // Globbal illumination "estimate" used to light the faces of voxels which are parallel to the sun or moon (which is a very common occurrence). - // Will be attenuated by k_d, which is assumed to carry any additional ambient occlusion information (e.g. about shadowing). - // float ambient_sides = clamp(mix(0.5, 0.0, abs(dot(-f_norm, sun_dir)) * 10000.0), 0.0, 0.5); - // NOTE: current assumption is that moon and sun shouldn't be out at the sae time. - // This assumption is (or can at least easily be) wrong, but if we pretend it's true we avoids having to explicitly pass in a separate shadow - // for the sun and moon (since they have different brightnesses / colors so the shadows shouldn't attenuate equally). - // float shade_frac = /*1.0;*/sun_shade_frac + moon_shade_frac; - - // DirectionalLight sun_info = get_sun_info(sun_dir, sun_shade_frac, light_pos); + float moon_shade_frac = 1.0; + DirectionalLight sun_info = get_sun_info(sun_dir, sun_shade_frac, /*sun_pos*/f_pos); DirectionalLight moon_info = get_moon_info(moon_dir, moon_shade_frac/*, light_pos*/); @@ -159,25 +88,15 @@ void main() { vec3 emitted_light, reflected_light; - // vec3 light_frac = /*vec3(1.0);*//*vec3(max(dot(f_norm, -sun_dir) * 0.5 + 0.5, 0.0));*/light_reflection_factor(f_norm, view_dir, vec3(0, 0, -1.0), vec3(1.0), vec3(R_s), alpha); - // vec3 point_light = light_at(f_pos, f_norm); - // vec3 light, diffuse_light, ambient_light; - //get_sun_diffuse(f_norm, time_of_day.x, view_dir, k_a * point_shadow * (shade_frac * 0.5 + light_frac * 0.5), k_d * point_shadow * shade_frac, k_s * point_shadow * shade_frac, alpha, emitted_light, reflected_light); float max_light = 0.0; - // reflected_light *= point_shadow * shade_frac; - // emitted_light *= point_shadow * max(shade_frac, MIN_SHADOW); - // max_light *= point_shadow * shade_frac; - // reflected_light *= point_shadow; - // emitted_light *= point_shadow; - // max_light *= point_shadow; vec3 cam_attenuation = vec3(1); float fluid_alt = max(f_pos.z + 1, floor(f_alt + 1)); vec3 mu = medium.x == MEDIUM_WATER ? MU_WATER : vec3(0.0); #if (FLUID_MODE >= FLUID_MODE_MEDIUM) cam_attenuation = - medium.x == MEDIUM_WATER ? compute_attenuation_point(cam_pos.xyz, view_dir, mu, fluid_alt, /*cam_pos.z <= fluid_alt ? cam_pos.xyz : f_pos*/f_pos) - : compute_attenuation_point(f_pos, -view_dir, mu, fluid_alt, /*cam_pos.z <= fluid_alt ? cam_pos.xyz : f_pos*/cam_pos.xyz); + medium.x == MEDIUM_WATER ? compute_attenuation_point(cam_pos.xyz, view_dir, mu, fluid_alt, f_pos) + : compute_attenuation_point(f_pos, -view_dir, mu, fluid_alt, cam_pos.xyz); #endif // Prevent the sky affecting light when underground @@ -188,7 +107,7 @@ void main() { max_light += lights_at(f_pos, f_norm, view_dir, mu, cam_attenuation, fluid_alt, k_a, k_d, k_s, alpha, f_norm, 1.0, emitted_light, reflected_light); // Apply baked AO - float ao = f_ao * sqrt(f_ao);//0.25 + f_ao * 0.75; ///*pow(f_ao, 0.5)*/f_ao * 0.85 + 0.15; + float ao = f_ao * sqrt(f_ao); reflected_light *= ao; emitted_light *= ao; @@ -197,37 +116,12 @@ void main() { reflected_light *= point_shadow; emitted_light *= point_shadow; - /* reflected_light *= cloud_shadow(f_pos); */ - /* vec3 point_light = light_at(f_pos, f_norm); - emitted_light += point_light; - reflected_light += point_light; */ - // get_sun_diffuse(f_norm, time_of_day.x, cam_to_frag, surf_color * f_light * point_shadow, 0.5 * surf_color * f_light * point_shadow, 0.5 * surf_color * f_light * point_shadow, 2.0, emitted_light, reflected_light); - - // get_sun_diffuse(f_norm, time_of_day.x, light, diffuse_light, ambient_light, 1.0); - // diffuse_light *= point_shadow; - // ambient_light *= point_shadow; - // vec3 point_light = light_at(f_pos, f_norm); - // light += point_light; - // diffuse_light += point_light; - // reflected_light += point_light; - // vec3 surf_color = illuminate(srgb_to_linear(highlight_col.rgb * f_col), light, diffuse_light, ambient_light); - float reflectance = 0.0; // TODO: Do reflectance properly like this later vec3 reflect_color = vec3(0); surf_color = illuminate(max_light, view_dir, mix(surf_color * emitted_light, reflect_color, reflectance), mix(surf_color * reflected_light, reflect_color, reflectance)); - // if ((flags & 1) == 1 && int(cam_mode) == 1) { - // float distance = distance(vec3(cam_pos), focus_pos.xyz) - 2; - - // float opacity = clamp(distance / distance_divider, 0, 1); - - // // if(threshold_matrix[int(gl_FragCoord.x) % 4][int(gl_FragCoord.y) % 4] > opacity) { - // // discard; - // // } - // } - tgt_color = vec4(surf_color, 1.0); tgt_mat = uvec4(uvec3((f_norm + 1.0) * 127.0), MAT_FIGURE); #endif diff --git a/assets/voxygen/shaders/skybox-frag.glsl b/assets/voxygen/shaders/skybox-frag.glsl index 9f95cd1a63..e6ca5bfde6 100644 --- a/assets/voxygen/shaders/skybox-frag.glsl +++ b/assets/voxygen/shaders/skybox-frag.glsl @@ -32,29 +32,18 @@ void main() { vec3 cam_dir = normalize(f_pos - cam_pos.xyz); float cam_alt = alt_at(cam_pos.xy); - // float f_alt = alt_at(f_pos.xy); float fluid_alt = medium.x == MEDIUM_WATER ? floor(cam_alt + 1) : view_distance.w; - // float fluid_alt = max(f_pos.z + 1, floor(f_alt)); - vec3 mu = medium.x == MEDIUM_WATER /* && f_pos.z <= fluid_alt*/ ? MU_WATER : vec3(0.0); - // vec3 sun_attenuation = compute_attenuation(wpos, -sun_dir, mu, surface_alt, wpos); - vec3 cam_attenuation = compute_attenuation(cam_pos.xyz, -cam_dir, mu, fluid_alt, /*cam_pos.z <= fluid_alt ? cam_pos.xyz : f_pos*//*f_pos*//*vec3(f_pos.xy, fluid_alt)*/cam_pos.xyz); - // vec3 cam_attenuation = compute_attenuation_point(f_pos, -view_dir, mu, fluid_alt, cam_pos.xyz); - // vec3 cam_attenuation = vec3(1.0); + vec3 mu = medium.x == MEDIUM_WATER ? MU_WATER : vec3(0.0); - /* vec3 world_pos = cam_pos.xyz + cam_dir * 500000.0; - tgt_color = vec4(get_sky_color(normalize(f_pos), time_of_day.x, cam_pos.xyz, world_pos, 1.0, true, _clouds), 1.0); */ float fog_level = fog(f_pos.xyz, focus_pos.xyz, medium.x); float dist = 100000.0; float refractionIndex = medium.x == MEDIUM_WATER ? 1.0 / 1.3325 : 1.0; - /* if (medium.x == 1u) { - dist = UNDERWATER_MIST_DIST; - } */ - vec3 wpos = cam_pos.xyz + /*normalize(f_pos)*/cam_dir * dist; + vec3 wpos = cam_pos.xyz + cam_dir * dist; - tgt_color = vec4(cam_attenuation * get_sky_color(normalize(f_pos), cam_pos.xyz, wpos, 1.0, true, refractionIndex, false, 1.0), 1.0); + tgt_color = vec4(get_sky_color(normalize(f_pos), cam_pos.xyz, wpos, 1.0, true, refractionIndex, false, 1.0), 1.0); tgt_mat = uvec4(uvec3(0), MAT_SKY); #endif } diff --git a/assets/voxygen/shaders/skybox-vert.glsl b/assets/voxygen/shaders/skybox-vert.glsl index bd4bf66d40..4dbd116558 100644 --- a/assets/voxygen/shaders/skybox-vert.glsl +++ b/assets/voxygen/shaders/skybox-vert.glsl @@ -35,12 +35,6 @@ void main() { // // Infinite projections of cubemaps are nice because they can be oriented // but still extend infinitely far. - gl_Position = - all_mat * - vec4(v_pos + cam_pos.xyz, 1); - // gl_Position = vec4(gl_Position.xy, sign(gl_Position.z) * gl_Position.w, gl_Position.w); + gl_Position = all_mat * vec4(v_pos + cam_pos.xyz, 1); gl_Position.z = 0; - // gl_Position.z = gl_Position.w - 0.000001;//0.0; - // gl_Position.z = 1.0; - // gl_Position.z = -1.0; } diff --git a/assets/voxygen/shaders/sprite-frag.glsl b/assets/voxygen/shaders/sprite-frag.glsl index 686c109b6d..61e8704930 100644 --- a/assets/voxygen/shaders/sprite-frag.glsl +++ b/assets/voxygen/shaders/sprite-frag.glsl @@ -113,8 +113,8 @@ void main() { vec3 mu = medium.x == MEDIUM_WATER ? MU_WATER : vec3(0.0); #if (FLUID_MODE >= FLUID_MODE_MEDIUM) cam_attenuation = - medium.x == MEDIUM_WATER ? compute_attenuation_point(cam_pos.xyz, view_dir, mu, fluid_alt, /*cam_pos.z <= fluid_alt ? cam_pos.xyz : f_pos*/f_pos) - : compute_attenuation_point(f_pos, -view_dir, mu, fluid_alt, /*cam_pos.z <= fluid_alt ? cam_pos.xyz : f_pos*/cam_pos.xyz); + medium.x == MEDIUM_WATER ? compute_attenuation_point(cam_pos.xyz, view_dir, mu, fluid_alt, f_pos) + : compute_attenuation_point(f_pos, -view_dir, mu, fluid_alt, cam_pos.xyz); #endif // Prevent the sky affecting light when underground @@ -158,8 +158,6 @@ void main() { surf_color += f_select * (surf_color + 0.1) * vec3(0.15, 0.15, 0.15); tgt_color = vec4(surf_color, render_alpha); - tgt_mat = uvec4(uvec3((f_norm + 1.0) * 127.0), render_mat); - //tgt_color = vec4(-f_norm, 1.0); #endif } diff --git a/assets/voxygen/shaders/sprite-vert.glsl b/assets/voxygen/shaders/sprite-vert.glsl index 8993df1eb1..bca61e615d 100644 --- a/assets/voxygen/shaders/sprite-vert.glsl +++ b/assets/voxygen/shaders/sprite-vert.glsl @@ -85,7 +85,7 @@ void main() { inst_mat[0] = inst_mat0; inst_mat[1] = inst_mat1; inst_mat[2] = inst_mat2; - inst_mat[3] = inst_mat3;// + vec4(-14.5, -16.5, 0.0, 0.0); + inst_mat[3] = inst_mat3; inst_mat = model_mat * inst_mat; @@ -112,7 +112,6 @@ void main() { // Expand the model vertex position bits into float values // TODO: Use this instead, see [https://gitlab.com/veloren/veloren/-/merge_requests/3091] - //vec3 v_pos = vec3(ivec3((uvec3(v_pos_norm) >> uvec3(0, 8, 16)) & uvec3(0xFFu, 0xFFu, 0x0FFFu)) - ivec3(VERT_EXTRA_NEG_XY, VERT_EXTRA_NEG_XY, VERT_EXTRA_NEG_Z)); vec3 v_pos = vec3( float(v_pos_norm & 0xFFu) - VERT_EXTRA_NEG_XY, float((v_pos_norm >> 8) & 0xFFu) - VERT_EXTRA_NEG_XY, @@ -140,7 +139,6 @@ void main() { // TODO: dx12 doesn't like dynamic index // TODO: use mix? // Shader@0x000001AABD89BEE0(112,43-53): error X4576: Input array signature parameter cannot be indexed dynamically. - //vec3 norm = (inst_mat[(v_pos_norm >> 30u) & 3u].xyz); uint index = v_pos_norm >> 30u & 3u; vec3 norm; if (index == 0) { @@ -200,7 +198,6 @@ void main() { wind_wave(f_pos.x * 0.1, 1.1, wind_vel.y, wind_vel.x) )) * model_wind_sway - //* mix(10.0, abs(v_pos.z), 1.0 / (1.0 + abs(v_pos.z) * 0.1)) * abs(v_pos.z) * model_z_scale * SCALE_FACTOR; diff --git a/assets/voxygen/shaders/terrain-frag.glsl b/assets/voxygen/shaders/terrain-frag.glsl index eae1e2baf2..d9d5154c5d 100644 --- a/assets/voxygen/shaders/terrain-frag.glsl +++ b/assets/voxygen/shaders/terrain-frag.glsl @@ -23,26 +23,8 @@ #include layout(location = 0) in vec3 f_pos; -// in float f_ao; -// in vec3 f_chunk_pos; -// #ifdef FLUID_MODE_SHINY layout(location = 1) flat in uint f_pos_norm; -// #else -// const uint f_pos_norm = 0u; -// #endif -// in float f_alt; -// in vec4 f_shadow; -// in vec3 f_col; -// in float f_light; -/*centroid */layout(location = 3) in vec2 f_uv_pos; -// in vec3 light_pos[2]; -// const vec3 light_pos[6] = vec3[](vec3(0), vec3(0), vec3(00), vec3(0), vec3(0), vec3(0)); - -/* #if (SHADOW_MODE == SHADOW_MODE_MAP) -in vec4 sun_pos; -#elif (SHADOW_MODE == SHADOW_MODE_CHEAP || SHADOW_MODE == SHADOW_MODE_NONE) -const vec4 sun_pos = vec4(0.0); -#endif */ +layout(location = 3) in vec2 f_uv_pos; layout(set = 2, binding = 0) uniform texture2D t_col_light; @@ -72,26 +54,10 @@ float vmin(vec2 v) { } void main() { - /* - float nz = abs(hash(vec4(floor((f_pos + focus_off.xyz) * 5.0), 0))); - if (nz > (tick.x - load_time) / 0.5 || distance(focus_pos.xy, f_pos.xy) / view_distance.x + nz * 0.1 > 1.0) { - discard; - } - */ - - // discard; - // vec4 f_col_light = textureGrad(t_col_light, f_uv_pos / texSize, 0.25, 0.25); - // vec4 f_col_light = texture(t_col_light, (f_uv_pos) / texSize); - // First 3 normals are negative, next 3 are positive const vec3 normals[8] = vec3[](vec3(-1,0,0), vec3(1,0,0), vec3(0,-1,0), vec3(0,1,0), vec3(0,0,-1), vec3(0,0,1), vec3(0,0,0), vec3(0,0,0)); - // uint norm_index = (f_pos_norm >> 29) & 0x7u; - // vec2 uv_delta = (norm_index & 0u) == 0u ? vec2(-1.0) : vec2(0); - vec2 f_uv_pos = f_uv_pos + atlas_offs.xy; - // vec4 f_col_light = textureProj(t_col_light, vec3(f_uv_pos + 0.5, textureSize(t_col_light, 0)));//(f_uv_pos/* + 0.5*/) / texSize); - // float f_light = textureProj(t_col_light, vec3(f_uv_pos + 0.5, textureSize(t_col_light, 0))).a;//1.0;//f_col_light.a * 4.0;// f_light = float(v_col_light & 0x3Fu) / 64.0; float f_light, f_glow, f_ao, f_sky_exposure; uint f_kind; vec3 f_col = greedy_extract_col_light_kind_terrain(t_col_light, s_col_light, t_kind, f_uv_pos, f_light, f_glow, f_ao, f_sky_exposure, f_kind); @@ -102,86 +68,6 @@ void main() { tgt_color = vec4(simple_lighting(f_pos.xyz, f_col, f_light), 1); #else - //float f_light = (uint(texture(t_col_light, (f_uv_pos + 0.5) / textureSize(t_col_light, 0)).r * 255.0) & 0x1Fu) / 31.0; - // vec2 texSize = textureSize(t_col_light, 0); - // float f_light = texture(t_col_light, f_uv_pos/* + vec2(atlas_offs.xy)*/).a;//1.0;//f_col_light.a * 4.0;// f_light = float(v_col_light & 0x3Fu) / 64.0; - // float f_light = textureProj(t_col_light, vec3(f_uv_pos/* + vec2(atlas_offs.xy)*/, texSize.x)).a;//1.0;//f_col_light.a * 4.0;// f_light = float(v_col_light & 0x3Fu) / 64.0; - // float f_light = textureProjLod(t_col_light, vec3(f_uv_pos/* + vec2(atlas_offs.xy)*/, texSize.x), 0).a;//1.0;//f_col_light.a * 4.0;// f_light = float(v_col_light & 0x3Fu) / 64.0; - // float f_light = textureGrad(t_col_light, (f_uv_pos + 0.5) / texSize, vec2(0.1, 0.0), vec2(0.0, 0.1)).a;//1.0;//f_col_light.a * 4.0;// f_light = float(v_col_light & 0x3Fu) / 64.0; - // f_light = sqrt(f_light); - // f_light = sqrt(f_light); - // f_col = vec3((uvec3(v_col_light) >> uvec3(8, 16, 24)) & uvec3(0xFFu)) / 255.0; - // vec3 f_col = light_col.rgb;//vec4(1.0, 0.0, 0.0, 1.0); - - // float f_ao = 1.0; - - // vec3 my_chunk_pos = vec3(ivec3((uvec3(f_pos_norm) >> uvec3(0, 6, 12)) & uvec3(0x3Fu, 0x3Fu, 0xFFFFu))); - // tgt_color = vec4(hash(floor(vec4(my_chunk_pos.x, 0, 0, 0))), hash(floor(vec4(0, my_chunk_pos.y, 0, 1))), hash(floor(vec4(0, 0, my_chunk_pos.z, 2))), 1.0); - // tgt_color.rgb *= f_light; - // tgt_color = vec4(vec3(f_light), 1.0); - // tgt_color = vec4(f_col, 1.0); - // return; - // vec4 light_pos[2]; - // vec4 light_col = vec4( - // hash(floor(vec4(f_pos.x, 0, 0, 0))), - // hash(floor(vec4(0, f_pos.y, 0, 1))), - // hash(floor(vec4(0, 0, f_pos.z, 2))), - // 1.0 - // ); - // vec3 f_col = light_col.rgb;//vec4(1.0, 0.0, 0.0, 1.0); - // tgt_color = vec4(f_col, 1.0); - // tgt_color = vec4(light_shadow_count.x <= 31u ? f_col : vec3(0.0), 1.0); - // tgt_color = vec4(0.0, 0.0, 0.0, 1.0); - // float sum = 0.0; - // for (uint i = 0u; i < /* 6 * */light_shadow_count.x; i ++) { - // // uint i = 1u; - // Light L = lights[i/* / 6*/]; - - // /* vec4 light_col = vec4( - // hash(vec4(1.0, 0.0, 0.0, i)), - // hash(vec4(1.0, 1.0, 0.0, i)), - // hash(vec4(1.0, 0.0, 1.0, i)), - // 1.0 - // ); */ - // vec3 light_col = vec3(1.0);//L.light_col.rgb; - // float light_strength = L.light_col.a / 255.0; - // // float light_strength = 1.0 / light_shadow_count.x; - - // vec3 light_pos = L.light_pos.xyz; - - // // Pre-calculate difference between light and fragment - // vec3 fragToLight = f_pos - light_pos; - - // // vec3 f_norm = normals[(f_pos_norm >> 29) & 0x7u]; - - // // use the light to fragment vector to sample from the depth map - // float bias = 0.0;//0.05;//0.05; - // // float closestDepth = texture(t_shadow_maps, vec4(fragToLight, i)/*, 0.0*//*, bias*/).r; - // // float closestDepth = texture(t_shadow_maps, vec4(fragToLight, lightIndex), bias); - // // float closestDepth = texture(t_shadow_maps, vec4(fragToLight, i + 1)/*, bias*/).r; - // float currentDepth = VectorToDepth(fragToLight) + bias; - // float closestDepth = texture(t_shadow_maps, vec3(fragToLight)/*, -2.5*/).r; - // - // // float visibility = texture(t_shadow_maps, vec4(fragToLight, i + 1), -(length(fragToLight) - bias)/* / screen_res.w*/); - // // it is currently in linear range between [0,1]. Re-transform back to original value - // // closestDepth *= screen_res.w; // far plane - // // now test for shadows - // // float shadow = /*currentDepth*/(screen_res.w - bias) > closestDepth ? 1.0 : 0.0; - // // float shadow = currentDepth - bias > closestDepth ? 1.0 : 0.0; - - // // tgt_color += light_col * vec4(vec3(/*closestDepth*/visibility/* + bias*//* / screen_res.w */) * 1.0 / light_shadow_count.x, 0.0); - // // tgt_color.rgb += light_col * vec3(closestDepth + 0.05 / screen_res.w) * 1.0 /*/ light_shadow_count.x*/ * light_strength; - // tgt_color.rgb += light_col * vec3(closestDepth) * 1.0 / screen_res.w /*/ light_shadow_count.x*/ * light_strength; - // sum += light_strength; - // } - - // TODO: last 3 bits in v_pos_norm should be a number between 0 and 5, rather than 0-2 and a direction. - // uint norm_axis = (f_pos_norm >> 30) & 0x3u; - // // Increase array access by 3 to access positive values - // uint norm_dir = ((f_pos_norm >> 29) & 0x1u) * 3u; - // Use an array to avoid conditional branching - // uint norm_index = (f_pos_norm >> 29) & 0x7u; - // vec3 f_norm = normals[norm_index]; vec3 face_norm = normals[(f_pos_norm >> 29) & 0x7u]; vec3 f_norm = face_norm; @@ -196,28 +82,11 @@ void main() { f_col /= 1.0 + length((fp - clamped) * sign(1.0 - f_norm)) * 2; #endif - // vec3 du = dFdx(f_pos); - // vec3 dv = dFdy(f_pos); - // vec3 f_norm = normalize(cross(du, dv)); - - // /* if (light_shadow_count.x == 1) { - // tgt_color.rgb = vec3(0.0); - // } */ - // if (sum > 0.0) { - // tgt_color.rgb /= sum; - // } - // return; // Whether this face is facing fluid or not. bool faces_fluid = bool((f_pos_norm >> 28) & 0x1u); vec3 cam_to_frag = normalize(f_pos - cam_pos.xyz); - // vec4 vert_pos4 = view_mat * vec4(f_pos, 1.0); - // vec3 view_dir = normalize(-vec3(vert_pos4)/* / vert_pos4.w*/); vec3 view_dir = -cam_to_frag; - // vec3 view_dir = normalize(f_pos - cam_pos.xyz); - - /* vec3 sun_dir = get_sun_dir(time_of_day.x); - vec3 moon_dir = get_moon_dir(time_of_day.x); */ #if (SHADOW_MODE == SHADOW_MODE_CHEAP || SHADOW_MODE == SHADOW_MODE_MAP || FLUID_MODE >= FLUID_MODE_MEDIUM) float f_alt = alt_at(f_pos.xy); @@ -225,18 +94,16 @@ void main() { float f_alt = f_pos.z; #endif - float alpha = 1.0;//0.0001;//1.0; + float alpha = 1.0; // TODO: Possibly angle with water surface into account? Since we can basically assume it's horizontal. - const float n2 = 1.5;//1.01; + const float n2 = 1.5; const float R_s2s0 = pow(abs((1.0 - n2) / (1.0 + n2)), 2); const float R_s1s0 = pow(abs((1.3325 - n2) / (1.3325 + n2)), 2); const float R_s2s1 = pow(abs((1.0 - 1.3325) / (1.0 + 1.3325)), 2); const float R_s1s2 = pow(abs((1.3325 - 1.0) / (1.3325 + 1.0)), 2); - // float faces_fluid = faces_fluid && f_pos.z <= floor(f_alt); float fluid_alt = max(f_pos.z + 1, floor(f_alt + 1)); - float R_s = /*(f_pos.z < f_alt)*/faces_fluid /*&& f_pos.z <= fluid_alt*/ ? mix(R_s2s1 * R_s1s0, R_s1s0, medium.x) : mix(R_s2s0, R_s1s2 * R_s2s0, medium.x); + float R_s = faces_fluid ? mix(R_s2s1 * R_s1s0, R_s1s0, medium.x) : mix(R_s2s0, R_s1s2 * R_s2s0, medium.x); - // vec3 surf_color = /*srgb_to_linear*/(f_col); vec3 k_a = vec3(1.0); vec3 k_d = vec3(1.0); vec3 k_s = vec3(R_s); @@ -314,28 +181,14 @@ void main() { } #endif - // float sun_light = get_sun_brightness(sun_dir); - // float moon_light = get_moon_brightness(moon_dir); - /* float sun_shade_frac = horizon_at(f_pos, sun_dir); - float moon_shade_frac = horizon_at(f_pos, moon_dir); */ - // float f_alt = alt_at(f_pos.xy); - // vec4 f_shadow = textureMaybeBicubic(t_horizon, pos_to_tex(f_pos.xy)); #if (SHADOW_MODE == SHADOW_MODE_CHEAP || SHADOW_MODE == SHADOW_MODE_MAP) vec4 f_shadow = textureMaybeBicubic(t_horizon, s_horizon, pos_to_tex(f_pos.xy)); float sun_shade_frac = horizon_at2(f_shadow, f_alt, f_pos, sun_dir); #elif (SHADOW_MODE == SHADOW_MODE_NONE) - float sun_shade_frac = 1.0;//horizon_at2(f_shadow, f_alt, f_pos, sun_dir); + float sun_shade_frac = 1.0; #endif - float moon_shade_frac = 1.0;//horizon_at2(f_shadow, f_alt, f_pos, moon_dir); - // Globbal illumination "estimate" used to light the faces of voxels which are parallel to the sun or moon (which is a very common occurrence). - // Will be attenuated by k_d, which is assumed to carry any additional ambient occlusion information (e.g. about shadowing). - // float ambient_sides = clamp(mix(0.5, 0.0, abs(dot(-f_norm, sun_dir)) * 10000.0), 0.0, 0.5); - // NOTE: current assumption is that moon and sun shouldn't be out at the sae time. - // This assumption is (or can at least easily be) wrong, but if we pretend it's true we avoids having to explicitly pass in a separate shadow - // for the sun and moon (since they have different brightnesses / colors so the shadows shouldn't attenuate equally). - // float shade_frac = /*1.0;*/sun_shade_frac + moon_shade_frac; + float moon_shade_frac = 1.0; - // DirectionalLight sun_info = get_sun_info(sun_dir, sun_shade_frac, light_pos); DirectionalLight sun_info = get_sun_info(sun_dir, sun_shade_frac, /*sun_pos*/f_pos); DirectionalLight moon_info = get_moon_info(moon_dir, moon_shade_frac/*, light_pos*/); @@ -372,17 +225,11 @@ void main() { float max_light = 0.0; - // After shadows are computed, we use a refracted sun and moon direction. - // sun_dir = faces_fluid && sun_shade_frac > 0.0 ? refract(sun_dir/*-view_dir*/, vec3(0.0, 0.0, 1.0), 1.0 / 1.3325) : sun_dir; - // moon_dir = faces_fluid && moon_shade_frac > 0.0 ? refract(moon_dir/*-view_dir*/, vec3(0.0, 0.0, 1.0), 1.0 / 1.3325) : moon_dir; - // Compute attenuation due to water from the camera. - vec3 mu = faces_fluid/* && f_pos.z <= fluid_alt*/ ? MU_WATER : vec3(0.0); + vec3 mu = faces_fluid ? MU_WATER : vec3(0.0); // NOTE: Default intersection point is camera position, meaning if we fail to intersect we assume the whole camera is in water. // Computing light attenuation from water. - vec3 cam_attenuation = - false/*medium.x == MEDIUM_WATER*/ ? compute_attenuation_point(cam_pos.xyz, view_dir, MU_WATER, fluid_alt, /*cam_pos.z <= fluid_alt ? cam_pos.xyz : f_pos*/f_pos) - : compute_attenuation_point(f_pos, -view_dir, mu, fluid_alt, /*cam_pos.z <= fluid_alt ? cam_pos.xyz : f_pos*/cam_pos.xyz); + vec3 cam_attenuation = compute_attenuation_point(f_pos, -view_dir, mu, fluid_alt, cam_pos.xyz); // Prevent the sky affecting light when underground float not_underground = clamp((f_pos.z - f_alt) / 128.0 + 1.0, 0.0, 1.0); @@ -400,9 +247,6 @@ void main() { float sun_diffuse = get_sun_diffuse2(sun_info, moon_info, f_norm, view_dir, f_pos, mu, cam_attenuation, fluid_alt, k_a/* * (shade_frac * 0.5 + light_frac * 0.5)*/, k_d, k_s, alpha, f_norm, 1.0, emitted_light, reflected_light); max_light += sun_diffuse; - // emitted_light *= f_light * point_shadow * max(shade_frac, MIN_SHADOW); - // reflected_light *= f_light * point_shadow * shade_frac; - // max_light *= f_light * point_shadow * shade_frac; emitted_light *= f_light; reflected_light *= f_light; max_light *= f_light; @@ -437,34 +281,6 @@ void main() { #endif #endif - // float f_ao = 1.0; - - // float ao = /*pow(f_ao, 0.5)*/f_ao * 0.9 + 0.1; - // emitted_light *= ao; - // reflected_light *= ao; - /* vec3 point_light = light_at(f_pos, f_norm); - emitted_light += point_light; - reflected_light += point_light; */ - - // float point_shadow = shadow_at(f_pos, f_norm); - // vec3 point_light = light_at(f_pos, f_norm); - // vec3 light, diffuse_light, ambient_light; - - // get_sun_diffuse(f_norm, time_of_day.x, cam_to_frag, k_a * f_light, k_d * f_light, k_s * f_light, alpha, emitted_light, reflected_light); - // get_sun_diffuse(f_norm, time_of_day.x, light, diffuse_light, ambient_light, 1.0); - // float point_shadow = shadow_at(f_pos, f_norm); - // diffuse_light *= f_light * point_shadow; - // ambient_light *= f_light * point_shadow; - // vec3 point_light = light_at(f_pos, f_norm); - // light += point_light; - // diffuse_light += point_light; - // reflected_light += point_light; - // reflected_light += light_reflection_factor(norm, cam_to_frag, , vec3 k_d, vec3 k_s, float alpha) { - - // light_reflection_factorplight_reflection_factor - - // vec3 surf_color = illuminate(srgb_to_linear(f_col), light, diffuse_light, ambient_light); - vec3 f_chunk_pos = f_pos - (model_mat[3].xyz - focus_off.xyz); #ifdef EXPERIMENTAL_NONOISE float noise = 0.0; @@ -476,72 +292,12 @@ void main() { #endif #endif -//vec3 srgb_to_linear(vec3 srgb) { -// bvec3 cutoff = lessThan(srgb, vec3(0.04045)); -// vec3 higher = pow((srgb + vec3(0.055))/vec3(1.055), vec3(2.4)); -// vec3 lower = srgb/vec3(12.92); -// -// return mix(higher, lower, cutoff); -//} -// -//vec3 linear_to_srgb(vec3 col) { -// // bvec3 cutoff = lessThan(col, vec3(0.0060)); -// // return mix(11.500726 * col, , cutoff); -// vec3 s1 = vec3(sqrt(col.r), sqrt(col.g), sqrt(col.b)); -// vec3 s2 = vec3(sqrt(s1.r), sqrt(s1.g), sqrt(s1.b)); -// vec3 s3 = vec3(sqrt(s2.r), sqrt(s2.g), sqrt(s2.b)); -// return vec3( -// mix(11.500726 * col.r, (0.585122381 * s1.r + 0.783140355 * s2.r - 0.368262736 * s3.r), clamp((col.r - 0.0060) * 10000.0, 0.0, 1.0)), -// mix(11.500726 * col.g, (0.585122381 * s1.g + 0.783140355 * s2.g - 0.368262736 * s3.g), clamp((col.g - 0.0060) * 10000.0, 0.0, 1.0)), -// mix(11.500726 * col.b, (0.585122381 * s1.b + 0.783140355 * s2.b - 0.368262736 * s3.b), clamp((col.b - 0.0060) * 10000.0, 0.0, 1.0)) -// ); -// -// 11.500726 -//} - // vec3 noise_delta = vec3(noise * 0.005); - // vec3 noise_delta = noise * 0.02 * (1.0 - vec3(0.2126, 0.7152, 0.0722)); - // vec3 noise_delta = noise * 0.002 / vec3(0.2126, 0.7152, 0.0722); - // vec3 noise_delta = sqrt(f_col) + noise; - /* vec3 noise_delta = f_col + noise * 0.02; - noise_delta *= noise_delta; - noise_delta -= f_col; */ - // vec3 noise_delta = (1.0 - f_col) * 0.02 * noise * noise; - // - // a = 0.055 - // - // 1 / (1 + a) = 1 / (1 + 0.055) ~ 0.947867299 - // - // l2s = x^(1/2.4) * (1 / (1 + a)) - a + c - // s2l = (l + a)^2.4 * (1 / (1 + a))^2.4 - // = ((x^(1/2.4) * (1 / (1 + a)) - a + c) + a)^2.4 * (1 / (1 + a))^2.4 - // = (x^(1/2.4) * (1 / (1 + a)) + c)^2.4 * (1 / (1 + a))^2.4 - // - // ~ (x^(1/2) * 1 / (1 + a) + c)^2 * (1 / (1 + a))^2 - // - // = ((x + a)^2.4 * (1 / (1 + a))^2.4 + c)^(1/2.4) * (1 / (1 + a))^(1/2.4) - // = (((x + a)^2.4 + c * (1 + a)^2.4) * (1 / (1 + a))^2.4)^(1/2.4) * (1 / (1 + a))^(1/2.4) - // = ((x + a)^2.4 + c * (1 + a)^2.4)^(1/2.4) * ((1 / (1 + a))^2.4)^(1/2.4) * (1 / (1 + a))^(1/2.4) - // = ((x + a)^2.4 + c * (1 + a)^2.4)^(1/2.4) * (1 / (1 + a))^(1/2.4) - // - // = ((x + a)^2 + c * (1 + a)^2)^(1/2) * (1 / (1 + a))^(1/2) - // = (x^2 + a^2 + 2xa + c + ca^2 + 2ac)^(1/2) * (1 / (1 + a))^(1/2) - // const float A = 0.055; const float W_INV = 1 / (1 + A); - const float W_2 = W_INV * W_INV;//pow(W_INV, 2.4); - const float NOISE_FACTOR = 0.015;//pow(0.02, 1.2); + const float W_2 = W_INV * W_INV; + const float NOISE_FACTOR = 0.015; vec3 noise_delta = (sqrt(f_col) * W_INV + noise * NOISE_FACTOR); - // noise_delta = noise_delta * noise_delta * W_2 - f_col; - // lum = W ⋅ col - // lum + noise = W ⋅ (col + delta) - // W ⋅ col + noise = W ⋅ col + W ⋅ delta - // noise = W ⋅ delta - // delta = noise / W - // vec3 col = (f_col + noise_delta); vec3 col = noise_delta * noise_delta * W_2; - // vec3 col = srgb_to_linear(linear_to_srgb(f_col) + noise * 0.02); - // vec3 col = /*srgb_to_linear*/(f_col + noise); // Small-scale noise - // vec3 col = /*srgb_to_linear*/(f_col + hash(vec4(floor(f_pos * 3.0 - f_norm * 0.5), 0)) * 0.01); // Small-scale noise vec3 surf_color = illuminate(max_light, view_dir, col * emitted_light, col * reflected_light); #ifdef EXPERIMENTAL_SNOWGLITTER if (f_kind == BLOCK_SNOW || f_kind == BLOCK_ART_SNOW) { @@ -572,8 +328,5 @@ void main() { tgt_color = vec4(surf_color, f_alpha); tgt_mat = uvec4(uvec3((f_norm + 1.0) * 127.0), f_mat); - //tgt_color = vec4(f_norm, f_alpha); - // Toggle to see rain_occlusion - // tgt_color = vec4(rain_occlusion_at(f_pos.xyz), 0.0, 0.0, 1.0); #endif } diff --git a/assets/voxygen/shaders/ui-vert.glsl b/assets/voxygen/shaders/ui-vert.glsl index f9900d5d5c..d2c77c0edf 100644 --- a/assets/voxygen/shaders/ui-vert.glsl +++ b/assets/voxygen/shaders/ui-vert.glsl @@ -31,10 +31,6 @@ layout(location = 3) flat out uint f_mode; void main() { f_color = v_color; - // vec2 v_pos = vec2(-1.0,1.0) * v_pos; - /* f_uv = vec2(1.0,1.0) * v_uv; */ - // vec2 v_uv = vec2(1.0,-1.0) * v_uv; - if (w_pos.w == 1.0) { f_uv = v_uv; // Fixed scale In-game element