Skip to content

Instantly share code, notes, and snippets.

@but0n
Last active March 14, 2019 14:11
Show Gist options
  • Save but0n/191cf8668b7ffd7576cfeab00e439a82 to your computer and use it in GitHub Desktop.
Save but0n/191cf8668b7ffd7576cfeab00e439a82 to your computer and use it in GitHub Desktop.
// uniform vec3 iResolution;// viewport resolution (in pixels)
// uniform float iTime;// shader playback time (in seconds)
// uniform float iTimeDelta;// render time (in seconds)
// uniform int iFrame;// shader playback frame
// uniform float iChannelTime[4];// channel playback time (in seconds)
// uniform vec3 iChannelResolution[4];// channel resolution (in pixels)
// uniform vec4 iMouse;// mouse pixel coords. xy: current (if MLB down), zw: click
// uniform samplerXX iChannel0..3;// input channel. XX = 2D/Cube
// uniform vec4 iDate;// (year, month, day, time in seconds)
// uniform float iSampleRate;// sound sample rate (i.e., 44100)
float dfield(vec3 p) {
vec3 s1 = vec3(0, 0, 5);
float d = distance(p, s1) - 1.0;
return d;
}
vec4 march(vec3 ray) {
vec3 color = vec3(0, 0, 0);
float d = 0.;
float delta = 0.;
for(int s = 0; s < 128; s++) {
delta = dfield(ray * d);
if(delta > 0.01) {
d += delta;
} else {
// return vec4(ray*d, 1);
vec3 n = normalize(ray * d - vec3(0,0,5));
float nol = dot(n, normalize(vec3(sin(iTime), 1, -1)));
color += vec3(nol);
break;
}
}
return vec4(color, 1);
}
void main() {
vec2 uv = (gl_FragCoord.xy-.5 * iResolution.xy) / iResolution.y;
vec3 ray = vec3(0, 0, -1);
ray = normalize(vec3(uv, 0) - ray);
gl_FragColor = vec4(ray, 1);
gl_FragColor = march(ray);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment