Welcome to Fractal Forums

Fractal Software => 3D Fractal Generation => Topic started by: khyperia on March 30, 2012, 09:19:05 PM




Title: Mandelbox DE formula
Post by: khyperia on March 30, 2012, 09:19:05 PM
This formula, a modified one from 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/), isn't working. Well, for scales above 1, it is, but for negative scales it isn't. Personally, I think negative scale mandelboxes are better, so I really want to get this working. I've basically narrowed the problem down to this core forumla. (Language is C#, 100% my own program (excluding the copy-pasta'd formulae), example render http://khyperia.tumblr.com/post/20060287683/moar-renders (http://khyperia.tumblr.com/post/20060287683/moar-renders))
Code:
public static float DistanceEstimator(Vector3 z)
        {
            Vector3 c = z;
            float dr = 1.0f;
            for (int n = 0; n < Settings.maxIterations; n++)
            {
                if (z.X > 1)
                    z.X = 2 - z.X;
                else if (z.X < -1)
                    z.X = -2 - z.X;
                if (z.Y > 1)
                    z.Y = 2 - z.Y;
                else if (z.Y < -1)
                    z.Y = -2 - z.Y;
                if (z.Z > 1)
                    z.Z = 2 - z.Z;
                else if (z.Z < -1)
                    z.Z = -2 - z.Z;

                float r2 = z.LengthSquared();

                if (r2 < 1)
                {
                    if (r2 < 0.25f) // 0.5 squared
                    {
                        z *= 4;
                        dr *= 4;
                    }
                    else
                    {
                        z /= r2;
                        dr /= r2;
                    }
                }

                z = Settings.scale * z + c;
                dr = dr * Settings.scale + 1.0f;
            }
            return z.Length() / Math.Abs(dr);
        }

Can anyone spot an error that would screw negative scales up?


Title: Re: Mandelbox DE formula
Post by: bib on March 30, 2012, 09:51:01 PM
the copy-pasta'd formulae

That must be Darkbeam's formula for sure :D (the spaghetti coder)


Title: Re: Mandelbox DE formula
Post by: Syntopia on March 31, 2012, 01:09:02 AM
Hi,

For negative values, you'd need the abs(scale) for the running derivative:
Code:
 dr = dr * Math.abs(Settings.scale) + 1.0f;


Title: Re: Mandelbox DE formula
Post by: DarkBeam on March 31, 2012, 10:09:23 AM
That must be Darkbeam's formula for sure :D (the spaghetti coder)
Oh well, somebody tries to imitate me ... Curse him! :evil:


Title: Re: Mandelbox DE formula
Post by: David Makin on April 01, 2012, 02:41:04 PM
That must be Darkbeam's formula for sure :D (the spaghetti coder)

Darkbeam's code....spaghetti ???

You have seen my UF code ? :D


Title: Re: Mandelbox DE formula
Post by: DarkBeam on April 04, 2012, 01:48:32 PM
It is well done! Mine is the worst possible trust me! :banana: :chilli: :banana: