Archived

This topic is now archived and is closed to further replies.

Vertex Shaders: Lights?

This topic is 5651 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

This question isn''t neccessarily a Direct3D specific question since OGL has shaders too but I use D3D so I''ll ask here. So when you use Shaders and skip the fixed rendering pipeline, commands like SetLight and the D3D8Light structure (in D3D funciton usage) become somewhat useless in implementation since you now control how lights really work. Well, since D3D did most of this stuff for you under the hood, is it now your responsibility to manage all the lights in your scene? I know the answer is yes but I''m leading up to how many people have actually implemented such a system. For instance, I''ve always created my own Lights Manager type class to manage the lights in a scene in an easy to handle manor, but how much goes into managing the lights for your Vertex Shaders. And can you now have more than 8 lights since you are doing them through the hardware? Would I for instance go through all the lights in the scene within my vertex shader using constants that define the current light positions and apply them this way? Seems like a lot of redundant shader code. I ask because all I''ve seen as far as Vertex Shader examples with lights is usage of 1 simple light that just points an arbitrary direction (0, 1, 0). In real implementations this isn''t how it works. Thanks for any help! "Love all, trust a few. Do wrong to none." - Shakespeare Dirge - Aurelio Reis www.CodeFortress.com

Share this post


Link to post
Share on other sites
You have complete control over the lighting and can add many lights (the total number is dependent on how complex each light is). You can write a shader that can handle 4 lights and then define/redefine those lights by setting the constants. You can do the same for 8 lights, 20 lights, etc. You could "turn off" some of the lights by setting the light color to black, but the shader instructions will still "cost you".

To answer your question, you could write a shader that handles 8 lights and write a set of manager functions that set the appropriate constants for each light. The only wrinkle is that you will want to optimize with different shaders for different numbers of lights and combinations. You might want to spend some time writing a multilight shader and optimize after you get used to the way they work.

Share this post


Link to post
Share on other sites