Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


flexible number of point lights in 1 effect/shader?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 cozzie   Members   -  Reputation: 1653

Like
0Likes
Like

Posted 15 February 2013 - 02:08 PM

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?



Sponsor:

#2 Seabolt   Members   -  Reputation: 633

Like
0Likes
Like

Posted 15 February 2013 - 10:19 PM

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

#3 cozzie   Members   -  Reputation: 1653

Like
0Likes
Like

Posted 16 February 2013 - 07:34 AM

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. (?)

#4 Seabolt   Members   -  Reputation: 633

Like
0Likes
Like

Posted 16 February 2013 - 11:38 AM

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

#5 cozzie   Members   -  Reputation: 1653

Like
0Likes
Like

Posted 16 February 2013 - 02:13 PM

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).




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS