Title: Mandelbox render glitch
Post by: lapinot on September 19, 2015, 03:16:56 AM
Hi, Im trying to render the Mandelbox with http://blog.hvidtfeldts.net/index.php/2011/11/distance-estimated-3d-fractals-vi-the-mandelbox/ (http://blog.hvidtfeldts.net/index.php/2011/11/distance-estimated-3d-fractals-vi-the-mandelbox/) formula but it seems I don't cut it. Here's my almost unmodified code (HLSL) (FScale = 2.2) : float fixedRadius2 = 1.0 * 1.0; float minRadius2 = 0.5 * 0.5; float foldingLimit = 1;
void sphereFold(inout float3 z, inout float dz) { float r2 = dot(z,z); if (r2 < minRadius2) { // linear inner scaling float temp = (fixedRadius2/minRadius2); z *= temp; dz*= temp; } else if (r2 < fixedRadius2) { // this is the actual sphere inversion float temp =(fixedRadius2/r2); z *= temp; dz*= temp; } }
void boxFold(inout float3 z, inout float dz) { z = clamp(z, -foldingLimit, foldingLimit) * 2.0 - z; }
float DE(float3 z) { float3 offset = z * FScale; float dr = FScale; for (int i = 0; i < FMaxIterations; i++) { boxFold(z,dr); // Reflect sphereFold(z,dr); // Sphere Inversion
z = FScale * z + offset; // Scale & Translate dr = dr * abs(FScale) + 1.0; } float r = length(z); return r / abs(dr); } Alternatively I tried with (Buddhi's ?) : float3 z = pos * FScale; float DEfactor = FScale; float fixedRadius = 1.0; float fR2 = fixedRadius * fixedRadius; float minRadius = 0.5; float mR2 = minRadius * minRadius; for (int i = 0; i != FMaxIterations; i++) {
if (pos.x > 1.0) pos.x = 2.0 - pos.x; else if (pos.x < -1.0) pos.x = -2.0 - pos.x; if (pos.y > 1.0) pos.y = 2.0 - pos.y; else if (pos.y < -1.0) pos.y = -2.0 - pos.y; if (pos.z > 1.0) pos.z = 2.0 - pos.z; else if (pos.z < -1.0) pos.z = -2.0 - pos.z;
float r2 = pos.x * pos.x + pos.y * pos.y + pos.z * pos.z;
if (r2 < mR2) { pos *= fR2 / mR2; DEfactor = DEfactor * fR2 / mR2; } else if (r2 < fR2) { pos *= fR2 / r2; DEfactor *= fR2 / r2; }
pos = pos * FScale + z; DEfactor *= FScale; } return min(2.0, sqrt(pos.x * pos.x + pos.y * pos.y + pos.z * pos.z) / abs(DEfactor)); but no good results either. Anything obvious ? Thanks for your time.
Title: Re: Mandelbox render glitch
Post by: mclarekin on September 19, 2015, 04:09:25 AM
To confuse you here it is in Buddhi's openCL code NOTE:- Initial Conditions outside the loopInitial DE = 1.0f; Initial z = point Inside the loopDE = DE * fabs( m ) + 1.0f; and the adding the addition constant multiplier in z = z * m + c ; c = point * constant multiplier . The constant multiplier is a default of 1.0f for standard Mboxes, BTW it is more fun setting up the constant multiplier as a vector of so you can tweak z.x, z.y & z.z by individual constant multipliers BTW z = z * m + c + cj, is even more fun, with cj being a vector3 of simple addition constants (julia) Hope this helps int3 cond1, cond2;
//Box fold cond1 = isgreater(z, foldingLimit); cond2 = isless(z, -foldingLimit); z = select(z, foldingValue - z, cond1); z = select(z, -foldingValue - z, cond2);
//Spherical fold float rr = dot(z,z); float m = scale; if (rr < mr2) m *= native_divide(fr2, mr2); else if (rr < fr2) m *= native_divide(fr2,rr);
Applying spherical fold (modified m) and adding the addition constant multiplier z = z * m + c ;
DE = DE * fabs( m ) + 1.0f;
r = distance(z, orbitTrap); colourMin += fabs(m );
//Bailout if(r>1024.0f)
Title: Re: Mandelbox render glitch
Post by: lapinot on September 19, 2015, 02:21:42 PM
Okay better now. ;D
(http://grid.turtlespeak.net/upload/LMo6pu2bZ3pYC5QU/lMiQKOZTmLoMe9nF/mandelbox-1.png)
Not sure what the culprit was - half my rendering code and not setting init values for DEfactor / z correctly.
Thanks for the help.
-Lap
|