It is currently Sat Aug 22, 2020 3:40 am


All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: mandelbulb
PostPosted: Sun Jan 22, 2012 2:41 pm 

Joined: Sun Jan 08, 2012 10:00 am
Posts: 31
Location: Germany
hey heres a code for mandelbulb
(took from: http://www.treblig.org/3dbrot/3dbrot.c
with maths from http://www.skytopia.com/project/fractal/mandelbulb.html )

Code:
const unsigned int size=256;
#define RANGE 1.2
const double xlow=-RANGE;
const double xhigh=RANGE;
const double ylow=-RANGE;
const double yhigh=RANGE;
const double zlow=-RANGE;
const double zhigh=RANGE;

const unsigned int maxiterations=80;
const double mandpow=8.0;
double r;

double valInRange(double low, double high, unsigned int size, unsigned int off)
{
  return low+((high-low)/(double)size)*(double)off;
}

unsigned int doPoint(double cx, double cy, double cz)
{
  // program from http://www.treblig.org/3dbrot/3dbrot.c
  double x,y,z;
  double newx,newy,newz;
  double theta,phi,rpow;
  //double r;
  unsigned int i;
  x=0.0;
  y=0.0;
  z=0.0;

  for(i=0;(i<maxiterations) && ((x*x+y*y+z*z) < 2.0);i++)
  {
   /* These maths from http://www.skytopia.com/project/fractal/mandelbulb.html */
    r = sqrt(x*x + y*y + z*z );
    theta = atan2(sqrt(x*x + y*y) , z);
    phi = atan2(y,x);
    rpow = pow(r,mandpow);
   
    newx = rpow * sin(theta*mandpow) * cos(phi*mandpow);
    newy = rpow * sin(theta*mandpow) * sin(phi*mandpow);
    newz = rpow * cos(theta*mandpow);
   
    x=newx+cx;
    y=newy+cy;
    z=newz+cz;
  }
  return i;
}


void createMandelbulb(PolyVox::SimpleVolume<PolyVox::Material8>& volData)
{
   PolyVox::Material8 uValue=1;
   //This three-level for loop iterates over every voxel in the volume
   for (int z = 0; z < volData.getWidth(); z++)
   {
      double fz=valInRange(zlow, zhigh, size, z);
      for (int y = 0; y < volData.getHeight(); y++)
      {
         double fy=valInRange(ylow, yhigh, size, y);
         for (int x = 0; x < volData.getDepth(); x++)
         {
            double fx=valInRange(xlow, xhigh, size, x);
            unsigned int val=doPoint(fx,fy,fz);
            //printf("%i ",val);
            if (val>=maxiterations-1)
            {
               uValue=r*12; //for example use r for material
               volData.setVoxelAt(x, y, z, uValue);
            }
         }
      }
   }
}
...
createMandelbulb(volData);
...


Example size 128
Image


Top
Offline Profile  
Reply with quote  
 Post subject: Re: mandelbulb
PostPosted: Mon Jan 23, 2012 4:36 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
Very nice! Reminds me of some work I did testing the Menger Sponge, though I didn't make any screenshots of that. Fractals are great for generating data to use with PolyVox. It would be interesting to have a whole game world built in this way...


Top
Offline Profile  
Reply with quote  
 Post subject: Re: mandelbulb
PostPosted: Fri Nov 02, 2012 3:25 pm 

Joined: Sun Jan 08, 2012 10:00 am
Posts: 31
Location: Germany
now i tried mandelbulb instead of cubicsurfaceextractor with surfaceextractor and the smooth look has its own charme:
Image


Top
Offline Profile  
Reply with quote  
 Post subject: Re: mandelbulb
PostPosted: Fri Nov 02, 2012 4:05 pm 
Developer
User avatar

Joined: Sun May 11, 2008 4:29 pm
Posts: 198
Location: UK
Very nice. This would make a very good stress test of the PolyVox surface extractors for benchmarking.

_________________
Matt Williams
Linux/CMake guy


Top
Offline Profile  
Reply with quote  
 Post subject: Re: mandelbulb
PostPosted: Sat Nov 03, 2012 8:10 am 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
Yep, I like it! I also discovered the Mandelbox recently and thought that would make a good test for just how far we can push PolyVox. I'll try to give it a go once the Gameplay3D integration has come a bit further.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: mandelbulb
PostPosted: Sun Mar 17, 2013 8:14 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
As you might have seen in this thread I've finally made a version of the Mandelbulb myself now. I haven't actually tried loading it into PolyVox/Cubiquity yet but I already have a question. How did you choose what colour each voxel should be?

For each voxel I am storing the number of iterations which were required for the fractal to converge (so it's a greyscale image). I can imagine this could be mapped to a colour gradient which would look great if you cut the volume in half, but I'm not sure it helps if you view the volume from the outside?

I assume you had to choose a threshold for how many iterations represented a solid and how many represented empty space. Let's say the threshold is 100... doesn't that mean that all voxels on the surface will have a value of 100 and so will all be the same colour?

Maybe you used a different approach such as computing the distance from the centre of the fractal to the voxel, and then using this to determine the colour?


Top
Offline Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Theme created StylerBB.net