Welcome to Fractal Forums

Fractal Software => Programming => Topic started by: ker2x on July 28, 2014, 08:59:51 PM




Title: 3D Anti-buddhabrot
Post by: ker2x on July 28, 2014, 08:59:51 PM
Awefull processing code  ::)

10 millions point at 30fps, video incoming  ;D

Code:
import javax.media.opengl.GL2;
import java.nio.*;
 
int nvert = 10000000;
int SIZEOF_INT = Integer.SIZE / 8;
int SIZEOF_FLOAT = Float.SIZE / 8;

final int MINITER = 20;
final int MAXITER = 400;
final float P_ALPHA = 0.1;
final float p = 2.0;

int step, oldstep = 0;

float[][] pts = new float[MAXITER+1][3];
 
PGL pgl;
 
IntBuffer vboName;
FloatBuffer vertData;
 
void setup() {
  size(1600, 1200, P3D);
  frameRate(2000);
 
  createGeometry();
  initVBO();
}
 
void draw() {
  background(0);
 
  translate(width/2, height/2,-1000);
  rotateY(frameCount * 0.001);
  
  pgl = beginPGL();
  GL2 gl2 = ((PJOGL)pgl).gl.getGL2();
 
  pgl.bindBuffer(PGL.ARRAY_BUFFER, vboName.get(0));
  gl2.glEnableClientState(GL2.GL_VERTEX_ARRAY);
  gl2.glEnableClientState(GL2.GL_COLOR_ARRAY);
 
  gl2.glVertexPointer(3, PGL.FLOAT, 7 * SIZEOF_FLOAT, 0);
  gl2.glColorPointer(4, PGL.FLOAT, 7 * SIZEOF_FLOAT, 3 * SIZEOF_FLOAT);
 
  pgl.drawArrays(PGL.POINTS, 0, nvert);
 
  gl2.glDisableClientState(GL2.GL_VERTEX_ARRAY);
  gl2.glDisableClientState(GL2.GL_COLOR_ARRAY);
  pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
 
  endPGL();
 
  if (frameCount % 60 == 0) println("fps: " + frameRate);
}
 
void createGeometry() {
  float[] temp = new float[nvert * 7];
 
  for (int n = 0; n < nvert; n++) {

    boolean needrefresh = false;

    while(!needrefresh) {
    float x,y,z,nx,ny,nz,r,r2p,th,ph = 0.0;  
    int iter = 0;

    x = random(-2.0,2.0);
    y = random(-2.0,2.0);
    z = random(-2.0,2.0);

    iter = 0;
    r = 0.0;
    nx = x;
    ny = y;
    nz = z;
    r=sqrt(x*x+y*y+z*z);
    th=atan(y/x)*p;
    ph=asin(z/r)*p;
  
    while(iter<MAXITER && r<2.0 && nx!=0.0 && r!=0.0 && nx!=-0.0 && r!=-0.0) {
      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;
      
      pts[iter][0] = nx;
      pts[iter][1] = ny;
      pts[iter][2] = nz;
      r=sqrt(nx*nx+ny*ny+nz*nz);
      iter++;
    }
    
    if(r<2.0 && iter > MINITER) {
      for(int i = MINITER; i < iter && n < nvert-1 ; i++) {
        if(pts[i][0]*pts[i][0] + pts[i][1]*pts[i][1] + pts[i][2]*pts[i][2] < 4) {
          // position
          temp[n * 7 + 0] = pts[i][0]*(width/2.0);
          temp[n * 7 + 1] = pts[i][1]*(width/2.0);
          temp[n * 7 + 2] = pts[i][2]*(width/2.0);
 
          // color
          temp[n * 7 + 3] = abs(pts[0][0]);
          temp[n * 7 + 4] = abs(pts[0][1]);
          temp[n * 7 + 5] = abs(pts[0][2]);
          temp[n * 7 + 6] = 0.8;
          n++;
        }
      }
      needrefresh = true;      
    }
    }        
  }
 
  vertData = allocateDirectFloatBuffer(nvert * 7);
  vertData.rewind();
  vertData.put(temp);
  vertData.position(0);
}
 
void initVBO() {
  vboName = allocateDirectIntBuffer(1);
  pgl = beginPGL();
  pgl.genBuffers(1, vboName);
  pgl.bindBuffer(PGL.ARRAY_BUFFER, vboName.get(0));
  pgl.bufferData(PGL.ARRAY_BUFFER, nvert * 7 * SIZEOF_FLOAT, vertData, PGL.STATIC_DRAW);
  pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
  endPGL();
}
 
IntBuffer allocateDirectIntBuffer(int n) {
  return ByteBuffer.allocateDirect(n * SIZEOF_INT).order(ByteOrder.nativeOrder()).asIntBuffer();
}
 
FloatBuffer allocateDirectFloatBuffer(int n) {
  return ByteBuffer.allocateDirect(n * SIZEOF_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();
}


Title: Re: 3D Anti-buddhabrot
Post by: ker2x on July 28, 2014, 09:06:48 PM
Here it is :
http://www.youtube.com/watch?v=0d7J1nwja4k

Enjoy 1440p :)


Title: Re: 3D Anti-buddhabrot
Post by: kram1032 on July 28, 2014, 09:34:18 PM
Pretty :D
This could easily be some system of bloodvessels or a connectome image (an image of the connections in a brian)
This actually looks much closer to what you might think of as a 3D mandlebrot set "holygrail" than most other works I've seen thus far. Very fine and spindly. I suppose those fine hair basically are the equivalent of whipped cream surfaces though.
I'd love to see one with more details. But I'm assuming this is a beast to render.
Btw, if you want it embedded instead of just linked, do the expanded link. The plugin this forum is using somehow doesn't recognize shortened YouTube links.


Title: Re: 3D Anti-buddhabrot
Post by: ker2x on July 28, 2014, 09:47:18 PM
Pretty :D
This could easily be some system of bloodvessels or a connectome image (an image of the connections in a brian)
This actually looks much closer to what you might think of as a 3D mandlebrot set "holygrail" than most other works I've seen thus far. Very fine and spindly. I suppose those fine hair basically are the equivalent of whipped cream surfaces though.
I'd love to see one with more details. But I'm assuming this is a beast to render.
Btw, if you want it embedded instead of just linked, do the expanded link. The plugin this forum is using somehow doesn't recognize shortened YouTube links.

Thx for the tips (it doesn't like https too) :)
Yes, the algorithm is a good old one, nothing new here.
It's a beast to render indeed. I think i can do some improvements however.

The older version used ~6GB of memory  :hmh:
The new version use less memory ("only" 600MB) but it's rendered in one step (a few mn)... not fun at all  :snore:


Title: Re: 3D Anti-buddhabrot
Post by: ker2x on July 28, 2014, 09:58:07 PM
The (anti-anti) buddhabrot version :

http://www.youtube.com/watch?v=iPp781NtSFQ


Title: Re: 3D Anti-buddhabrot
Post by: kram1032 on July 29, 2014, 12:32:02 PM
what do you mean by "Anti-anti-buddhabrot"?
Looks nice too


Title: Re: 3D Anti-buddhabrot
Post by: ker2x on July 29, 2014, 03:50:36 PM
a regular buddhabrot, where you plot the orbit that escape :)


Title: Re: 3D Anti-buddhabrot
Post by: knighty on July 29, 2014, 06:57:45 PM
 :headbatting: Obviously... LOL!  :rotfl:
Impressive work BTW!