Sign in to follow this  

Quick shader question

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

This topic is 3591 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this