|

楼主 |
发表于 2009-9-18 20:24:00
|
显示全部楼层
Re:为什么相同的材质,在同一个平面上会有这么大的反光
感谢5楼的resplendence朋友提供在回复中上传图片的方法!
场景中这些Box我都是用D3DXCreateBox方法创建出来的,这时它各个顶点的法线应该是自动计算好了的吧,还要我们再修改吗?惭愧,在下初学D3D,懂得不多。看了楼上cO_olWinD朋友的回复后,还是花了好几个小时确认一下D3DXCreateBox创建出来的Box的顶点参数是否正确,代码如下:
//我们来研究一下窗户右侧的墙的顶点数据
DWORD FVF = m_meshWallFront[2]->GetFVF(); //这里得到FVF的结果为18,说明它的灵活顶点格式为:D3DFVF_XYZ | D3DFVF_NORMAL
struct CurrentVertex
{
float x, y, z;
float nx, ny, nz;
};
CurrentVertex *pCurrentVertex = 0;
if(D3DFVF_XYZ | D3DFVF_NORMAL == FVF)
{
if(D3D_OK != m_meshWallFront[2]->LockVertexBuffer(0, (void**)&pCurrentVertex))
::MessageBox(m_hWnd, "无法得到顶点的缓存!", "出错", MB_OK);
else
{
//得到组成Box的三角形的数量
DWORD nNumFaces = m_meshWallFront[2]->GetNumFaces();
D3DXVECTOR3 v0, v1, v2, nv0, nv1, nv2; //组成三角形的顶点坐标及法线
char strOutput[2256] = {0}; //输出每个三角形各顶点的信息
WORD* index = 0;
m_meshWallFront[2]->LockIndexBuffer(0, (void**)&index);//得到每个顶点在顶点数组中的的索引号
//好了,现在可以得到每个三角形的顶点信息了
for(int i=0; i<nNumFaces; i++)
{
//顶点一坐标数据
v0.x = pCurrentVertex[index[i*3]].x;
v0.y = pCurrentVertex[index[i*3]].y;
v0.z = pCurrentVertex[index[i*3]].z;
//顶点二坐标数据
v1.x = pCurrentVertex[index[i*3+1]].x;
v1.y = pCurrentVertex[index[i*3+1]].y;
v1.z = pCurrentVertex[index[i*3+1]].z;
//顶点三坐标数据
v2.x = pCurrentVertex[index[i*3+2]].x;
v2.y = pCurrentVertex[index[i*3+2]].y;
v2.z = pCurrentVertex[index[i*3+2]].z;
//顶点一法线数据
nv0.x = pCurrentVertex[index[i*3]].nx;
nv0.y = pCurrentVertex[index[i*3]].ny;
nv0.z = pCurrentVertex[index[i*3]].nz;
//顶点二法数据
nv1.x = pCurrentVertex[index[i*3+1]].nx;
nv1.y = pCurrentVertex[index[i*3+1]].ny;
nv1.z = pCurrentVertex[index[i*3+1]].nz;
//顶点三法数据
nv2.x = pCurrentVertex[index[i*3+2]].nx;
nv2.y = pCurrentVertex[index[i*3+2]].ny;
nv2.z = pCurrentVertex[index[i*3+2]].nz;
//输出信息
sprintf(strOutput, "顶点一坐标(%f, %f, %f),\n顶点一法线(%f, %f, %f)。\n\n顶点二坐标(%f, %f, %f),\n顶点二法线(%f, %f, %f)。\n\n顶点三坐标(%f, %f, %f),\n顶点三法线(%f, %f, %f)。\n\n",
v0.x, v0.y, v0.z, nv0.x, nv0.y, nv0.z,
v1.x, v1.y, v1.z, nv1.x, nv1.y, nv1.z,
v2.x, v2.y, v2.z, nv2.x, nv2.y, nv2.z);
::MessageBox(m_hWnd, strOutput, "三角形信息", MB_OK);
}
m_meshWallFront[2]->UnlockIndexBuffer();
m_meshWallFront[2]->UnlockVertexBuffer();
}
}
else
{
::MessageBox(m_hWnd, "顶点的格式不是D3DFVF_XYZ | D3DFVF_NORMAL的!", "出错", MB_OK);
}
显示结果表明,每个顶点的法线都是正确无误的,包括组成正面墙壁的其他几个Box的各个顶点的法线也是对的,看来:这里也不是因为顶点法线不正确造成光照效果的差异。那是什么原因呢,继续请教各位兄弟们! |
|