Logo by fractalwizz - 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: Visit us on facebook
 
*
Welcome, Guest. Please login or register. August 07, 2022, 08:47:13 PM


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: GPU friendly implementation (in quaternion form)  (Read 3280 times)
0 Members and 1 Guest are viewing this topic.
Snakehand
Guest
« on: December 19, 2009, 05:07:47 PM »

I am working on an efficient DE GPU implementation of the power 8 bulb. My old code was taken from the nvidia formus, and frankly I didn't understand any of it. But now I had some success in implementing a trig free iteration code in quaternion form.

What remains to be done, is to optimize the quaternion multiplications with 0 terms, and then get to work on the derivative. In the quaternion implementation multiplying the angles by 8 is performed by squaring the quaternion 2 times. The initial quaternion can be constructed by picking components from the (normalized) zval. There is no need to halve the angle when raising to the power of 8, but for the derivative, I will need to construct a half angle quaternion without using trigonometric functions.

Code:
kernel float4 quaternion_multiply(float4 p, float4 q)
{
    float w = p.w*q.w - dot(p.xyz,q.xyz);
    float3 v = float3(p.w,p.w,p.w)*q.xyz+
        float3(q.w,q.w,q.w)*p.xyz+
        cross(p.xyz,q.xyz);

    return float4(v.x,v.y,v.z,w);
}

kernel float2 bulb_iterate(float3 cval, int maxiter)
{
    float3 zval = cval;
    float4 qt2;
    float4 qt4;
    float4 qt8;

    float4 qp2;
    float4 qp4;
    float4 qp8;

    float4 quat_pre;
    float4 quat;
    float4 quat_post;
    float4 quat_half = float4(0.0f, -0.70710678f, 0.0f, 0.7071067811f);

    float2 res;
    float r2;
    float r;
    int i;

    r = sqrt(dot(zval,zval));

    for (i = 0; i < maxiter ; i++) {
        qt2.zw = normalize(zval.xy);
        qt2.x = 0.0f;
        qt2.y = 0.0f;
        qt4 = quaternion_multiply( qt2, qt2 );
        qt8 = quaternion_multiply( qt4, qt4 );

        qp2.x = 0.0f;
        qp2.z = 0.0f;
        qp2.w = zval.z / r;
        qp2.y = sqrt( 1.0f - qp2.w * qp2.w);
        qp4 = quaternion_multiply( qp2, qp2 );
        qp8 = quaternion_multiply( quat_half,
           quaternion_multiply( qp4, qp4 ));

        quat = float4(1.0f,0.0f,0.0f,0.0f);

        quat_pre = quaternion_multiply(qt8, qp8);
        quat_post.xyz = -quat_pre.xyz;
        quat_post.w = quat_pre.w;

        r = pow(r, 8.0f);
        quat = quaternion_multiply(
            quaternion_multiply( quat_pre, quat) , quat_post);

        zval = quat.xyz * float3(r,r,r) + cval;

        r2 = dot(zval,zval);
        r = sqrt(r2);

        if (r2>2.0f) break;

    }

    if (r<2.0f) {
        r = 0.0f;
    }

    if (i==0) {
        r = 0.0f;
    }

    res.x = (float)i;
    res.y = r;

    return res;
}



Logged
cbuchner1
Fractal Phenom
******
Posts: 443


« Reply #1 on: December 20, 2009, 01:21:50 AM »

But now I had some success in implementing a trig free iteration code in quaternion form.

I also recently did succeed in getting the trigonometry out for powers 2 to 9 based on Quaternion code  - however I still got a couple of these pesky square root expressions lingering around.

My current quaternion based C++ code for voxel computation can be found in the "A new class of bulb?" thread in the Renderings subforum. This is roughly equivalent to the cosine method as summarized by bugman (i.e the angle theta is measured from the north pole of the spherical coordinate system, and PI/2 marks the "equator").

Because a quaternion needs sine/cosine of the half the rotation angle, it means that for a power 8 fractal one only needs the sin/cos expression of 4 times the original angle.

I recently noticed some visual differences between rendering a voxel fractal and rendering the same fractal using DE methods and I cannot figure out where these come from. This merits further investigation.

Christian
Logged
Buddhi
Fractal Iambus
***
Posts: 895



WWW
« Reply #2 on: December 20, 2009, 09:48:33 AM »

I recently noticed some visual differences between rendering a voxel fractal and rendering the same fractal using DE methods and I cannot figure out where these come from. This merits further investigation.
Yes, there is difference between rendering voxel fractal and with DE because there is completely another condition to decide what is inside fractal and what is outside. I think when you render voxel fractal you set-up threshold for some value of iteration count (when iteration count is greater than N then it means that this voxel is inside fractal). With distance estimation algorithms there is completely another criterion. The voxel is inside fractal when distance to the boundary of Mandelbrot set is smaller than some threshold.
I attached two images with 2D Mandelbrot sets. First was rendered using DE (distance threshold = 0.02)- shapes are very smooth. Please try imaging for example some pin (25mm long) and draw area in distance 10mm form pin. It looks nearly like ellipse. Second was rendered using escape time algorithm (man N = 12). It looks very sharp because in some areas iteration count is growing very fast.


* zrzut_ekranu-Test2D.png (15.19 KB, 400x400 - viewed 1227 times.)

* zrzut_ekranu-Test2D-1.png (14.01 KB, 400x400 - viewed 1136 times.)
Logged

Buddhi
Fractal Iambus
***
Posts: 895



WWW
« Reply #3 on: December 20, 2009, 02:04:21 PM »

I recently noticed some visual differences between rendering a voxel fractal and rendering the same fractal using DE methods and I cannot figure out where these come from. This merits further investigation.
Another reason of differences could be maximum number of iteration in rendering without DE. Attached fractals was rendered using the same formula but with different maximum number of iteration.
1. N=10
2. N=20
3. N=1000


* fractal N10.jpg (25.82 KB, 400x400 - viewed 1101 times.)

* fractal N20.jpg (29.47 KB, 400x400 - viewed 1096 times.)

* fractal N1000.jpg (21.03 KB, 400x400 - viewed 1089 times.)
Logged

cbuchner1
Fractal Phenom
******
Posts: 443


« Reply #4 on: December 20, 2009, 02:30:13 PM »

2. N=20
3. N=1000

Yes, that looks more like it. The differences that I am seeing are much like the difference between your N=20 and N=1000 render, i.e. the whipped cream notably disappearing in the "flat mandelbrot" (power 2) and shapes generally getting "rounder".
Logged
cKleinhuis
Administrator
Fractal Senior
*******
Posts: 7044


formerly known as 'Trifox'


WWW
« Reply #5 on: December 20, 2009, 07:58:23 PM »

ehrm, sure that the last image isnt a computation error ?! e.g. float overflow smiley
because it makes no sense that it changes its shape in such manner when increasing iteration!
Logged

---

divide and conquer - iterate and rule - chaos is No random!
kram1032
Fractal Senior
******
Posts: 1863


« Reply #6 on: December 20, 2009, 08:00:55 PM »

oh yes it does.

the details get a lot sharper and more dustlike.
A lot of the details disappear for being way smaller than a pixel.
So you can see "through the dust" more or less, giving this wink
Logged
David Makin
Global Moderator
Fractal Senior
******
Posts: 2286



Makin' Magic Fractals
WWW
« Reply #7 on: December 20, 2009, 09:39:15 PM »

That's why IMHO to get a true view of where the "inside" is needs distance estimation, using plain iteration will always miss details.

Edit: Distance Estimation effectively "evens out" the detail - if you look at the 2D examples earlier in the thread it's quite clear that on the colour by iteration image there are sharper details in the areas of high iteration density but loss of detail in low density areas (e.g. the neck) whereas the neck in the DE image is much sharper and the other details less-sharp.
This issue is more noticeable on 3D+ renders because we only see the "surface" - there are no further visual clues to the fractal shape unlike with 2D colouring where the colour changes add more implied detail.
« Last Edit: December 20, 2009, 10:59:29 PM by David Makin » Logged

The meaning and purpose of life is to give life purpose and meaning.

http://www.fractalgallery.co.uk/
"Makin' Magic Music" on Jango
cKleinhuis
Administrator
Fractal Senior
*******
Posts: 7044


formerly known as 'Trifox'


WWW
« Reply #8 on: December 20, 2009, 10:15:48 PM »

ok, i understand, it is the big mandelbrot we see smiley
its borders are fractal .. stil have to adjust some of my 2d experience to 3d, it simply gets to fine, in the 2d view we color by iteration,
here we just view the "black" of the formula, sorry for interrupting ...  angel
Logged

---

divide and conquer - iterate and rule - chaos is No random!
David Makin
Global Moderator
Fractal Senior
******
Posts: 2286



Makin' Magic Fractals
WWW
« Reply #9 on: December 20, 2009, 11:02:25 PM »

But now I had some success in implementing a trig free iteration code in quaternion form.

I also recently did succeed in getting the trigonometry out for powers 2 to 9 based on Quaternion code  - however I still got a couple of these pesky square root expressions lingering around.

My current quaternion based C++ code for voxel computation can be found in the "A new class of bulb?" thread in the Renderings subforum. This is roughly equivalent to the cosine method as summarized by bugman (i.e the angle theta is measured from the north pole of the spherical coordinate system, and PI/2 marks the "equator").

Because a quaternion needs sine/cosine of the half the rotation angle, it means that for a power 8 fractal one only needs the sin/cos expression of 4 times the original angle.

I recently noticed some visual differences between rendering a voxel fractal and rendering the same fractal using DE methods and I cannot figure out where these come from. This merits further investigation.

Christian


Just change your voxel method to be based on analytical DE - i.e. for a given voxel get the DE value at the centre, if the point is "inside" or the DE value is less than the distance to a corner of the voxel (or maybe *2 for accuracy) then split the voxel.
Logged

The meaning and purpose of life is to give life purpose and meaning.

http://www.fractalgallery.co.uk/
"Makin' Magic Music" on Jango
Snakehand
Guest
« Reply #10 on: December 21, 2009, 09:03:15 AM »

I managed to get a quaternion distance estimator working. Only problem is that the bulb is slightly distorted. I probably have a bug with my basic formula. Actually I had many bugs along the way, but almost every bug produces interesting fractals, so it seems that there is a large variety of fractals in "triplex space". At any rate, I want to say thanks to the regulars in the forum that has been a great help in putting the code together. The DE from the pixel bender script was also much faster than my old stepping code, and  wish everyone could be able to do interactive exploration of the bulb like I am able to do now.



Sample from my distorted bulb.
Logged
bib
Global Moderator
Fractal Senior
******
Posts: 2070


At the borders...


100008697663777 @bib993
WWW
« Reply #11 on: December 21, 2009, 10:47:15 AM »


Sample from my distorted bulb.


It does not look more distorted than as usual
Logged

Between order and disorder reigns a delicious moment. (Paul ValÚry)
Pages: [1]   Go Down
  Print  
 
Jump to:  

Related Topics
Subject Started by Replies Views Last post
Are the Mandelbrot Cardoids in fact loose form each other? Philosophy kek 3 1484 Last post February 21, 2011, 11:01:28 PM
by David Makin
Positional lights - user friendly amount control Mandelbulb 3d Erisian 7 1189 Last post October 29, 2011, 05:20:44 PM
by Erisian
Choose the form of the destructor.... Fractal Humor David Makin 0 858 Last post October 02, 2011, 07:45:13 PM
by David Makin
Bioluminiscent life form 2 Mandelbulb3D Gallery Tahyon 0 386 Last post October 09, 2011, 05:00:11 PM
by Tahyon
Life Form Mandelbulb3D Gallery FractalJam 1 393 Last post September 24, 2013, 07:56:02 PM
by Nahee_Enterprises

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.201 seconds with 29 queries. (Pretty URLs adds 0.009s, 2q)