uniform vec2 resolution; uniform float time; bool isphere( in vec4 sph, in vec3 ro, in vec3 rd, out vec2 t ) { vec3 oc = ro - sph.xyz; float b = dot(oc,rd); float c = dot(oc,oc) - sph.w*sph.w; float h = b*b - c; if( h<0.0 ) return false; float g = sqrt( h ); t.x = - b - g; t.y = - b + g; return true; } const int NumIte = 7; const float Bailout = 100.0; bool iterate( in vec3 q, out float resPot, out vec4 resColor ) { vec4 trap = vec4(100.0); vec3 zz = q; float m = dot(zz,zz); if( m > Bailout ) { resPot = 0.5*log(m)/pow(8.0,0.0); resColor = vec4(1.0); return false; } for( int i=1; i Bailout ) { resColor = trap; resPot = 0.5*log(m)/pow(8.0,float(i)); return false; } } resColor = trap; resPot = 0.0; return true; } bool ifractal( in vec3 ro, in vec3 rd, out float rest, in float maxt, out vec3 resnor, out vec4 rescol, float fov ) { vec4 sph = vec4( 0.0, 0.0, 0.0, 1.25 ); vec2 dis; // bounding sphere if( !isphere(sph,ro,rd,dis) ) return false; // early skip if( dis.y<0.001 ) return false; // clip to near! if( dis.x<0.001 )dis.x = 0.001; if( dis.y>maxt) dis.y = maxt; float dt; vec3 gra; vec4 color; float fovfactor = 1.0/sqrt(1.0+fov*fov); // raymarch! for( float t=dis.x; t0.001 ) if( ifractal(xyz,light1,lt1,1e20,ln,lc,fov) ) dif1 = 0.1; // material color rgb = vec3(1.0,1.0,1.0); rgb = mix( rgb, vec3(0.8,0.6,0.2), sqrt(col.x)*1.25 ); rgb = mix( rgb, vec3(0.8,0.3,0.3), sqrt(col.y)*1.25 ); rgb = mix( rgb, vec3(0.7,0.4,0.3), sqrt(col.z)*1.25 ); // lighting rgb *= (0.5+0.5*nor.y)*vec3(.14,.15,.16)*0.8 + dif1*vec3(1.0,.85,.4) + 0.5*dif2*vec3(.08,.10,.14); rgb *= vec3( pow(ao,0.8), pow(ao,1.00), pow(ao,1.1) ); // gamma rgb = 1.5*(rgb*0.15 + 0.85*sqrt(rgb)); } vec2 uv = p*0.5+0.5; rgb *= 0.7 + 0.3*16.0*uv.x*uv.y*(1.0-uv.x)*(1.0-uv.y); rgb = clamp( rgb, 0.0, 1.0 ); gl_FragColor = vec4(rgb,1.0); }