Jump to content
  • Advertisement
Sign in to follow this  
MindWipe

Quick shader question

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

I've googled it but I just can't find the answer. So I compile a few fragment shaders and a few vertex shaders and put them in a program I then use. Now how do I switch what fragment shader is used? Or should I just have one fragment/vertex shader per program and then just bind different programs? /MindWipe

Share this post


Link to post
Share on other sites
Advertisement
Bind different programs;
The only way to bind a different fragment shader to a different vertex shader is to relink the program this is expensive and best done at startup times.

The now somwhat mythical GL3 update plans to remove this requirement iirc.. but well... mythical right now it seems.

Share this post


Link to post
Share on other sites
Awesome thanks! Then my professor must have done something weird when he used two fragment files with one program?

/MindWipe

Share this post


Link to post
Share on other sites
Quote:
Original post by MindWipe
Awesome thanks! Then my professor must have done something weird when he used two fragment files with one program?

/MindWipe


Hmm. You can put several fragment (or vertex) shader files into one program, so long as there's only one main function for the fragments, and one for the vertexes.

Share this post


Link to post
Share on other sites
Quote:
Original post by sprite_hound
Quote:
Original post by MindWipe
Awesome thanks! Then my professor must have done something weird when he used two fragment files with one program?

/MindWipe


Hmm. You can put several fragment (or vertex) shader files into one program, so long as there's only one main function for the fragments, and one for the vertexes.


Oh, but then... then if you have to fragment shaders then one of them will only contain functions to help the other file? Or can you switch method to use per fragment, so that you use another not main function? If this is the case then why bind many programs?

/MindWipe

Share this post


Link to post
Share on other sites
Quote:
Original post by MindWipe

Oh, but then... then if you have to fragment shaders then one of them will only contain functions to help the other file? Or can you switch method to use per fragment, so that you use another not main function? If this is the case then why bind many programs?

/MindWipe


The former.

I've never used this, so this is just a guess, but it would probably be useful if you had different variations of one function that you wanted to use with your main program.

For example:

// frag shader 1

// fwd declaration
void crazyFunc(inout vec4 c1);

void main() {
vec4 color = vec4(0.0);

crazyFunc(color);

gl_FragColor = color;
}


// frag shader 2
void crazyFunc(inout vec4 c1) {
// simple version, low requirements.
}

// frag shader 3
void crazyFunc(inout vec4 c2) {
// more complicated version with higher hardware / shader model requirements.
}


You'd attach the main fragment program, along with either 2 or 3 depending on what hardware or other requirements you found on the machine you're running on.

Like I said, this is what I'd imagine it'd be most useful for, but I'm not certain.

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!