# Lighting

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

## Recommended Posts

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

##### Share on other sites
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

Cheers Chris,

Best regards,
Steve

1. 1
Rutin
28
2. 2
3. 3
4. 4
5. 5

• 13
• 11
• 10
• 13
• 20
• ### Forum Statistics

• Total Topics
632950
• Total Posts
3009424
• ### Who's Online (See full list)

There are no registered users currently online

×