Jump to content
  • Advertisement
Sign in to follow this  

How to the light a mesh properly

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

I created a simple mesh using the D3DXLoadMeshFromXInMemory() function. The mesh .x file contains normals data. I set up the lighting as follows :
	memset(&m_Light, 0, sizeof(D3DLIGHT9));
	m_Light.Type = D3DLIGHT_POINT;
	m_Light.Diffuse.a = 0.0f;
	m_Light.Diffuse.r = 1.0f;
	m_Light.Diffuse.g = 1.0f;
	m_Light.Diffuse.b = 1.0f;
	m_Light.Ambient = m_Light.Diffuse;
	m_Light.Specular.r = 1.0f;
	m_Light.Specular.g = 1.0f;
	m_Light.Specular.b = 1.0f;

	m_Light.Position.x = 0.0f;
	m_Light.Position.y = 0.0f;
	m_Light.Position.z = -50.0f;
	m_Light.Range = 1000.0f;
	m_Light.Attenuation1 = 1.0f;

	hr = D3D9DEVICE()->SetLight(0, &m_Light);
	hr = D3D9DEVICE()->LightEnable( 0, true);
	hr = D3D9DEVICE()->SetRenderState(D3DRS_LIGHTING,  true);
	hr = D3D9DEVICE()->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(128, 128, 128));
	hr = D3D9DEVICE()->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
	hr = D3D9DEVICE()->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);
	hr = D3D9DEVICE()->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_CURRENT);

The mesh has no texture, only a single material has been applied to it. The object is rendered with the right color but it seems to be affected only by the ambient light setup. When I rotate the object (placed at the origin) the color doesn't change as it should have. I loaded the same file with DX mesh viewer and there the light had the desired effects. What am I doing wrong here ? thx. P.S when I change m_Light.Attenuation1 = 1.0f; to m_Light.Attenuation0 = 1.0f; the mesh is rendered with the white color, why is that ???

Share this post

Link to post
Share on other sites
I set the mesh's material , exactly as shown in SDK examples.
The mesh has only one material and no texture applied.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!