Archived

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

johnnyBravo

Why dont my meshes light up from the point light?

Recommended Posts

Im using the directx 9 sdk meshes tutorial to load meshes and draw them. Then i get a point light in there with them, but the point light only lights up my vertices on which i set the normals and materials for. How can i get the meshes to light up awell?

Share this post


Link to post
Share on other sites
For a mesh to recieve lighting it NEEDS to have normals. And for the lighting to make sense, you NEED to set a valid material.

So add normals to the meshes that don''t have them.

Share this post


Link to post
Share on other sites
how would i go about that?
Heres 2 functions that i use to load and draw meshes.

load mesh

void LoadMesh(char mesh[],int index=0)
{
LPD3DXBUFFER pD3DXMtrlBuffer;
D3DXLoadMeshFromX( mesh, D3DXMESH_SYSTEMMEM, myDevice, NULL, &pD3DXMtrlBuffer, NULL, &myNumMaterials[index], &myMesh[index] ) ;
D3DXMATERIAL* d3dxMaterials = (D3DXMATERIAL*)pD3DXMtrlBuffer->GetBufferPointer();
myMeshMaterials[index] = new D3DMATERIAL9[myNumMaterials[index]];
myMeshTextures[index] = new LPDIRECT3DTEXTURE9[myNumMaterials[index]];

for( DWORD i=0; i<myNumMaterials[index]; i++ )
{
myMeshMaterials[index][i] = d3dxMaterials[i].MatD3D;
myMeshMaterials[index][i].Ambient = myMeshMaterials[index][i].Diffuse;

myMeshTextures[index][i] = NULL;
if( d3dxMaterials[i].pTextureFilename != NULL && lstrlen(d3dxMaterials[i].pTextureFilename) > 0 )
D3DXCreateTextureFromFile( myDevice, d3dxMaterials[i].pTextureFilename, &myMeshTextures[index][i] ) ;
}
pD3DXMtrlBuffer->Release();
}



draw mesh



void DrawMesh(int index=0, int keyFrame =-1)
{
for( DWORD i=0; i<myNumMaterials[index]; i++ )
{
myDevice->SetMaterial( &myMeshMaterials[index][i] );
myDevice->SetTexture( 0, myMeshTextures[index][i] );
myMesh[index]->DrawSubset( i );
}
}

Share this post


Link to post
Share on other sites