Logo by Jimpan1973 - 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: Support us via Flattr FLATTR Link
 
*
Welcome, Guest. Please login or register. April 20, 2024, 10:52:53 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]   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: About powN1 and powN2 in the default Mandelbulb DE  (Read 2627 times)
0 Members and 1 Guest are viewing this topic.
Feline
Alien
***
Posts: 29


« on: July 29, 2012, 02:36:27 AM »

Very brief intro by way of a caveat: I'm a physicist, not a mathematician. I understand and appreciate the mathematical exposition on syntopia's blog, but I tinker with all this to make pretty pictures; and as long as a DE does that for me, I couldn't care less whether it is entirely mathematically sound. I am beholden to mathematical correctness in my work life; in my free time I want to be allowed to play around. I've been collecting (and wanted to post somewhere for a while) a variety of notes on Fragmentarium, and just to finally kick that off, this post.

Having said that, here's what I can discern about the two power functions in the default Mandelbulb distance estimator in Fragmentarium.

The shader will use the one or the other, depending on the state of the "AlternateVersion" checkbox. Fire it up, select the Mandelbulb Tab and toggle it on or off a couple times to remind yourself how they're different.

Next, click the little arrow that allows you to change the value of the "Power" slider by one, such that power=9.000  then toggle the "AlternateVersion" checkbox again.

Surprised?

The two versions of the power function are identical to each other, for integer values of power = (n*4+1) = 1,5,9,13,17...
For other values (including fractional values) the difference between them is merely a phase angle in theta (the "latitude" of the Mandelbulb). To see how that works, make the following small additions to the DE:

1) Somewhere at the beginning add a line that says

#define PI 3.14159265

(this is just for convenience - I have that in my "MathUtils", it is a riddle to me why this isn't standard).

2) right before the line that goes
void powN1(...
add the following line, which will give you an additional slider that you can use to add a phase angle to theta:

uniform float ExtraQ; slider[-2,0,2]

3) Lastly, add the value of the slider to theta at the end of the first line of code in the function as follows:

float theta = acos(z.z/r)+ExtraQ*PI/power;

(The part before the plus sign is already there, just add the stuff at the end).

That's it: hit the "Build" button, make sure "AlternateVersion" is NOT checked and slowly slide the new "ExtraQ" slider a little left-and-right to get a feeling for the kinds of things you can do with it.

Now it gets interesting: Change the "Power" slider to any value you like (can be a fractional value) then set the "ExtraQ" slider to the value (1-Power)/2    (*).

(* If that doesn't fit into the slider range, you're allowed to add integer multiples of 2 to the value. Since the whole thing gets multiplied by pi and phases of 2pi are identical to phases of zero).

Toggle the "AlternateVersion" checkbox and you'll notice that the two versions are identical.

Finally: since that term is the only difference between the two versions, you can modify the line that defines theta one more time like this:

float theta = acos(z.z/r)-AlternateVersion*((1-Power)/2*PI/Power);

remove the line that defines ExtraQ (unless you'd like to keep it around for other effects) and replace the whole chunk down in the DE that goes like this:

if (AlternateVersion) {
   powN2(z,r,dr);
} else {
   powN1(z,r,dr);
}


With the single line

powN1(z,r,dr);

This avoids a conditional in the main DE loop, which is almost always a speed gain in GPU calculations since GPUs are notoriously bad at branch predictions.

Footnotes:
- There is an obvious analog phase "ExtraP" that one could add to Phi, but that is not terribly useful. Think about it, then try it.
- Extend your "Power" slider to go from [-4.,8.,18] and verify that Power=-3 satisfies the condition above, where ExtraQ=0 yields the same result for both versions. Incidentily this'll unlock a number of interesting shapes for negative powers. Unfortunately the DE will blow up for those in various places, unless you make a couple other modifications. (in another post, maybe.)

Logged
Syntopia
Fractal Molossus
**
Posts: 681



syntopiadk
WWW
« Reply #1 on: August 01, 2012, 11:35:51 PM »

Hi, I'm also a physicist - and my goal is the same as you: generating interesting graphics - for me the mathematics mostly becomes interesting as a tool to getting there.

Nice find with two versions of the Mandelbulb - I just find the two different versions of the DE floating around the forums, and never gave much thought to why they differ.

Quote
This avoids a conditional in the main DE loop, which is almost always a speed gain in GPU calculations since GPUs are notoriously bad at branch predictions.

Since each thread on the multiprocessor will take the same path, this particular branch is not bad (On my machine, there is no measurable overhead with this conditional) - the problem arise with divergent branches, where both branches may need to be executed. In Fragmentarium it is also possible to lock user variables (by clicking the padlock next to them) - here the uniforms will be turned into constants, and the GLSL compiler will almost certainly remove dead code paths.
Logged
hobold
Fractal Bachius
*
Posts: 573


« Reply #2 on: August 02, 2012, 10:33:37 AM »

I am beholden to mathematical correctness in my work life; in my free time I want to be allowed to play around.
I am a mathematician by trade, and I am telling you that tinkering, playing around, is not a bad thing. The craft lies in knowing the rules, and the art in knowing when to break them. Only _after_ you found something new do you go to the trouble of verifying that it does not contradict good ole' logic. Then what was breaking the rules turns into new rules, new insights.

I like tunable phase angles; they break symmetry a bit. Yet the end result still looks fair, balanced. I encountered them when I tweaked the Mandelbulb idea to use a Riemann sphere instead of longitude/latitude coordinates. Phase shifting tends to be more visible when the shape in question has less rotational symmetry. But it never has a drastic effect on the result. All you do is translating a regular grid (possibly one with curved grid lines).
Logged
Pages: [1]   Go Down
  Print  
 
Jump to:  

Related Topics
Subject Started by Replies Views Last post
Default Color now Silver - in memorian of Death of Mandelbrot Fractal Forums News cKleinhuis 0 1482 Last post October 16, 2010, 11:56:18 PM
by cKleinhuis
Default Fractal Humor Vega 8 3491 Last post September 06, 2011, 11:39:46 PM
by Xazo-Tak
Option to save outgoing PMs by default? Discuss Fractal Forums stardust4ever 2 1367 Last post October 25, 2014, 08:21:45 PM
by stardust4ever
The default M3D bulb file seems quite buggy bug reporting Dowser 22 2 7644 Last post January 01, 2016, 12:01:12 PM
by Dowser 22
preset Default Fragmentarium Gallery Tim Emit 2 1063 Last post December 22, 2016, 05:08:37 PM
by Sabine

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.128 seconds with 25 queries. (Pretty URLs adds 0.006s, 2q)