Title: A couple of programming related questions Post by: A Noniem on August 11, 2011, 12:47:57 AM So I'm currently writing my own ray tracer in openCL and I'm starting to produce some images that look fractalish. However I hit a few bumps in the road and I got a couple of questions considering coloring, distance estimation etc. So perhaps you guys can help me out.
- I'm currently using buddhi's distance estimation formula. It works fine for scale -1.5 for me, but for almost any other scale I get pictures which are nowhere near the ones I see in mandelbulber. - Second the coloring. In 2d fractals you color the places that escape, but in 3d you color the parts of the fractal. How do you give these points a nice looking color? I've tried a couple of things, but they all look horrible. The nicests pictures I got so far are those from the z-buffer and I'm sure there are better ways to color a fractal :embarrass: Well that's a lot of questions. If you can help me with any of these problems (or you have any other tips that might be useful) feel free to help me out and post here. Your help is very much appreciated! Here is my openCL code. It's basically a rippoff from buddhi's distance estimation. Using absolute values made my -1.5 scale look a lot better. Before I put that in the fractals looked a lot less detailed. I don't get however why it has to be in there. Code: float mandelBoxDistance(float4 v,float scale,int maxIter) Title: Re: A couple of programming related questions Post by: Syntopia on August 11, 2011, 09:23:07 AM - First of all the distance estimation. I've seen the name passing by quite a lot, but what is it? What does it do, how does it work and (how) does it speed up rendering time? I googled a bit, but couldn't find a good article about it. - Second the coloring. In 2d fractals you color the places that escape, but in 3d you color the parts of the fractal. How do you give these points a nice looking color? I've tried a couple of things, but they all look horrible. The nicests pictures I got so far are those from the z-buffer and I'm sure there are better ways to color a fractal :embarrass: I see you found my blog posts :-) The first part talks a bit about distance estimation (http://blog.hvidtfeldts.net/index.php/2011/06/distance-estimated-3d-fractals-part-i/). The second part (the one you link to) also mentions the standard ways of coloring 3D fractals: orbit traps, smooth iteration count and so on. Quote - When shading fractals the problem is that you don't have normals, so you have to calculate the normals depending on the "heights" of the surrounding area. I thought that you could just do this as a 2nd pass. Output the first rendering pass into a regular picture and a z-buffer and then in a second pass calculate the normals in a point using the z-buffer and apply the shading on the regular picture (which is basically deferred shading I believe). I stumbled on a site however that does this a little bit differently (http://blog.hvidtfeldts.net/index.php/2011/08/distance-estimated-3d-fractals-ii-lighting-and-coloring/) This uses distance estimation (and since I don't really know how that works...) Using this method however you have 6 extra points to calculate per pixel drawn, but you can do all the shading in one pass and you can use a higher precision than the z-buffer. So my question is, which method is faster? And when using the z-buffer which has a lower precision compared to the other method, do you see artifacts? Drawing a single pixel requires multiple (perhaps hundreds) of ray steps. And each ray step requires one distance estimator evaluation. So adding six more distance estimator evalutions for the normal vector does not require a lot overhead, and will only slow rendering a few percents. z-buffer normals will be faster though, but I think you might end up with more artifacts (not sure, though). On the other hand, the z-buffer might be useful for other stuff as well (Screen Space AO and Depth-of-field for instance). And in OpenCL you can use whatever resolution you see fit for your z-buffer. Title: Re: A couple of programming related questions Post by: ker2x on August 11, 2011, 11:08:24 AM Ho... now that's interesting !
As you probably noticed in the same programming section, i started by learning how to compute/render a mandelbulb and flowabrot/flowabulb (3D buddhabrot), then switched to OpenCL, and now i'm starting to learn how to write a raytracer :))) And i started learning yesterday by... reading syntopia's blog and links. ;D About Distance Estimation, i can't tell you why it works. What i understand is that, instead of moving your ray (and probing for intersection (which is very expensive in the case of a fractal)) by a fixed step, you use the Distance Estimation to move your ray by large step when the ray is far (according to the DE) from the fractal and smaller step when the ray is very close to reach the fractal's surface. Less step -> less probing -> faster (stronger, better :whistle2: ) What langage do you use for your raytracer ? is the source code available ? :D Title: Re: A couple of programming related questions Post by: ker2x on August 11, 2011, 11:14:14 AM Btw ... here is my openCL code for the Mandelbulb (not optimized at all, but it's a (working) early prototype) :
Code: __kernel void computeMandelbulb( (you'll notice that all my ray are parallel, which probably not exactly what i'm supposed to do for a raytracer (i don't know ^^ )) Title: Re: A couple of programming related questions Post by: A Noniem on August 11, 2011, 04:28:03 PM Unfortunately my openCL codes looks a lot different, because it has perspective and I'm rendering a mandelbox instead of a bulb.
This morning I implemented buddhi's distance estimation formula and added shading (which luckily I did before) using Syntopia's blog post. I got a couple of nice images, but some are still a bit grainy (especially negative mandelboxes) and when I render the same fractal in Mandelbulber it just looks completely different. My fractals are less boxy and have more round shapes. Also blinn-phong shading makes everything look even more granier, which looks rather bad. This is an image of inside a 2.5 scale mandelbox. I still need a nice way to color it, but just plain black/white lightning isn't that bad either. (it's rather large, so i'll just link to it) http://img196.imageshack.us/img196/3376/44myfractal.jpg Rendering takes a couple of seconds on my ati 4350 (which is probably the slowest openCL capable gpu out there ;D) Edit: I found a couple bugs in my formula which fixed all the spherical stuff and after I implemented some basic camera movement I saw some parts of the fractal are stretched, which I also fixed. My scale -1.5 looks exactly like the one in mandelbulber, however other scales look completely different and for the positive scales the distance estimation formula doesn't work that well. I'll look into that tomorrow. Title: Re: A couple of programming related questions Post by: ker2x on August 12, 2011, 11:48:45 AM Edit: I found a couple bugs in my formula which fixed all the spherical stuff and after I implemented some basic camera movement I saw some parts of the fractal are stretched, which I also fixed. My scale -1.5 looks exactly like the one in mandelbulber, however other scales look completely different and for the positive scales the distance estimation formula doesn't work that well. I'll look into that tomorrow. no code available ? :'( Title: Re: A couple of programming related questions Post by: A Noniem on August 12, 2011, 01:03:48 PM Edit: I found a couple bugs in my formula which fixed all the spherical stuff and after I implemented some basic camera movement I saw some parts of the fractal are stretched, which I also fixed. My scale -1.5 looks exactly like the one in mandelbulber, however other scales look completely different and for the positive scales the distance estimation formula doesn't work that well. I'll look into that tomorrow. no code available ? :'( I put the openCL code in the first post. Might help you guys out a little ^-^ Atm the scale -1.5 looks perfect, apart from the single precision artifacts, however other scales look completely different. The code should be good (otherwise the scale -1.5 wouldn't look the same as the one I made in mandelbulber and it's almost a complete copy from buddhi's one), but most other scales are nowhere near their mandelbulber cousins or sometimes aren't even boxy (my scale 2 is more of a sphere) Title: Re: A couple of programming related questions Post by: ker2x on August 12, 2011, 01:11:19 PM Thank you :angel1: Edit : Nice code. it seems that to managed to avoid the most common performance pitfall . (which is not my case in the code i pasted, it's a very direct port from my cpu code to opencl. i'll do that later :embarrass: ). |