commit 45bf5ffe31f47541fe5a5d611505ccc8dc07cb43 parent 75745ceafd53891ea769dfe3894d03a6b744e750 Author: Michael Savage <mikejsavage@gmail.com> Date: Sat Aug 26 16:30:18 +0100 Add common.glsl Diffstat:
shaders/common.glsl | | | 5 | +++++ |
shaders/terrain.glsl | | | 8 | +------- |
diff --git a/shaders/common.glsl b/shaders/common.glsl @@ -0,0 +1,5 @@ +vec3 alu_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.5; +} diff --git a/shaders/terrain.glsl b/shaders/terrain.glsl @@ -37,12 +37,6 @@ uniform sampler2D horizons; uniform samplerBuffer point_light_origins; 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.5; -} - void main() { vec2 world_pos = mod( v2f.world_position.xy, textureSize( normals, 0 ) - ivec2( 1, 1 ) ); @@ -99,7 +93,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 ) ); - vec3 dither_noise = noise( gl_FragCoord.xy ); + vec3 dither_noise = alu_noise( gl_FragCoord.xy ); colour = vec4( mix( c, fog_colour, fog_t ) + dither_noise, 1.0 ); }