Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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

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

:-(

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top