Reputation: 146970
I'm looking at writing some code that performs shadow mapping, in DX9. The sample code that I've got only shadow maps from one light source. Is it performance viable to shadow map from more than one light source? My scene is VERY light to render otherwise- there's no textures, and only a few hundred or few thousand vertices.
The trouble is that my scene takes place in space, close to the Sun. I was going to create the Sun as a sphere, and render each vertex as a light source- this was also going to produce some good effects for various sci-fi space-ship effects. But reading through the code, I'm very concerned that this is going to destroy my performance, and I'm not entirely sure that it's going to produce the incredible lighting effects that I'm looking for. Am I just overkilling here?
Upvotes: 0
Views: 815
Reputation: 62333
TBH you ARE just overkilling. A light source from every vertex in a large sphere is waay too many. If you are after getting the soft edges on shadows then you are far better off looking into soft shadowing in general.
To give you an example Half-life 2 achieved soft shadowing by rendering the shadow maps into a seperate render buffer (while using the Z-Buffer from the main render buffer). Then blurring that buffer and apply it back on to the main render buffer. The result is pretty nice looking shadows ...
Upvotes: 0
Reputation: 3383
An easy way to render multiple lights that each cast shadows is to------>
For Every Light in a loop do the following::
{
Clear a Offscreen RenderTarget black.
Render the scene with the current light only... on the Offscreen RenderTarget.
Then with Blending(Add, One to One) turned on, draw/overlay the Offscreen RenderTarget onto your main backbuffer.
}
After all the lights are rendered, present the scene. Because light is just addition in the end, you can just keep rendering as many lights as you want. This method will work whether your using differed lighting or not. You can also turn shadows on or off for each light.
If any of this is unclear & needs a better explanation let me know...
Upvotes: 1
Reputation: 26171
If your ever looking for DX or OGL code for 'advanced' efects/techniques, take a look at Humus 3D there are a few samples of shadow maps, one should have multiple sources. Also this section of GPU Gems 3 might be of interest.
Upvotes: 0