• Advertisement
Sign in to follow this  

flexible number of point lights in 1 effect/shader?

This topic is 1798 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,

 

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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. (?)

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement