From 303b931fb76685b3b8ed79611afc310f89763db9 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 1 Oct 2025 11:25:00 +0200 Subject: [PATCH] feat: opacity + shininess + illumination support --- include/model.h | 6 ++++++ src/model.cpp | 19 ++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/include/model.h b/include/model.h index aeab2dc..381ed54 100644 --- a/include/model.h +++ b/include/model.h @@ -64,6 +64,8 @@ private: glm::vec3 m_diffuse { 0.8f, 0.8f, 0.8f }; glm::vec3 m_specular { 1.0f, 1.0f, 1.0f }; float m_shininess { 32.0f }; + float m_opacity { 1.0f }; + int m_illum { 2 }; std::unique_ptr m_diffuse_tex { nullptr }; public: @@ -77,12 +79,16 @@ public: inline const float GetSpecularWeight() const { return m_shininess; } inline const bool HasDiffuseTexture() const { return m_diffuse_tex != nullptr; } inline const Texture* GetDiffuseTexture() const { return m_diffuse_tex.get(); } + inline const float GetOpacity() const { return m_opacity; } + inline const int GetIllumination() const { return m_illum; } public: inline void SetAmbientColor(glm::vec3 ambient) { m_ambient = ambient; } inline void SetDiffuseColor(glm::vec3 diffuse) { m_diffuse = diffuse; } inline void SetSpecularColor(glm::vec3 specular) { m_specular = specular; } inline void SetSpecularWeight(float weight) { m_shininess = weight; } inline void SetDiffuseTexture(std::unique_ptr&& texture) { m_diffuse_tex = std::move(texture); } + inline void SetOpacity(float opacity) { m_opacity = opacity; } + inline void SetIllumination(float illum) { m_illum = illum; } }; class Mesh { diff --git a/src/model.cpp b/src/model.cpp index c99cbbf..76bdd0f 100644 --- a/src/model.cpp +++ b/src/model.cpp @@ -142,6 +142,20 @@ void Object::LoadMaterials(const std::filesystem::path& filename) { currentMaterial->SetDiffuseColor(glm::vec3(r, g, b)); break; } + case MtlElement::D: + { + float d; + iss >> d; + currentMaterial->SetOpacity(d); + break; + } + case MtlElement::ILLUM: + { + int illum; + iss >> illum; + currentMaterial->SetIllumination(illum); + break; + } case MtlElement::MAP_KD: { std::string texturePath; @@ -325,7 +339,10 @@ void Object::Render(Shader& shader) auto material = GetMaterial(mesh.materialName); shader.setFloat("ambientStrength", 0.2f); - shader.setFloat("specularStrength", material->GetSpecularWeight()); + shader.setFloat("shininess", material->GetSpecularWeight()); + shader.setFloat("opacity", material->GetOpacity()); + shader.setBool("useSpecular", material->GetIllumination() >= 2); + shader.setFloat("specularStrength", 1.0f); shader.setVec3("ambientColor", material->GetAmbientColor()); shader.setVec3("diffuseColor", material->GetDiffuseColor()); shader.setVec3("specularColor", material->GetSpecularColor());