-
-
Notifications
You must be signed in to change notification settings - Fork 790
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
43 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,48 @@ | ||
precision mediump float; | ||
|
||
uniform sampler2D uSampler; | ||
uniform sampler2D uSnow; | ||
uniform vec2 uResolution; | ||
uniform float uTime; | ||
|
||
varying vec2 vTextureCoord; | ||
|
||
/* | ||
Returns a texel of snowflake. | ||
*/ | ||
vec4 getSnow(vec2 pos) { | ||
// Get a texel of the noise image. | ||
vec3 texel; | ||
if (pos.x < 0.0 || pos.x > 1.0 || pos.y < 0.0 || pos.y > 1.0) { | ||
texel = vec3(0.0, 0.0, 0.0); | ||
} else { | ||
texel = texture2D(uSnow, pos).rgb; | ||
#define pi 3.1415926 | ||
|
||
vec2 hash(vec2 p) { | ||
p = vec2(dot(p, vec2(127.1, 311.7)), dot(p, vec2(269.5, 183.3))); | ||
return fract(sin(p) * 18.5453); | ||
} | ||
|
||
float simplegridnoise(vec2 v) { | ||
float s = 1.0 / 256.; | ||
vec2 fl = floor(v), fr = fract(v); | ||
float mindist = 1e9; | ||
for(int y = -1; y <= 1; y++) { | ||
for(int x = -1; x <= 1; x++) { | ||
vec2 offset = vec2(x, y); | ||
vec2 pos = 0.5 + 0.5 * cos(2.0 * pi * (uTime * 0.1 + hash(fl+offset)) + vec2(0, 1.6)); | ||
mindist = min(mindist, length(pos+offset -fr)); | ||
} | ||
} | ||
// Only use extremely bright values. | ||
texel = smoothstep(0.6, 1.0, texel); | ||
// Okay how can this give a transparent rgba value? | ||
return vec4(texel, 1.0); | ||
return mindist; | ||
} | ||
|
||
/* | ||
Provides a 2D vector with which to warp the sampling location | ||
of the snow_flakes texture. | ||
*/ | ||
vec2 warpSpeed(float time, float gravity, vec2 pos) { | ||
// Do some things to stretch out the timescale based on 2D position and actual time. | ||
return vec2(-time * 5.55 + sin(pos.x * 10.0 * sin(time * 0.2)) * 0.4, | ||
time * gravity + sin(pos.y * 10.0 * sin(time * 0.4)) * 0.4); | ||
float blobnoise(vec2 v, float s) { | ||
return pow(0.5 + 0.5 * cos(pi * clamp(simplegridnoise(v) * 2.0, 0.0, 1.0)), s); | ||
} | ||
|
||
vec4 getSnowField(vec2 pos) { | ||
// Just some not-so-magic inversely related values. | ||
// That's all they are. | ||
return getSnow(pos - 0.75 + uTime * 0.25) + | ||
getSnow(pos - 0.5 + uTime * 0.25) + | ||
getSnow(pos - 0.25 + uTime * 0.25) + | ||
getSnow(pos - 0.0 + uTime * 0.25); | ||
float fractalblobnoise(vec2 v, float s) { | ||
float val = 0.0; | ||
const float n = 4.0; | ||
for(float i = 0.0; i < n; i++) { | ||
val += pow(0.5, i + 1.0) * blobnoise(exp2(i) * v + vec2(0, uTime), s); | ||
} | ||
return val; | ||
} | ||
|
||
void main() { | ||
gl_FragColor = max(texture2D(uSampler, vTextureCoord), getSnowField(vTextureCoord)); | ||
vec2 r = vec2(1.0, uResolution.y / uResolution.x); | ||
vec2 uv = vTextureCoord.xy / uResolution.xy; | ||
float val = fractalblobnoise(r * vTextureCoord * 20.0, 5.0); //more snowflakes r * uv * 40.0, 1.25 | ||
gl_FragColor = mix(texture2D(uSampler, vTextureCoord), vec4(1.0), vec4(val)); | ||
} |