Sign in to follow this  
danromeo

Light optimization, optimizing in general

Recommended Posts

Hiya. As always, thanks for reading this. 1. I am currently disabling, resetting, and reenabling almost every light in a scene for every object in that scene, so that I can use up to MAX_LIGHTS per object in a scene, using a sort of bounding sphere collision detection to decide whether any given light is within range of any given object, so that only lights that will actually hit a given scene object are being used when that object renders, and ALL of the lights that hit that object will be used. The code works great but I'm wondering if all of these calls to SetLight and LightEnable are going to be extremely time consuming. Pseudocode: for every active light SetLight(x, FALSE); nActiveLights=0 for every scene object{ for every other scene object{ if every other scene object.Light.Range < every scene objects distance from that light SetLight(nActiveLights, &every other scene object.Light) LightEnable(nActiveLights, TRUE) nActiveLights++; } } My question is, are all of these repetitive calls to SetLight and LightEnable going to be extremely time consuming? I.e., what kind of overhead do these calls carry? 2. Can somebody point me in the direction of some good web resources on optimizing DX9 in general? Thanks again. Love this forum.

Share this post


Link to post
Share on other sites
Quote:
Original post by danromeo
2. Can somebody point me in the direction of some good web resources on optimizing DX9 in general?


http://developer.nvidia.com
and
http://www.ati.com/developer

are both the best resources for optimizing d3d. Just run a search on either site for d3d optimizations or something an you'll get a lot of results.

Share this post


Link to post
Share on other sites
Hello

In my experience, it is best to set each active light at
the beginning of the scene, and then for every object, check
for the closest lights, enable them, and disable the rest.

pseudocode:

framebegin
loop through all lights
SetLight
Disable
loop end

loop through objects
loop through lights
if light is close, enable it
loop end (lights)
disable formerly enabled lights that werent re-enabled now
draw
loop end (objects)
frameend

If you keep track of recently enabled lights, then there will
be only a minimal LightEnable calls, which is just what you want.

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