Hi,
I have been trying to get a distance estimated render working for rendering a 3D slice through the Julia Set. My approach is based off of some example code (http://users.cms.caltech.edu/~keenan/project_qjulia_source.html) and some theory (http://blog.hvidtfeldts.net/index.php/2011/09/distance-estimated-3d-fractals-iv-the-holy-grail/). It is:
#define COMPLEX_MUL(V1,V2, RESULT) { vec2 _temp=V1*V2; RESULT=vec2(_temp.x-_temp.y,V1.x*V2.y+V1.y*V2.x); } /* RESULT = V1 * V2 */
#define COMPLEX_SQADD(V1,V2, RESULT) { vec2 _temp1=V1*V1; float _temp2=V1.x*V1.y; RESULT=vec2(_temp1.x-_temp1.y,_temp2+_temp2)+V2; } /* RESULT = V1*V1 + V2 */
float julia3D_de(int n, vec3 pos) { //returns distance
//Complex numbers are stored as a two element vector (vec2) as <real,imag>.
vec2 z=pos.xy; //z
vec2 c=vec2(pos.z,0.5); //c; I have tried many other values than 0.5
vec2 zp = vec2(1.0,0.0); //z', the running derivative, initially 1.0+0.0i
for (int j=0;j<n;++j) {
vec2 temp = z;
COMPLEX_MUL(z,zp, temp) //temp = z*zp, complex multiplication
zp = 2.0 * temp;
COMPLEX_SQADD(z,c, z) //z = z*z + c
if (dot(z,z) > 16.0) { //Have tried 2.0, 4.0, and several other values here
break;
}
}
float normZ = length(z);
return 0.5 * normZ * log(normZ) / length(zp);
};This code doesn't produce anything that looks right; it produces a blob with filaments--and no internal structure. The boundary for stepping is -5.0 to 5.0 on all axes, and is iterated to distance tolerance 0.0001.
Does this look like the right approach? Am I missing anything obvious?
Thanks,
Ian