Created
October 6, 2018 17:57
-
-
Save leinonen/30444be3bf814da46b7236fed6d33746 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
#ifdef GL_ES | |
precision mediump float; | |
#endif | |
uniform float time; | |
uniform vec2 resolution; | |
#define PI 3.1415926535898 | |
#define EPS 0.01 | |
const float clipFar = 100.0; | |
const float scaler = 1.0; | |
mat2 rot2( float a ) { float c = cos(a); float s = sin(a); return mat2( c, s,-s, c); } | |
float bump(vec3 p) { float t = 0.2*time*PI; return cos(p.x*t)*sin(p.y*t)*sin(-p.z*t);} | |
float map(vec3 p) { | |
float b = bump(p/scaler); | |
return length(p + b) - 2.5; | |
} | |
void main( void ) { | |
vec2 uv = (2.0*gl_FragCoord.xy/resolution.xy - 1.0) * vec2(resolution.x/resolution.y, 1.0); | |
vec3 lookAt = vec3(0,0, 0.0); | |
vec3 camPos = lookAt + vec3(0, 0, lookAt.z - 2.0); | |
vec3 lightPos = lookAt + vec3(0, 0, lookAt.z - 2.0); | |
vec3 forward = normalize(camPos); | |
vec3 right = vec3(forward.z, 0., -forward.x ); | |
vec3 up = cross(forward, right); | |
vec3 rd = normalize(forward + uv.x*right + uv.y*up); | |
rd.xz *= rot2(time * PI / 19.); | |
// rd.yz *= rot2(PI / 2.); | |
rd.yz *= rot2(sin(time *PI*.22)*PI/12.); | |
float t = 0.0; | |
// for (int i = 0 ; i < 1; i++) { | |
float k = map(camPos + rd * t); | |
t += k; | |
// t += k * 0.35; | |
// if ((k < 0.0) || (t > clipFar)) { | |
// break; | |
// } | |
// } | |
vec3 final = vec3(0); | |
vec3 p = camPos + rd * t; | |
vec3 normal = normalize(vec3( | |
map(vec3(p.x+EPS,p.y,p.z)) - map(vec3(p.x-EPS,p.y,p.z)), | |
map(vec3(p.x,p.y+EPS,p.z)) - map(vec3(p.x,p.y-EPS,p.z)), | |
map(vec3(p.x,p.y,p.z+EPS)) - map(vec3(p.x,p.y,p.z-EPS)) | |
)); | |
vec3 lightDirection = normalize(lightPos - p); | |
vec3 eyeDirection = normalize(camPos - p); | |
float shade = 0.05 + 0.95 * max( 0.0, dot(normal, lightDirection) ); | |
final += shade; | |
final += pow(max( 0.0, dot(reflect(-lightDirection, normal), eyeDirection) ), 12.0); | |
float speed = 2.3; | |
final += vec3(1.0, 0, 0) * cos(length(p + bump(p))*PI + time * PI * speed); | |
final += vec3(1.0, 1.0, 0) * cos(length(p - bump(p))*PI + time * PI * speed*.8); | |
gl_FragColor = vec4(clamp(pow(final, vec3(1.0 / 2.4)), 0.0, 1.0) , 1.0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment