How to use global effect with local effect

Started by
4 comments, last by jwang 14 years, 7 months ago
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?
Advertisement
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.
Or render the scene to a texture with the local things, than draw the texture (as quad) with the global shader.
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.
Draw everything in the local thing pass, then draw everything again n the global pass
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.

This topic is closed to new replies.

Advertisement