Logo by mauxuam - 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. March 29, 2024, 04:17:03 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 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 14175 times)
0 Members and 1 Guest are viewing this topic.
ker2x
Fractal Molossus
**
Posts: 795


WWW
« Reply #30 on: August 10, 2011, 11:24:00 PM »

Now i'm wondering...

what is the next logical feature to add ?
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/
marius
Fractal Lover
**
Posts: 206


« Reply #31 on: August 10, 2011, 11:33:22 PM »

Now i'm wondering...

what is the next logical feature to add ?

stereoscopy!
Logged
ker2x
Fractal Molossus
**
Posts: 795


WWW
« Reply #32 on: August 10, 2011, 11:55:20 PM »

Ho! wow ... i have NVidia's 3D Vision google and i never tought to test it on my 3D flowabulb  (it's openGL, so it should works directly without problem) shocked
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 #33 on: August 11, 2011, 12:46:18 AM »

That would be a truly awesome feature  wink
Images look nice btw, they are getting nicer every day.
Logged
richardrosenman
Conqueror
*******
Posts: 104



WWW
« Reply #34 on: March 22, 2012, 06:55:26 PM »

Hi gang;

I too, like Ker2X, am trying to learn how to generate the Mandelbulb, through studying and learning source code (I understand that much better than algorithms).

I have been working with the previously posted code and understanding how it works, as well as adapting it for my own purposes.

I would love any help and suggestions on how to continue developing this further. Building a raytracer would be an amazing experience but that is far beyond my capabilities (I'm primarily an artist and only secondarily a programmer - the two don't mix!).

The first thing I did was take ker2X's great code and try to optimize it by removing the random sampling part and instead convert it to a pixel by pixel ray marcher.

 
Code:
for(y = 0; y < Y; y++)
  for(x = 0; x < X; x++) {
   xx = 2.0* ((float)x/(float)X) -1.0;
   yy = 2.0* ((float)y/(float)Y) -1.0;
   zz = -4.0;

In other words, march a ray from every screen pixel and draw the fractal that way. Although it is far faster (you don't end up using duplicate rays), it presents some problems which I can't figure out:



This is a render of the MB using 2 iterations only and it shows these black speckles. They are present in any iteration count but this one is the clearest to see. I think this is because those points are not being rendered but I don't understand why since a ray is being marched from every pixel. In theory, it shouldn't miss any points.

I had a hunch it was something to do with the bounding box:

Code:

xx = 2.0* ((float)x/(float)X) -1.0;
yy = 2.0* ((float)y/(float)Y) -1.0;

So I started experimenting with a larger one to see if that was the problem. For the next image, I tried:

Code:

xx = 4.0* ((float)x/(float)X) -2.0;
yy = 4.0* ((float)y/(float)Y) -2.0;

And then:

Code:

xx = 8.0* ((float)x/(float)X) -4.0;
yy = 8.0* ((float)y/(float)Y) -4.0;



So it looks like those are spaces in between the pixels that I'm tracing? Is this the cause of the speckling I'm getting in the first image? I tried the opposite and minimized the bounding box to a smaller than usual value and the black speckles became fewer.

Anyway, I suppose my first question is: Am I doing this the right way? If I want to trace a ray from each pixel to draw a clean MB? If so, why am I getting these artifacts?

Thanks in advance for any suggestions and help. I am really looking forward to learning how to do this with some of your much appreciated help!

-Rich
« Last Edit: March 22, 2012, 07:08:19 PM by richardrosenman » Logged

ker2x
Fractal Molossus
**
Posts: 795


WWW
« Reply #35 on: March 23, 2012, 08:03:39 AM »

a point is black if the ray stop before being close enough to a surface.
(or if it's detected outside of the mandelbulb set, of course)


try with a higher value of maxstep ?
AND/OR
if(0.5*log(r)*r/dr < 0.00001) <- try with 0.001 ?

(i don't remember why the 0.5 ratio but, if i remember correctly, it's a bad idea to change it)
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 #36 on: March 23, 2012, 08:10:08 AM »

btw, that's why i like montecarlo method. It's very simple and it eventually converge to an ideal.  grin
(some code is missing, i should average/smooth/whatever the value of a pixel when many rays it the same pixel)
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/
richardrosenman
Conqueror
*******
Posts: 104



WWW
« Reply #37 on: March 23, 2012, 04:15:10 PM »

a point is black if the ray stop before being close enough to a surface.
(or if it's detected outside of the mandelbulb set, of course)


try with a higher value of maxstep ?
AND/OR
if(0.5*log(r)*r/dr < 0.00001) <- try with 0.001 ?

(i don't remember why the 0.5 ratio but, if i remember correctly, it's a bad idea to change it)

Hi Ker2x;

Yes, I've tried playing with that value and although the accuracy varies it still produces the black speckles. With the Monte Carlo it doesn't produce the artifacts but it takes forever to render and never clean enough unless you let it run indefinitely.

I'm sampling a ray per pixel so there shouldn't be any missed rays.

I wonder if perhaps it has something to do wih my compiler and floating point accuracy? (I've had problems with that before). I guess I am looking for confirmation of whether I was doing that correctly or if there's a better way to do it?

Rich
Logged

yv3
Conqueror
*******
Posts: 149



WWW
« Reply #38 on: March 23, 2012, 10:50:57 PM »

Thank you ker2x very much for providing the mandelbulb formula!! My math knowledge is bad and i was looking for something like this a long time. Now i can explore mandelbulbs the first time in my own tool! its like a new era has come :). I never liked mandelbulbs/3d fractals much in the past time, but its something other if you "try" it out by yourself, modifying the formula and adding parameters to it. I changed your algorithm to calculate the color of a specific position like in did it for traditional mandelbrot rendering. It works perfectly for me, i was overwhelmed when the first images appeared on the screen after a half hour of trying around:


[FULL SIZE]


[FULL SIZE]
Yeah i found it :)


[FULL SIZE]

I found the formula of god, it produces models of fairy women without arms :)

The only problem is, its very slow compared to the calculation of traditional 2d fractals in my tool. Anyone has an idea how to speed up my code?

Code:
void yFractal::GetFractalColor999()
{
static float x, y, z, r, dr, nx, ny, nz, th, ph, r2p, cr1, cr2, cr4, max_z, mag;
static int iter, step;

cr1 = float(m_CustomRange1);
cr2 = float(m_CustomRange2);
max_z = float(m_CustomRange3); 
cr4 = float(m_CustomRange4);
mag = float(m_Magnitude)/1000.0f;

x = float(m_StartX);
y = float(m_StartY);
z = -max_z;

for(step=0; step<m_Iterations && z<max_z; step++)
{
iter=0;
r=0.0f;
dr=1.0f;
nx=x;
ny=y;
nz=z;
r=sqrtf(x*x + y*y + z*z);
th=atanf(y/x) * cr2;
ph=asinf(z/r) * cr2;

while(iter<cr1 && r<4.0f)
{
r2p=powf(r, cr2);

th=atan2f(ny, nx) * cr2;
ph=asinf(nz/r) * cr2;

nx=r2p*cosf(ph)*cosf(th) + x;
ny=r2p*cosf(ph)*sinf(th) + y;
nz=r2p*sinf(ph) + z;

dr=dr*cr2*powf(r, cr2-1.0f) + 1.0f; 
r=sqrtf(nx*nx + ny*ny + nz*nz);

iter++;
}

if(0.001f*logf(r)*r/dr < mag)
{
m_C=int( float(step) * m_ColorPerIteration ); // Return color index from range 0 to (m_NumColors-1)
return;
}
else
{
step++;
z+=cr4*logf(r)*r/dr;
}

} //for(step=0; step<m_Iterations && z<max_z; step++)

m_C=0;
}

HELP
« Last Edit: March 24, 2012, 09:23:01 AM by yv3 » Logged

Creator of yFract
ker2x
Fractal Molossus
**
Posts: 795


WWW
« Reply #39 on: March 24, 2012, 01:11:08 AM »

i'm glad it help more than myself  grin
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/
asimes
Fractal Lover
**
Posts: 212



asimes
WWW
« Reply #40 on: March 25, 2012, 08:08:52 AM »

That's a very nice result, could you post your new code please? I wanted to wrap my head around doing something like that. I made a Mandelbulb code in Processing recently but it just is testing every point in a voxel space. Here's my code:

Code:
float xmin = -2;
float ymin = -2;
float zmin = -2;
float wh = 4;
int maxIterations = 6;
int power = 8;
int screenSize = 200;

void setup() {
  size(screenSize, screenSize, P3D);
  noStroke();
  noLoop();
}

void draw() {
  background(255);
  translate(0, screenSize/2, 0);
  rotateX(-HALF_PI);
  translate(0, -screenSize/2, -screenSize/2);
  float xmax = xmin+wh;
  float ymax = ymin+wh;
  float zmax = zmin+wh;
  float dx = (xmax-xmin)/screenSize;
  float dy = (ymax-ymin)/screenSize;
  float dz = (zmax-zmin)/screenSize;
  int count = 0;
  float x = xmin;
  for (int i = 0; i < screenSize; i++) {
    float y = ymin;
    for (int j = 0; j < screenSize; j++) {
      float z = zmin;
      for (int k = 0; k < screenSize; k++) {
        float nx = x;
        float ny = y;
        float nz = z;
        int n = 0;
        while (n < maxIterations) {
          float rad = pow(sqrt(nx*nx+ny*ny+nz*nz), power);
          float theta = atan2(sqrt(nx*nx+ny*ny), nz)*power;
          float phi = atan2(ny, nx)*power;
          nx = sin(theta)*cos(phi)*rad+x;
          ny = sin(theta)*sin(phi)*rad+y;
          nz = cos(theta)*rad+z;
          if (nx*nx+ny*ny+nz*nz > 16) break;
          n++;
        }
        if (n == maxIterations) {
          float distE = sqrt(x*x+y*y+z*z);
          float cr = 98*(abs(x)+distE);
          float cg = 98*(abs(y)+distE);
          float cb = 98*(abs(z)+distE);
          fill(cr, cg, cb);
          translate(i, j, k);
          box(1);
          translate(-i, -j, -k);
        }
        z += dz;
      }
      y += dy;
    }
    x += dx;
    println((float(count)/screenSize*100)+"%");
    count++;
  }
  println("Time: "+millis());
  saveFrame("result.png");
}
Logged
asimes
Fractal Lover
**
Posts: 212



asimes
WWW
« Reply #41 on: March 27, 2012, 04:11:48 AM »

My bad, I was looking at the post more carefully and realized your code for the black one could easily become the white one by changing the coloring to: color(255-step);

I was wondering how you figured out how to get the 3D points to work with pixels[]. My code goes through all the points in a bounding box so z changes. I used to just use screenX and screenY like but it left me with visual artifacts.
Logged
richardrosenman
Conqueror
*******
Posts: 104



WWW
« Reply #42 on: March 27, 2012, 04:25:12 AM »

My bad, I was looking at the post more carefully and realized your code for the black one could easily become the white one by changing the coloring to: color(255-step);

I was wondering how you figured out how to get the 3D points to work with pixels[]. My code goes through all the points in a bounding box so z changes. I used to just use screenX and screenY like but it left me with visual artifacts.

I would like to know this too since I too am getting artifacts when I run thought the pixels. I am comparing my renders to Tom Beddard's and his are perfectly clean, while mine are very noisy.

-Richard
Logged

ker2x
Fractal Molossus
**
Posts: 795


WWW
« Reply #43 on: March 27, 2012, 04:29:38 PM »

now it may be a good idea to learn about raymarching  grin

http://www.fractalforums.com/general-discussion/ray-marching/msg40101/#msg40101
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/
richardrosenman
Conqueror
*******
Posts: 104



WWW
« Reply #44 on: March 28, 2012, 03:18:31 AM »

Hi Ker2x;

I understand the premise of raymarching and (vaguely) the raymarcher in the sample code. It is very similar to Tom's as well but yet produces noise in my images and not in his. This means I must have an error in the code, or Tom uses additional improvement functions which I cannot see.

Here's an example:



You can see the results are extremely different. I know Tom's has specularity, light sources, and all that but even without, the surfaces are intact. Mine are not. Any ideas?

-Rich
« Last Edit: March 28, 2012, 03:20:50 AM by richardrosenman » Logged

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 1584 Last post January 16, 2009, 12:13:07 PM
by Cyclops
some code Mandelbulb 3d Jesse 7 2983 Last post August 15, 2011, 10:27:15 PM
by Jesse
Break the code Fractal Humor KRAFTWERK 11 7049 Last post November 25, 2011, 05:27:04 PM
by cKleinhuis
Mandelbulb Source Code? Programming neosettler 5 5373 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 1437 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.412 seconds with 28 queries. (Pretty URLs adds 0.019s, 2q)