From 6e9041a2147a0c41c93a88decdc597a490204f7b Mon Sep 17 00:00:00 2001 From: milek7 Date: Mon, 7 Mar 2022 20:36:36 +0100 Subject: [PATCH] opacity handling hacks (part 2) --- Model3d.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/Model3d.cpp b/Model3d.cpp index 88ef89c4..1dbeef03 100644 --- a/Model3d.cpp +++ b/Model3d.cpp @@ -422,7 +422,7 @@ std::pair TSubModel::Load( cParser &parser, bool dynamic ) { const opengl_material &mat = GfxRenderer->Material(m_material); - // if material have opacity set, replace submodel opacity with it + // if material does have opacity set, replace submodel opacity with it if (mat.opacity) { iFlags &= ~0x30; @@ -579,7 +579,7 @@ std::pair TSubModel::Load( cParser &parser, bool dynamic ) >> vertex->texture.s >> vertex->texture.t; - if (idx % 3 == 2) { + if (idx % 3 == 2) { // jeżeli wczytano 3 punkty if( true == degenerate( vertex->position, (vertex - 1)->position, (vertex - 2)->position ) ) { // jeżeli punkty się nakładają na siebie @@ -618,7 +618,7 @@ std::pair TSubModel::Load( cParser &parser, bool dynamic ) glm::vec3() ); } glm::vec3 vertexnormal; // roboczy wektor normalny - for (int vertexidx = 0; vertexidx < m_geometry.vertex_count; ++vertexidx) { + for (int vertexidx = 0; vertexidx < m_geometry.vertex_count; ++vertexidx) { // pętla po wierzchołkach trójkątów auto vertex { vertices + vertexidx }; if( wsp[ vertexidx ] >= 0 ) { @@ -1357,7 +1357,7 @@ void TSubModel::ParentMatrix( float4x4 *m ) const { *m = *sm->Parent->GetMatrix() * *m; sm = sm->Parent; } -*/ +*/ }; void TSubModel::ReplaceMatrix(const glm::mat4 &mat) @@ -2051,11 +2051,21 @@ void TSubModel::BinInit(TSubModel *s, float4x4 *m, std::vector *t, else iFlags |= 0x10; // opaque } - + if ( m_material != null_handle ) { opengl_material const &mat = GfxRenderer->Material(m_material); + // if material does have opacity set, replace submodel opacity with it + if (mat.opacity) + { + iFlags &= ~0x30; + if (*mat.opacity == 0.0f) + iFlags |= 0x20; // translucent + else + iFlags |= 0x10; // opaque + } + // replace submodel selfillum with material one if( mat.selfillum ) { fLight = mat.selfillum.value(); @@ -2124,7 +2134,7 @@ void TSubModel::BinInit(TSubModel *s, float4x4 *m, std::vector *t, void TModel3d::LoadFromBinFile(std::string const &FileName, bool dynamic) { // wczytanie modelu z pliku binarnego WriteLog( "Loading binary format 3d model data from \"" + FileName + "\"...", logtype::model ); - + std::ifstream file(FileName, std::ios::binary); uint32_t type = sn_utils::ld_uint32(file); @@ -2191,7 +2201,7 @@ void TModel3d::LoadFromTextFile(std::string const &FileName, bool dynamic) m_vertexcount += result.second; } // będzie potrzebne do wyliczenia pozycji, np. pantografu - SubModel->Parent = AddToNamed(parent.c_str(), SubModel); + SubModel->Parent = AddToNamed(parent.c_str(), SubModel); parser.getTokens(); parser >> token;