Jump to content
  • Advertisement
Sign in to follow this  
RenHoek

OpenGL no GLSL light enabled flag?

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

Hi Everybody I'm a bit of a GLSL noob sorry. But I'm currently writing a GLSL fragment shader that is to be used in an already existing openGL application. ( It does normal mapping etc... ) It handles both point lights and directional lights. But it must be able to cope with an arbitary number of lights. ( eg, no way of knowing what number or combination of point/directional lights it will get ) So I was going to loop through 0->(gl_MaxLights-1), test (gl_LightSource.position.w == 0.0) to choose between point and directional lights. Thing is, I cannot find any way of knowing if a light is enabled or disabled!? :( A wonderful feature of GLSL would have been to provide an array of enabled lights. (aswell as an array of all lights ). I _could_ pass into the shader an array of the currently enabled light indicies, and loop over that. But this seems like a workaround for something that should not have been a problem in the first place. I feel like I'm misunderstood something major about GLSL here. Anybody know what I should do? Thanks heaps Brian

Share this post


Link to post
Share on other sites
Advertisement

bool isEnabled = false;

if(glIsEnabled(GL_LIGHTING) == GL_TRUE)
{
if(glIsEnabled(GL_LIGHT0) == GL_TRUE)
{
isEnabled = true;
}


}


Share this post


Link to post
Share on other sites
keep your own uniforms to flag whether each light is on or off.

The fixed function lighting and material parameters are only provided in glsl for convenience - they don't do anything unless you use them. As glsl doesn't do your lighting for you, I can appreciate the design decision not to have the fixed function light on/off flags available as builtins in glsl.

That said, I haven't actually checked if they exist or not.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Hi Guys

Thanks for the replies!

Crack123:
I'm looking for a glLights.enabled flag within GLSL.

MrBastard:
My shader is designed to be generic.
( work for any possible combination of lights.
All lights between 0->(gl_MaxLights-1) have the possibility
of being enabled or disabled )
Having the glLights.enabled flag missing, causes a
dependancy between the shader and calling app.
So I dont agree with your appreciation of the design decision.

Well....
looks like I'll have change app code to pass in an
array of the enabled light indicies and loop over that.
Still seems very odd that I have to do this when the
GLSL designers have got to great lengths to remove
fixedFuctionGLSL dependancies. (ie exposing so many of
the fixed function parameters available within GLSL)

Thanks heaps guys!
Brian

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!