16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-20 06:49:19 +02:00

opacity bugfix

This commit is contained in:
milek7
2018-07-17 17:45:06 +02:00
parent a29379ed8b
commit 61bbfe667b
10 changed files with 101 additions and 58 deletions

View File

@@ -309,27 +309,27 @@ int TSubModel::Load( cParser &parser, TModel3d *Model, /*int Pos,*/ bool dynamic
else if (material.find("replacableskin") != material.npos)
{ // McZapkie-060702: zmienialne skory modelu
m_material = -1;
iFlags |= (Opacity == 1.0f) ? 1 : 0x10; // zmienna tekstura 1
iFlags |= (Opacity < 1.0) ? 1 : 0x10; // zmienna tekstura 1
}
else if (material == "-1")
{
m_material = -1;
iFlags |= (Opacity == 1.0f) ? 1 : 0x10; // zmienna tekstura 1
iFlags |= (Opacity < 1.0) ? 1 : 0x10; // zmienna tekstura 1
}
else if (material == "-2")
{
m_material = -2;
iFlags |= (Opacity == 1.0f) ? 2 : 0x10; // zmienna tekstura 2
iFlags |= (Opacity < 1.0) ? 2 : 0x10; // zmienna tekstura 2
}
else if (material == "-3")
{
m_material = -3;
iFlags |= (Opacity == 1.0f) ? 4 : 0x10; // zmienna tekstura 3
iFlags |= (Opacity < 1.0) ? 4 : 0x10; // zmienna tekstura 3
}
else if (material == "-4")
{
m_material = -4;
iFlags |= (Opacity == 1.0f) ? 8 : 0x10; // zmienna tekstura 4
iFlags |= (Opacity < 1.0) ? 8 : 0x10; // zmienna tekstura 4
}
else {
Name_Material(material);
@@ -341,14 +341,8 @@ int TSubModel::Load( cParser &parser, TModel3d *Model, /*int Pos,*/ bool dynamic
*/
m_material = GfxRenderer.Fetch_Material( material );
// renderowanie w cyklu przezroczystych tylko jeśli:
// 1. Opacity=0 (przejściowo <1, czy tam <100) oraz
// 2. tekstura ma przezroczystość
iFlags |=
( ( ( Opacity == 0.0f )
&& ( ( m_material != null_handle )
&& ( GfxRenderer.Material( m_material ).opacity == 0.0f ) ) ) ?
0x20 :
0x10 ); // 0x10-nieprzezroczysta, 0x20-przezroczysta
// 1. Opacity=0 (przejściowo <1, czy tam <100)
iFlags |= Opacity < 1.0f ? 0x20 : 0x10 ; // 0x20-przezroczysta, 0x10-nieprzezroczysta
};
}
else if (eType == TP_STARS)
@@ -359,6 +353,27 @@ int TSubModel::Load( cParser &parser, TModel3d *Model, /*int Pos,*/ bool dynamic
else
iFlags |= 0x10;
if (m_material != null_handle)
{
opengl_material &mat = GfxRenderer.Material(m_material);
// if material don't have opacity set, set legacy submodel opacity
if (std::isnan(mat.opacity))
{
if (iFlags & 0x20) // translucent
mat.opacity = 0.0f;
else if (iFlags & 0x10) // opaque
mat.opacity = 0.5f;
}
else // but if it does, replace submodel opacity with material one
{
iFlags &= ~0x30;
if (mat.opacity == 0.0f)
iFlags |= 0x20; // translucent
else
iFlags |= 0x10; // opaque
}
}
// visibility range
std::string discard;
parser.getTokens(5, false);
@@ -1683,13 +1698,20 @@ void TSubModel::BinInit(TSubModel *s, float4x4 *m, std::vector<std::string> *t,
}
*/
m_material = GfxRenderer.Fetch_Material( m_materialname );
if( ( iFlags & 0x30 ) == 0 ) {
// texture-alpha based fallback if for some reason we don't have opacity flag set yet
iFlags |= (
( ( m_material != null_handle )
&& ( GfxRenderer.Material( m_material ).opacity == 0.0f ) ) ?
0x20 :
0x10 ); // 0x10-nieprzezroczysta, 0x20-przezroczysta
// if we don't have phase flags set for some reason, try to fix it
if (!(iFlags & 0x30) && m_material != null_handle)
{
opengl_material &mat = GfxRenderer.Material(m_material);
if (std::isnan(mat.opacity))
// if material don't have opacity set, try to guess it
mat.opacity = mat.get_or_guess_opacity();
// set phase flag based on material opacity
if (mat.opacity == 0.0f)
iFlags |= 0x20; // translucent
else
iFlags |= 0x10; // opaque
}
}
else {