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.

demandé il y a 7 ans165 vues
3 réponses
0
Réponse acceptée

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;
}
répondu il y a 7 ans
0

Thanks, that worked!

répondu il y a 7 ans
0

Np, I gotcha, bro!

répondu il y a 7 ans

Cette publication est fermée : l'ajout de nouvelles réponses, commentaires et votes est désactivé.