Logo by DsyneGrafix - 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: Follow us on Twitter
 
*
Welcome, Guest. Please login or register. April 19, 2024, 01:54:55 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] 3 4 5   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: the simpliest naive bruteforce code for mandelbulb  (Read 14820 times)
0 Members and 2 Guests are viewing this topic.
ker2x
Fractal Molossus
**
Posts: 795


WWW
« Reply #15 on: August 01, 2011, 08:50:19 AM »

the 3d buddha is emerges wink

Done  grin
Window binary and source code : http://fractals.s3.amazonaws.com/flowabulb/voxelflowabrot-0.2.zip

A video of the program :
<a href="http://www.youtube.com/v/lGLcslZqE8c&rel=1&fs=1&hd=1" target="_blank">http://www.youtube.com/v/lGLcslZqE8c&rel=1&fs=1&hd=1</a>
Logged

often times... there are other approaches which are kinda crappy until you put them in the context of parallel machines
(en) http://www.blog-gpgpu.com/ , (fr) http://www.keru.org/ ,
Sysadmin & DBA @ http://www.over-blog.com/
ker2x
Fractal Molossus
**
Posts: 795


WWW
« Reply #16 on: August 02, 2011, 09:49:59 PM »

voxelflowabrot-0.4 : http://fractals.s3.amazonaws.com/flowabulb/voxelflowabrot-0.4.zip

Lot of code refactoring and some openGL tuning (including antialiasing) smiley
« Last Edit: August 02, 2011, 10:14:24 PM by ker2x » Logged

often times... there are other approaches which are kinda crappy until you put them in the context of parallel machines
(en) http://www.blog-gpgpu.com/ , (fr) http://www.keru.org/ ,
Sysadmin & DBA @ http://www.over-blog.com/
ker2x
Fractal Molossus
**
Posts: 795


WWW
« Reply #17 on: August 07, 2011, 10:12:21 PM »

Good you caught that typo.
I assume you are already ray-marching thru z until you hit the bulb so why not add DE like this:
dr=1.0
inside iterate:
dr=dr*p*pow(r,p-1.0)+1.0
after iterate advance z by 0.5*log(r)*r/dr

It will greatly increase the speed and make experimenting with coloring much more enjoyable.

It doesn't work sad
i coded what i understood of the raymarching thingy.
If i advance by 0.1 instead of your formula, i have something.
if i use 0.5*log(r)*r/dr; i have nothing.

Can you take a look at this very ugly code and help please ? smiley

Code:
final int MAXITER = 16;
final int MAXSTEP = 255;
final float p=8.0;
final color white = color(255);

float[][] pts = new float[MAXITER+1][3];
int count = 0;
float x,y,z;


void setup() {
  size(800,800,P2D);
  frameRate(1000);
  background(0);
  stroke(255);
}

void draw() {
  loadPixels();
  count++;
  if(count > 10000) {
    count=0;
    randomSeed(millis());
  }
  for(int i = 0; i < 1000; i++) {
  x = random(-1.5,1.5);
  y = random(-1.5,1.5);
  z = -4.0;
  float dr = 1.0;
  int step =0;

  for(step = 0; step < MAXSTEP; step++) {
  int iter = 0;
  float r = 0.0;
  float nx = x;
  float ny = y;
  float nz = z;
  r=sqrt(x*x+y*y+z*z);
  float th=atan(y/x)*p;
  float ph=asin(z/r)*p;
  float u,v;

    while(iter < MAXITER && r<2.0  ) {
      float r2p = pow(r,p);
      th=atan(ny/nx)*p;
      ph=asin(nz/r)*p;
      nx=r2p*cos(ph)*cos(th)+x;
      ny=r2p*cos(ph)*sin(th)+y;
      nz=r2p*sin(ph)+z;
      r=sqrt(nx*nx+ny*ny+nz*nz);
      dr=dr*p*pow(r,p-1.0)+1.0;
      iter++;
    }
    //println(dr);
    if(r<2.0) {
        u =  x * 6.0 / (z + 4.0);
        v = y  * 6.0 / (z + 4.0);
        u = (2.0 + u) / 4.0 * width;
        v = (2.0 + v) / 4.0 * height;
        if(u > 0 && u < width && v > 0 && v < height) {
          pixels[(int)((int)u + (int)v * width)] = color(step*1,step*1,step*1);
        }
        break;
    } else {
      step++;
      z+=0.1;//*log(r)*r/dr;
    }
  }
  } 
  updatePixels();


 
Logged

often times... there are other approaches which are kinda crappy until you put them in the context of parallel machines
(en) http://www.blog-gpgpu.com/ , (fr) http://www.keru.org/ ,
Sysadmin & DBA @ http://www.over-blog.com/
ker2x
Fractal Molossus
**
Posts: 795


WWW
« Reply #18 on: August 07, 2011, 10:23:26 PM »

i just noticed that the mandelbulb formula in fragmentarium was very easy to understand and i'll try to learn from it smiley
Logged

often times... there are other approaches which are kinda crappy until you put them in the context of parallel machines
(en) http://www.blog-gpgpu.com/ , (fr) http://www.keru.org/ ,
Sysadmin & DBA @ http://www.over-blog.com/
ker2x
Fractal Molossus
**
Posts: 795


WWW
« Reply #19 on: August 07, 2011, 10:41:42 PM »

My problem is that dr quickly become == Double.POSITIVE_INFINITY
Logged

often times... there are other approaches which are kinda crappy until you put them in the context of parallel machines
(en) http://www.blog-gpgpu.com/ , (fr) http://www.keru.org/ ,
Sysadmin & DBA @ http://www.over-blog.com/
Syntopia
Fractal Molossus
**
Posts: 681



syntopiadk
WWW
« Reply #20 on: August 08, 2011, 12:16:00 AM »

The 'dr'-value must be reset inside the MAXSTEP loop, just like 'r'.
Logged
ker2x
Fractal Molossus
**
Posts: 795


WWW
« Reply #21 on: August 08, 2011, 01:03:21 AM »

The 'dr'-value must be reset inside the MAXSTEP loop, just like 'r'.

Well, it still doesn't work  cry
But at least one insane error is patched  grin

here is the current code :

Code:
final int MAXITER = 16;
final int MAXSTEP = 255;
final float p=8.0;
final color white = color(255);

float[][] pts = new float[MAXITER+1][3];
int count = 0;
float x,y,z;


void setup() {
  size(800,800,P2D);
  frameRate(1000);
  background(0);
  stroke(255);
}

void draw() {
  loadPixels();
  count++;
  if(count > 10000) {
    count=0;
    randomSeed(millis());
  }
  for(int i = 0; i < 1000; i++) {
  x = random(-1.5,1.5);
  y = random(-1.5,1.5);
  z = -4.0;
 
  int step =0;

  for(step = 0; step < MAXSTEP; step++) {
  int iter = 0;
  float r = 0.0;
  float dr = 1.0;
  float nx = x;
  float ny = y;
  float nz = z;
  r=sqrt(x*x+y*y+z*z);
  float th=atan(y/x)*p;
  float ph=asin(z/r)*p;
  float u,v;
 
    while(iter < MAXITER /*&& r<2.0*/  ) {
      float r2p = pow(r,p);
      th=atan2(ny,nx)*p;
      ph=asin(nz/r)*p;
      nx=r2p*cos(ph)*cos(th)+x;
      ny=r2p*cos(ph)*sin(th)+y;
      nz=r2p*sin(ph)+z;
      r=sqrt(nx*nx+ny*ny+nz*nz);
      dr=dr*p*pow(r,p-1.0)+1.0; 
      iter++;
    }
   
    if(r<2.0) {
        println(dr);
        u =  x * 6.0 / (z + 4.0);
        v = y  * 6.0 / (z + 4.0);
        u = (2.0 + u) / 4.0 * width;
        v = (2.0 + v) / 4.0 * height;
        if(u > 0 && u < width && v > 0 && v < height) {
          pixels[(int)((int)u + (int)v * width)] = color(step*1,step*1,step*1);
        }
        break;
    } else {
      step++;
      z+=0.1;
      z+=0.5*log(r)*r/dr; //<-nothing
    }
  }
  } 
  updatePixels();




the output that display dr whrn r < 2.0 :
11.36559
3.330166
12.572722
10.215517
5.687963
28.261217
43.640415
3.3310628
3.3878212
13.518621
3.347372
10.360928
7.386033
...
Logged

often times... there are other approaches which are kinda crappy until you put them in the context of parallel machines
(en) http://www.blog-gpgpu.com/ , (fr) http://www.keru.org/ ,
Sysadmin & DBA @ http://www.over-blog.com/
ker2x
Fractal Molossus
**
Posts: 795


WWW
« Reply #22 on: August 08, 2011, 01:15:08 AM »

Well, obviously i should display println(0.5*log(r)*r/dr); to see how big was supposed to be my last step :

4.1891032E-4
0.0011521813
5.504626E-4
-0.003734893
-0.051313702
1.649025E-4
-0.015488651
2.312548E-6
-0.0359119
-0.013137315
-0.0013213182
-0.036753275
-1.0157118E-4
-3.4222467E-7
-0.0076081255
-0.014232793
-0.03867302
-2.776414E-4
-8.763797E-6
-0.039671708
-0.0022190188
9.5214637E-4
-6.9133566E-5
-0.029464567
-2.9889583E-7
-0.0017719215
-0.027600588
-0.011584057
-0.00846173
-6.32731E-5
Logged

often times... there are other approaches which are kinda crappy until you put them in the context of parallel machines
(en) http://www.blog-gpgpu.com/ , (fr) http://www.keru.org/ ,
Sysadmin & DBA @ http://www.over-blog.com/
ker2x
Fractal Molossus
**
Posts: 795


WWW
« Reply #23 on: August 08, 2011, 01:20:50 AM »

if i replace :
if(r<2.0)
by :
if(0.5*log(r)*r/dr > -10e-20 && 0.5*log(r)*r/dr < 10e-20)
i have a correct something that look like a buddhabrot.


but i still can't do z+=0.5*log(r)*r/dr;
« Last Edit: August 08, 2011, 01:22:26 AM by ker2x » Logged

often times... there are other approaches which are kinda crappy until you put them in the context of parallel machines
(en) http://www.blog-gpgpu.com/ , (fr) http://www.keru.org/ ,
Sysadmin & DBA @ http://www.over-blog.com/
eiffie
Guest
« Reply #24 on: August 09, 2011, 05:31:23 PM »

One problem I see with the code is the order you are calculating r and dr. Switch them.
dr=dr*...   //you want to calc using the old r
then
r=sqrt(...

also typically we bail at r<2.0 so I am not sure this works well for your purpose.
I was confusing myself there! Glad it works for you.
« Last Edit: August 09, 2011, 10:34:25 PM by eiffie » Logged
ker2x
Fractal Molossus
**
Posts: 795


WWW
« Reply #25 on: August 09, 2011, 07:29:56 PM »

It works \o/
Thank you  grin



Code:
final int MAXITER = 16;
final int MAXSTEP = 255;
final float p=8.0;
final color white = color(255);

float[][] pts = new float[MAXITER+1][3];
int count = 0;
float x,y,z;


void setup() {
  size(800,800,P2D);
  frameRate(1000);
  background(0);
  stroke(255);
}

void draw() {
  loadPixels();
  count++;
  if(count > 10000) {
    count=0;
    randomSeed(millis());
  }
  for(int i = 0; i < 10000; i++) {
  x = random(-1.5,1.5);
  y = random(-1.5,1.5);
  z = -4.0;
  
  int step =0;

  for(step = 0; step < MAXSTEP && z < 4.0; step++) {
  int iter = 0;
  float r = 0.0;
  float dr = 1.0;
  float nx = x;
  float ny = y;
  float nz = z;
  r=sqrt(x*x+y*y+z*z);
  float th=atan(y/x)*p;
  float ph=asin(z/r)*p;
  float u,v;
  
    while(iter < MAXITER && r<2.0  ) {
      float r2p = pow(r,p);
      th=atan2(ny,nx)*p;
      ph=asin(nz/r)*p;
      nx=r2p*cos(ph)*cos(th)+x;
      ny=r2p*cos(ph)*sin(th)+y;
      nz=r2p*sin(ph)+z;
      dr=dr*p*pow(r,p-1.0)+1.0;  
      r=sqrt(nx*nx+ny*ny+nz*nz);
      iter++;
    }
    
    if(0.5*log(r)*r/dr < 0.00001) {
        
        u =  x * 6.0 / (z + 4.0);
        v = y  * 6.0 / (z + 4.0);
        u = (2.0 + u) / 4.0 * width;
        v = (2.0 + v) / 4.0 * height;
        if(u > 0 && u < width && v > 0 && v < height) {
          pixels[(int)((int)u + (int)v * width)] = color(step*1,step*1,step*1);
        }
        break;
    } else {
      step++;
      z+=0.5*log(r)*r/dr;
    }
  }
  }  
  updatePixels();
}  

  

Logged

often times... there are other approaches which are kinda crappy until you put them in the context of parallel machines
(en) http://www.blog-gpgpu.com/ , (fr) http://www.keru.org/ ,
Sysadmin & DBA @ http://www.over-blog.com/
A Noniem
Alien
***
Posts: 38


« Reply #26 on: August 09, 2011, 08:23:13 PM »

If I were you i'd make a ray tracer (if you know how it works, beginning from scratch is hard). It's more difficult, but the results are a lot nicer and the rendering time is a lot less.
Logged
ker2x
Fractal Molossus
**
Posts: 795


WWW
« Reply #27 on: August 10, 2011, 12:56:46 PM »

If I were you i'd make a ray tracer (if you know how it works, beginning from scratch is hard). It's more difficult, but the results are a lot nicer and the rendering time is a lot less.

Step by step, i want to understand what i'm doing.
I took a few hours to translate some code to OpenCL, not yet optimized but it's much much faster already  grin

However, i will keep the Monte Carlo method, i like it  embarrass
I'm not good enough to write the best fractal software, and i don't have enough time for that anyway, i want to learn and have fun.

Yes, i'll write a raytracer, with openCL.
Logged

often times... there are other approaches which are kinda crappy until you put them in the context of parallel machines
(en) http://www.blog-gpgpu.com/ , (fr) http://www.keru.org/ ,
Sysadmin & DBA @ http://www.over-blog.com/
ker2x
Fractal Molossus
**
Posts: 795


WWW
« Reply #28 on: August 10, 2011, 11:01:12 PM »

some improvments  grin

It's much nicer when the fractal is white and more step = more shadow   embarrass
(instead of a black fractal with color = number of step)

Logged

often times... there are other approaches which are kinda crappy until you put them in the context of parallel machines
(en) http://www.blog-gpgpu.com/ , (fr) http://www.keru.org/ ,
Sysadmin & DBA @ http://www.over-blog.com/
ker2x
Fractal Molossus
**
Posts: 795


WWW
« Reply #29 on: August 10, 2011, 11:12:46 PM »

and some fake lightning colors based on X,Y,Z position


« Last Edit: August 10, 2011, 11:22:52 PM by ker2x » Logged

often times... there are other approaches which are kinda crappy until you put them in the context of parallel machines
(en) http://www.blog-gpgpu.com/ , (fr) http://www.keru.org/ ,
Sysadmin & DBA @ http://www.over-blog.com/
Pages: 1 [2] 3 4 5   Go Down
  Print  
 
Jump to:  

Related Topics
Subject Started by Replies Views Last post
I arrive, and I come with code. Meet & Greet CraigM 3 1617 Last post January 16, 2009, 12:13:07 PM
by Cyclops
some code Mandelbulb 3d Jesse 7 3061 Last post August 15, 2011, 10:27:15 PM
by Jesse
Break the code Fractal Humor KRAFTWERK 11 7150 Last post November 25, 2011, 05:27:04 PM
by cKleinhuis
Mandelbulb Source Code? Programming neosettler 5 5520 Last post April 14, 2015, 11:38:51 AM
by DarkBeam
Set S of S: Simpliest location, eXtreme Depth. Images Showcase (Rate My Fractal) SeryZone 4 1476 Last post October 31, 2014, 08:52:09 PM
by SeryZone

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.149 seconds with 27 queries. (Pretty URLs adds 0.008s, 2q)