Skip to main content
gamedev.net
🔒 Locked

Lighting

Started by steg Oct 10, 2004 at 9:28 AM 1 replies 350+ views
Original Post
steg
steg
Hi, I was wondering, if you have a game with various objects such as spaceships, planets, space stations would each of these objects have its own lighting ? I take it we are limited to a maximum number of lights which I believe to be around 8. If for instance I had a directional light on the planets and say a point light on spaceship would I need to call the SetLight method each frame or just the once for each light, for example :

pDevice->SetLight( 0, &light1 );
pDevice->SetLight( 1, &light2 );
pDevice->LightEnable( 0, true );
pDevice->LightEnable( 1, true );

Could I just do the above on initialisation of the game ? Any help is much appreciated. Steve
If it isn't working, take a bath, have a think and try again...
Supernat02
Supernat02
If you write the rendering code and are guarenteed that no lights will ever be disabled, then you can just initialize the lights and leave them I believe. I don't think that is a state that has to be re-established each frame, but I'm not sure. It's no matter though. DirectX will cache the states. If you turned the light on and it's already on, it will know that and ignore your request to turn it on again.

To answer your first question, when you call DrawPrimitive or DrawSubset or however you get your vertices to the video card, whatever light is enabled right then will be used to light the vertices being committed to the video card. So, if you want a spotlight on a spaceship only, then you'll need to enable it before drawing the spaceship and disable it after. You could batch lighting calls, but I don't think their state changes are significant enough to warrant that. Anyone know?

Also don't forget these meshes require a material and normals for lighting to work.

Good luck,
Chris
Chris ByersMicrosoft DirectX MVP - 2005
steg
steg
Cheers Chris,

I really appreciate your advice.

Best regards,
Steve
If it isn't working, take a bath, have a think and try again...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.