From d47faaaa890827f6f070b1498f91cbad76b1f55b Mon Sep 17 00:00:00 2001 From: Marianne Gagnon Date: Mon, 5 Oct 2015 19:22:08 -0400 Subject: [PATCH] Fix billboard text --- src/graphics/material.hpp | 1 + src/graphics/material_manager.cpp | 84 +++++++++++++------------------ src/graphics/material_manager.hpp | 6 ++- 3 files changed, 40 insertions(+), 51 deletions(-) diff --git a/src/graphics/material.hpp b/src/graphics/material.hpp index cea48fd6a..c1b5fec10 100644 --- a/src/graphics/material.hpp +++ b/src/graphics/material.hpp @@ -377,6 +377,7 @@ public: float getZipperMinSpeed() const { return m_zipper_min_speed; } // ------------------------------------------------------------------------ ShaderType getShaderType() const { return m_shader_type; } + void setShaderType(ShaderType st) { m_shader_type = st; } // ------------------------------------------------------------------------ /** True if this texture should have the U coordinates mirrored. */ char getMirrorAxisInReverse() const { return m_mirror_axis_when_reverse; } diff --git a/src/graphics/material_manager.cpp b/src/graphics/material_manager.cpp index 7d63ce869..2f012be7e 100644 --- a/src/graphics/material_manager.cpp +++ b/src/graphics/material_manager.cpp @@ -24,6 +24,7 @@ #include "config/user_config.hpp" #include "graphics/material.hpp" +#include "graphics/shaders.hpp" #include "io/file_manager.hpp" #include "io/xml_node.hpp" #include "modes/world.hpp" @@ -40,7 +41,6 @@ MaterialManager::MaterialManager() { /* Create list - and default material zero */ - m_default_material = NULL; m_materials.reserve(256); // We can't call init/loadMaterial here, since the global variable // material_manager has not yet been initialised, and @@ -67,7 +67,7 @@ Material* MaterialManager::getMaterialFor(video::ITexture* t, scene::IMeshBuffer *mb) { if (t == NULL) - return m_default_material; + return getDefaultMaterial(mb->getMaterial().MaterialType); core::stringc img_path = core::stringc(t->getName()); const std::string image = StringUtils::getBasename(img_path.c_str()); @@ -92,7 +92,8 @@ Material* MaterialManager::getMaterialFor(video::ITexture* t, } } // for i } - return m_default_material; + + return getDefaultMaterial(mb->getMaterial().MaterialType); } //----------------------------------------------------------------------------- @@ -111,53 +112,39 @@ void MaterialManager::setAllMaterialFlags(video::ITexture* t, return; } - if (m_default_material == NULL) - m_default_material = new Material("", false, false, false); - m_default_material->setMaterialProperties(&(mb->getMaterial()), mb); - - /* - // This material does not appear in materials.xml. Set some common flags... - if (UserConfigParams::m_anisotropic > 0) - { - for (u32 i=0; igetMaterial().TextureLayer[i].AnisotropicFilter = - UserConfigParams::m_anisotropic; - } - } - else if (UserConfigParams::m_trilinear) - { - mb->getMaterial().setFlag(video::EMF_TRILINEAR_FILTER, true); - } - - mb->getMaterial().ColorMaterial = video::ECM_DIFFUSE_AND_AMBIENT; - - if (World::getWorld() != NULL) - { - mb->getMaterial().FogEnable = World::getWorld()->isFogEnabled(); - } - - - // Modify lightmap materials so that vertex colors are taken into account. - // But disable lighting because we assume all lighting is already part - // of the lightmap - if (mb->getMaterial().MaterialType == video::EMT_LIGHTMAP) - { - mb->getMaterial().MaterialType = video::EMT_LIGHTMAP_LIGHTING; - mb->getMaterial().AmbientColor = video::SColor(255, 255, 255, 255); - mb->getMaterial().DiffuseColor = video::SColor(255, 255, 255, 255); - mb->getMaterial().EmissiveColor = video::SColor(255, 255, 255, 255); - mb->getMaterial().SpecularColor = video::SColor(255, 255, 255, 255); - } - - - //if (UserConfigParams::m_fullscreen_antialiasing) - // mb->getMaterial().AntiAliasing = video::EAAM_LINE_SMOOTH; - */ + Material* default_material = getDefaultMaterial(mb->getMaterial().MaterialType); + default_material->setMaterialProperties(&(mb->getMaterial()), mb); } // setAllMaterialFlags //----------------------------------------------------------------------------- +Material* MaterialManager::getDefaultMaterial(video::E_MATERIAL_TYPE shader_type) +{ + auto it = m_default_materials.find(shader_type); + if (it == m_default_materials.end()) + { + Material* default_material = new Material("", false, false, false); + + // TODO: workaround, should not hardcode these material types here? + // Try to find a cleaner way + if (shader_type == Shaders::getShader(ShaderType::ES_OBJECT_UNLIT)) + default_material->setShaderType(Material::SHADERTYPE_SOLID_UNLIT); + else if (shader_type == Shaders::getShader(ShaderType::ES_OBJECTPASS_REF)) + default_material->setShaderType(Material::SHADERTYPE_ALPHA_TEST); + else if (shader_type == Shaders::getShader(ShaderType::ES_OBJECTPASS)) + default_material->setShaderType(Material::SHADERTYPE_ALPHA_BLEND); + + m_default_materials[shader_type] = default_material; + return default_material; + } + else + { + return it->second; + } +} + +//----------------------------------------------------------------------------- + void MaterialManager::adjustForFog(video::ITexture* t, scene::IMeshBuffer *mb, scene::ISceneNode* parent, @@ -191,9 +178,8 @@ void MaterialManager::setAllUntexturedMaterialFlags(scene::IMeshBuffer *mb) material.MaterialType = irr::video::EMT_SOLID; } - if (m_default_material == NULL) - m_default_material = new Material("", false, false, false); - m_default_material->setMaterialProperties(&(mb->getMaterial()), mb); + Material* default_material = getDefaultMaterial(mb->getMaterial().MaterialType); + default_material->setMaterialProperties(&(mb->getMaterial()), mb); } //----------------------------------------------------------------------------- int MaterialManager::addEntity(Material *m) diff --git a/src/graphics/material_manager.hpp b/src/graphics/material_manager.hpp index d791c9dcb..fc95bc02f 100644 --- a/src/graphics/material_manager.hpp +++ b/src/graphics/material_manager.hpp @@ -24,13 +24,14 @@ namespace irr { - namespace video { class ITexture; } + namespace video { class ITexture; enum E_MATERIAL_TYPE; } namespace scene { class IMeshBuffer; class ISceneNode; } } using namespace irr; #include #include +#include class Material; class XMLReader; @@ -48,7 +49,8 @@ private: std::vector m_materials; - Material* m_default_material; + std::map m_default_materials; + Material* getDefaultMaterial(video::E_MATERIAL_TYPE material_type); public: MaterialManager();