Skip navigation.

exploreopera

| Help

Sign up | Help

A Blag About Graphics and Programming

...and Stuff

Fractals are Even More Fun!

The algorithm for generating the Mandelbrot set looks like this:

for each pixel
{
  C= (x,y);
  Z= (0,0);
  i= 0;
  while i<MAX_NUMBER_OF_ITERATIONS and Z distance to origin< 2 
  { 
     Z= Z^2 + C;
     i++;
  }
  Color= ColorTable[i];
  DrawPixel(x,y, Color);
}
Where C and Z are complex numbers.

When MAX_NUMBER_OF_ITERATIONS= 256, generating this(1280x1024) image takes about 20 seconds.

But, as you can see, the algorithm is very easy to parallelize: the pixels are independent of each other, there's no writing to the same memory locations etc.
So, for example, you could run it with two threads (one thread generates one half, the second- the other half of the image). And on a dual core machine it should run two times faster (on quad core- four times, etc.)

Now if only I had access to some kind of processor that had more that two cores, much more. A processor that would be built to run parallel code. Maybe those cores could be called, I don't know, "stream processing units"? And there could be a 100, no, 120 of them!

Oh... wait... :wink:

Wrote a little program that generates the same image (1280x1024, 256 iterations, the color table is in a 256x1 texture) in the pixel shader.
It runs on 17fps. That is 20 seconds on the CPU and 0.06 seconds on the GPU! w00t?

The shader is a perfect test to see how dynamic and static branching/looping performs in different situations.

I should be posting a demo in a couple of days.

P.S. Updated a very old post with info how to use 3dmax sdk's IGame to export animations.

Fractals are FunDemo: GPU Fractals

Write a comment

Comment
(BBcode and HTML is turned off for anonymous user comments.)

Please type this security code : 16aa97

Smilies

October 2008
SMTWTFS
September 2008November 2008
1234
567891011
12131415161718
19202122232425
262728293031