【发布时间】:2020-08-07 02:25:32
【问题描述】:
我在尝试绘制球体时遇到三个问题:
代码。渲染:
void Game::Render()
{
if (m_timer.GetFrameCount() == 0)
{
return;
}
m_deviceResources->Prepare();
Clear();
auto commandList = m_deviceResources->GetCommandList();
PIXBeginEvent(commandList, PIX_COLOR_DEFAULT, L"Render");
auto commandList2 = m_deviceResources->GetCommandList();
PIXBeginEvent(commandList2, PIX_COLOR_DEFAULT, L"Draw Sphere");
m_shapeEffect->Apply(m_deviceResources->GetCommandList());
for (int i(0); i < vsphere; i++)
{
m_shapeEffect->SetWorld(d3dsphere[i]->world);
d3dsphere[i]->Draw(commandList2);
}
PIXEndEvent(commandList2);
PIXEndEvent(commandList);
PIXBeginEvent(m_deviceResources->GetCommandQueue(), PIX_COLOR_DEFAULT, L"Present");
m_deviceResources->Present();
m_graphicsMemory->Commit(m_deviceResources->GetCommandQueue());
PIXEndEvent(m_deviceResources->GetCommandQueue());
}
我如何创建形状效果
EffectPipelineStateDescription pd(
&VertexPositionColor::InputLayout,
CommonStates::Opaque,
CommonStates::DepthNone,
CommonStates::CullNone,
rtState,
D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE);
m_shapeEffect = std::make_unique<BasicEffect>(device, EffectFlags::VertexColor, pd);
d3dsphere 是一个D3DSphere 类对象;构造函数和Draw 方法
D3DSphere(float x, float y, float z, float radius, float r, float g, float b, float a)
{
this->x = x;
this->y = y;
this->z = z;
this->radius = radius;
this->shape = GeometricPrimitive::CreateSphere(radius*2.0f);
this->world = Matrix::Identity;
this->world = XMMatrixMultiply(this->world, Matrix::CreateTranslation(x, y, z));
this->index = vsphere;
d3dsphere[vsphere] = this;
vsphere++;
}
void D3DSphere::Draw(ID3d12GraphicsCommandList* commandList)
{
this->shape->Draw(commandList);
}
如果我认为球体半径(以及我场景中的所有内容)非常小(~10^-6),也许会很有用
由于我不知道的原因,Microsoft DirectX12 Tool Kit wiki page 中的示例代码大部分与我通过 NuGet 包安装的头文件不兼容 - 我有不同的构造函数,方法中的参数不同。我认为问题在于我使用的是 Visual Studio 15,但微软建议至少使用 17 个(有两种不同的 DirectX12TK NuGet 包 - 一种用于 VS15,一种用于 VS17 及更高版本)。这很奇怪。
我通过更改渲染中的代码解决了第三个问题:
for(int i(0);i<vsphere;i++)
{
m_shapeEffect->SetMatrices(d3dsphere->world, m_view, m_projection);
m_shapeEffect->Apply(m_deviceResources->GetCommandList());
d3dsphere[i]->Draw();
}
我使用的DirectX12TK NuGet包版本是2019.12.17.1
【问题讨论】:
-
您使用的是哪个特定的 NuGet 包?您的设备资源构造函数的参数是什么?在我看来,深度缓冲区设置不正确。
-
为什么这里有多个 commandList 变量?
-
@ChuckWalbourn,可能是因为我理解错了,但它有效,所以我没有改变它。我应该只有一个吗?
-
确保您在同一个项目中只有以下之一:
directxtk12_desktop_2015、directxtk12_desktop_2017、directxtk12_uwp。还要确保您没有使用directxtk_desktop_2015、directxtk_desktop_2015或directxtk_uwp(即DX11 版本) -
@ChuckWalbourn 我的意思是命令列表。我已经安装了
directxtk12_desktop_2015版本2019.12.17.1,这是我项目中唯一的NuGet 包。我通过在资源管理器中打开“包”文件夹直接检查它
标签: c++ directx-12 directxtk