Sign in to follow this  

profile requires index expression to be compile-time constant

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

Hello, I'm currently writing a fragment shader to render specular highlights. Because my scene contains more than one light source, I wanted to use my single fragment shader to render each light source in a single pass one after the other. To tell the shader which light source to process, I use a uniform variable as in loc = glGetUniformLocation(p,"lightSourceIndex"); glUniform1i(loc,1); The problem is now that the shader does not compile with the message "profile requires index expression to be compile-time constant". The respective shader code is -------------
uniform int lightSourceIndex;
....
att = 1.0 / (gl_LightSource[lightSourceIndex].constantAttenuation +
  gl_LightSourcelight[lightSourceIndex].linearAttenuation * dist +
  gl_LightSourcelight[lightSourceIndex].quadraticAttenuation * dist * dist);
------------- Is there another way to make it possible to tell the shader which light source to process while circumventing to use not-compile-time constant indices? Thanks in advance, greets Tobias

Share this post


Link to post
Share on other sites
Is really no one here that encountered that problem? If so, there must be a better way accomplish the task of rendering several light sources... May someone could enLIGHTen me :-)

Greetings, Tobias

Share this post


Link to post
Share on other sites
in your case its easily solved by not using gl_LightSource but just use a uniform
eg

unifrom float constantAttenuation;
att = 1.0 / (constantAttenuation + linearAttenuation * dist +

much cleaner also

gl_LightSource etc are a legacy used if u wanna access the fixed function pipeline state

Share this post


Link to post
Share on other sites
Hey zedzeek,
thanks for your answer.

Your advice works with my problem, however it doesn't scale well with multiple parameters. In my vertex shader, I need 9 floats describing the current light source (position, direction, diffuse, ambient and specular). Should I create 9 uniform float variables for these values or what's better practice?

Greetings, Tobias

Share this post


Link to post
Share on other sites

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