Sign in to follow this  
Aqua Costa

[DirectX 10] Multiple ligths

Recommended Posts

I want to create a shader to handle multiple lights... This is my idea (one pass): -Create an array of lights (specifying light type, position, direction, etc); -Pass the array to the shader; -Create a loop and keep adding the diffuse/specular colour of each light to each pixel; Is this technique good or what should I change? Is there any good whitepaper/doc talking about multiple lights?

Share this post


Link to post
Share on other sites
At the very beginning of my own engine, I tried that, too. If you really know the light you will use, it is *may* a way. But if you want the user to create some lights, it's just horrible.

When you need many dynamic lights, you may take a look at this article: Deferred Rendering Demystified

When you need not so many dynamic lights, you could use forward rendering. This is done by drawing the mesh for each light on top of the other again and blending it together. So, if you have 4 lights, the mesh would be renderd 5 times: 1 Diffuse, 4 lights. Thats pretty slow for many of them.

If you don't need any dynamic lights, it is best to pre process some lightmaps. This means: Calculate the lighting once, save it to lightmaps and put them on the meshes. I never did that before, so I don't know how to do that. ;)

I hope this helped :)

Share this post


Link to post
Share on other sites
I know this problem, too. Maybe you can render them with forward rendering?
Also, I don't really know what happens when you draw them like any other object. When I think about it, there shouldn't be a problem but that the light color will not modulate with you glass/water/whatever. And your light will go through walls anyways.

Please correct me if I am wrong. Haven't tested it so far...

Share this post


Link to post
Share on other sites
I'm building in Deferred Lighting at the moment. I think this is the better solution, as I need many dynamic lights. Forward rendering is simple, but too slow for my needs.

What kind of game do you make? Do you need *many* lights? Or just a few?

Share this post


Link to post
Share on other sites
I wanna create a first or third person shooter (I haven't decided yet), just a little level. So I will need a parallel directional light (the sun), and some point/spot lights. But I want to set up my engine to be able to handle good graphics from the beginning so I think I will try to implement deferred rendering.

Do you know any good article about Deferred rendering in DiretcX 10, because that article "Deferred rendering demystified isn't directX 10 at all

How long did it took you to implement DR?

Share this post


Link to post
Share on other sites
I'm currently on it, and I also use DirectX10. Anyways, the steps are the same. Set up MRTs, render GBuffer/Depth,etc. Render it to full screen quads, calculate them together. I'm at the step with the FullScreen quads. As I got there I moved on with post processing, to have a good interface for that. Also I will use it to finish my deferred lighting pipeline. Getting there took me some hours of work, but not THAT long.

For a first person shooter deferred lighting is best (For dynamic use)!

Share this post


Link to post
Share on other sites
No, I did not use any book for that. But you can check out GPU gems from nvida:
http://http.developer.nvidia.com/GPUGems3/gpugems3_part01.html

there was an article about that. Maybe it was the 2nd part. I don't know now. Anyways, it is a good resourde :)

Share this post


Link to post
Share on other sites
The method you suggested originally is still a feasible idea, just because you want multiple lights doesn't mean you have to use a deferred renderer, the other person said for 5 lights you would have to render a mesh 5 times that's not true at all, you can do multiple lights in a shader like you suggested, that person was explaining multi-pass lighting which is a pretty old technique and was used when hardware lights were limited so you could get more lights than you were allowed in hardware. Why the hell you you would render a mesh 5 times for 5 lights? that is totally insane.

I have implemented both deferred and forward renderers before, at first I thought deferred was great until I realised that actually the performance benefits weren't as good as I had thought they would be.

Deferred rendering introduced some new problems to address : no hardware anti-aliasing, its a bit restrictive in terms of having multiple material types, large fullscreen floating point gbuffers can be pretty hefty in terms of memory consumption (although there are methods to reduce this as much as possible like reconstructing position from depth) and deferred rendering doesn't handle transparent objects well.

Have a look at the pros and cons for each and what you want to achieve, I just felt the advice you had previously been given was completely biased towards deferred rendering, and explained forward rendering incorrectly.

Share this post


Link to post
Share on other sites
I think I will try deferred rendering...
I just haven't understood one thing:
-After creating the G-Buffer all pixels are in screen-space coordinates;
-So, when I want to apply the lights/shadow maps, how do I convert the pixel screen-space coordinates back to world space coordinates, so I can calculate if the pixel is affected by the light,shadow map, etc??

Share this post


Link to post
Share on other sites
I've read about this technique somewhere. Isn't this the same as forward rendering? What is it then?

Quote:

Why the hell you you would render a mesh 5 times for 5 lights? that is totally insane.


- Render diffuse
- Render lighting for Light #1 -> Blend it to the backbuffer
- Render lighting for Light #2 -> Blend it to the backbuffer
- Render lighting for Light #... -> Blend it to the backbuffer

And yes, that IS insane. And thats why I don't use it. But putting every light into every shader isn't good at all, too (When you a large scene with many lights). When you would put a mesh with a shader at point A in to the scene, and another with the same shader at point B, you'll get a problem when point A is at the left side, and B on the right side. They both need to process all the lights from point A AND B (Unless you copy the shader for each mesh).

I also said: When you know what lights you are using (For a small game or a demo), putting the lights into the mesh-shader is a good technique. But if you want a user, who don't understands these things to create lights himself, you could get a problem.

Quote:

Have a look at the pros and cons for each and what you want to achieve, I just felt the advice you had previously been given was completely biased towards deferred rendering, and explained forward rendering incorrectly.


I'm sorry for that. Could you tell me what forward rendering is in detail?

@Aqua Costa: In the GPU gems 3 book (or was it 1?) is a chapter about screen space shadow mapping. I think thats what you need. :)

Share this post


Link to post
Share on other sites
Quote:
Original post by mind in a box
@Aqua Costa: In the GPU gems 3 book (or was it 1?) is a chapter about screen space shadow mapping. I think thats what you need. :)


I cant find that article...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this