Jump to content
  • Advertisement


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


How do lights work?

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

Hi! Well, D3D is definitely more complex than I thought it was!... I keep running into problem after problem. I hope things will calm down a bit once I have more experience... Anyway, here goes... I have an application in which I display a rotating cube. I define my vertexes with the following format:
My normals are all normalized and my diffuse color is set to blue (r:0, g:0, b:200). If I set lighting off with a call to SetRenderState( D3DRS_LIGHTING, FALSE ); I get a blue rotating cube with no shading, just the same uniform blue on every face of the cube. As far as I know, that is what I should be getting. The problem comes from when I try to add a light to my scene. Here''s what I do:
	m_pDevice->SetRenderState( D3DRS_LIGHTING, TRUE );
	m_pDevice->SetRenderState( D3DRS_AMBIENT, D3DCOLOR_XRGB( 128, 128, 128 ) );

	D3DMATERIAL8 material;
		ZeroMemory( &material, sizeof( material ) );
		material.Diffuse = D3DXCOLOR( 1.0f, 1.0f, 1.0f, 1.0f );
		material.Ambient = D3DXCOLOR( 1.0f, 1.0f, 1.0f, 1.0f );

	m_pDevice->SetMaterial( &material );

	D3DLIGHT8 light;
		ZeroMemory( &light, sizeof( light ) );
		light.Type      = D3DLIGHT_DIRECTIONAL;
		light.Diffuse   = D3DXCOLOR( 1.0f, 1.0f, 1.0f, 0.0f );
		light.Direction = D3DXVECTOR3( 0.0f, -1.0f, 0.0f );

	m_pDevice->SetLight( 0, &light );
	m_pDevice->LightEnable( 0, TRUE );
With the above code, my cube is gray instead of blue, but is otherwise identical to what I get with lighting turned off. I was expecting the different faces on my cube to at least be of different shades of gray. A face hit directly by the light should be brighter than one that is on the opposite side, right? Am I missing anything here? Thanks for any advice!

Share this post

Link to post
Share on other sites
Nevermind that, I found my error. I was not copying my normals to the vertex buffer! No wonder it didn''t work properly... I''m surprised I didn''t get weirder results than what I was getting.

Share this post

Link to post
Share on other sites
If you only use the ambient light, is your quad gray then? I have problems with the ambient light not mixing its colors with the diffuse color of the quad. Does that work for you?

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!