Created
September 25, 2016 14:37
-
-
Save kmltml/2e2091c4ff2df84d26ac624ecc4beb14 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #define R 1.1 | |
| float wave(in vec2 uv, in vec2 center, in float radius) { | |
| vec2 s = uv - center; | |
| float r = length(s); | |
| float h = sin(r * 50.0 + float(iFrame) / 10.0) * 0.1 * (radius - r); | |
| if(r >= radius) | |
| return 0.0; | |
| else | |
| return h; | |
| } | |
| float computeH(in vec2 uv) { | |
| return wave(uv, vec2(0.0, 0.0), 0.9) | |
| + wave(uv, vec2(1.0, 0.0), 0.9) | |
| + wave(uv, vec2(0.5, 1.0), 0.9) | |
| + 0.5; | |
| } | |
| vec2 displacement(float h, vec2 delta) { | |
| vec2 beta = asin(sin(delta) / R); | |
| vec2 x = tan(delta - beta); | |
| return x*h; | |
| } | |
| float derivativeX(vec2 uv, float e) { | |
| float h = computeH(uv); | |
| float h1 = computeH(uv + vec2(e, 0.0)); | |
| float dh = h1 - h; | |
| return dh / (e); | |
| } | |
| float derivativeY(vec2 uv, float e) { | |
| float h = computeH(uv - vec2(0.0, e)); | |
| float h1 = computeH(uv + vec2(0.0, e)); | |
| float dh = h1 - h; | |
| return dh / (2.0 * e); | |
| } | |
| vec2 derivative(vec2 uv, vec2 e) { | |
| return vec2(derivativeX(uv, e.x), derivativeY(uv, e.y)); | |
| } | |
| void mainImage(out vec4 fragColor, in vec2 fragCoord) { | |
| vec2 uv = fragCoord.xy / iResolution.xy; | |
| float h = computeH(uv); | |
| vec2 der = derivative(uv, vec2(1.0) / iResolution.xy); | |
| vec2 delta = atan(der); | |
| //fragColor = vec4(h, delta, 1.0); | |
| //fragColor = vec4(vec3(h), 1.0); | |
| //fragColor = vec4(h, der.y / 30.0, 0.0, 1.0) / 0.5 + 0.5; | |
| //fragColor = vec4(der.x / 40.0, -der.x / 40.0, 0.0, 1.0); | |
| //fragColor = vec4(delta.x/2.0, -delta.x/2.0, 0.0, 1.0); | |
| fragColor = texture2D(iChannel0, uv + displacement(h, delta) / 50.0); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment