启用照明时 DirectX 9 顶点颜色会被忽略吗?
DirectX 9 vertex colors ingored when lighting is enabled?
嗯,问题说到做到了。当我禁用光 (pd3dDevice->SetRenderState(D3DRS_LIGHTING, TRUE);
) 时,我得到了预期的颜色,当我将它设置为 true 时,我得到纯黑色,即使我设置了环境光,但是当还设置 material.但是顶点颜色完全被忽略了,我只得到了环境光的颜色。
目前搜索:
我发现的唯一有用的文章是这篇 vertex lighting tutorial, but it removes the diffuse color from the vertices, and instead adds a normal vector. Also on 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);
如果您想使用顶点颜色作为光照计算的输入,您需要将渲染状态 D3DRS_AMBIENTMATERIALSOURCE
设置为 D3DMCS_COLOR1
(对于漫反射顶点颜色)。这同样适用于其他颜色分量。
嗯,问题说到做到了。当我禁用光 (pd3dDevice->SetRenderState(D3DRS_LIGHTING, TRUE);
) 时,我得到了预期的颜色,当我将它设置为 true 时,我得到纯黑色,即使我设置了环境光,但是当还设置 material.但是顶点颜色完全被忽略了,我只得到了环境光的颜色。
目前搜索: 我发现的唯一有用的文章是这篇 vertex lighting tutorial, but it removes the diffuse color from the vertices, and instead adds a normal vector. Also on 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);
如果您想使用顶点颜色作为光照计算的输入,您需要将渲染状态 D3DRS_AMBIENTMATERIALSOURCE
设置为 D3DMCS_COLOR1
(对于漫反射顶点颜色)。这同样适用于其他颜色分量。