Jump to content
  • Advertisement
Sign in to follow this  
maxest

[GLSL] The same named uniform in vertex and fragment shaders

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

In OGL-GLSL, the program object is combined of vertex and fragment programs. And we pass uniforms to the program, not to shaders. So, is it possible to have two different uniforms (one in vertex, and one i fragment shader) with the same name and to access these two different uniforms via application?

Share this post


Link to post
Share on other sites
Advertisement
But what if I want them to be two different uniforms? Let's say I have a uniform "my_color" in vs and fs, and I want it to be (1,1,1,1) in vs, and (0,0,0,0) in fs. How to achieve that?

Share this post


Link to post
Share on other sites
You can't, you need to have a different Uniform name. The memory space for shaders is organise per-program, not per-shader. So your Vertex/Fragment shader pair all share the same Memory Space.

This means that my_color in Vertex Shader is the exact same Variable as my_color in Fragment Shader. Think of it as two different functions accessing a global variable in C/C++.

Simply have the Uniform named something different in the fragment shader.

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!