How do I update materials?

0

So I have a function that sets up a material:

    IMaterial* DynamicUITextureComponent::SetupNewMaterial()
{
AZStd::string materialName = "EntMat_" + GetEntityId().ToString();
IMaterialManager* matManager = GetIEditor()->Get3DEngine()->GetMaterialManager();
IMaterial* material{ matManager->CloneMaterial(matManager->GetDefaultMaterial())};
material->SetName(materialName.c_str());
material->GetShaderItem().m_pShaderResources->GetTexture(0)->m_Name = m_renderTargetName.c_str();
return material;
}

and after that function, the returning material is set as the entities material:

    m_UIMaterial = SetupNewMaterial();
EBUS_EVENT_ID(id, LmbrCentral::MaterialRequestBus, SetMaterial, m_UIMaterial);

But this only shows the default material and not my render target I actually want to display.

If I check the render target via

r_ShowRenderTarget RENDERTARGETNAME

I am able to see the texture. Also if I write the targets name directly into the material (in material editor) it works, so I ran confirm, that this should work at run time in theory. Whats missing is sort of an update to my changes after creating the material.

질문됨 7년 전166회 조회
3개 답변
0
수락된 답변

Try this:

    IMaterial* DynamicUITextureComponent::SetupNewMaterial()
{
AZStd::string materialName = "EntMat_" + GetEntityId().ToString();
IMaterialManager* matManager = GetIEditor()->Get3DEngine()->GetMaterialManager();
IMaterial* material{ matManager->CloneMaterial(matManager->GetDefaultMaterial()) };
material->SetName(materialName.c_str());
SInputShaderResources inputShaderResources{ material->GetShaderItem().m_pShaderResources };
inputShaderResources.m_Textures[EFTT_DIFFUSE].m_Name = m_renderTargetName.c_str();
material->AssignShaderItem(gEnv->pRenderer->EF_LoadShaderItem("Illum", true, 0, &inputShaderResources));
return material;
}
답변함 7년 전
0

Thanks, that worked!

답변함 7년 전
0

Np, I gotcha, bro!

답변함 7년 전

이 게시물은 마감됨: 새 답변, 댓글 및 투표 추가가 비활성화되었습니다.

관련 콘텐츠