3
\$\begingroup\$

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?

\$\endgroup\$

1 Answer 1

5
\$\begingroup\$

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

\$\endgroup\$
2
  • \$\begingroup\$ That's some pretty sweet screenshots. I think this has got to be the accepted answer. \$\endgroup\$
    – DeadMG
    Commented Jan 24, 2011 at 14:23
  • \$\begingroup\$ 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. \$\endgroup\$
    – DeadMG
    Commented Jan 29, 2011 at 22:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .