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