I have three problems when trying to draw spheres:
- Sphere is glitching in some angles:
- Don’t know how to apply a color to sphere
- Can’t draw two spheres at one - only one is shown.
Code. Render:
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());
}
How I create shape effect
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
is a D3DSphere
class object; the constructor and Draw
method
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);
}
Perhaps it will be useful if I figure, that the sphere radius(and everything in my scene) is very tiny(~10^-6)
By unknown for me reasons, the code of examples in Microsoft DirectX12 Tool Kit wiki page in most is not compatible with the headers I have installed via NuGet packages - I have different constructors, different arguments in methods. I think the problem is that I am using Visual Studio 15, but Microsoft recommends to use at least 17(there are two different DirectX12TK NuGet packages - one for VS15 and one for VS17 and above). It is weird.
I solved the third problem by changing code in rendering:
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 package version I use is 2019.12.17.1