Sign in to follow this  

What is the BEST lighting algorithm for many Lights?

This topic is 2856 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello! As my Engine needs to take use of the effects of many dynamic lights, I need a very perfo friendly lighting algorithm. The first thing I tried, was to loop all lights in the PixelShader, but that was tooo slow. Any Ideas? I am using DirectX 10 and C++

Share this post


Link to post
Share on other sites
How about deferred lightning? This algo is predestined for many light sources. Do you want to support dynamic shadows? How many lights do you want to support? Why was the pixelshader light loop to slow (because if this is to slow, then I think there is no faster way to calculate the color of a pixel if you want per-pixel-lightning).

Share this post


Link to post
Share on other sites
I can probably use Deffered Shading since you use DX10. I'm not to pro with shading etc, but I heard Derrered shading was good for some lighting situations and can speed up some stuff. Thats just a suggestion.

Share this post


Link to post
Share on other sites
I need as many lights you see in the night in a city-street for example.
When I loop 30 lights per pixel, with calculations, this IS slow.

What is deffered lighting? I thougt, that I could calculate all lights into a ScreenPlane, based on the Normals of the Scene. Or is there a better solution?

EDIT: Yes, I want to support dynamic Shadowing, but maybe just for the sunlight.

Share this post


Link to post
Share on other sites
Are you sure they *all* need to be dynamic? Will they really all be moving, or changing orientation, or animating intensity?

For any that aren't, precomputed lightmaps are the fastest way of applying an infinite amount of static lights to your scene, if you can afford the memory.

Share this post


Link to post
Share on other sites
As WuTz said in his initial post, he wants many dynamic lights, so precomputation is in my opinion not an option. With "preffered lightning" I ofcourse meant "preffered shading" ^^. Sorry for my bad english.

Bacause there are dynamic lights, and you want to apply all the lights to a pixel, which sould be shaded, you have to calculate every light on this pixel. The fastest method will be a loop for every light on the pixel you render (one pass ofcourse, rendering that pixel in a pass for every light would be a performance killer). If this is already to slow, then there is nothing you can do, except:

All you can do, is to minimize the amount of calculations. For example: not every light touches every pixel. The rasterization of a pixel (calculating its screen-position, z-value, etc.) should be done once, as described by deffered shading. The second advantage is: No light calculation for pixels without any lights. For your non-deffered pixelshader loop you maybe use an "if" or multiply some value by 0 for "disabling" a light, which consumes some performance. With deffered shading there is a disadvantage: alpha blending is harder to implement (I'm not sure about this, maybe there is something..).

If your pixelshader is still to slow, maybe you can optimize your code in some way. You always have to known, how the shader compiler compiles your code and what can the hardware do efficiently and what not. For example: In some situations it is better to have a look-up on a texture. Im some other situations it is better to calculate a value instead to read it out of a texture. Unrolling loops, functions maybe would be better, because the shader compiler can better optimize the code, if there are less jumps (into a function, back to loop start, etc.).

Maybe you post your pixelshader code here, so we can take a look on this?

Share this post


Link to post
Share on other sites

This topic is 2856 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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