Jump to content

  • Log In with Google      Sign In   
  • Create Account


Multiple Lights - How to design?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 FelixK15   Members   -  Reputation: 210

Like
0Likes
Like

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 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.

Edited by FelixK15, 05 October 2012 - 09:28 AM.

Visit my blog or follow me on twitter.

Sponsor:

#2 esoufiane   Members   -  Reputation: 480

Like
0Likes
Like

Posted 05 October 2012 - 11:00 AM

You don't need to redraw your objects for every light.
You can follow this algorithm:

[source lang="java"]Color finalColor;for every lightif(light is spotLight)finalColor += shadeSpotLight(currentLight);else if (light is omni)finalColor += shadeOmniLight(currentLight);...[/source]

This should be implemented in your pixel shader.

When you became familiar with shaders You can use a Deferred Lighting technique which is much more appropriate for multiple lights.

#3 MJP   Moderators   -  Reputation: 10226

Like
0Likes
Like

Posted 05 October 2012 - 11:19 AM

What you're describing is called "multipass lighting", and it's definitely feasible. A lot of games have used it, including pretty much every UE3 game. While it's easy to implement, the downside is that you waste a lot of performance re-rendering the mesh for each. On DX11 hardware you have a lot of flexibility, and you can use that do something more optimal. Like the above poster mentioned you can loop over lights in the pixel shader, or you can use deferred rendering.

#4 FelixK15   Members   -  Reputation: 210

Like
0Likes
Like

Posted 05 October 2012 - 11:30 AM

Thanks for your replies!

I read a bit about deferred rendering, but being new in the field of graphic programming and shader programming I think its a bit too heavy to begin with.

But what happens to the initial pixel shader if I replace is with the "lighting pixel shader"? Wouldn't it be reasonable to draw the geometry with its initial pixel shader and then redraw it with the "lighting pixel shader" and then blend those two?
Visit my blog or follow me on twitter.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS