Jump to content
  • Advertisement
Sign in to follow this  
ic0de

using multiple shaders at once

This topic is 2537 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!