Welcome to Fractal Forums

Fractal Software => 3D Fractal Generation => Topic started by: David Makin on October 13, 2010, 01:00:12 PM




Title: 3D fractals using shader 2
Post by: David Makin on October 13, 2010, 01:00:12 PM
Hi all, am fairly new to programming GPU. Am using OpenGL ES2 and so far have just released "Free iCandy" for the iPhone which does realtime Julia Set animations (32 formulas, 150 colourings) including animation to external sound/music:

http://itunes.apple.com/us/app/free-icandy/id381061184?mt=8 (http://itunes.apple.com/us/app/free-icandy/id381061184?mt=8)

At the moment only available in the US.

I want to go on to do more fractal stuff for shader 2, including 3D fractals but am inexperienced with OpenGL so have some questions that I think will take a while to answer by myself.
Obviously using shader 2 to render 3D fractals has the same issue as rendering using Ultra Fractal in that there is no shared information from one pixel to another so I have the following questions:

1. Can a shader 2 program render such that it not only sets colours in the render buffer but also sets correct values in a z-buffer at the same time ?
and assuming this is possible:
2. Could a second shader 2 program then use the colour buffer and z buffer produced by the first program to add lighting to the values from the colour buffer (as a source texture) and render to a destination buffer ?

Or am I completely on the wrong track here ?


Title: Re: 3D fractals using shader 2
Post by: cKleinhuis on October 13, 2010, 02:44:42 PM
hi dave, nice you are stepping into gpu programming

in the latest shader versions you can define multiple render targets, as far as i know it is not possible with 2.0 shaders, but i am not sure,

one solution might be to use a 4 component float bitmap format as output, and use the alpha value as z-value,

after that it is easy to combine multiple textures ( for any purpose ) into a new shader, this is common practice, and
hence it never leaves the gpu memory very efficent...


Title: Re: 3D fractals using shader 2
Post by: David Makin on October 14, 2010, 04:08:21 AM
Oh, I thought z-buffering was included and all that was required was to enable it (I mean that there was a mechanism that would allow z-buffer output as well as the actual render buffer), I guess I need to do more reading up on OpenGL :)
But using 4-valued float output is a workable alternative :)


Title: Re: 3D fractals using shader 2
Post by: lycium on October 14, 2010, 12:43:57 PM
Trifox: I don't think OpenGL ES will support fp render targets?

Great stuff Dave :) (You'll want to help that disgruntled user on the app store page soon however!)

Regarding how to do the rendering, you basically make two passes: in the first pass, a fullscreen shader outputs depth data into a write-only texture (1:1). In a subsequent pass, this texture is bound to a full-screen quad (or single triangle if you're crafty) as read-only input and used to produce the final output image.

The issue of depth representation is a trick one in the absence of floating point output. I don't know if you can have a shader output plain z, so you might use some 4-byte depth representation (perhaps fixed point?) at the cost of some overhead.


Title: Re: 3D fractals using shader 2
Post by: David Makin on October 14, 2010, 06:10:59 PM
Thanks Lyc - without checking I seem to remember that ES2 does allow fp output or at least I'm sure it's possible to cofigure the output buffer as an fp colour buffer - just not sure whether that means it woud actually work with the current hardware or not without trying it :)
As to the disgruntled customer, we sent an explanation/apology but unfortunately can't respond with a comment in the App store as Apple do not allow developers to reply to comments on their apps (!!). There's not much to complain about though since the App is coimpletely free. Steve has now modified the text on the page to try and make sure that the requirement for the newer (3GS or later) OpenGL ES2 devices is clearer to the readers/customers.