From 8a4493b4d3076a25b20d159b388cd82ecfc3895e Mon Sep 17 00:00:00 2001 From: ahcorde Date: Tue, 22 Dec 2020 22:35:44 +0100 Subject: [PATCH] Added render order to material Signed-off-by: ahcorde --- include/ignition/rendering/Material.hh | 11 ++++++++ .../ignition/rendering/base/BaseMaterial.hh | 26 +++++++++++++++++++ .../ignition/rendering/ogre/OgreMaterial.hh | 6 +++++ ogre/src/OgreMaterial.cc | 13 ++++++++++ .../ignition/rendering/ogre2/Ogre2Material.hh | 6 +++++ ogre2/src/Ogre2Material.cc | 16 ++++++++++++ 6 files changed, 78 insertions(+) diff --git a/include/ignition/rendering/Material.hh b/include/ignition/rendering/Material.hh index b74c82774..eab0dee94 100644 --- a/include/ignition/rendering/Material.hh +++ b/include/ignition/rendering/Material.hh @@ -301,6 +301,17 @@ namespace ignition /// \brief Removes any emissive map mapped to this material public: virtual void ClearEmissiveMap() = 0; + /// \brief Set the render order. When polygons are coplanar, you can get + /// problems with 'depth fighting' where the pixels from the two polys + /// compete for the same screen pixel. This param help to avoid this + /// problem. + /// \param[in] _renderOrder Render order to set to + public: virtual void SetRenderOrder(const float _renderOrder) = 0; + + /// \brief Get the render order value of this material. + /// \return Material render order + public: virtual float RenderOrder() const = 0; + /// \brief Set the roughness value. Only affects material of type MT_PBS /// \param[in] _roughness Roughness to set to public: virtual void SetRoughness(const float _roughness) = 0; diff --git a/include/ignition/rendering/base/BaseMaterial.hh b/include/ignition/rendering/base/BaseMaterial.hh index f77200659..4494a6559 100644 --- a/include/ignition/rendering/base/BaseMaterial.hh +++ b/include/ignition/rendering/base/BaseMaterial.hh @@ -232,6 +232,12 @@ namespace ignition // Documentation inherited public: virtual void ClearEmissiveMap() override; + // Documentation inherited + public: virtual void SetRenderOrder(const float _renderOrder) override; + + // Documentation inherited + public: virtual float RenderOrder() const override; + // Documentation inherited public: virtual void SetRoughness(const float _roughness) override; @@ -322,6 +328,9 @@ namespace ignition /// \brief Enable two sided rendering protected: bool twoSidedEnabled = false; + /// \brief Material render order + protected: double renderOrder = 0.0; + /// \brief Shininess factor protected: double shininess = 0.0; @@ -513,6 +522,13 @@ namespace ignition this->receiveShadows = _receive; } + ////////////////////////////////////////////////// + template + void BaseMaterial::SetRenderOrder(const float _renderorder) + { + this->renderOrder = _renderorder; + } + ////////////////////////////////////////////////// template math::Color BaseMaterial::Ambient() const @@ -555,6 +571,13 @@ namespace ignition return this->transparency; } + ////////////////////////////////////////////////// + template + float BaseMaterial::RenderOrder() const + { + return this->renderOrder; + } + ////////////////////////////////////////////////// template double BaseMaterial::Reflectivity() const @@ -872,6 +895,7 @@ namespace ignition this->SetDiffuse(_material->Diffuse()); this->SetSpecular(_material->Specular()); this->SetEmissive(_material->Emissive()); + this->SetRenderOrder(_material->RenderOrder()); this->SetShininess(_material->Shininess()); this->SetTransparency(_material->Transparency()); this->SetAlphaFromTexture(_material->TextureAlphaEnabled(), @@ -910,6 +934,7 @@ namespace ignition this->SetAlphaFromTexture(_material.TextureAlphaEnabled(), _material.AlphaThreshold(), _material.TwoSidedEnabled()); // TODO(anyone): update common::Material + this->SetRenderOrder(_material.RenderOrder()); this->SetReflectivity(0); this->SetTexture(_material.TextureImage()); // TODO(anyone): update common::Material @@ -961,6 +986,7 @@ namespace ignition this->SetDiffuse(1.0, 1.0, 1.0); this->SetSpecular(0.2, 0.2, 0.2); this->SetEmissive(0, 0, 0); + this->SetRenderOrder(0); this->SetShininess(1.5); this->SetTransparency(0); this->SetReflectivity(0); diff --git a/ogre/include/ignition/rendering/ogre/OgreMaterial.hh b/ogre/include/ignition/rendering/ogre/OgreMaterial.hh index 1e14fe3ef..9f56aea64 100644 --- a/ogre/include/ignition/rendering/ogre/OgreMaterial.hh +++ b/ogre/include/ignition/rendering/ogre/OgreMaterial.hh @@ -103,6 +103,12 @@ namespace ignition public: virtual void SetReceiveShadows(const bool _receiveShadows) override; + // Documentation inherited + public: virtual float RenderOrder() const override; + + // Documentation inherited + public: virtual void SetRenderOrder(const float _enabled) override; + public: virtual bool ReflectionEnabled() const override; public: virtual void SetReflectionEnabled(const bool _enabled) override; diff --git a/ogre/src/OgreMaterial.cc b/ogre/src/OgreMaterial.cc index a92132791..7bb90d0c4 100644 --- a/ogre/src/OgreMaterial.cc +++ b/ogre/src/OgreMaterial.cc @@ -156,6 +156,19 @@ void OgreMaterial::SetEmissive(const math::Color &_color) #endif } +////////////////////////////////////////////////// +float OgreMaterial::RenderOrder() const +{ + return this->renderOrder; +} + +////////////////////////////////////////////////// +void OgreMaterial::SetRenderOrder(const float _renderOrder) +{ + this->renderOrder = _renderOrder; + this->ogrePass->setDepthBias(this->renderOrder); +} + ////////////////////////////////////////////////// double OgreMaterial::Shininess() const { diff --git a/ogre2/include/ignition/rendering/ogre2/Ogre2Material.hh b/ogre2/include/ignition/rendering/ogre2/Ogre2Material.hh index 56258eceb..f0cf01940 100644 --- a/ogre2/include/ignition/rendering/ogre2/Ogre2Material.hh +++ b/ogre2/include/ignition/rendering/ogre2/Ogre2Material.hh @@ -71,6 +71,12 @@ namespace ignition public: virtual void SetAlphaFromTexture(bool _enabled, double _alpha = 0.5, bool _twoSided = true) override; + // Documentation inherited + public: virtual float RenderOrder() const override; + + // Documentation inherited + public: virtual void SetRenderOrder(const float _enabled) override; + // Documentation inherited public: virtual bool ReceiveShadows() const override; diff --git a/ogre2/src/Ogre2Material.cc b/ogre2/src/Ogre2Material.cc index ce9a968a0..e8f83acd6 100644 --- a/ogre2/src/Ogre2Material.cc +++ b/ogre2/src/Ogre2Material.cc @@ -167,6 +167,22 @@ void Ogre2Material::SetAlphaFromTexture(bool _enabled, this->ogreDatablock->setTwoSidedLighting(_twoSided); } +////////////////////////////////////////////////// +float Ogre2Material::RenderOrder() const +{ + return this->renderOrder; +} + +////////////////////////////////////////////////// +void Ogre2Material::SetRenderOrder(const float _renderOrder) +{ + this->renderOrder = _renderOrder; + Ogre::HlmsMacroblock macroblock( + *this->ogreDatablock->getMacroblock()); + macroblock.mDepthBiasConstant = _renderOrder; + this->ogreDatablock->setMacroblock(macroblock); +} + ////////////////////////////////////////////////// bool Ogre2Material::ReceiveShadows() const {