Title: bug in perspective Post by: willvarfar on July 10, 2012, 10:52:52 AM I am failing at an embarrassingly simple task - trying to draw a mandelbox (or anything) on the CPU.
I have a width*height bitmap to render to. For each pixel, I want to march towards the cube: Code: static float eye = 0.0f; eye = glm::clamp(eye+0.005f,0.0f,1.0f); // animate I think my fundamental problem is working out where my rays should go for each pixel. My distance estimator function is a very literal classic mandelbox and looks like this: Code: float DE(glm::vec3 p) {And the output looks completely unbox-like: (http://i.stack.imgur.com/xoY4D.jpg) I asked on StackOverflow (http://stackoverflow.com/questions/11402495/drawing-a-cube-with-perspective) but no bites. How do I set the eye transform up so I see the cube properly? Title: Re: bug in perspective Post by: bib on July 10, 2012, 11:40:59 AM I have no idea what your code means but I can tell you that your image definitely looks like a cut Mandelbox, so you are on the right track.
Perhaps you should try to set the viewpoint somewhere else, farther from the origin, in order to get the big picture. Title: Re: bug in perspective Post by: willvarfar on July 10, 2012, 01:01:52 PM Obvious fixes and now it draws cubes and spheres and such spinning as I'd expect.
It doesn't draw any mandelbox though :( Code: enum { DEBUG = 0 };(http://i.imgur.com/Zqfs5.png) Presumably the mandelbox is at -1,-1,-1 to 1,1,1 ? And asking for a DE from a point outside that will compute the distance to that? Title: Re: bug in perspective Post by: taurus on July 10, 2012, 01:15:50 PM Presumably the mandelbox is at -1,-1,-1 to 1,1,1 ? i have also no clou about code, but depending on scale it should be bigger. At least -2 to 2 Title: Re: bug in perspective Post by: willvarfar on July 10, 2012, 05:39:03 PM Basic spheres and cubes and such that I ray-march on work fine with proper perspective and draw where I put them.
But my mandelbox - which I copied, naturally (http://blog.hvidtfeldts.net/index.php/2011/11/distance-estimated-3d-fractals-vi-the-mandelbox/) - doesn't want to compute properly; it shows nothing, and the estimates it gives back are in the 1000s. When I change the dr to Scale - as emphasised in this link by Buddhi (http://www.fractalforums.com/3d-fractal-generation/a-mandelbox-distance-estimate-formula/msg14893/#msg14893) - it draws... this: (http://i.imgur.com/UkgM1.jpg) As it rotates it wobbles; its not properly box-shaped. Code: const float Scale = -1.77f, fixedRadius2 = 1.0f, minRadius2 = (0.5f*0.5f); I had imagined it was clipping problems but, really, how? The sphere and box tests spin around the entire viewport. Title: Re: bug in perspective Post by: taurus on July 10, 2012, 06:12:54 PM still looks cut. Try a standard scale like 2 and get the camera off from the orgin, five or six i'd suggest.
Title: Re: bug in perspective Post by: Syntopia on July 10, 2012, 10:15:45 PM Hi Willvarfar,
You DE-code look right - it works in Fragmentarium, but I must set a fudge-factor to 0.5 to avoid clipping, when the scale is negative. This might also be your problem: try multiplying the returned DE-value by 0.5. Since you have a clamp-function, you can also try this version (due to Rrrola, I think), which works good for both positive and negative values: Code: float AbsScalem1 = abs(Scale - 1.0); Btw, consider using a 'using namespace glm;' - then I could have pasted your C++ directly as GLSL :-) Title: Re: bug in perspective Post by: willvarfar on July 11, 2012, 09:28:47 AM Thx Syntopia,
a scale of 2 or -2 works; -1.77 doesn't. I have not experimented with other values nor tried to work out why. I will park this mystery as I now have a nice -2 mandelbox to depth-estimate against. http://www.pouet.net/topic.php?which=6675&page=4 sounds like the demo guys used a put-spheres-on-a-list sphere-marching kind of thing. Title: Re: bug in perspective Post by: willvarfar on July 12, 2012, 02:33:48 PM I don't have swizzle so this is my translation of Rrrola's mandelbox:
Code: const int Iterations = 13; But I must have a strange bug in it (apart from not working with negative numbers etc too); it draws this ugly unstable thing that wobbles when viewed from different angles: (http://i.imgur.com/P5Rfc.jpg) What can I possibly have mistranslated to C++? Title: Re: bug in perspective Post by: willvarfar on July 12, 2012, 09:50:41 PM I seem beset with problems
For example, rendering a very normal mandelbulb with this code: Code: const Vec3 pos = p; I have typedefs to switch between floats (32 bits) and doubles (64). The left column shows doubles The right column shows floats The top row shows deep inside the mandelbulb The bottom row shows it from outside (http://i.imgur.com/Vx5Zl.jpg) How do I get this to work with floats? GPUs are 32 bits; why does a literal copy of the GLSL code, like the mandelbox in the code in my previous post, not work when I compile it (linux, gcc 4.6.3, 64-bit)? What simple thing am I doing wrong? I'm going to kick myself when you point this out to me, promise! Title: Re: bug in perspective Post by: eiffie on July 13, 2012, 12:02:33 AM Try a smaller bailout like 2.0 perhaps. |