-
-
Save shinmai/d87f740343b4f200f9ff7ce18c7e75fc 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 PI 3.14159265359 | |
#define PI2 6.28318530718 | |
// Comment or uncomment | |
// (Leave commented if in shadergif) | |
// (uncomment if in shadertoy) | |
//#define shadertoy 1 | |
#ifdef shadertoy | |
// time is iGlobalTime in shadertoy | |
#define time iGlobalTime | |
#endif | |
#ifndef shadertoy | |
// Define some uniforms | |
// (which shadertoy already defines for us, but not shadergif) | |
precision highp float; | |
uniform float time; | |
uniform float iGlobalTime; | |
varying vec2 UV; | |
uniform vec3 iResolution; | |
#endif | |
float map(vec3 pos){ | |
pos = fract(pos) * 2.0 - 1.0; | |
if(abs(pos.x) > 0.2 || abs(pos.y) > 0.2){ | |
return 1.0; | |
} | |
return length(pos) - 0.3; | |
} | |
float trace(vec3 o, vec3 r){ | |
vec3 p; | |
float t = 0.0; | |
float d; | |
for(int i = 0; i < 32; i++){ | |
p = o + r * t; | |
d = map(p); | |
t += d * 0.5; | |
} | |
return t; | |
} | |
void mainImage( out vec4 fragColor, in vec2 fragCoord ) | |
{ | |
vec2 uv = fragCoord.xy / iResolution.xy; | |
float ratio = iResolution.x / iResolution.y; | |
uv.x *= ratio; | |
vec4 col = vec4(0.0); | |
vec2 pos = uv - vec2(0.5 * ratio, 0.5); | |
pos *= 1.0; | |
vec3 r,o; | |
r = normalize(vec3(pos, 1.0)); | |
o = vec3(0.0, 0.0, -3.0); | |
o.z += time; | |
float t = trace(o, r); | |
col += 1.0 / (1.0 + t * t * 0.03); | |
col = 0.1 * floor(col * 10.0); | |
col.a = 1.0; | |
fragColor = col; | |
} | |
#ifndef shadertoy | |
void main(){ | |
vec2 uv = UV.xy * iResolution.xy; | |
vec4 col; | |
mainImage(col, uv); | |
gl_FragColor = col; | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment