Added another material flag to enable front face culling. Can be useful for special effects.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@1308 dfc29bdd-3216-0410-991c-e03cc46cb475
master
hybrid 2008-04-04 08:48:22 +00:00
parent 1a45ab5d92
commit ec8f03d70e
6 changed files with 52 additions and 11 deletions

View File

@ -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,

View File

@ -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; i<MATERIAL_MAX_TEXTURES; ++i)
@ -323,6 +329,8 @@ namespace video
return ZWriteEnable;
case EMF_BACK_FACE_CULLING:
return BackfaceCulling;
case EMF_FRONT_FACE_CULLING:
return FrontfaceCulling;
case EMF_BILINEAR_FILTER:
return TextureLayer[0].BilinearFilter;
case EMF_TRILINEAR_FILTER:
@ -362,6 +370,7 @@ namespace video
ZBuffer != b.ZBuffer ||
ZWriteEnable != b.ZWriteEnable ||
BackfaceCulling != b.BackfaceCulling ||
FrontfaceCulling != b.FrontfaceCulling ||
FogEnable != b.FogEnable ||
NormalizeNormals != b.NormalizeNormals;
for (u32 i=0; (i<MATERIAL_MAX_TEXTURES) && !different; ++i)

View File

@ -1305,12 +1305,18 @@ void CD3D8Driver::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

View File

@ -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

View File

@ -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";

View File

@ -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);
}