1 #include "shaders_common.h" 2 3 static const char *stock_fragment_xmb_simple_snow = GLSL( 4 uniform float time; 5 uniform vec2 OutputSize; 6 7 float baseScale = 1.25; /* [1.0 .. 10.0] */ 8 float density = 0.5; /* [0.01 .. 1.0] */ 9 float speed = 0.15; /* [0.1 .. 1.0] */ 10 11 float rand(vec2 co) 12 { 13 return fract(sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453); 14 } 15 16 float dist_func(vec2 distv) 17 { 18 float dist = sqrt((distv.x * distv.x) + (distv.y * distv.y)) * (40.0 / baseScale); 19 dist = clamp(dist, 0.0, 1.0); 20 return cos(dist * (3.14159265358 * 0.5)) * 0.5; 21 } 22 23 float random_dots(vec2 co) 24 { 25 float part = 1.0 / 20.0; 26 vec2 cd = floor(co / part); 27 float p = rand(cd); 28 29 if (p > 0.005 * (density * 40.0)) 30 return 0.0; 31 32 vec2 dpos = (vec2(fract(p * 2.0) , p) + vec2(2.0, 2.0)) * 0.25; 33 34 vec2 cellpos = fract(co / part); 35 vec2 distv = (cellpos - dpos); 36 37 return dist_func(distv); 38 } 39 40 float snow(vec2 pos, float time, float scale) 41 { 42 /* add wobble */ 43 pos.x += cos(pos.y * 1.2 + time * 3.14159 * 2.0 + 1.0 / scale) / (8.0 / scale) * 4.0; 44 /* add gravity */ 45 pos += time * scale * vec2(-0.5, 1.0) * 4.0; 46 return random_dots(pos / scale) * (scale * 0.5 + 0.5); 47 } 48 49 void main(void) 50 { 51 float tim = time * 0.4 * speed; 52 vec2 pos = gl_FragCoord.xy / OutputSize.xx; 53 float a = 0.0; 54 /** 55 * Each of these is a layer of snow 56 * Remove some for better performance 57 * Changing the scale (3rd value) will mess with the looping 58 **/ 59 a += snow(pos, tim, 1.0); 60 a += snow(pos, tim, 0.7); 61 a += snow(pos, tim, 0.6); 62 a += snow(pos, tim, 0.5); 63 a += snow(pos, tim, 0.4); 64 a += snow(pos, tim, 0.3); 65 a += snow(pos, tim, 0.25); 66 a += snow(pos, tim, 0.125); 67 a = a * min(pos.y * 4.0, 1.0); 68 gl_FragColor = vec4(1.0, 1.0, 1.0, a); 69 } 70 71 ); 72