From 7edd0e701c47b0ebc495a9a299e6734021cc225d Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Tue, 21 Apr 2020 14:15:32 +0100 Subject: [PATCH] Fixed sub-voxel noise flickering on NVIDIA cards --- assets/voxygen/shaders/terrain-frag.glsl | 3 ++- assets/voxygen/shaders/terrain-vert.glsl | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/assets/voxygen/shaders/terrain-frag.glsl b/assets/voxygen/shaders/terrain-frag.glsl index 3b8e0bd45b..ba16a1c28f 100644 --- a/assets/voxygen/shaders/terrain-frag.glsl +++ b/assets/voxygen/shaders/terrain-frag.glsl @@ -4,6 +4,7 @@ #include in vec3 f_pos; +in vec3 f_chunk_pos; flat in uint f_pos_norm; in vec3 f_col; in float f_light; @@ -48,7 +49,7 @@ void main() { diffuse_light *= f_light * ao; diffuse_light += point_light * ao; - vec3 col = f_col + hash(vec4(mod(floor(f_pos * 3.0), 100.0) * 10.0, 0)) * 0.02; // Small-scale noise + vec3 col = f_col + hash(vec4(floor(mod(f_chunk_pos, 100.0) * 3.0) * 10.0, 0)) * 0.02; // Small-scale noise vec3 surf_color = illuminate(srgb_to_linear(col), light, diffuse_light, ambient_light); float fog_level = fog(f_pos.xyz, focus_pos.xyz, medium.x); diff --git a/assets/voxygen/shaders/terrain-vert.glsl b/assets/voxygen/shaders/terrain-vert.glsl index a1a0bb6be9..eb81ee8bef 100644 --- a/assets/voxygen/shaders/terrain-vert.glsl +++ b/assets/voxygen/shaders/terrain-vert.glsl @@ -13,6 +13,7 @@ uniform u_locals { }; out vec3 f_pos; +out vec3 f_chunk_pos; flat out uint f_pos_norm; out vec3 f_col; out float f_light; @@ -21,7 +22,8 @@ out float f_ao; const float EXTRA_NEG_Z = 65536.0; void main() { - f_pos = vec3((uvec3(v_pos_norm) >> uvec3(0, 6, 12)) & uvec3(0x3Fu, 0x3Fu, 0x1FFFFu)) - vec3(0, 0, EXTRA_NEG_Z) + model_offs; + f_chunk_pos = vec3((uvec3(v_pos_norm) >> uvec3(0, 6, 12)) & uvec3(0x3Fu, 0x3Fu, 0x1FFFFu)) - vec3(0, 0, EXTRA_NEG_Z); + f_pos = f_chunk_pos + model_offs; f_pos.z -= 250.0 * (1.0 - min(1.0001 - 0.02 / pow(tick.x - load_time, 10.0), 1.0)); f_pos.z -= 25.0 * pow(distance(focus_pos.xy, f_pos.xy) / view_distance.x, 20.0);