views:

255

answers:

2

Hopefully this is an easy question. I like things being organised, so I would like to have two pixel shaders; the first doing one thing, and then the next doing something else. Is this possible, or do I have to pack everything into the one shader? Thanks.

+2  A: 

They can't run at the same time, but you are free to use different shaders for different geometry, or to render in multiple passes using different shaders.

Michael Daum
So would that require a different program? So a different program for each pass? As in, I could have a vertex and fragment shader on one program (which is one pass?) and then have a vertex and fragment shader on another program (the second pass?)? Can I just change glUseProgram() when I feel like it? So I'm essentially rendering a scene twice...?
Harry
Exactly right. Just like a multi-pass render in fixed pipeline, but instead of changing openGL settings between passes, you're loading different programs.
Michael Daum
+3  A: 

You can do do this, e.g. by doing function calls from the main entrypoint to functions that are implemented in the various shader objects.

main() {
    callToShaderObject1()
    callToShaderObject2()
}

each of those callToShaderObject functions can live in different shader objects, but all objects have to be attached and linked in the same program before it can be used.

Bahbar