diff --git a/assets/voxygen/shaders/figure-frag.glsl b/assets/voxygen/shaders/figure-frag.glsl index d02fba8f17..df2439e47d 100644 --- a/assets/voxygen/shaders/figure-frag.glsl +++ b/assets/voxygen/shaders/figure-frag.glsl @@ -46,13 +46,15 @@ void main() { vec3 fog_color = get_sky_color(normalize(f_pos - cam_pos.xyz), time_of_day.x, cam_pos.xyz, f_pos, 0.5, true, clouds); vec3 color = mix(mix(surf_color, fog_color, fog_level), clouds.rgb, clouds.a); - float opacity = 1.0; - if ((flags & 1) == 1 && int(cam_mode) == 1) { - float distance = distance(vec3(cam_pos), f_pos) - 1; + float distance = distance(vec3(cam_pos), vec3(model_mat * vec4(vec3(0), 1))) - 2; + + float opacity = clamp(distance / distance_divider, 0, 1); - opacity = clamp(distance / 3, 0, 1); + if(threshold_matrix[int(gl_FragCoord.x) % 4][int(gl_FragCoord.y) % 4] > opacity) { + discard; + } } - tgt_color = vec4(color, opacity); + tgt_color = vec4(color, 1.0); } diff --git a/assets/voxygen/shaders/include/globals.glsl b/assets/voxygen/shaders/include/globals.glsl index fb80fe9909..b35fab1228 100644 --- a/assets/voxygen/shaders/include/globals.glsl +++ b/assets/voxygen/shaders/include/globals.glsl @@ -13,5 +13,17 @@ uniform u_globals { uvec4 medium; ivec4 select_pos; vec4 gamma; + // 0 - FirstPerson + // 1 - ThirdPerson uint cam_mode; }; + +// Specifies the pattern used in the player dithering +mat4 threshold_matrix = mat4( + vec4(1.0 / 17.0, 9.0 / 17.0, 3.0 / 17.0, 11.0 / 17.0), + vec4(13.0 / 17.0, 5.0 / 17.0, 15.0 / 17.0, 7.0 / 17.0), + vec4(4.0 / 17.0, 12.0 / 17.0, 2.0 / 17.0, 10.0 / 17.0), + vec4(16.0 / 17.0, 8.0 / 17.0, 14.0 / 17.0, 6.0 / 17.0) +); +float distance_divider = 2; +float shadow_dithering = 0.5; \ No newline at end of file diff --git a/assets/voxygen/shaders/player-shadow-frag.glsl b/assets/voxygen/shaders/player-shadow-frag.glsl index 66c0dac893..25bd05ed0a 100644 --- a/assets/voxygen/shaders/player-shadow-frag.glsl +++ b/assets/voxygen/shaders/player-shadow-frag.glsl @@ -29,5 +29,17 @@ uniform u_bones { out vec4 tgt_color; void main() { + float distance = distance(vec3(cam_pos), vec3(model_mat * vec4(vec3(0), 1))) - 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); } \ No newline at end of file diff --git a/voxygen/src/scene/mod.rs b/voxygen/src/scene/mod.rs index bbb4efe64d..d8a2fbe300 100644 --- a/voxygen/src/scene/mod.rs +++ b/voxygen/src/scene/mod.rs @@ -403,14 +403,6 @@ impl Scene { // Render the skybox. renderer.render_skybox(&self.skybox.model, &self.globals, &self.skybox.locals); - self.terrain.render_translucent( - renderer, - &self.globals, - &self.lights, - &self.shadows, - self.camera.get_focus_pos(), - ); - self.figure_mgr.render_player( renderer, state, @@ -422,6 +414,14 @@ impl Scene { &self.camera, ); + self.terrain.render_translucent( + renderer, + &self.globals, + &self.lights, + &self.shadows, + self.camera.get_focus_pos(), + ); + renderer.render_post_process( &self.postprocess.model, &self.globals,