Jump to content
  • Advertisement
Sign in to follow this  
dpadam450

OpenGL GLSL Light structure

Recommended Posts

I have this code below in both my vertex and fragment shader, however when I request glGetUniformLocation("Lights[0].diffuse") or "Lights[0].attenuation", it returns -1. It will only give me a valid uniform location if I actually use the diffuse/attenuation variables in the VERTEX shader. Because I use position in the vertex shader, it always returns a valid uniform location. I've read that I can share uniforms across both vertex and fragment, but I'm confused what this is even compiling to if this is the case.

 

#define NUM_LIGHTS 2

struct Light
{
    vec3 position;
    vec3 diffuse;
    float attenuation;
};
uniform Light Lights[NUM_LIGHTS];

 

 

Share this post


Link to post
Share on other sites
Advertisement
18 minutes ago, dpadam450 said:

It will only give me a valid uniform location if I actually use the diffuse/attenuation variables in the VERTEX shader.

Did you use diffuse/attenuation variables in fragment shader too when getting -1? If not, probably compiler removed them as unused code so you can't get their locations

Share this post


Link to post
Share on other sites

That's correct. Using it in the fragment shader seems to not effect anything. Copy/pasted the structure declarations, they are identical.

Share this post


Link to post
Share on other sites

I tried the same it worked for me. Copy-pasting structure is not enough it must be used in frag or vert shader, also I tried to use only position in vertex shader even that case I got others' locations (0, 1, 2). It seems GLSL compiler don't remove individual members of  structure, if I don't use any structure member then I get all -1

Share this post


Link to post
Share on other sites

if you are using uniform blocks you must use layout( std140 ) or layout( shared ) to ensure the compiler will not optimize away unused uniforms

Share this post


Link to post
Share on other sites

I must have been smoking crack. It all works now with no changes. I think I was editing the wrong fragment shader for the vertex shader. And therefore it was bad testing.

Share this post


Link to post
Share on other sites

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  

  • 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!