Jump to content
  • Advertisement
Sign in to follow this  
tobiaslangner

profile requires index expression to be compile-time constant

This topic is 4448 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
Advertisement
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
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!