|
This thread is locked; no one can reply to it. |
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
|
Just use another float2 (vec2 in GLSL) to store the previous coordinate. Then you can reference and overwrite it each iteration. --- |
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? EDIT: never mind, I found the correct code here. The article is wrong.
|
gnolam
Member #2,030
March 2002
|
It looked right to me. 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. -- |
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
|
Correct. -- |
|
1
2
|