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

opacity handling hacks

This commit is contained in:
milek7
2022-03-07 20:32:51 +01:00
parent 364d7630c9
commit 520342f6f0
4 changed files with 35 additions and 78 deletions

View File

@@ -206,19 +206,21 @@ material_data::assign( std::string const &Replacableskin ) {
replacable_skins[ 1 ] = GfxRenderer->Fetch_Material( Replacableskin );
}
// BUGS! it's not entierly designed whether opacity is property of material or submodel,
// and code does confusing things with this in various places
textures_alpha = (
GfxRenderer->Material( replacable_skins[ 1 ] ).is_translucent() ?
GfxRenderer->Material( replacable_skins[ 1 ] ).get_or_guess_opacity() == 0.0f ?
0x31310031 : // tekstura -1 z kanałem alfa - nie renderować w cyklu nieprzezroczystych
0x30300030 ); // wszystkie tekstury nieprzezroczyste - nie renderować w cyklu przezroczystych
if( GfxRenderer->Material( replacable_skins[ 2 ] ).is_translucent() ) {
if( GfxRenderer->Material( replacable_skins[ 2 ] ).get_or_guess_opacity() == 0.0f ) {
// tekstura -2 z kanałem alfa - nie renderować w cyklu nieprzezroczystych
textures_alpha |= 0x02020002;
}
if( GfxRenderer->Material( replacable_skins[ 3 ] ).is_translucent() ) {
if( GfxRenderer->Material( replacable_skins[ 3 ] ).get_or_guess_opacity() == 0.0f ) {
// tekstura -3 z kanałem alfa - nie renderować w cyklu nieprzezroczystych
textures_alpha |= 0x04040004;
}
if( GfxRenderer->Material( replacable_skins[ 4 ] ).is_translucent() ) {
if( GfxRenderer->Material( replacable_skins[ 4 ] ).get_or_guess_opacity() == 0.0f ) {
// tekstura -4 z kanałem alfa - nie renderować w cyklu nieprzezroczystych
textures_alpha |= 0x08080008;
}

View File

@@ -418,39 +418,6 @@ std::pair<int, int> TSubModel::Load( cParser &parser, bool dynamic )
iFlags |= 0x10;
}
if (m_material > 0)
{
opengl_material const &mat = GfxRenderer->Material(m_material);
/*
if( eType == TP_FREESPOTLIGHT ) {
iFlags &= ~0x30;
iFlags |= 0x20;
}
else
*/
{
// if material has opacity set, replace submodel opacity with it
// NOTE: reverted to use base opacity, this allows to define opacity threshold in material
// without it causing the translucent models to become opaque
auto const opacity { (
/*
false == std::isnan( mat.opacity ) ?
mat.opacity :
*/
Opacity ) };
iFlags &= ~0x30;
iFlags |= (
( ( opacity < 0.01f )
&& ( GfxRenderer->Material( m_material ).is_translucent() ) ) ?
0x20 :
0x10 ); // 0x10-nieprzezroczysta, 0x20-przezroczysta
}
// and same thing with selfillum
if( mat.selfillum ) {
fLight = mat.selfillum.value();
}
}
if (m_material > 0)
{
const opengl_material &mat = GfxRenderer->Material(m_material);
@@ -1624,7 +1591,10 @@ void TSubModel::serialize(std::ostream &s,
sn_utils::ls_int32(s, (int32_t)get_container_pos(names, pName));
sn_utils::ls_int32(s, (int)b_Anim);
sn_utils::ls_uint32(s, iFlags);
uint32_t flags = iFlags;
if (m_material > 0 && (Global.iConvertModels & 16))
flags &= ~0x30; // don't save phase information, will be guessed on binary load from material
sn_utils::ls_uint32(s, flags);
sn_utils::ls_int32(s, (int32_t)get_container_pos(transforms, *fMatrix));
sn_utils::ls_int32( s, m_geometry.vertex_count );
@@ -2073,12 +2043,7 @@ void TSubModel::BinInit(TSubModel *s, float4x4 *m, std::vector<std::string> *t,
if (!(iFlags & 0x30) && m_material != null_handle)
{
const opengl_material &mat = GfxRenderer->Material(m_material);
float opacity;
if (mat.opacity)
opacity = *mat.opacity;
// if material don't have opacity set, try to guess it
else
opacity = mat.get_or_guess_opacity();
float opacity = mat.get_or_guess_opacity();
// set phase flag based on material opacity
if (opacity == 0.0f)

View File

@@ -443,16 +443,7 @@ float opengl_material::get_or_guess_opacity() const {
return 0.5f;
}
return 0.0f;
}
bool
opengl_material::is_translucent() const {
return (
textures[ 0 ] != null_handle ?
GfxRenderer->Texture( textures[ 0 ] ).has_alpha :
false );
return 0.5f;
}
// create material object from data stored in specified file.

View File

@@ -41,7 +41,6 @@ struct opengl_material {
void finalize(bool Loadnow);
bool update();
float get_or_guess_opacity() const;
bool is_translucent() const;
// members
static struct path_data {
std::unordered_map<std::string, int> index_map;