using multiple shaders at once

Started by
-1 comments, last by ic0de 12 years, 4 months ago
up till this point I have only needed to use one shader at a time, then I started implementing a bloom shader and found I needed to use three shaders a highpass filter, a horizontal blur filter and a vertical blur filter. How do I get them all working on the same texture?

do I attach multiple shaders to one program object like so:

glAttachShader(bloom, highpass);
glAttachShader(bloom, blurh);
glAttachShader(bloom, blurv);


Or do I use multiple program objects at once?

How do I handle uniform variables with all these shaders?

How do I specify the order that the shaders are run in?
Advertisement
I'm sorry that I cannot be more help, as I am new to GLSL myself. However, I do know it is possible, but there can be only one main function per vertex shader and one per fragment shader. As far as how that helps, I do not know. I've been curious about this myself.
As MarkS correctly stated, you can only have one main function. glAttachShader is a way to split the functions of a single pass into many shader pieces, similar to how you split your source code among many c/cpp files. This allows you to "include" certain functions like packing and unpacking gBuffer data into every shader that needs it, without having to write and compile it multiple times.

If you need multiple passes however (and separating a blur into an horizontal and vertical filter needs multiple passes), then you need to issue multiple draw calls, one for each pass. In the case of a blur filter, you would also bind the result (render target) of the first pass as a texture to the second pass.

There is no way that OpenGL can chain render passes for you automatically, because it can't know what kind of render targets each pass is supposed to use.

This topic is closed to new replies.

Advertisement