commit 81dbce2d8a5d6112380a3f1747aff281d3e417ae parent 824c7244d139e2dc8680ce5c22c24415ae730b2e Author: Michael Savage <mikejsavage@gmail.com> Date: Wed Jul 26 19:55:48 +0300 Better dithering again Diffstat:
shaders/terrain.glsl | | | 10 | +++------- |
diff --git a/shaders/terrain.glsl b/shaders/terrain.glsl @@ -1,7 +1,6 @@ struct VSOut { vec4 view_position; vec3 world_position; - vec4 screen_position; }; #ifdef VERTEX_SHADER @@ -17,8 +16,7 @@ layout( std140 ) uniform view { void main() { v2f.world_position = position; v2f.view_position = V * vec4( position, 1.0 ); - v2f.screen_position = P * v2f.view_position; - gl_Position = v2f.screen_position; + gl_Position = P * v2f.view_position; } #else @@ -42,7 +40,7 @@ uniform samplerBuffer point_light_colours; vec3 noise( vec2 uv ) { vec3 dither = vec3( dot( vec2( 171.0, 231.0 ), uv ) ); dither = fract( dither / vec3( 103.0, 71.0, 97.0 ) ) - vec3( 0.5, 0.5, 0.5 ); - return ( dither / 256.0 ) * 0.375; + return ( dither / 256.0 ) * 0.5; } void main() { @@ -101,9 +99,7 @@ void main() { float fog_distance_bias = 100.0; float fog_t = 1.0 - exp( -fog_strength * max( ( length( v2f.view_position ) - fog_distance_bias ), 0.0 ) ); - vec2 ndc = v2f.screen_position.xy / v2f.screen_position.w; - // seems to produce good results even at other resolutions - vec3 dither_noise = noise( ndc * vec2( 1920, 1080 ) ); + vec3 dither_noise = noise( gl_FragCoord.xy ); colour = vec4( mix( c, fog_colour, fog_t ) + dither_noise, 1.0 ); }