• May 08, 2021, 04:24:06 AM

GAZ_42
Previous Image | Next Image
Description: Rendition of Fractal 42 by gaz:   https://www.shadertoy.com/view/Nss3WB

01 #define R(p,a,r)mix(a*dot(p,a),p,cos(r))+sin(r)*cross(p,a)
02
03 void mainImage(out vec4 O, vec2 C)
04 {
05  O=vec4(0);
06  vec3 p,q,r=iResolution,
07  d=normalize(vec3((C-.5*r.xy)/r.y,1));
08  for(float i=0.,s,e,g=1.;
09      ++i<80.;
10      O.xyz+=.04*abs(cos(d+log(s)*.3))*exp(-i*i*e)
11  )
12  {
13      p=g*d;
14      p.z-=mix(.5,10.,step(.5,fract(iTime*.1)));
15      p=R(p,normalize(vec3(1,2,3)),iTime*.2);
16      q=p;
17      s=1.5;
18      for(int j=0;j++<12;)
19          p=sign(p)*(1.5-abs(p-1.5)),
20          p=p*(e=8./clamp(dot(p,p),.5,5.))+q,s*=e;
21      g+=e=length(p)/s;
22  }
23 }

My dissection, with goal of extracting a DE() routine (please correct my mistakes)

01. Many shadertoy images are animated. This routine pans the image via 'iTime'.   I don't need this.
03. 'O' is the output color for pixel 'C',  where pixel coordinates are mapped to -1...1
05. Output color defaults to black
06. 'p' = position along the ray marching ray,  'r' scales pixel coordinate
07. 'd' = direction vector for the ray
08. We will march along the ray 80 times
10. output color added to according to 'd' direction vector, 's' scale factor and loop count.   Need help understanding this
13. Position on ray is direction vector * 'g'
14. animation tweak we can ignore
15. animation tweak we can ignore
17. Default scaling factor
18. DE() routine executed 12 times
19. DE meat
20. DE meat   'e' temporary variable calcs scaling delta using new and old position
p = p * e + q position updated
s *= e scaling factor updated
21. 'g' = amount to advance along ray

What I came up with may not match what Gaza was doing, but it still results in an interesting fractal:

CPU -----------------------------------

control.isteps = 13
control.cx = 1.182
control.cy = 2.108
control.cz = -0.865
control.cw = 2.012

GPU  ---------------------------------

float DE(float3 p, device Control &control,thread float4 &orbitTrap) {
float e,s = 1.5;
float3 q = p;

for (int i=0; i<control.isteps; i++) {
p = sign(p) * (control.cx - abs(p - control.cx));
e = control.cy / clamp(dot(p,p),control.cz,control.cz+control.cw);
p = p * e + q;
s *= e;

orbitTrap = min(orbitTrap, float4(abs(p), dot(p,p)));
}

return length(p)/ s - 0.001;
}

Stats:
Views: 23
Total Favorities: 0 View Who Favorited
Filesize: 3.85MB
Height: 1043 Width: 1800
Keywords: stereo
Posted by: kosalos April 04, 2021, 06:21:19 PM

Rating: by 1 members.
Total Likes: 1