Logo by haltenny - Contribute your own Logo!

END OF AN ERA, FRACTALFORUMS.COM IS CONTINUED ON FRACTALFORUMS.ORG

it was a great time but no longer maintainable by c.Kleinhuis contact him for any data retrieval,
thanks and see you perhaps in 10 years again

this forum will stay online for reference
News: Did you know ? you can use LaTex inside Postings on fractalforums.com!
 
*
Welcome, Guest. Please login or register. March 29, 2024, 11:04:09 AM


Login with username, password and session length


The All New FractalForums is now in Public Beta Testing! Visit FractalForums.org and check it out!


Pages: [1] 2   Go Down
  Print  
Share this topic on DiggShare this topic on FacebookShare this topic on GoogleShare this topic on RedditShare this topic on StumbleUponShare this topic on Twitter
Author Topic: Mandelbuld render glitch  (Read 4072 times)
Description: Something wrong in my formula ?
0 Members and 1 Guest are viewing this topic.
lapinot
Alien
***
Posts: 25


« 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.



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 :



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
#DISTANCE# 17.8838

#STEP 1# x=-0.107225 y=-2.16106 z=2.60185
#DISTANCE# 3.00974

#STEP 2# x=-0.12527 y=-2.69305 z=5.56415
#DISTANCE# 9.87785

#STEP 3# x=-0.184495 y=-4.43902 z=15.2863
#DISTANCE# 24.4502

#STEP 4# x=-0.33109 y=-8.76075 z=39.3511
#DISTANCE# 74.5188

#STEP 5# x=-0.777879 y=-21.9324 z=112.695
#DISTANCE# 272.294

#EXIT#

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) {

D3Vec z = w;
float r = z.getLength();
float dr = 1.0;

int escape = 20;
int Power = 4;
double Scale = 1;

// Iterate
for (int i = 0; i != 10 && r < escape * Scale; i++) {

// extract polar coordinates
float wr = std::sqrt(w * w);
float wo = std::acos(w.y / wr);
float wi = std::atan2(w.x, w.z);

// scale and rotate the point
wr = std::pow(wr, Power);
wo = wo * Power;
wi = wi * Power;

// convert back to cartesian coordinates
w.x = std::sin(wo) * std::sin(wi);
w.y = std::cos(wo);
w.z = std::sin(wo) * std::cos(wi);

z = z + w;
r = Scale * z.getLength();
}

// Back
return 0.5 * std::log(r) * r / dr;
}

Thanks for any hint!

-Lapinot
« Last Edit: February 10, 2015, 04:32:01 PM by lapinot » Logged
eiffie
Guest
« Reply #1 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
Logged
lapinot
Alien
***
Posts: 25


« Reply #2 on: February 11, 2015, 12:19:06 PM »

I added this dr computation line in my code :

Code:
// Iterate
for (int i = 0; i != 10 && r < escape * Scale; i++) {

//if (i > 0) std::cout << i << std::endl;

// extract polar coordinates
float wr = std::sqrt(w * w);
float wo = std::acos(w.y / wr);
float wi = std::atan2(w.x, w.z);
//float wi = std::atan2(w.z, w.x); // <-- test

// scale and rotate the point
wr = std::pow(wr, Power);
wo = wo * Power;
wi = wi * Power;

// convert back to cartesian coordinates
w.x = std::sin(wo) * std::sin(wi);
w.y = std::cos(wo);
w.z = std::sin(wo) * std::cos(wi);

// running derivative
dr = std::pow(r, Power - 1) * Power * dr + 1;

z = z + w;
r = Scale * z.getLength();
}

Something is wrong. My DR ends up reaching infinity at step 10. Here is a sample :

Code:
step #0: 13591.1
step #1: 1.98131e+008
step #2: 2.46404e+012
step #3: 3.6136e+016
step #4: 4.3393e+020
step #5: 4.47056e+024
step #6: 5.11905e+028
step #7: 6.40744e+032
step #8: 9.51215e+036
step #9: inf

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).
Logged
knighty
Fractal Iambus
***
Posts: 819


« Reply #3 on: February 11, 2015, 04:28:13 PM »

Try this: (not tested)
Code:
double DistanceEstimators::CPPDE (D3Vec w) {

D3Vec z = w;
double wr = w.getLength();
double dr = 1.0;

double escape = 20;
int Power = 4;

// Iterate
for (int i = 0; i < 10 && wr < escape ; i++) {

// extract polar coordinates

double wo = std::acos(w.y / wr);
double wi = std::atan2(w.x, w.z);

dr= dr * Power * std::pow(wr, Power-1) + 1.;//"scalar" running derivative update

// scale and rotate the point
wr = std::pow(wr, Power);
wo = wo * Power;
wi = wi * Power;

// convert back to cartesian coordinates
w.x = wr * std::sin(wo) * std::sin(wi);
w.y = wr * std::cos(wo);
w.z = wr * std::sin(wo) * std::cos(wi);

w = w + z;
wr = w.getlength();
}

// Back

return 0.5 * std::log(wr) * wr / dr;
}
Logged
lapinot
Alien
***
Posts: 25


« Reply #4 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
#DISTANCE# 20.3728

#STEP 1# x=-0.122148 y=-2.60101 z=5.05162
#DISTANCE# 4.96099

#STEP 2# x=-0.151893 y=-3.47789 z=9.93441
#DISTANCE# 12.3968

#STEP 3# x=-0.226219 y=-5.66909 z=22.1357
#DISTANCE# 35.7509

#STEP 4# x=-0.44057 y=-11.9883 z=57.3231
#DISTANCE# 119.184
Logged
lapinot
Alien
***
Posts: 25


« Reply #5 on: February 13, 2015, 06:33:31 PM »

Bump I need help sad

Here is a sample power 8 bulb:



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:



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) {

D3Vec z = w;
float r = z.getLength();
float dr = 1.0;

int escape = 20;
int Power = 8;
double Scale = 1; // or 0.5

// Iterate
for (int i = 0; i != 10 && r < escape * Scale; i++) {

// extract polar coordinates
float wr = std::sqrt(w * w);
float wo = std::acos(w.y / wr);
float wi = std::atan2(w.x, w.z);

// scale and rotate the point
wr = std::pow(wr, Power);
wo = wo * Power;
wi = wi * Power;

// convert back to cartesian coordinates
w.x = std::sin(wo) * std::sin(wi);
w.y = std::cos(wo);
w.z = std::sin(wo) * std::cos(wi);

z = z + w;
r = Scale * z.getLength();
}

// Back
return 0.5 * std::log(r) * r / dr;
}

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;
« Last Edit: February 13, 2015, 06:38:04 PM by lapinot » Logged
eiffie
Guest
« Reply #6 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 smiley
Logged
lapinot
Alien
***
Posts: 25


« Reply #7 on: February 13, 2015, 07:31:21 PM »

Thx. Working on it ill keep you updated smiley Funny thing tho, I still get a mandelbulb-like render with the wrong math  alien
« Last Edit: February 13, 2015, 07:35:58 PM by lapinot » Logged
lapinot
Alien
***
Posts: 25


« Reply #8 on: February 13, 2015, 08:31:56 PM »

OK I reverted back + fixed to:
Code:
long double DistanceEstimators::CPPDE (D3Vec w) {

D3Vec z = w;
float wr = w.getLength();
float dr = 1.0;

int escape = 20;
int Power = 4;

// Iterate
for (int i = 0; i != 10 && wr < escape; i++) {

// extract polar coordinates
float wo = std::acos(w.y / wr);
float wi = std::atan2(w.x, w.z);
dr = std::pow(wr, Power - 1) * Power * dr + 1;

// scale and rotate the point
wr = std::pow(wr, Power);
wo = wo * Power;
wi = wi * Power;

// convert back to cartesian coordinates
w.x = std::sin(wo) * std::sin(wi);
w.y = std::cos(wo);
w.z = std::sin(wo) * std::cos(wi);

// add starting point to new point
w = w + z;
wr = w.getLength();
}

// Back
return std::min(1.0, 0.5 * std::log(wr) * wr / dr);
}

I still get the infinite DR aka DE evals = 0  sad
http://grid.turtlespeak.net/upload/LMo6pu2bZ3pYC5QU/OUmytkQpaGkM6C5e/DR_sample.png
Logged
knighty
Fractal Iambus
***
Posts: 819


« Reply #9 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.
Logged
lapinot
Alien
***
Posts: 25


« Reply #10 on: February 14, 2015, 04:48:56 PM »

Yes I can render scene from a long time ago.

For example sphere + ground



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 grin

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
w.x = std::sin(wo) * std::sin(wi);
w.y = std::cos(wo);
w.z = std::sin(wo) * std::cos(wi);
w *= wr; // ?

Thanks.
Logged
eiffie
Guest
« Reply #11 on: February 14, 2015, 06:11:12 PM »

Yes multiply that way. It seems like that is all you are missing.
Logged
lapinot
Alien
***
Posts: 25


« Reply #12 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  grin

Too high DE bailout


Smaller DE bailout


Double res.


Close-up view


Lightning test


Need to work on the lighting  grin
Logged
cKleinhuis
Administrator
Fractal Senior
*******
Posts: 7044


formerly known as 'Trifox'


WWW
« Reply #13 on: February 15, 2015, 01:47:16 AM »

congrats, wonderful wink now for the colors,lighting and stuff wink say hello to pandorras box you just opened!
Logged

---

divide and conquer - iterate and rule - chaos is No random!
lapinot
Alien
***
Posts: 25


« Reply #14 on: February 15, 2015, 03:55:07 PM »

Thx  grin

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.
Logged
Pages: [1] 2   Go Down
  Print  
 
Jump to:  

Related Topics
Subject Started by Replies Views Last post
glitch 3D Fractal Generation lycium 0 1583 Last post February 26, 2008, 12:50:25 AM
by lycium
1.7.3 Animation glitch? Mandelbulb 3d muchogrande 4 8791 Last post August 04, 2011, 12:42:30 AM
by Jesse
Pause render, save project and continue render from the same spot, possible? Mandelbulb 3d dissolvingstudios 5 6834 Last post January 25, 2012, 06:33:32 AM
by taurus
Mandelbuld 3D v1.8.6 beta test Releases « 1 2 ... 5 6 » Jesse 86 24652 Last post September 15, 2013, 06:26:25 AM
by 0Encrypted0
Mandelbox render glitch 3D Fractal Generation lapinot 2 2620 Last post September 19, 2015, 02:21:42 PM
by lapinot

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines

Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM
Page created in 0.253 seconds with 24 queries. (Pretty URLs adds 0.022s, 2q)