PDA

View Full Version : Light states variables



Purvis
04-16-2004, 07:51 AM
Hi,

Is there a way to know from a vertex/fragment shader which lights are on or off, and what is the state of OpenGL lighting?

PanzerSchreck
04-16-2004, 12:59 PM
I guess you're looking for those :

struct gl_LightSourceParameters
{
vec4 ambient;
vec4 diffuse;
vec4 specular;
vec4 position;
vec4 halfVector;
vec3 spotDirection;
float spotExponent;
float spotCutoff;
float spotCosCutoff;
float constantAttenuation;
float linearAttenuation;
float quadraticAttenuation;
};
gl_LightSourceParameters gl_LightSource[gl_MaxLights]; Don't know about the enabled/disabled state of a lightsource, but it shouldn't be too hard to tell the shader from your app what lights are on.

mrbill
04-16-2004, 03:11 PM
Originally posted by AdrianPi:
Hi,

Is there a way to know from a vertex/fragment shader which lights are on or off, and what is the state of OpenGL lighting?What is the state of OpenGL lighting? Yes.

Which light is enabled? Not directly. You can declare your own:


uniform bool myLightEnable[8];And then load it with:


int myLightLocation = glGetUniformLocationARB( programObj, "myLightEnable");
glUniform1fvARB( myLightLocation, 8, pFloats );-mr. bill

mikeman
04-17-2004, 06:03 AM
Or you can just set the intensity of disabled lights to zero.

Purvis
04-17-2004, 08:51 AM
Thanks MrBill, but how do I know the lighting state from glsl?
You just said "yes", but not "how" :eek:

Korval
04-17-2004, 12:09 PM
Maybe you didn't notice the rather large gl_LightSourceParameters struct that PanzerSchreck posted. Or the array of these structures that he also mentioned. Maybe you should take a look at these, seeing as how they encapsulate OpenGL's lighting state.

Purvis
04-21-2004, 05:48 AM
Ys I saw that Korval, but I'm talking about the global lighting state, the one we set with glEnable(GL_LIGHTING) :confused:

Purvis
04-21-2004, 05:50 AM
Yes, I saw that, but I'm talking about the global lighting state, the one we set with glEnable(GL_LIGHTING)

mrbill
04-21-2004, 06:28 AM
Originally posted by AdrianPi:
Yes, I saw that, but I'm talking about the global lighting state, the one we set with glEnable(GL_LIGHTING)
// There *ARE* much *faster* ways to do this!
// For teaching purposes only....
GLfloat Floats[8];
GLfloat *pFloats = &Floats[0];
for (int i=0; i<8; i++)
{
Floats[i] = glIsEnabled( GL_LIGHT0+i );
}
int myLightLocation = glGetUniformLocationARB( programObj, "myLightEnable");
glUniform1fvARB( myLightLocation, 8, pFloats );-mr. bill