我正在绘制D3DPT_POINTLIST
并将我的direct3d 9设备设置为多个州。我不想使用灯光,因为我只想显示顶点颜色。
根据我的视图矩阵,顶点看起来变暗或变亮。他们一下子改变了,我找不到任何解决这个问题的渲染器。
我会尽量保持这个。如果缺少信息,请告诉我。
struct MyVertex {
float x, y, z;
D3DCOLOR color;
};
// In the initialization of the device
g_D3D9Device->CreateVertexBuffer (sizeof(MyVertex)*g_MaxVerts, D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC, 0, D3DPOOL_DEFAULT, &g_D3D9DynamicVB, NULL);
我设置这些渲染状态的每一帧:
g_D3D9Device->SetRenderState (D3DRS_CULLMODE, D3DCULL_NONE);
g_D3D9Device->SetRenderState (D3DRS_ALPHABLENDENABLE, FALSE);
g_D3D9Device->SetRenderState (D3DRS_ZFUNC, D3DCMP_LESSEQUAL);
g_D3D9Device->SetRenderState (D3DRS_ZWRITEENABLE, TRUE);
g_D3D9Device->SetRenderState (D3DRS_ZENABLE, TRUE);
g_D3D9Device->SetRenderState(D3DRS_LOCALVIEWER, FALSE);
g_D3D9Device->SetRenderState (D3DRS_LIGHTING, FALSE);
g_D3D9Device->SetRenderState (D3DRS_COLORVERTEX, FALSE);
float size = g_PCManager.GetPointSize();
g_D3D9Device->SetRenderState (D3DRS_POINTSIZE, *((DWORD*)&size));
g_D3D9Device->SetFVF (D3DFVF_XYZ|D3DFVF_DIFFUSE);
// and render
void* vbPtr;// = new char[m_VertsBuff0.size() * sizeof(MyVertex)];
UINT maxverts = std::min(m_VertsBuff0.size(),(UINT)g_MaxVerts);
if(SUCCEEDED(vertexbuffer->Lock (0, 0, &vbPtr, D3DLOCK_DISCARD)))
{
memcpy (vbPtr, m_VertsBuff0.data(), sizeof(MyVertex) * maxverts);
vertexbuffer->Unlock ();
//without setting the streamsource, D3D9 will just take some (undefined) memory to read/draw from
device->SetStreamSource (0, vertexbuffer, 0, sizeof(m_VertsBuff0[0]));
// Draw!
device->DrawPrimitive (D3DPT_POINTLIST, 0, maxverts);
}
我想说明这是一个Unity3D本机C ++插件,所以可能有一些我不知道的故障。
这是从不同角度看起来的样子:
答案 0 :(得分:0)
我需要在实际绘制对象之前添加一些纹理阶段。
device->SetTextureStageState (0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
device->SetTextureStageState (0, D3DTSS_COLORARG1, D3DTA_CURRENT);
device->SetTextureStageState (0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
device->SetTextureStageState (0, D3DTSS_ALPHAARG1, D3DTA_CURRENT);
device->SetTextureStageState (1, D3DTSS_COLOROP, D3DTOP_DISABLE);
device->SetTextureStageState (1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);