Title: Mandelbuld render glitch Post by: lapinot on February 10, 2015, 04:14:11 PM Hello there.
I am programming a raymarcher in C++. It is still 100% CPU but planning to move to OpenGL as soon as I can. So far I tried rendering a mandelbulb (variation) using Quilez formula (http://www.iquilezles.org/www/articles/mandelbulb/mandelbulb.htm - the non-optimized one) but can't figure out where to look exactly to solve this problem. Here is a small render of it - please note the red color is the background/sky color. (http://grid.turtlespeak.net/upload/LMo6pu2bZ3pYC5QU/OUmytkQpaGkM6C5e/Render-1423476821.png) It looks like some kind of shiva/elephant to me - using a power = 4 (code below). The only problem being, most of the fractal surface isn't displayed at all but gets overshooten. I guess it should look something like : (http://grid.turtlespeak.net/upload/LMo6pu2bZ3pYC5QU/OUmytkQpaGkM6C5e/Render-1423476821-bounded.png) with the area approximately inside the green bound fully drawn. Worth mentioning too : the white pixels are actually shaded using the raymarching steps ambiant occlusion method. They "appear" white because for some reason, all the "white" pixels are intersected at either step 1 or 2. Any step more and I get geometry overshoot and no intersection at all. So I dumped the raymarch steps of a random "red" pixel and I get : Code: #STEP 0# x=0 y=1 z=-15 The weird thing is at Step 0 the distance is already 17.8 when the point of view is only at z=-15 so it looks to me the fractal geometry got overshot. I get the same kind of results with a "real" power 8 mandelbulb formula. Is my DE function not correct ? Code: long double DistanceEstimators::CPPDE (D3Vec w) {Thanks for any hint! -Lapinot Title: Re: Mandelbuld render glitch Post by: eiffie on February 10, 2015, 06:58:12 PM 2 things:
1) the distance estimate for bulbs is inaccurate at long distances so just use something like DE=min(DE,1.0) or start your ray closer to the bulb. 2) I don't see where you set dr to anything? just dr=1.0 dr is the running derivative so for power 4 it looks something like... dr=dr*4.0*pow(r,3.0)+1.0; ..inside the loop Title: Re: Mandelbuld render glitch Post by: lapinot on February 11, 2015, 12:19:06 PM I added this dr computation line in my code :
Code: // Iterate Something is wrong. My DR ends up reaching infinity at step 10. Here is a sample : Code: step #0: 13591.1 Of course my returned distance is then 0 for all DE evals. Anything obvious ? I didn't change my PoV (x=0 y=1 z=-15). Title: Re: Mandelbuld render glitch Post by: knighty on February 11, 2015, 04:28:13 PM Try this: (not tested)
Code: double DistanceEstimators::CPPDE (D3Vec w) {Title: Re: Mandelbuld render glitch Post by: lapinot on February 13, 2015, 10:58:26 AM I get the same problem with your DE Knighty.
For the same sample point I get : Code: #STEP 0# x=0 y=1 z=-15 Title: Re: Mandelbuld render glitch Post by: lapinot on February 13, 2015, 06:33:31 PM Bump I need help :(
Here is a sample power 8 bulb: (http://grid.turtlespeak.net/upload/LMo6pu2bZ3pYC5QU/OUmytkQpaGkM6C5e/Render-1423848275-bulb.png) It definitely looks like the bulb to me, except it's not filled ofc. I used Quilez formula and no DR. When computing a DR I get: (http://grid.turtlespeak.net/upload/LMo6pu2bZ3pYC5QU/OUmytkQpaGkM6C5e/Render-1423848640-bulb-dr.png) a full white image because the DR gets infinite so the returned distance is 0 for all DE evals. Code below for the first image: Code: long double DistanceEstimators::CPPDE (D3Vec w) {I think the DR is the culprit here and it shouldn't reach infinity so quick ? The DR I used in the second image is: Code: dr = std::pow(r, Power - 1) * Power * dr + 1; Title: Re: Mandelbuld render glitch Post by: eiffie on February 13, 2015, 07:27:22 PM It is getting worse! The last bit of code posted is backwards. You are doing the triplex math on w then adding it to z. Go back to adding z to w like the previous code. The distance estimate is bad at long distances (look at your steps - you step right over it, that is why dr goes to infinity). Do something like this...
return min(0.5 * std::log(wr) * wr / dr,1.0); ...and post the complete code using dr. We all know it won't work without a running derivative. You'll get it! oh and drop the scale until you get it working at scale 1.0 :) Title: Re: Mandelbuld render glitch Post by: lapinot on February 13, 2015, 07:31:21 PM Thx. Working on it ill keep you updated :) Funny thing tho, I still get a mandelbulb-like render with the wrong math :alien:
Title: Re: Mandelbuld render glitch Post by: lapinot on February 13, 2015, 08:31:56 PM OK I reverted back + fixed to:
Code: long double DistanceEstimators::CPPDE (D3Vec w) {I still get the infinite DR aka DE evals = 0 :( http://grid.turtlespeak.net/upload/LMo6pu2bZ3pYC5QU/OUmytkQpaGkM6C5e/DR_sample.png (http://grid.turtlespeak.net/upload/LMo6pu2bZ3pYC5QU/OUmytkQpaGkM6C5e/DR_sample.png) Title: Re: Mandelbuld render glitch Post by: knighty on February 14, 2015, 03:20:37 PM You forgot to multiply w by wr in "convert back to cartesian coordinates" section. As eiffie said the DE obtained by using 0.5*r*log(r)/dr is always too big when far away from the fractal.
You are also using floats inside the function. better use doubles for now because it doesn't overflow (giving infinty) as easily as floats. This may happen when the point where the DE is computed is very close to the surface of the fractal. Could we see the raymarching code? Have you tried your raymarching code with a simple object (say a sphere: DE=w.length()-radius;)? Beside this I don't understand why your function returns long double. Title: Re: Mandelbuld render glitch Post by: lapinot on February 14, 2015, 04:48:56 PM Yes I can render scene from a long time ago.
For example sphere + ground (http://grid.turtlespeak.net/upload/LMo6pu2bZ3pYC5QU/OUmytkQpaGkM6C5e/Render-1423928350.png) I return long doubles to get as much precision as I can. I just pretty much copied the DE code from around the web (Quilez/Hvidfeldts) hence the floats. I can as well use long doubles instead I guess. As you can see from the picture above, I think my raymarching code is OK. I'm not keen on posting it all there tho ;D Should I just do a scalar multiply of w by wr ? I don't pretend to understand the math here hehe. Code: // convert back to cartesian coordinates Thanks. Title: Re: Mandelbuld render glitch Post by: eiffie on February 14, 2015, 06:11:12 PM Yes multiply that way. It seems like that is all you are missing.
Title: Re: Mandelbuld render glitch Post by: lapinot on February 15, 2015, 12:46:05 AM Sooooooooooooooooooo. Here are my first renders of the bulb!!
Thx a lot guys for the help so far ;D Too high DE bailout (http://grid.turtlespeak.net/upload/LMo6pu2bZ3pYC5QU/OUmytkQpaGkM6C5e/Render-1423954752.png) Smaller DE bailout (http://grid.turtlespeak.net/upload/LMo6pu2bZ3pYC5QU/OUmytkQpaGkM6C5e/Render-1423954833.png) Double res. (http://grid.turtlespeak.net/upload/LMo6pu2bZ3pYC5QU/OUmytkQpaGkM6C5e/Render-1423954995.png) Close-up view (http://grid.turtlespeak.net/upload/LMo6pu2bZ3pYC5QU/OUmytkQpaGkM6C5e/Render-1423955632.png) Lightning test (http://grid.turtlespeak.net/upload/LMo6pu2bZ3pYC5QU/OUmytkQpaGkM6C5e/Render-1423956071.png) Need to work on the lighting ;D Title: Re: Mandelbuld render glitch Post by: cKleinhuis on February 15, 2015, 01:47:16 AM congrats, wonderful ;) now for the colors,lighting and stuff ;) say hello to pandorras box you just opened!
Title: Re: Mandelbuld render glitch Post by: lapinot on February 15, 2015, 03:55:07 PM Thx ;D
I have no idea about the colouring yet. I did implement lighting tho but need to retwink it. The last image is with lighting but is way too dark. Title: Re: Mandelbuld render glitch Post by: lapinot on February 15, 2015, 05:32:31 PM I just tried to improve the rendering speed using Quilez optimization and I get:
(http://grid.turtlespeak.net/upload/LMo6pu2bZ3pYC5QU/OUmytkQpaGkM6C5e/Render-1424017245.png) The (working) code I used for the images above was: Code: long double DistanceEstimators::CPPDE (D3Vec w) {And the one with Quilez optimization: Code: long double DistanceEstimators::CPPDE (D3Vec w) {I basically tried to insert the modification into the previous code. And checked that my vars are initialized in the correct order regarding previous code but there's a mistake. Title: Re: Mandelbuld render glitch Post by: eiffie on February 15, 2015, 06:45:13 PM Glad you got it working! I would stick with the version that lets you adjust the power easily. When you switch from CPU to GPU it will be plenty fast.
Title: Re: Mandelbuld render glitch Post by: lapinot on February 15, 2015, 09:43:33 PM Yes you're right.. Actually I even mixed Powers 4 and 8 in the formula. With only power 8 I still get the same kind of image tho. I'll save it for later maybe :)
Title: Re: Mandelbuld render glitch Post by: lapinot on February 17, 2015, 06:24:17 PM Trying to improve my raymarcher's escape condition and I got: (http://grid.turtlespeak.net/upload/LMo6pu2bZ3pYC5QU/OUmytkQpaGkM6C5e/Render-1424193130.png) (http://grid.turtlespeak.net/upload/LMo6pu2bZ3pYC5QU/OUmytkQpaGkM6C5e/Render-1424193703.png) Funny pics ;D |