Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualFelixK15

Posted 05 October 2012 - 09:28 AM

Hi!

I'm currently learning Direct3D 11 via the book 3D Game Programming with DirectX11 from Frank D. Luna.

I just finished the chapter about lighting and I was wondering myself how I could implement a system that supports multiple lights.

The current approach I find most straight-forward is to have an array of current active lights.
Whenever an objects gets drawn, it first gets drawn with its initial vertex and pixel shader and then gets redrawn for each light
in the array. The system now replaces the pixelshader of the object with a pixelshader for a specific light type (e.g. if the current light is a spotlight, set the spotlight pixelshader - and so forth) - the vertex shader stays untouched.

The question I ask myself is, if that is even a reasonable approach?

That system doesn't even work very well as all the pixels that gets redrawn via the light shaders are getting rejected by the depth test. I assume that is because the object is redrawn at the exact same position as it was drawn before and the depth of the new pixel has the same depth as the old pixel (is that correct?). The solution for this would be to disable depth testing, but as I said before I don't know if that is even a reasonable approach.

Can someone fill the gap in my mind and give me an advice or two on how to implement multiple lights well?

Thanks in advance.

#1FelixK15

Posted 05 October 2012 - 09:27 AM

Hi!

I'm currently learning Direct3D 11 via the book 3D Game Programming with DirectX11 from Frank D. Luna.

I just finished the chapter about lighting and I was wondering myself how I could implement a system that supports multiple lights.

The current approach I find most straight-forward is to have an array of current active lights.
Whenever an objects gets drawn, it first gets drawn with its initial vertex and pixel shader and then gets redrawn for each light
in the array. The system now replaces the pixelshader of the object with a pixelshader for a specific light type (e.g. if the current light is a spotlight, set the spotlight pixelshader - and so forth).

The question I ask myself is, if that is even a reasonable approach?

That system doesn't even work very well as all the pixels that gets redrawn via the light shaders are getting rejected by the depth test. I assume that is because the object is redrawn at the exact same position as it was drawn before and the depth of the new pixel has the same depth as the old pixel (is that correct?). The solution for this would be to disable depth testing, but as I said before I don't know if that is even a reasonable approach.

Can someone fill the gap in my mind and give me an advice or two on how to implement multiple lights well?

Thanks in advance.

PARTNERS