Hello! I’m trying to do a lighting shader and determine which lights are enabled. I made a simple IF to see what lights should be used but it slowed things down instead of speeding things up.
How much faster ?
What is your video card ?
Is “pointLight” a costly function ?
Hardware support for conditionals is not always very fast.
Depending on the hardware, both branches are executed, and one discarded. Sometimes there is a fixed cost for IF.
It’s normal. Heard it many times now.
Conditionals are costly. They are worth it if there is a large number of instructions that can be skipped.
If a light is off, either set its properties to zero or write multiple shader versions, one for 1 light, another for 2 lights, etc.
You should try to use a boolean “lightEnabled” instead of testing if the diffuse color isn’t pure black. I think it’ll allow the driver to do some optimizations, since the state of a light is a constant for all pixels.
Is it really faster to have multiple versions of the same shader with different number of lights, even if I need to switch active shader a few times (3-8) per pass? That sounds like a strange work around.