嗯,问题是这样说的。当我禁用灯光(pd3dDevice->SetRenderState(D3DRS_LIGHTING, TRUE);
)时,我得到了预期的颜色,当我将其设置为true时,即使我设置了环境光,我也会得到纯黑色,但是当设置了材料。但是顶点颜色然后被完全忽略,我只得到环境光的颜色。
到目前为止的搜索: 我发现的唯一有用的文章是vertex lighting tutorial,,但是它会从顶点中删除漫反射颜色,而是添加一个法线向量。同样在MSDN上,关于漫反射光照,它没有参考顶点的颜色。我开始怀疑顶点的颜色,如RHW值,通常在运行时计算,并且在声明期间设置它只是给出颜色而不需要光照。是吗?
与照明相关的代码:
pd3dDevice->SetRenderState(D3DRS_LIGHTING, TRUE);
pd3dDevice->SetRenderState(D3DRS_COLORVERTEX, TRUE); // not sure if needed
pd3dDevice->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_ARGB(22, 255, 255, 255)); // no visible difference on A
pd3dDevice->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_GOURAUD); // probably not needed yet, can't harm
D3DMATERIAL9 material;
D3DCOLORVALUE zeroColor;
D3DCOLORVALUE oneColor;
zeroColor.a = 0;
zeroColor.r = 0;
zeroColor.g = 0;
zeroColor.b = 0;
oneColor.a = 0; // no perceivable difference between 0 and 1
oneColor.r = 1;
oneColor.g = 1;
oneColor.b = 1;
material.Ambient = oneColor;
material.Diffuse = zeroColor; //setting it to oneColor has no effect
material.Emissive = zeroColor;
material.Power = 0; //no difference if 0 or 1
material.Specular = zeroColor;
pd3dDevice->SetMaterial(&material);
答案 0 :(得分:1)
If you want to use the vertex colors as input to the lighting calculation, you need to set the render state D3DRS_AMBIENTMATERIALSOURCE
to D3DMCS_COLOR1
(for the diffuse vertex color). The same applies to the other color components.