|
|
ker2x
Fractal Molossus
Posts: 795
|
|
« 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 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 ? 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
|
|
|
|
ker2x
Fractal Molossus
Posts: 795
|
|
« 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
|
|
|
Logged
|
|
|
|
ker2x
Fractal Molossus
Posts: 795
|
|
« Reply #19 on: August 07, 2011, 10:41:42 PM » |
|
My problem is that dr quickly become == Double.POSITIVE_INFINITY
|
|
|
Logged
|
|
|
|
Syntopia
|
|
« 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
|
|
« 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 But at least one insane error is patched here is the current 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
|
|
|
|
ker2x
Fractal Molossus
Posts: 795
|
|
« 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
|
|
|
|
ker2x
Fractal Molossus
Posts: 795
|
|
« 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
|
|
|
|
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
|
|
« Reply #25 on: August 09, 2011, 07:29:56 PM » |
|
It works \o/ Thank you 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
|
|
|
|
A Noniem
|
|
« 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
|
|
« 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 However, i will keep the Monte Carlo method, i like it 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
|
|
|
|
ker2x
Fractal Molossus
Posts: 795
|
|
« Reply #28 on: August 10, 2011, 11:01:12 PM » |
|
some improvments It's much nicer when the fractal is white and more step = more shadow (instead of a black fractal with color = number of step)
|
|
|
Logged
|
|
|
|
ker2x
Fractal Molossus
Posts: 795
|
|
« 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
|
|
|
|
|