Jump to content
  • Advertisement
Sign in to follow this  
Scouting Ninja

OpenGL Why do we split shaders into passes?

This topic is 450 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

So I was making a Gaussian blur shader then when it got to the point where I do the X and Y blur in there own passes, I realized I had no idea why a pass was needed for each, or what a pass is.

So why do we split the X an Y axis into there own passes?

The internet says it's faster, in my own test there was little to no difference, and no one explains why it's faster. 

 

How do passes work?

Is it one pass per frame and it gets blended in some way?

 

I honestly have no idea how shaders work. The only reason I can even make shaders is because the math is the same for texturing.

Half of my shader code is things I don't understand and only know is needed or the shader doesn't work.

Share this post


Link to post
Share on other sites
Advertisement
9 minutes ago, WFP said:

 If you did it in one pass, you would need to sample all nine points, i.e. the center point, the left and right, the above and below, and all four corners - those are values you get for "free" when you break it up into two passes.

I see so that means because all the pixels where shifted on the X axis, shifting them on the Y axis in the new pass, allows us to shift them after the first shift.

 

So a pass isn't executed per frame or such. Instead a pass is just a shader function we want to run after a other shader function made a change.

The same as if we had saved the result of the first pass to a texture and then used a other shader to change it? 

Share this post


Link to post
Share on other sites

Yep, that's exactly it.  When a technique (for example, a blur) has multiple passes, a pass is typically just a separate draw call with either a new shader, updated data, or both.

3 minutes ago, Scouting Ninja said:

The same as if we had saved the result of the first pass to a texture and then used a other shader to change it?

Exactly that.

Share this post


Link to post
Share on other sites
1 minute ago, WFP said:

Yep, that's exactly it.  When a technique (for example, a blur) has multiple passes, a pass is typically just a separate draw call with either a new shader, updated data, or both.

One more question when is a pass executed?

For example if I did a hundred passes will the program freeze while it runs, like a while loop?

 

Thanks for the help just knowing this will already greatly improve the shaders I can make.

Share this post


Link to post
Share on other sites

Passes are typically ran sequentially.  If you ran 100 passes, the instructions would get executed serially just like any other instruction.  Looking at it at a bit of a finer grain - the CPU instructions will get executed serially, and move along.  At some point in the future the commands that the CPU generates and sends to the GPU will get executed in the order sent.

Your program should be no more or less prone to freezing while processing a loop of 100 render passes than it would be a loop of anything else.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!