Sign in to follow this  
mcguile25

Ambient lighting not working with hardware vertex processing

Recommended Posts

Hello, I am trying to get ambient lighting working in my application to highlight my models/meshes with a certain color. It seems to be working fine with D3DCREATE_SOFTWARE_VERTEXPROCESSING, but when I switch the device creation code to use D3DCREATE_HARDWARE_VERTEXPROCESSING, I don't get any ambient lighting on my models. Here is the code I use for the ambience:
m_displayDevice->SetRenderState( D3DRS_LIGHTING, true );
m_displayDevice->SetRenderState( D3DRS_AMBIENT, D3DCOLOR_XRGB( 255, 0, 0 ) ); // hardcoded to red for this example
m_displayDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
m_displayDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
m_displayDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_COMPLEMENT );



Oh, and yes, I have this check in my device code (so I'm not just blatantly using hardware processing without it being available :)
if ( d3dcaps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT )
{
	vertexProcessing = D3DCREATE_HARDWARE_VERTEXPROCESSING;
}



Is there anything blatantly wrong with what I am trying to do? Any suggestions?

Share this post


Link to post
Share on other sites
Quote:
Original post by mcguile25
D3DTA_COMPLEMENT
This is a modifier flag. It should be ORed with the argument you want complemented. Likely "D3DTA_DIFFUSE | D3DTA_COMPLEMENT"... except D3DTA_DIFFUSE already happens to be == 0, so you're okay there, but only by fluke.

Have you set a material. There is an ambient setting in the material. According to the help (mathematics of lighting, then ambient lighting), the final color will be:

material.ambient * (globalambient + sum of each light's ambient).

Without a material set, the global D3DRS_AMBIENT won't necessarily do anything.

Share this post


Link to post
Share on other sites
Thanks for the reply! However, I added a material to the scene with ambient color and it still doesn't work in conjunction with hardware vertex processing. Switched back to software vertex processing and all is well. This is what I am confused about. Any other suggestions?

Share this post


Link to post
Share on other sites
Do your vertices have normals? Technically ambient doesn't need normals, but the rest of the lighting system does. I have no idea what is acceptable behaviour if lighting is on, and you have no normals.

Other ways to tint the mesh without lighting.

D3DRS_TEXTUREFACTOR and D3DTA_TFACTOR (dx7 hardware, buggy on some old cards like RagePro)

SetTextureStageState(n, D3DTSS_CONSTANT, x) and D3DTA_CONSTANT (likely only shader capable hardware. There is a caps bit for this feature)

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