Jump to content
  • Advertisement

Archived

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

Dovyman

lighting issues

This topic is 5638 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

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?

Share this post


Link to post
Share on other sites
Advertisement
*bump*



These are the problems I'm talking about, those white patches, as it rotates, they turn black, and then white again. Anybody have any idea what my problem is?


[edited by - dovyman on April 19, 2003 4:39:10 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
It could be MIP map problems. I e, some of your MIP map images/levels are not correctly specified, or you have a lot of white area going close up to your textured area, and the MIP map filtering causes those areas to blend that in.

Share this post


Link to post
Share on other sites
To be more precise. Your specular level is set too high. Forgot what the code is in OpenGL. Shouldn''t be too hard to find.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites

  
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]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!