Microsoft DirectX 9.0

Lighting Sample


The Lighting sample show how to use Microsoft?Direct3D?lights when rendering. It shows the difference between the various types of lights—ambient, point, directional, and spot—how to configure these lights, and how to enable and disable them.

Note   This sample does not include textures, to make it easier to see the detail of the lighting.


Source: (SDK root)\Samples\C++\Direct3D\Lighting

Executable: (SDK root)\Samples\C++\Direct3D\Bin

User's Guide

The following table lists the keys that are implemented. You can use menu commands for the same controls.

ENTERStarts and stops the scene.
SPACEBARAdvances the scene by a small increment.
F2Prompts the user to select a new rendering device or display mode.
ALT+ENTERToggles between full-screen and windowed modes.
UP ARROW, DOWN ARROWIncrease or decrease vertices in walls.
WWireframe mode.
SSolid mode.
ESCExits the application.

Programming Notes

Direct3D lights can be used to shade and color objects that are rendered. They modify the color at each vertex of the primitives rendered while the lights are active. Note that the walls and floor of this sample contain many vertices, so the lighting is fairly detailed. If the vertices were only at the corners of the walls and floor, the lighting effects would be much rougher because of the reduced number of vertices. You can modify the m_m and m_n member variables in this program to see how the vertex count affects the lighting of the surfaces.

There are ways to generate lighting effects other than by using Direct3D lights. Techniques like light mapping can create lighting effects that are not limited to being computed only at each vertex. Vertex shaders can generate more unusual, realistic, or customized lighting at each vertex. Pixel shaders can perform lighting computation at each pixel of the polygons being rendered.

This sample uses common Microsoft DirectX?code that consists of programming elements such as helper functions. This code is shared with other samples in the DirectX software development kit (SDK). You can find the sample framework headers and source code in (SDK root)\DXSDK\Samples\C++\Common\Include and (SDK root)\DXSDK\Samples\C++\Common\Src.

© 2002 Microsoft Corporation. All rights reserved.