Skip to content

Commit

Permalink
[engine] fix culling when material is singleSided
Browse files Browse the repository at this point in the history
  • Loading branch information
MathiasPaulin committed Aug 29, 2023
1 parent bf49105 commit 9d9684d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Engine/Data/GLTFMaterial.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ class RA_ENGINE_API GLTFMaterial : public Material, public ParameterSetEditingIn
float getAlphaCutoff() const { return m_alphaCutoff; }
void setAlphaCutoff( float alphaCutoff ) { m_alphaCutoff = alphaCutoff; }

bool isDoubleSided() const { return m_doubleSided; }
bool isDoubleSided() const override { return m_doubleSided; }
void setDoubleSided( bool doubleSided ) { m_doubleSided = doubleSided; }

float getIndexOfRefraction() const { return m_indexOfRefraction; }
Expand Down
5 changes: 5 additions & 0 deletions src/Engine/Data/Material.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ class RA_ENGINE_API Material : public Data::ShaderParameterProvider
*/
virtual bool isTransparent() const;

/** Test if material is transperent.
* @return true if the material is transparent
*/
virtual bool isDoubleSided() const { return true; }

/**
* Get the list of properties the material migh use in a shader.
* each property will be added to the shader used for rendering this material under the form
Expand Down
4 changes: 4 additions & 0 deletions src/Engine/Rendering/RenderObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,11 @@ void RenderObject::render( const Data::RenderParameters& lightParams,
// Note that this hack implies the inclusion of OpenGL.h in this file
if ( viewParams.viewMatrix.determinant() < 0 ) { glFrontFace( GL_CW ); }
else { glFrontFace( GL_CCW ); }
// To enable correct culling when required (e.g. by gltf material)
GLboolean cullEnable = glIsEnabled( GL_CULL_FACE );
if ( !m_material->isDoubleSided() ) { glEnable( GL_CULL_FACE ); }
m_mesh->render( shader );
if ( !cullEnable ) glDisable( GL_CULL_FACE );
}

void RenderObject::render( const Data::RenderParameters& lightParams,
Expand Down

0 comments on commit 9d9684d

Please sign in to comment.