gpt4 book ai didi

c++ - direct3d 中奇怪的照明效果切换黑暗和光明

转载 作者:太空狗 更新时间:2023-10-29 23:17:22 25 4
gpt4 key购买 nike

我正在绘制一个 D3DPT_POINTLIST 并将我的 direct3d 9 设备设置为多种状态。我不想使用光照,因为我只想显示顶点颜色。

根据我的 View 矩阵,顶点似乎变暗或变亮。它们一次全部改变,我找不到任何可以解决这个问题的渲染状态。

我会尽量保持简短。如果缺少信息,请告诉我。

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++ 插件,因此可能存在一些我不知道的故障。

这是从不同角度看的样子:

light version dark version

最佳答案

我需要在实际绘制对象之前添加一些纹理阶段。

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);

关于c++ - direct3d 中奇怪的照明效果切换黑暗和光明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18485919/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com