Advertisement Jump to content


This topic is now archived and is closed to further replies.

Muhammad Haggag

Updating the FAQ

This topic is 5538 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

Am I the only one who thinks we really need to add a lot of items to the FAQ, like the VSync and lighting issues, DrawPrimitiveUP, ...etc? I''ve created this thread in the hope of gathering the material to be added to the FAQ so that: - We contact Jim Adams, so that he''d add it - We contact Dave or any other mod (if Jim''s not free) to do it. Thanks, Muhammad Haggag

Share this post

Link to post
Share on other sites
Here's the "lighting FAQ" post, by namethatnobodyelsetook
Original post by Namethatnobodyelsetook
We seem to get lots of lighting questions around here. I thought I'd share the complete set of basics of everything there is to know about renderstates, materials, and lighting. Note, this isn't all the details, I'm not covering math and/or shaders.

If this could be placed into the FAQ, it'd be nice.

| | D3DFVF_DIFFUSE in vertex
| | | Result
0 0 0White
1 0 0White
0 1 0White
1 1 0Vertex Color
0 0 1Material Color * Light
1 0 1Material Color * Light
0 1 1Material Color * Light
1 1 1(Material Or Vertex Color) * Light

When Material Or Vertex Color, the choice is made via:

Each of these can be set to D3DMCS_MATERIAL to use the appropriate material coloring (Set using SetMaterial(&material), D3DMCS_COLOR 1to use the vertex diffuse color, or D3DMCS_COLOR 2to use the vertex specular color.

There is no way to get material colors without enabling lighting.

Lighting is controlled with:
D3DRS_LOCALVIEWER, bool on/off
SetLight(n, &light);
LightEnable(n, bool on/off);

Ambient light a directionless minimal light value. If no lights hit an object, it can still be seen because of ambient light. Ambient light makes things look fake. Use a small value, if not0 .

Specular highlights are the white (or other color) shiny spots you see on plastic, glossy magazines, polished cars, etc. Local Viewer controls whether or not to properly take the light and viewer positions into account when doing specular highlighting, or to fake it. Specular is controlled with a material color, and the material's Power value. A power of 0 is off, a power of0 . 1is a large highlight, and a power of 100 is a small highlight.

Note that specular makes software rendering very, very, slow.

Emissive light is a color value added to the regular light. If no light hits an object, it's emissive color is still present.

The light or diffuse color is used via a TextureStageState, using a color argument of D3DTA_DIFFUSE.

For example:
// Lit vertex
pDev->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SLECTARG1);
pDev->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);
pDev->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);

// Lit texture vertex
pDev->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
pDev->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
pDev->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
pDev->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);

Some cards support multiplication of the result. MODULATE makes the texture look normal brightness when the light is full brightness. ATI RageProTurbo and similar cards only support this type.

MODULATE2X multiplies the result by2 . If the light is50 % bright, the texture appears normal. If the light is over50 % bright, the texture is brightened. This looks cool for explosions and things like that. This is what the PS 2does. Not all cards will support it.

MODULATE4X multiplies the result by4 .25 % light is normal brightness, over25 % makes things brighter. It's very easy to oversaturate your light and get lots of white when using this mode.

Hope you learned something. If I've left out anything or made a mistake somewhere, feel free to post a correction.

Muhammad Haggag


[edited by - Coder on November 18, 2003 7:45:43 AM]

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!