Skip to content

Commit

Permalink
Added render order to material
Browse files Browse the repository at this point in the history
Signed-off-by: ahcorde <[email protected]>
  • Loading branch information
ahcorde committed Dec 23, 2020
1 parent d4406e1 commit 8a4493b
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 0 deletions.
11 changes: 11 additions & 0 deletions include/ignition/rendering/Material.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
26 changes: 26 additions & 0 deletions include/ignition/rendering/base/BaseMaterial.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -513,6 +522,13 @@ namespace ignition
this->receiveShadows = _receive;
}

//////////////////////////////////////////////////
template <class T>
void BaseMaterial<T>::SetRenderOrder(const float _renderorder)
{
this->renderOrder = _renderorder;
}

//////////////////////////////////////////////////
template <class T>
math::Color BaseMaterial<T>::Ambient() const
Expand Down Expand Up @@ -555,6 +571,13 @@ namespace ignition
return this->transparency;
}

//////////////////////////////////////////////////
template <class T>
float BaseMaterial<T>::RenderOrder() const
{
return this->renderOrder;
}

//////////////////////////////////////////////////
template <class T>
double BaseMaterial<T>::Reflectivity() const
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions ogre/include/ignition/rendering/ogre/OgreMaterial.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 13 additions & 0 deletions ogre/src/OgreMaterial.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
6 changes: 6 additions & 0 deletions ogre2/include/ignition/rendering/ogre2/Ogre2Material.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
16 changes: 16 additions & 0 deletions ogre2/src/Ogre2Material.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit 8a4493b

Please sign in to comment.