Tuesday, February 28, 2017

c++ - D3D9 Effects- variable parameters



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?



Answer



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


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...