Skip to main content
GameDev.net gamedev.net
🔒 Locked

Ambient Lighting

Started by SiliconMunky Nov 21, 2003 at 1:41 AM 0 replies 350+ views
Original Post
SiliconMunky
SiliconMunky
Ok, I'm curious as to why my terrain is not being lit by the ambient light? Currently the terrain just gets drawn completly black. Is it that the verticies need a normal to display ambient lighting? I don't beleive so, because one of my models is not being lit either and I know that it has normals. Here's the relevent parts of my code.
//constants
#define D3DFVF_CUSTOMVERTEX	( D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1 )

//structures
typedef struct D3DVERTEX
{
	float	fX,	fY,	fZ;
	DWORD	dwColor;
	FLOAT   tu, tv;   // The texture coordinates
} D3DVERTEX;


//the init part 	
	mlpD3dDevice->SetRenderState( D3DRS_LIGHTING, true );
	mlpD3dDevice->SetRenderState( D3DRS_AMBIENT,RGB(255,255,255));	


//the colour of each vertex is set as
pVertexData[index].dwColor = 0xffaaaaaa; //color


//the render part
void CMap::Draw(void)
{
	D3DXMATRIXA16 matWorld;
	D3DXMatrixIdentity(&matWorld);
	mlpD3DDevice->SetTransform( D3DTS_WORLD, &matWorld);

	mlpD3DDevice->SetTexture( 0, mlpTexture );
	mlpD3DDevice->SetFVF( D3DFVF_CUSTOMVERTEX );

	mlpD3DDevice->SetStreamSource(0,m_pTerrainVB,0,sizeof(D3DVERTEX));
	mlpD3DDevice->SetIndices(m_pTerrainIB);
	mlpD3DDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0, m_dwTerrainVertices, 0, m_dwTerrainPrimitives);
}
  
Thanks for any help. Edit: typo [edited by - SiliconMunky on November 21, 2003 2:43:09 AM]
SiliconMunky
SiliconMunky
ok, I figured it out. I didn''t have an ambient value set on the material.

This fixed it.

D3DMATERIAL9 mat;

// Set the RGBA for diffuse reflection.
mat.Diffuse.r = 0.5f;
mat.Diffuse.g = 0.5f;
mat.Diffuse.b = 0.5f;
mat.Diffuse.a = 1.0f;

// Set the RGBA for ambient reflection.
mat.Ambient.r = 0.5f;
mat.Ambient.g = 0.5f;
mat.Ambient.b = 0.5f;
mat.Ambient.a = 1.0f;

// Set the color and sharpness of specular highlights.
mat.Specular.r = 1.0f;
mat.Specular.g = 1.0f;
mat.Specular.b = 1.0f;
mat.Specular.a = 1.0f;
mat.Power = 50.0f;

// Set the RGBA for emissive color.
mat.Emissive.r = 0.0f;
mat.Emissive.g = 0.0f;
mat.Emissive.b = 0.0f;
mat.Emissive.a = 0.0f;

mlpD3DDevice->SetMaterial(&mat);

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.