Welcome to Fractal Forums

Community => Let's collaborate on something! => Topic started by: eiffie on December 15, 2011, 06:34:59 PM




Title: A vector running derivative for a multi-scaled box.
Post by: eiffie on December 15, 2011, 06:34:59 PM
After reading Syntopia's excellent post on using dual numbers to create a multi-scale box ...
http://www.fractalforums.com/new-theories-and-research/dual-numbers-for-creating-distance-estimators/ (http://www.fractalforums.com/new-theories-and-research/dual-numbers-for-creating-distance-estimators/)
I decided to dust off an old script that used a vector derivative for doing same. (When dual numbers become standard types I will abandon this quest.) The idea is simple and I am sure others have tried it and I'm hoping they can explain it to me! I simply changed all the scalars to vectors so the code looks much the same (in glsl).
Code:
const vec3 minRadius=vec3(0.25,0.25,0.25);
const vec3 fixRadius=vec3(1.0,1.0,1.0);
const vec3 foldLimit=vec3(1.0,1.0,1.0);
const vec3 SCALE=vec3(-2.5,-2.5,-2.5);
const vec3 scale=SCALE/minRadius;
const vec3 boundingVolume=abs(SCALE*foldLimit)*3.0;//????
const vec3 dc=vec3(1.0,1.0,1.0);
float DE(vec3 z0)
{
vec3 z=z0;
vec3 dz=dc;
for (int n=0;n<iters;n++) {
z=clamp(z,-foldLimit,foldLimit)*2.0-z;
vec3 scl=scale*clamp(minRadius/dot(z,z),minRadius,fixRadius);
z*=scl;dz*=abs(scl);
z+=z0;dz+=dc;
}
return length(z)/length(dz);
//...or for a rect signed value
//z=(abs(z)-boundingVolume)/dz;
//return max(z.x,max(z.y,z.z));
}
All the constants minRadius,fixRadius,foldLimit and SCALE can be different in each dimension.
The code above "works" but it raises more questions.
First what should the return value be for a signed and scaled sphere?
Should dz really be initialized to vec3(1.0) or normalize(vec3(1.0))?
I assumed if I rotate z I must also rotate dz. This isn't true and creates a worse estimate. Why?
If we now have an idea of how the function is changing in each dimension can we use the ray march direction to look only at the change in the direction we are marching???

Has anyone tried this and can give their insight?

Here's the output...
http://www.youtube.com/watch?v=mmmRg-oVOoM


Title: Re: A vector running derivative for a multi-scaled box.
Post by: Syntopia on December 16, 2011, 05:11:19 PM
Well, I'm surprised that works! Now, if only we could get to know why :-)

Quote
I assumed if I rotate z I must also rotate dz. This isn't true and creates a worse estimate. Why?

Your 'dz' vector doesn't seem to be directional - it is certainly not a gradient of length(z). If I use the normalized dz vector as color, it seems to point in the same directions at all points in the Mandelbox - only the length changes.


Quote
If we now have an idea of how the function is changing in each dimension can we use the ray march direction to look only at the change in the direction we are marching???

I've also thought about this. David Makin has some comments about why a four point method is beter than a two point directional method here: http://blog.hvidtfeldts.net/index.php/2011/09/distance-estimated-3d-fractals-v-the-mandelbulb-different-de-approximations/


Title: Re: A vector running derivative for a multi-scaled box.
Post by: eiffie on December 16, 2011, 05:31:58 PM
Good insite. It may only work because length(vec3(1.0)) is already greater than 1.0 so dividing by length(dz) at the end is just a big enough fudge factor. I definitely need to experiment with it more!


Title: Re: A vector running derivative for a multi-scaled box.
Post by: eiffie on December 20, 2011, 04:48:23 PM
In keeping with my origin "logic" :) of keeping a running derivative in each dimension seperately the return value should be:
return length(z/dz);