Jump to content
  • Advertisement
Sign in to follow this  

Lighting question

This topic is 3934 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've exported a simple sphere that has normals and a texture as a .x file and load it with D3DXLoadMeshFromX(). And have setup a light as follows:
        m_D3DDevice->SetRenderState( D3DRS_LIGHTING, TRUE );
	// Fill in a light structure defining our light
	D3DLIGHT9 light;
	ZeroMemory( &light, sizeof(D3DLIGHT9) );
	light.Type    = D3DLIGHT_POINT;
	light.Diffuse.r = 0.0f;
	light.Diffuse.g = 0.0f;
	light.Diffuse.b = 1.0f;

	light.Ambient.r  = 1.0f;
	light.Ambient.g  = 1.0f;
	light.Ambient.b  = 1.0f;
	light.Specular.r = 1.0f;
	light.Specular.g = 1.0f;
	light.Specular.b = 1.0f;

	// Point lights have no direction but do have a position
	light.Position = D3DXVECTOR3(0, 100, 0);
	// Tell the device about the light and turn it on
	light.Attenuation0 = 1.0f;
	m_D3DDevice->SetLight( 0, &light );
	m_D3DDevice->LightEnable( 0, TRUE ); 

Here is the mesh rendering code:
for (DWORD i=0; i<numMaterials; i++)
		// Set the material and texture for this subset
		m_D3DDevice->SetTexture(0, meshTextures);

		m_D3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
		// Draw the mesh subset

I get no lighting at all with this. Even m_D3DDevice->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(0, 0, 0)) doesn't seem to have any effect either.

Share this post

Link to post
Share on other sites
Have you tried a directional light. A directional light will immediately let you know if there are any irregularities.

I hope this helps.
Take care.

Share this post

Link to post
Share on other sites
I can't tell by just looking at it, but if you want some more documentation on lighting in general, you could always take a look at this and this. It may help you find, where you may be going wrong. The second link, would be more what I believe you're trying to accomplish.

Best of luck.

Share this post

Link to post
Share on other sites
What are the values of the material you're setting? It acts as a multiplier of the light's properties, so if it were all zero'd out you'd get completely black.

Also, any transformations including scaling? Scaling affects normals so you might want to try D3DRS_NORMALIZENORMALS = TRUE.

I second Pieter's suggestion about trying a directional light - they have no attenuation and are easier to debug with. At least that way you can eliminate your geometry and material properties...


Share this post

Link to post
Share on other sites
m_D3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
means that you are just using the texture without "modulating" the light.

Try setting:
m_D3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
m_D3DDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_CURRENT);
m_D3DDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_TEXTURE);

Share this post

Link to post
Share on other sites
Seems the problem is I was trying to use a blue light. With blue directional light you can very faintly see the models. If I use a white light then it seems to work as it should. But the lighting in general doesn't seem to work as it should. Tried to cast a yellow light but nothing really changed. I even hard coded the ambient and diffuse for the textures to one.

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.

GameDev.net 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!