我正在使用 DirectXToolKit。我创建了一个这样的模型
m_Model = Model::CreateFromCMO(device, L"Content/Meshes/cube.cmo", *m_EffectFactory);
我想使用从 DirectX::IEffect 继承的自定义效果。
m_ModelEffect = std::make_shared<UnlitEffect>(device);
但是,DirectX::Model 默认创建自己的效果,这意味着为了使用我自己的着色器,我必须使用替换它们
MeshPart::ModifyEffect(ID3D11Device* d3dDevice, std::shared_ptr<IEffect>& ieffect, bool isalpha);
我对如何将效果发送到该功能感到困惑。
这是我现在使用的代码:
for(const auto& mesh : m_Model->meshes)
{
for(const auto& part : mesh->meshParts)
{
part->ModifyEffect(device, &m_ModelEffect);
}
}
但是,这会导致此错误 initial value of reference to non-const must be an lvalue
搜索该错误为我提供了许多解决方案,这些解决方案涉及更改函数签名以使用 const 引用,但是我应该如何在不更改函数的情况下按原样使用该函数?传递shared_ptr地址的正确方法是什么?
编辑:我让它使用这个代码工作
m_ModelEffect = std::make_shared<UnlitEffect>(device);
m_Model = Model::CreateFromCMO(device, L"Content/Meshes/cube.cmo", *m_EffectFactory);
for(auto& mesh : m_Model->meshes)
{
for(auto& part : mesh->meshParts)
{
part->ModifyEffect(device, m_ModelEffect);
}
}