From 7c176c3d14ad1bbaca790a8bb629b9a14466c6b7 Mon Sep 17 00:00:00 2001 From: Brad Parker Date: Sun, 11 Dec 2016 12:59:32 -0500 Subject: [PATCH] replace simple snow with fancy snow code with different parameters --- .../pipeline_snow_simple.glsl.frag.h | 105 ++++++++++-------- 1 file changed, 61 insertions(+), 44 deletions(-) diff --git a/gfx/drivers/gl_shaders/pipeline_snow_simple.glsl.frag.h b/gfx/drivers/gl_shaders/pipeline_snow_simple.glsl.frag.h index 94687fe269..a72ad96299 100644 --- a/gfx/drivers/gl_shaders/pipeline_snow_simple.glsl.frag.h +++ b/gfx/drivers/gl_shaders/pipeline_snow_simple.glsl.frag.h @@ -1,52 +1,69 @@ #include "shaders_common.h" static const char *stock_fragment_xmb_simple_snow = GLSL( - uniform float time; - vec2 res = vec2(1920*3, 1080*3); - float quality = 8.0; + uniform float time; + uniform vec2 OutputSize; - float Cellular2D(vec2 P) { - vec2 Pi = floor(P); - vec2 Pf = P - Pi; - vec2 Pt = vec2( Pi.x, Pi.y + 1.0 ); - Pt = Pt - floor(Pt * ( 1.0 / 71.0 )) * 71.0; - Pt += vec2( 26.0, 161.0 ); - Pt *= Pt; - Pt = Pt.xy * Pt.yx; - float hash_x = fract( Pt.x * ( 1.0 / 951.135664 ) ) * 2.0 - 1.0; - float hash_y = fract( Pt.y * ( 1.0 / 642.949883 ) ) * 2.0 - 1.0; - const float JITTER_WINDOW = 0.25; - hash_x = ( ( hash_x * hash_x * hash_x ) - sign( hash_x ) ) * JITTER_WINDOW; - hash_y = ( ( hash_y * hash_y * hash_y ) - sign( hash_y ) ) * JITTER_WINDOW; - vec2 dd = vec2(Pf.x - hash_x, Pf.y - hash_y); - float d = dd.x * dd.x + dd.y * dd.y; - return d * ( 1.0 / 1.125 ); - } + float baseScale = 1.25; // [1.0 .. 10.0] + float density = 0.5; // [0.01 .. 1.0] + float speed = 0.15; // [0.1 .. 1.0] - float snow(vec2 pos, float time, float scale) { - pos.x += cos(pos.y*4.0 + time*3.14159*2.0 + 1.0/scale)/(8.0/scale); - pos += time*scale*vec2(-0.5, 1.0); - return max( - 1.0 - Cellular2D(mod(pos/scale, scale*quality)*16.0)*1024.0, - 0.0 - ) * (scale*0.5 + 0.5); - } + float rand(vec2 co) + { + return fract(sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453); + } - void main( void ) { - float winscale = max(res.x, res.y); - float tim = mod(time/8.0, 84.0*quality); - vec2 pos = gl_FragCoord.xy/winscale; - float a = 0.0; - a += snow(pos, tim, 1.0); - a += snow(pos, tim, 0.7); - a += snow(pos, tim, 0.6); - a += snow(pos, tim, 0.5); - a += snow(pos, tim, 0.4); - a += snow(pos, tim, 0.3); - a += snow(pos, tim, 0.25); - a += snow(pos, tim, 0.125); - a = a * min(pos.y*4.0, 1.0); - gl_FragColor = vec4(1.0, 1.0, 1.0, a); - } + float dist_func(vec2 distv) + { + float dist = sqrt((distv.x * distv.x) + (distv.y * distv.y)) * (40.0 / baseScale); + dist = clamp(dist, 0.0, 1.0); + return cos(dist * (3.14159265358 * 0.5)) * 0.5; + } + + float random_dots(vec2 co) + { + float part = 1.0 / 20.0; + vec2 cd = floor(co / part); + float p = rand(cd); + + if (p > 0.005 * (density * 40.0)) + return 0.0; + + vec2 dpos = (vec2(fract(p * 2.0) , p) + vec2(2.0, 2.0)) * 0.25; + + vec2 cellpos = fract(co / part); + vec2 distv = (cellpos - dpos); + + return dist_func(distv); + } + + float snow(vec2 pos, float time, float scale) + { + // add wobble + pos.x += cos(pos.y * 1.2 + time * 3.14159 * 2.0 + 1.0 / scale) / (8.0 / scale) * 4.0; + // add gravity + pos += time * scale * vec2(-0.5, 1.0) * 4.0; + return random_dots(pos / scale) * (scale * 0.5 + 0.5); + } + + void main(void) + { + float tim = time * 0.4 * speed; + vec2 pos = gl_FragCoord.xy / OutputSize.xx; + float a = 0.0; + // Each of these is a layer of snow + // Remove some for better performance + // Changing the scale (3rd value) will mess with the looping + a += snow(pos, tim, 1.0); + a += snow(pos, tim, 0.7); + a += snow(pos, tim, 0.6); + a += snow(pos, tim, 0.5); + a += snow(pos, tim, 0.4); + a += snow(pos, tim, 0.3); + a += snow(pos, tim, 0.25); + a += snow(pos, tim, 0.125); + a = a * min(pos.y * 4.0, 1.0); + gl_FragColor = vec4(1.0, 1.0, 1.0, a); + } );