🔒 Locked
lighting issues
Advertisement
Original Post
When I''m rotating a model i frequently get patches that become unlit near the edges of faces, they either turn white or black depending on the angle. I''m wondering what the source of this problem is, is it lighting or something? or did I not calculate the normals of the faces right?
Thanks for the suggestion, first off I have no idea what a MIP map is.. so I'm going to venture a guess that that isn't the problem. And I turned off specular highlights, but the problem didn't go away. Also I should mention I'm using DirectX9 Any other ideas?
[edited by - dovyman on April 19, 2003 7:59:18 PM]
[edited by - dovyman on April 19, 2003 7:59:18 PM]
void cModel::FillBuffers(IDirect3DDevice9 *lpDevice)
{
cGeometry *tempMesh; //holds the current mesh info
tempMesh = new cGeometry; //alocate the temp mesh
tempMesh = HeadMesh;
bool IsDone = false;
//loop through all meshs and set their vertex buffers, index buffers, and materials
while(IsDone == false)
{
if(tempMesh->dwNumVerts == 0)
{
IsDone = true;
break;
}
if(UseD3DLighting == true)
ComputeMeshNormals(tempMesh->MeshVerts, tempMesh->MeshIndices, tempMesh->dwNumVerts, (tempMesh->dwNumFaces * 3)); //compute the mesh normals so that we can apply lighting
//create a new vertex buffer
if(UseD3DLighting == true)
lpDevice->CreateVertexBuffer((tempMesh->dwNumVerts * sizeof(VERTEX)), D3DUSAGE_WRITEONLY, D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1, D3DPOOL_DEFAULT, &tempMesh->lpMeshVB, NULL);
else
lpDevice->CreateVertexBuffer((tempMesh->dwNumVerts * sizeof(VERTEX)), D3DUSAGE_WRITEONLY, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1, D3DPOOL_DEFAULT, &tempMesh->lpMeshVB, NULL);
//assign the meshs material to it
if(HeadMat != NULL)
{
cShader *tempMat;
tempMat = HeadMat;
//search for the mesh's material
for(DWORD i = 0; i < dwNumMats; i++)
{
if(strcmp(tempMesh->matName, tempMat->mName) != 0)
{
if(tempMat->Next != NULL)
tempMat = tempMat->Next;
}
else
break;
}
//if the meshs material has a texture map, load it
if(tempMat->HasTextureMap == true)
{
if(tempMat->tFileName != NULL)
{
D3DXCreateTextureFromFile(lpDevice, tempMat->tFileName, &tempMesh->lpTexture);
}
}
if(UseD3DLighting == true)
{
//if the mesh's material has material values, set them onto its d3dmaterial
if(tempMat->HasMaterial == true)
{
ZeroMemory(&tempMesh->lpMat, sizeof(D3DMATERIAL9));
tempMesh->lpMat.Ambient.r = tempMat->AmbR;
tempMesh->lpMat.Ambient.g = tempMat->AmbG;
tempMesh->lpMat.Ambient.b = tempMat->AmbB;
tempMesh->lpMat.Ambient.a = 1.0f;
tempMesh->lpMat.Diffuse.r = tempMat->DifR;
tempMesh->lpMat.Diffuse.g = tempMat->DifG;
tempMesh->lpMat.Diffuse.b = tempMat->DifB;
tempMesh->lpMat.Diffuse.a = 1.0f;
tempMesh->lpMat.Specular.r = tempMat->SpcR;
tempMesh->lpMat.Specular.g = tempMat->SpcG;
tempMesh->lpMat.Specular.b = tempMat->SpcB;
tempMesh->lpMat.Diffuse.a = 1.0f;
tempMesh->lpMat.Power = 50.0f;
tempMat = NULL;
}
//if not set a default material value(white)
else
{
ZeroMemory(&tempMesh->lpMat, sizeof(D3DMATERIAL9));
tempMesh->lpMat.Ambient.r = 1.0f;
tempMesh->lpMat.Ambient.g = 1.0f;
tempMesh->lpMat.Ambient.b = 1.0f;
tempMesh->lpMat.Ambient.a = 1.0f;
tempMesh->lpMat.Diffuse.r = 1.0f;
tempMesh->lpMat.Diffuse.g = 1.0f;
tempMesh->lpMat.Diffuse.b = 1.0f;
tempMesh->lpMat.Diffuse.a = 1.0f;
tempMesh->lpMat.Specular.r = 1.0f;
tempMesh->lpMat.Specular.g = 1.0f;
tempMesh->lpMat.Specular.b = 1.0f;
tempMesh->lpMat.Diffuse.a = 1.0f;
tempMesh->lpMat.Power = 50.0f;
} //use the defualt white material
}
else
{
for(DWORD i = 0; i < tempMesh->dwNumVerts; i++)
{
tempMesh->LMeshVerts[i].dwColor = tempMat->dwColor;
}
}
}
if(UseD3DLighting == true)
{
VERTEX *v; //temp vertex
//put the mesh vertex info into its vertex buffer
tempMesh->lpMeshVB->Lock(0, 0, (VOID**)&v, 0);
for(DWORD i = 0; i < tempMesh->dwNumVerts; i++)
{
v[i].x = tempMesh->MeshVerts[i].x;
v[i].y = tempMesh->MeshVerts[i].y;
v[i].z = tempMesh->MeshVerts[i].z;
v[i].nx = tempMesh->MeshVerts[i].nx;
v[i].ny = tempMesh->MeshVerts[i].ny;
v[i].nz = tempMesh->MeshVerts[i].nz;
v[i].tu = tempMesh->MeshVerts[i].tu;
v[i].tv = tempMesh->MeshVerts[i].tv;
}
tempMesh->lpMeshVB->Unlock();
}
else
{
LVERTEX *lv; //temp vertex
//put the mesh vertex info into its vertex buffer
//NOTE: CHANGED WHILE CONVERTING TO DX9
tempMesh->lpMeshVB->Lock(0, 0, (VOID**)&lv, 0);
for(DWORD i = 0; i < tempMesh->dwNumVerts; i++)
{
lv[i].x = tempMesh->LMeshVerts[i].x;
lv[i].y = tempMesh->LMeshVerts[i].y;
lv[i].z = tempMesh->LMeshVerts[i].z;
lv[i].dwColor = tempMesh->LMeshVerts[i].dwColor;
lv[i].tu = tempMesh->LMeshVerts[i].tu;
lv[i].tv = tempMesh->LMeshVerts[i].tv;
}
tempMesh->lpMeshVB->Unlock();
}
//now put all the meshs indices into its vertex buffer
if(tempMesh->dwNumFaces > 0)
{
//NOTE: CHANGED WHILE CONVERTING TO DX9
lpDevice->CreateIndexBuffer((tempMesh->dwNumFaces * 3) * sizeof(WORD), D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_DEFAULT, &tempMesh->lpMeshIB, NULL);
WORD *idx;
//NOTE: CHANGED WHILE CONVERTING TO DX9
tempMesh->lpMeshIB->Lock(0, 0, (VOID**)&idx, 0);
for(DWORD i = 0; i < (tempMesh->dwNumFaces * 3); i++)
{
idx[i] = tempMesh->MeshIndices[i];
}
tempMesh->lpMeshIB->Unlock();
}
//delete all the verts and indices since we dont need them anymore
tempMesh->MeshVerts = NULL;
tempMesh->LMeshVerts = NULL;
tempMesh->MeshIndices = NULL;
if(tempMesh->Next == NULL)
{
IsDone = true;
break;
}
else
{
tempMesh = tempMesh->Next;
}
}
}
[edited by - dovyman on April 20, 2003 8:22:04 AM]
Its there, heres it by itself
[edited by - dovyman on April 20, 2003 4:06:00 PM]
//if the meshs material has a texture map, load it
if(tempMat->HasTextureMap == true)
{
if(tempMat->tFileName != NULL) { D3DXCreateTextureFromFile(lpDevice, tempMat->tFileName, &tempMesh->lpTexture); } }
[edited by - dovyman on April 20, 2003 4:06:00 PM]
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement