diff --git a/include/EMaterialFlags.h b/include/EMaterialFlags.h index 4cb07673..6596b312 100644 --- a/include/EMaterialFlags.h +++ b/include/EMaterialFlags.h @@ -32,9 +32,12 @@ namespace video //! This flag is ignored, if the material type is a transparent type. EMF_ZWRITE_ENABLE, - //! Is backfaceculling enabled? Default: true + //! Is backface culling enabled? Default: true EMF_BACK_FACE_CULLING, + //! Is frontface culling enabled? Default: false + EMF_FRONT_FACE_CULLING, + //! Is bilinear filtering enabled? Default: true EMF_BILINEAR_FILTER, diff --git a/include/SMaterial.h b/include/SMaterial.h index c618fef8..d9dbda3b 100644 --- a/include/SMaterial.h +++ b/include/SMaterial.h @@ -71,7 +71,7 @@ namespace video EmissiveColor(0,0,0,0), SpecularColor(255,255,255,255), Shininess(0.0f), MaterialTypeParam(0.0f), MaterialTypeParam2(0.0f), Thickness(1.0f), Wireframe(false), PointCloud(false), GouraudShading(true), Lighting(true), - ZWriteEnable(true), BackfaceCulling(true), + ZWriteEnable(true), BackfaceCulling(true), FrontfaceCulling(false), FogEnable(false), NormalizeNormals(false), ZBuffer(1) { } @@ -108,6 +108,7 @@ namespace video Lighting = other.Lighting; ZWriteEnable = other.ZWriteEnable; BackfaceCulling = other.BackfaceCulling; + FrontfaceCulling = other.FrontfaceCulling; FogEnable = other.FogEnable; NormalizeNormals = other.NormalizeNormals; ZBuffer = other.ZBuffer; @@ -204,6 +205,9 @@ namespace video //! Is backface culling enabled? Default: true bool BackfaceCulling; + //! Is frontface culling enabled? Default: false + bool FrontfaceCulling; + //! Is fog enabled? Default: false bool FogEnable; @@ -271,6 +275,8 @@ namespace video ZWriteEnable = value; break; case EMF_BACK_FACE_CULLING: BackfaceCulling = value; break; + case EMF_FRONT_FACE_CULLING: + FrontfaceCulling = value; break; case EMF_BILINEAR_FILTER: { for (u32 i=0; iSetRenderState( D3DRS_CULLMODE, D3DCULL_CCW); + if (material.FrontfaceCulling && material.BackfaceCulling) + pID3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW|D3DCULL_CCW); else - pID3DDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE); + if (material.FrontfaceCulling) + pID3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW); + else + if (material.BackfaceCulling) + pID3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW); + else + pID3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); } // fog diff --git a/source/Irrlicht/CD3D9Driver.cpp b/source/Irrlicht/CD3D9Driver.cpp index c4847ddf..369732e1 100644 --- a/source/Irrlicht/CD3D9Driver.cpp +++ b/source/Irrlicht/CD3D9Driver.cpp @@ -1318,12 +1318,18 @@ void CD3D9Driver::setBasicRenderStates(const SMaterial& material, const SMateria // back face culling - if (resetAllRenderstates || lastmaterial.BackfaceCulling != material.BackfaceCulling) + if (resetAllRenderstates || (lastmaterial.FrontfaceCulling != material.FrontfaceCulling) || (lastmaterial.BackfaceCulling != material.BackfaceCulling)) { - if (material.BackfaceCulling) - pID3DDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_CCW); + if (material.FrontfaceCulling && material.BackfaceCulling) + pID3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW|D3DCULL_CCW); else - pID3DDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE); + if (material.FrontfaceCulling) + pID3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW); + else + if (material.BackfaceCulling) + pID3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW); + else + pID3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); } // fog diff --git a/source/Irrlicht/CNullDriver.cpp b/source/Irrlicht/CNullDriver.cpp index 7d848bdc..5dc55ca4 100644 --- a/source/Irrlicht/CNullDriver.cpp +++ b/source/Irrlicht/CNullDriver.cpp @@ -1399,6 +1399,7 @@ io::IAttributes* CNullDriver::createAttributesFromMaterial(const video::SMateria attr->addBool("ZWriteEnable", material.ZWriteEnable); attr->addInt("ZBuffer", material.ZBuffer); attr->addBool("BackfaceCulling", material.BackfaceCulling); + attr->addBool("FrontfaceCulling", material.FrontfaceCulling); attr->addBool("FogEnable", material.FogEnable); attr->addBool("NormalizeNormals", material.NormalizeNormals); @@ -1454,6 +1455,7 @@ void CNullDriver::fillMaterialStructureFromAttributes(video::SMaterial& outMater outMaterial.ZWriteEnable = attr->getAttributeAsBool("ZWriteEnable"); outMaterial.ZBuffer = attr->getAttributeAsInt("ZBuffer"); outMaterial.BackfaceCulling = attr->getAttributeAsBool("BackfaceCulling"); + outMaterial.FrontfaceCulling = attr->getAttributeAsBool("FrontfaceCulling"); outMaterial.FogEnable = attr->getAttributeAsBool("FogEnable"); outMaterial.NormalizeNormals = attr->getAttributeAsBool("NormalizeNormals"); prefix = "BilinearFilter"; diff --git a/source/Irrlicht/COpenGLDriver.cpp b/source/Irrlicht/COpenGLDriver.cpp index 8ba82e90..ea2ea323 100644 --- a/source/Irrlicht/COpenGLDriver.cpp +++ b/source/Irrlicht/COpenGLDriver.cpp @@ -1685,8 +1685,23 @@ void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMater // back face culling if (resetAllRenderStates || lastmaterial.BackfaceCulling != material.BackfaceCulling) { - if (material.BackfaceCulling) + if ((material.FrontfaceCulling) && (material.BackfaceCulling)) + { + glCullFace(GL_FRONT_AND_BACK); glEnable(GL_CULL_FACE); + } + else + if (material.BackfaceCulling) + { + glCullFace(GL_BACK); + glEnable(GL_CULL_FACE); + } + else + if (material.FrontfaceCulling) + { + glCullFace(GL_FRONT); + glEnable(GL_CULL_FACE); + } else glDisable(GL_CULL_FACE); }