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
profile requires index expression to be compile-time constant
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
-------------
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
Greetings, Tobias
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
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
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement