Experimentation with Shadertoy. Helped me understand signed distance fields. I was obsessing over a paper on signed distance field modeling but had to realize that this effort would take much more time. I'd love to pick it up again sometime.
//primitive functions float sdSphere( vec3 p ) { return length(p)-0.1; } float sdTorus( vec3 p ) { vec2 t = vec2 (0.45,0.04); vec2 q = vec2(length(p.xz)-t.x,p.y); return length(q)-t.y; } //-------------------------------------------------------- float map(vec3 p) { //Repetition vec3 c = vec3 (1.0,1.0,1.0); vec3 q = mod(p,c)-0.5*c; return sdTorus (q); } float trace(vec3 o, vec3 r) //raymarching function { float t = 0.0; for (int i=0; i<32;i++) { vec3 p = o + r * t; float d = map(p); t += d*1.0; } return t; } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { //resolution/uv adjustments vec2 uv = fragCoord.xy / iResolution.xy; uv = uv*2.0 -1.0; uv.x *= iResolution.x/iResolution.y; vec3 r = normalize (vec3(uv,1.0)); //camera vec3 o = vec3 (0.0, iGlobalTime/5.0,+3.0- iMouse.x/50.0); float t = trace(o,r); float fog = 1.0 / (1.0 +t *t * 0.1); vec3 fc = vec3(fog); fragColor = vec4(fc,1.0); }