views:

294

answers:

4

Is there a way to find out if a light is enabled in GLSL that doesn't involve passing attributes or creating a ton of different shaders?

What about using NVidia's C for Graphics (Cg)? Can I do it with Cg?

I am now convinced that you can't do it. But now I ask: why not?

+1  A: 

If GLSL is anything like HLSL (DirectX's equivalent), which I suspect it is, I think you are stuck with passing attributes.

:-(

unforgiven3
+2  A: 

unforgiven3 is right - GLSL doesn't provide access to the fixed pipe enable states. You have to pass it in as a uniform.

Nathan Monteleone
Is there a reason for that?
Martinho Fernandes
Don't know for sure, but it probably would have been too expensive to support from a hardware standpoint.
Nathan Monteleone
A: 

You could set the light color to (0,0,0,0) and either branch on that, or just let it loop over the now non-contributing lights.

heeen
Nice trick. It might work, but it seems clumsy (setting the light on/off is so much cleaner than saving/restoring it's colour). I kinda gave up on the original question. You can't do it. Now I am more interested in "why not?"
Martinho Fernandes
+2  A: 

According to my understanding of "Enable or Not to Enable" part of GLSL Common Mistakes this is a philosophical reason: shaders are written to override fixed pipeline, therefore they shouldn't rely on fixed pipeline states. You gotta use a different shader for each capability you need.

Also I guess this might be a design choice based on the fact that branches are expensive on the GPU and someone must have thought that you shouldn't be doing things like

if (gl_LightSource[0].enabled)
{ ... }

in the first place.

Can