Jump to content
  • Advertisement
Sign in to follow this  
Gyiove Sparkle

Shader variables (uniform)

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

Hi everone!

I have this code here:

uniform int something;
varying vec2 texcoord;

void main()
{

	vec4 tex = texture2D ( img, texcoord );
        if(something)
        {
	    if( tex.a == 0.0 ) discard;
        }
	gl_FragColor = tex;
}

I was wondering, is 
if(something) called every time it renders pixels?

To think logically, the variable something doens't change so it doesn't have to check it everytime. It just have to check it when im activating this shader right?
Thanks!

 

Share this post


Link to post
Share on other sites
Advertisement

It will run the check every time the shader is run (which is every fragment/pixel).

 

The shader won't necessarily have the uniform value at the time you activate the shader; it would likely get sent to the GPU when a draw call is issued.

Share this post


Link to post
Share on other sites

If your drivers are really nice, they might recompile your shader code every time you change the value of the uniform, making it free...

But you should assume that the driver isn't going to be that magically nice, and that you're going to pay the cost of that if for every pixel that you draw.

 

Often, games design these kinds of shaders using #if / #endif instead, and then compile the shader code multiple times.

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!