PDA

View Full Version : Passing through multiple shaders



PropPutty
10-07-2010, 04:53 PM
How would I go about passing my scene through different shaders? Because what I want is to be able to pass through small objects through different shaders and then the entire scene through another shader.

I thought about just making either one big shader that handles all the individual parts as well as the entire scene. Or multiple small shaders and link them the entire scene shader. But I think there must be a much better way? Like the main problem I see with doing it this way is what happens when I need to perform more shaders on one particular part at one stage, it then starts becoming really messy.

Alfonse Reinheart
10-07-2010, 07:13 PM
How would I go about passing my scene through different shaders? Because what I want is to be able to pass through small objects through different shaders and then the entire scene through another shader.

glUseProgram causes all draw calls to use that program for rendering. If you call glUseProgram again, with a different program object, then that program will be used for rendering.

So if you want to render one object with a certain program, call glUseProgram with that object, then do the rendering for it. When drawing with a different shader, call glUseProgram again with that program and render the object(s) you want to render with that shader.

PropPutty
10-07-2010, 07:36 PM
I don't think I made it clear, the part I wasn't sure how to accomplish. But I know how to change between the shaders, the problem I'm having is how do I go from rendering all the individual objects with their individual shaders to then render the entire scene with another shader.

It's the double rendering part I don't know how to do. Like here's an example, say I want to render two triangles with a different shader each. One shader makes the texture red, the other blue. But then I want to now render the entire scene with a shader that inverts the colours.

So how do I go from rendering the two triangles to then rendering it all again, with the effects their individual shaders had on them?

Like I'm not sure since I haven't looked into them yet, but maybe this could be done with FBO's?

Alfonse Reinheart
10-07-2010, 09:57 PM
So how do I go from rendering the two triangles to then rendering it all again, with the effects their individual shaders had on them?

The hard way. You build a second set of individual shaders that do whatever it is you need them to do. You cannot stack shaders like that.

BionicBytes
10-08-2010, 12:35 PM
Or perhaps you could perform some postprocessing on the entire scene with one shader. If necessary you could make use of the stencil buffer to identify the different objects.