Various fixes, added Rain-Simulation

master
Stefan Krulj 7 years ago
parent 0e23850ebc
commit f59d5073ee
  1. 3
      2D/BoxTiling.glsl
  2. 2
      2D/HexTiling.glsl
  3. 83
      2D/rainyWindow/rainyWindow.glsl
  4. BIN
      2D/water/sand.jpg
  5. 7
      2D/water/water.glsl
  6. BIN
      Textures/forrest.jpg
  7. 0
      Textures/sand.jpg

@ -1,9 +1,6 @@
#iChannel0 "https://i.imgur.com/TnmUwCn.jpg"
float XNUM = 10.;
float YNUM = 10.;
vec4 BoxCoords(vec2 uv) {
vec2 gv = fract(uv);

@ -42,7 +42,7 @@ void mainImage ( out vec4 fragColor, in vec2 fragCoord) {
vec4 hc = HexCoords(uv);
//col.rg = hc(uv).xy;
col.rgb = texture(iChannel0, hc(uv).xy+0.5).rgb;
col.rgb = texture(iChannel0, hc.xy+0.5).rgb;
col.rgb *= vec3(smoothstep(0.09, 0.99, sin(hc.z+hc.w/17.+iTime) ));
fragColor = vec4(col, 1.0);

@ -0,0 +1,83 @@
#iChannel0 "file://./Textures/forrest.jpg"
#iChannel0::MinFilter "LinearMipMapLinear"
#iChannel0::WrapMode "Mirror"
#define S(a,b,c) smoothstep(a,b,c)
float size = 4.0;
vec2 aspect = vec2(2,1);
float N21(vec2 p) {
//return fract( sin(p.x*100.0+p.y*6574.0)*5647.0 );
p = fract(p*vec2(233.32, 851.73));
p += dot(p, p+23.45);
return fract(p.x*p.y);
}
vec4 BoxCoords(vec2 uv) {
vec2 gv = fract(uv);
vec2 id = floor(uv);
//standard uv
return vec4(gv.x, gv.y, id.x, id.y);
}
vec3 RainLayer(vec2 uv, float t) {
vec2 iuv = uv;
uv.y += t * 0.13;
uv *= size * aspect;
vec4 gv = BoxCoords(uv);
gv.xy -= 0.5;
float dt = N21(gv.zw);
t += dt*6.22134;
float w = (iuv.y) * 10.;
float x = (dt-0.5)*0.8;
x += (.4-abs(x))*sin(3.*w)*pow(sin(w),6.)*0.45;
float y = -sin(t+sin(t+sin(t)*0.5))*0.45;
y -= (gv.x-x)*(gv.x-x);
vec2 dropPos = (gv.xy-vec2(x,y))/aspect;
float drop = S(.05, 0.03, length(dropPos));
vec2 trailPos = (gv.xy-vec2(x,t * 0.25))/aspect;
trailPos.y = (fract(trailPos.y * 8.)-0.5) /8.;
float trail = S(.03, 0.01, length(trailPos));
float fogTrail = S(-.05, .05, dropPos.y);
fogTrail *= S(.5, y, gv.y);
trail *= fogTrail;
fogTrail *= S(0.05, 0.04, abs(dropPos.x));
vec2 offset = drop*dropPos + vec2(trail)*trailPos;
offset *= -2.;
return vec3(offset, fogTrail);
//return vec3(drop,1, fogTrail);
}
void mainImage ( out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = (fragCoord/iResolution.y);
float t = iTime; //mod(iTime, 7200.);
vec4 col = vec4(0,0,0,1.0);
vec3 rain = RainLayer(uv,t);
rain += RainLayer(uv*1.2+7.21,t);
rain += RainLayer(uv*1.35+1.21,t);
rain += RainLayer(uv*1.55-1.21,t);
float blur = 4.0*(1.-rain.z);
col.rgb = texture(iChannel0, uv + rain.xy, blur).rgb;
//col = vec4(rain.xxx,1.);
//if (gv.x > 0.48 || gv.y > 0.48) col = vec4(1,0,0,1);
//col.rgb = vec3(N21(uv.xy));
fragColor = col;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 88 KiB

@ -1,5 +1,5 @@
#iChannel0::WrapMode "Repeat"
#iChannel0 "file://./sand2.jpg"
#iChannel0 "file://./Textures/sand.jpg"
float N21(vec2 p) {
//return fract( sin(p.x*100.0+p.y*6574.0)*5647.0 );
@ -41,12 +41,11 @@ float SmoothNoise2(vec2 uv, int ocataves) {
void mainImage ( out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = (fragCoord-0.5*iResolution.xy)/iResolution.y;
uv = uv*4.;
float tmp;
float b = SmoothNoise2(uv+iTime*0.5,2)*0.5+SmoothNoise2(uv-iTime*0.2,2)*0.5;
float b = SmoothNoise2(uv*4.+iTime*0.5,2)*0.5+SmoothNoise2(uv*4.-iTime*0.2,2)*0.5;
tmp = smoothstep(0.5, 0.505, b);
b = tmp - smoothstep(0.505, 0.51, b);
fragColor = vec4( texture(iChannel0, uv+ SmoothNoise2(uv+iTime*0.5,2)*0.4 ).xyz+b, 1.0 );
fragColor = vec4( texture(iChannel0, uv*1.5+ SmoothNoise2(uv+iTime*0.5,2)*0.4 ).xyz+b, 1.0 );
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 905 KiB

Before

Width:  |  Height:  |  Size: 196 KiB

After

Width:  |  Height:  |  Size: 196 KiB

Loading…
Cancel
Save