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.

asked 7 years ago160 views
3 Answers
0
Accepted Answer

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;
}
answered 7 years ago
0

Thanks, that worked!

answered 7 years ago
0

Np, I gotcha, bro!

answered 7 years ago

This post is closed: Adding new answers, comments, and votes is disabled.