Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I've created some simple Phong shading code from a sample. The issue is that the sample only handles one light. If I wanted a variable number of lights set at the start of each frame, how could I specify in the effect file that I need to pass a variable number of e.g. light positions and etc to render from?

share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

For each light do one render pass and use Additive blending. It is called forward rendering.

Question is: Why to do it this way and not just send all of the light positions and params in few arrays? Answer is that this is much easier to handle once you start making some more complex effects. And there is one plus more. You can use your current shader.

Edit: To prove my point, i added two renders, because this technique sometimes sounds weird. One is rendered with gpu renderer which using described technique. And second is same scene rendered with Maya. Scene is lighted with 3 lights. One emits red, one blue and one green color. Common shadow mapping is used.

Realtime renderer:
furryball

Rendered with maya

maya

share|improve this answer
    
That's some pretty sweet screenshots. I think this has got to be the accepted answer. –  DeadMG Jan 24 '11 at 14:23
    
So just to be sure: Render the scene from the perspective of a light to a texture, phong shade and blend to backbuffer, repeat for each light but ignore material. –  DeadMG Jan 29 '11 at 22:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.