Sign in to follow this  
jwang

How to use global effect with local effect

Recommended Posts

Hi, guys, In my scene, all the object has its own effects, such as bump mapping using GLSL, and depth peeling shader is finally used on the whole scene to achieve the half transparent effect. As at any time, only one shader program can be used in the pipeline, it is not a problem for every object's individual shader effect, however, how can I apply the global scene effect at the same time?

Share this post


Link to post
Share on other sites
Either by dymamically compiling a shader for every local/global combination (probely not the best idea) or by simply applying the global effect in a additional pass using the right blend function

i.e something like

glEnable (GL_BLEND)
glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA);


then just draw everything twice in your render loop. once with your global effect and once with your local effects.

Share this post


Link to post
Share on other sites
To EternityZA :

Do you mean that for every object in the scene, I render it in two passes, one is global and one is local? However, some global effects such as depth peeling needs several passes and it needs the information from other object in the scene. Every path in the depth peeling requires to render the whole scene, but not individual object. So how to deal with this situation.

To szecs :

I tried to use this method too. It definitely can work. However, after I moved to Collada scene graph, the rendering of the scene is totally controlled by the Collada, which means I cannot specify to render the scene first into a texture by myself if the collada file dose not specify that.

Share this post


Link to post
Share on other sites
Is that should be first global, then local?

If we use this following example, rendering a scene which has a sphere in a box, the sphere and box will be rendered using the bump mapping, and the whole scene will be rendered using depth peeling to get half transparent effect.

The depth peeling peels the whole scene into different layers based on the depth value. For every layer, it will test a fragment against the depth buffer generated from the rendering of the last layer, and to decide if the fragment will be kept or dropped. The color of the fragment should come from the evaluation of the bump mapping. However, this cannot be evaluated when depth peeling is taking effect.

If we rendering the scene in local first, then the result is an non transparent bump mapping box. Then, if we evaluate the half transparent effect, at least, the sphere will not have any bump mapping effect on it as in global pass, sphere cannot be evaluated using bump effect at the same time. The result will not be correct.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this