Could you make a screenshot of the values of the material you use in the material editor?
Maybe Illum is really just not able to do dynamic opacity changes. There must be something that blocks it.
Re: Modify Material opacity via C++ code
#12As far as I know it's case sensitive. So try "Opacity" instead.
Edit: Nevermind it's not case sensitive. It's been a while since I've done it
. It appears the opacity value range is 0 to 1, not 0 to 100. So setting your m_fTransparentValue to something like 0.5 should work.
Edit: Nevermind it's not case sensitive. It's been a while since I've done it

Last edited by gshot on Thu Jul 20, 2017 11:49 am, edited 1 time in total.
Re: Modify Material opacity via C++ code
#13Or did you try to set any other parameter ? Not sure about the case sensitivity though. I use
Code: Select all
if (GetEntity()->GetStatObj(0))
{
IMaterial *pMat = GetEntity()->GetStatObj(0)->GetMaterial();
if (pMat)
{
pMat->SetGetMaterialParamVec3("diffuse", vDiffuse, false);
}
}
Cryengine tutorial videos on my Youtube channel! Check it out !
https://www.youtube.com/user/MusicForLifePL20
https://www.youtube.com/user/MusicForLifePL20
Re: Modify Material opacity via C++ code
#14In MaterialHelpers::SetXmlFromLighting
CMatMan::InitDefaults()
and
IEntity::SetOpacity(float fAmount)
Code: Select all
node->setAttr("Opacity", pShaderResources.m_LMaterial.m_Opacity);
CMatMan::InitDefaults()
Code: Select all
SInputShaderResourcesPtr pIsr = GetRenderer()->EF_CreateInputShaderResource();
pIsr->m_LMaterial.m_Opacity = 1;
pIsr->m_LMaterial.m_Diffuse.set(1, 1, 1, 1);
pIsr->m_Textures[EFTT_DIFFUSE].m_Name = szReplaceMe;
SShaderItem si = GetRenderer()->EF_LoadShaderItem(shader_name, true, 0, pIsr);
if (si.m_pShaderResources)
si.m_pShaderResources->SetMaterialName(mat_name);
mi->AssignShaderItem(si);
IEntity::SetOpacity(float fAmount)
Re: Modify Material opacity via C++ code
#15Okay, I did further tests and got the following results.
1. "diffuse" modifications do work without problems
2. "opacity" modifications DO WORK ->ONLY<- if the transparency does not reach 1.f
So with a material which opacity value is < 1 by default can be modifed to all values. But as soon as I set the opacity parameter to 1.f once, it never can get transparent again.
I started at 0.5, and switched it between 0.1 and 0.9. After switching to 1.f which removed transparency, it never was able to go back to values beneath 1.f.
The described behavior does occur when using this function:
The above one does not work at all. No matter what I set as value, he does set transparency to 1.f all the time.
Not sure why this happens. I need both states but maybe I just have to write my own shader for it.
1. "diffuse" modifications do work without problems
2. "opacity" modifications DO WORK ->ONLY<- if the transparency does not reach 1.f
So with a material which opacity value is < 1 by default can be modifed to all values. But as soon as I set the opacity parameter to 1.f once, it never can get transparent again.
I started at 0.5, and switched it between 0.1 and 0.9. After switching to 1.f which removed transparency, it never was able to go back to values beneath 1.f.
The described behavior does occur when using this function:
Code: Select all
pMat->SetGetMaterialParamFloat("opacity", m_fTransparentValue, false);
Code: Select all
GetEntity()->SetOpacity(0.1f);
Not sure why this happens. I need both states but maybe I just have to write my own shader for it.
Last edited by savi on Thu Jul 20, 2017 4:43 pm, edited 2 times in total.
Re: Modify Material opacity via C++ code
#16Not sure, but I think this is something that Crytek should get informed about.
Cryengine tutorial videos on my Youtube channel! Check it out !
https://www.youtube.com/user/MusicForLifePL20
https://www.youtube.com/user/MusicForLifePL20
Re: Modify Material opacity via C++ code
#17It would be nice if you guys could repeat this test by your own. I may have a dumb error somehow but if you would get the same results, we could assume with greater chance that this is really a bug.
Re: Modify Material opacity via C++ code
#18After all this time I can put the answer to this thread. Thanks @Cry-Flare for providing that solution. This can be used as a workaround due issues in the engines shader/texture/flags handling. It is not meant as final solution, is not that much tested and therefore really just acts as a temporary unofficial workaround until the issues gets resolved on the engine side.
Also it could cause crashes when there is no normal map assigned.
Also it could cause crashes when there is no normal map assigned.
Code: Select all
void SetOpacity(const char * szEntityName, float fValue)
{
if (IEntity* pEntity = gEnv->pEntitySystem->FindEntityByName(szEntityName))
{
if (IRenderNode* pRenderNode = pEntity->GetRenderNode())
{
if (IMaterial* pMaterial = pRenderNode->GetMaterial())
{
const SShaderItem& oldShaderItem = pMaterial->GetShaderItem();
// Create new shader resources
SInputShaderResources* pInputShaderResources = gEnv->pRenderer->EF_CreateInputShaderResource(oldShaderItem.m_pShaderResources);
// Set material property
pInputShaderResources->m_LMaterial.m_Opacity = fValue;
// Refresh the shader item with the new resources
SShaderItem newShaderItem = gEnv->pRenderer->EF_LoadShaderItem(oldShaderItem.m_pShader->GetName(), false, oldShaderItem.m_pShader->GetFlags(), pInputShaderResources);
// Assign the new shader item to the material
pMaterial->AssignShaderItem(newShaderItem);
// Sync with render thread so we dont get any pop-in
gEnv->pRenderer->FlushRTCommands(true, true, true);
}
}
}
}
Re: Modify Material opacity via C++ code
#19I‘ve also tried this today. Seems as if the problem
is right the other way around now. Setting opacity to 1.f works fine but if I ever reach 0.f, the model will never get visible again (however the opacity value of the material still changes. I confirmed this by getting the value and logging it. But the model will stay fully transparent if opacity ever reached 0.f).
- Jannis
is right the other way around now. Setting opacity to 1.f works fine but if I ever reach 0.f, the model will never get visible again (however the opacity value of the material still changes. I confirmed this by getting the value and logging it. But the model will stay fully transparent if opacity ever reached 0.f).
- Jannis