How to the light a mesh properly

Started by
1 comment, last by DesignerX 16 years, 11 months ago
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 ???
There is nothing that can't be solved. Just people that can't solve it. :)
Advertisement
What are you setting for the object's material?
NextWar: The Quest for Earth available now for Windows Phone 7.
I set the mesh's material , exactly as shown in SDK examples.
The mesh has only one material and no texture applied.

There is nothing that can't be solved. Just people that can't solve it. :)

This topic is closed to new replies.

Advertisement