Allegro.cc - Online Community

Allegro.cc Forums » Off-Topic Ordeals » Mandelbox?

This thread is locked; no one can reply to it. rss feed Print
 1   2 
Mandelbox?
Peter Wang
Member #23
April 2000

This thread finally inspired me to learn GLSL. I tried to implement the multi-pass Mandelbrot algorithm described here, where we render to alternating buffers, with the other buffer holding the values from the previous iteration.

uniform sampler2D input;
uniform float curIteration;
void main ()
{
  // Lookup value from last iteration
  vec4 inputValue = texture2D(input, gl_TexCoord[0].xy);
  vec2 z = inputValue.xy;
  vec2 c = gl_TexCoord[0].xy;
...  
}

The value of c at this point is gotten from the texture coordinate, but then the same texture coordinate is also used to index into the texture to look up the value from the previous iteration. How does that work?

blargmob
Member #8,356
February 2007
avatar

Just use another float2 (vec2 in GLSL) to store the previous coordinate. Then you can reference and overwrite it each iteration.

---
"No amount of prayer would have produced the computers you use to spread your nonsense." Arthur Kalliokoski

Peter Wang
Member #23
April 2000

I think you're thinking of the single pass algorithm, where you just do a loop for every point in the complex plane.

In the multi-pass algorithm I linked to, you initialise a buffer with the initial z values. Then you compute a single iteration into another buffer: z := z^2 + c. In the code above, the value of c is given directly by the texture coordinate, so how can the same texture coordinates also lookup the value of z in the other buffer?
Either I'm missing something, or that code is wrong.

EDIT: never mind, I found the correct code here. The article is wrong.

gnolam
Member #2,030
March 2002
avatar

It looked right to me. :)
You have a set of complex numbers (c) represented as texture coordinates. From those complex numbers, you calculate a corresponding recursive set of complex numbers (z), represented as texture values. In each iteration, you calculate the zn (the fragment's color) using c (the texture coordinate) and zn-1 (the input texture value).

What you're doing in each iteration is basically

complex zin[imax][rmax]
complex zout[imax][rmax]

for i=0 to imax
   for r=0 to rmax
      complex c = (r, i)
      zout[i][r] = zin[i][r]^2 + c

But with textures playing the parts of zin and zout (ping-ponging between the two) and the texture coordinates used as i,r.
(Naturally you'll need to do offsetting and scaling to get things interesting)

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

Peter Wang
Member #23
April 2000

Yep, I understand that, just not the specific code in the article. Can you clear this up for me?

  vec4 inputValue = texture2D(input, gl_TexCoord[0].xy);

  vec2 c = gl_TexCoord[0].xy;

If I understand correctly, the first line implies that you should provide texture coordinates that range from (0,0) to (1,1). On the second line there is no scaling and offsetting, so c is restricted to 0+0i to 1+1i.

gnolam
Member #2,030
March 2002
avatar

Correct.

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

 1   2 


Go to: