flexible number of point lights in 1 effect/shader?

Started by
3 comments, last by cozzie 11 years, 2 months ago

Hi,

Is it possible to have a flexible number of say point lights in one effect (.fx/shader)?

With of course some sort of maximum.

I was thinking about the following approach:

- define max lights is 8 or 10

- effect includes float3 lightposition[max lights]

- effect includes float lightrange[max lights]

- set lightrange to 0.0 in the effect, set to needed value while processing shaders in my engine

- loop through max lights and if range != 0, calculate attenation in float att[8]

- add them all up at the end and voila, goal achieved

(or not?)

I'm using d3dxeffects and vs/ps 2.0 (or 3.0, also working).

I'm planning to develop my engine to 'push' max nr. of pointlights to the shader, based on spatial culling in the active scene/ viewpoint.

What are your thoughts on this?

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

Advertisement

So if you use a #define to set your limit, it's absolutely possible, though the branch may be a little costly. Especially in SM 2.0. Though it's definitely possible.

If you try and make the number of lights variable, (like passing in a shader constant for it), you may run into issues because the loop can't be unrolled.

Perception is when one imagination clashes with another
Thanks. I can also use sm3.0 (to increase max instructions).

For the flexible number of point lights (with the limit of the max defined), i was thinking to set range in the shader for each point light to 0.0 and only loop through the point lights with range !0. The ones i used have another range passed through in my scene graph/ engine.

That should work, i think. (?)

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

It can definitely work! Though I'd still be abit worried about the branch, shaders in SM 3.0 aren't a big fan of them. It might be cheaper just to do the calculations with a "black" light.

Perception is when one imagination clashes with another
Thanks, that will save checking how much there are as a bonus :)
I'll set the default color for the lights in the shader to 0, 0, 0, 1 then and just go through them all (up till defined max lights).

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

This topic is closed to new replies.

Advertisement