Commit d2169fc4 authored by cutealien's avatar cutealien

Add a new flag for controlling zbuffer writing to SMaterial.

In 4774 we tried fixing zwriting for shader materials as those are ignored in SMaterial::isTransparent.
This affected too many existing projects and made it hard to still write to zbuffer in some situations where it was necessary. So trying now another approach which brings back old functionality mostly, but allows users to have more fine-control with a new flag. Using an enum instead of bool for the new flag as it's foreseeable that more options might be necessary for this in the future.
Note: Several tests are currently failing, but they did that before, so that has to be debugged on it's own.


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@5076 dfc29bdd-3216-0410-991c-e03cc46cb475
parent a1cf2945
...@@ -246,6 +246,16 @@ namespace video ...@@ -246,6 +246,16 @@ namespace video
0 0
}; };
//! Fine-tuning for SMaterial.ZWriteFineControl
enum E_ZWRITE_FINE_CONTROL
{
//! Default. Only write zbuffer when When SMaterial::ZBuffer is true and SMaterial::isTransparent() returns false.
EZI_ONLY_NON_TRANSPARENT,
//! Writing will just be based on SMaterial::ZBuffer value, transparency is ignored.
//! Needed mostly for certain shader materials as SMaterial::isTransparent will always return false for those.
EZI_ZBUFFER_FLAG
};
//! Maximum number of texture an SMaterial can have. //! Maximum number of texture an SMaterial can have.
const u32 MATERIAL_MAX_TEXTURES = _IRR_MATERIAL_MAX_TEXTURES_; const u32 MATERIAL_MAX_TEXTURES = _IRR_MATERIAL_MAX_TEXTURES_;
...@@ -264,7 +274,8 @@ namespace video ...@@ -264,7 +274,8 @@ namespace video
PolygonOffsetFactor(0), PolygonOffsetDirection(EPO_FRONT), PolygonOffsetFactor(0), PolygonOffsetDirection(EPO_FRONT),
Wireframe(false), PointCloud(false), GouraudShading(true), Wireframe(false), PointCloud(false), GouraudShading(true),
Lighting(true), ZWriteEnable(true), BackfaceCulling(true), FrontfaceCulling(false), Lighting(true), ZWriteEnable(true), BackfaceCulling(true), FrontfaceCulling(false),
FogEnable(false), NormalizeNormals(false), UseMipMaps(true) FogEnable(false), NormalizeNormals(false), UseMipMaps(true),
ZWriteFineControl(EZI_ONLY_NON_TRANSPARENT)
{ } { }
//! Copy constructor //! Copy constructor
...@@ -318,6 +329,7 @@ namespace video ...@@ -318,6 +329,7 @@ namespace video
PolygonOffsetFactor = other.PolygonOffsetFactor; PolygonOffsetFactor = other.PolygonOffsetFactor;
PolygonOffsetDirection = other.PolygonOffsetDirection; PolygonOffsetDirection = other.PolygonOffsetDirection;
UseMipMaps = other.UseMipMaps; UseMipMaps = other.UseMipMaps;
ZWriteFineControl = other.ZWriteFineControl;
return *this; return *this;
} }
...@@ -475,6 +487,11 @@ namespace video ...@@ -475,6 +487,11 @@ namespace video
/** Sometimes, disabling mipmap usage can be useful. Default: true */ /** Sometimes, disabling mipmap usage can be useful. Default: true */
bool UseMipMaps:1; bool UseMipMaps:1;
//! Give more control how the ZWriteEnable flag is interpreted
/** Note that there is also the global flag AllowZWriteOnTransparent
which when set acts like all materials have set EZI_ALLOW_ON_TRANSPARENT. */
E_ZWRITE_FINE_CONTROL ZWriteFineControl;
//! Gets the texture transformation matrix for level i //! Gets the texture transformation matrix for level i
/** \param i The desired level. Must not be larger than MATERIAL_MAX_TEXTURES. /** \param i The desired level. Must not be larger than MATERIAL_MAX_TEXTURES.
\return Texture matrix for texture level i. */ \return Texture matrix for texture level i. */
...@@ -695,7 +712,9 @@ namespace video ...@@ -695,7 +712,9 @@ namespace video
BlendFactor != b.BlendFactor || BlendFactor != b.BlendFactor ||
PolygonOffsetFactor != b.PolygonOffsetFactor || PolygonOffsetFactor != b.PolygonOffsetFactor ||
PolygonOffsetDirection != b.PolygonOffsetDirection || PolygonOffsetDirection != b.PolygonOffsetDirection ||
UseMipMaps != b.UseMipMaps; UseMipMaps != b.UseMipMaps ||
ZWriteFineControl != b.ZWriteFineControl;
;
for (u32 i=0; (i<MATERIAL_MAX_TEXTURES) && !different; ++i) for (u32 i=0; (i<MATERIAL_MAX_TEXTURES) && !different; ++i)
{ {
different |= (TextureLayer[i] != b.TextureLayer[i]); different |= (TextureLayer[i] != b.TextureLayer[i]);
......
...@@ -2130,15 +2130,13 @@ void CD3D9Driver::setBasicRenderStates(const SMaterial& material, const SMateria ...@@ -2130,15 +2130,13 @@ void CD3D9Driver::setBasicRenderStates(const SMaterial& material, const SMateria
} }
// zwrite // zwrite
// if (resetAllRenderstates || (lastmaterial.ZWriteEnable != material.ZWriteEnable)) if (getWriteZBuffer(material))
{
if (material.ZWriteEnable && (AllowZWriteOnTransparent || (!material.isTransparent() &&
!MaterialRenderers[material.MaterialType].Renderer->isTransparent())))
{ {
pID3DDevice->SetRenderState( D3DRS_ZWRITEENABLE, TRUE); pID3DDevice->SetRenderState( D3DRS_ZWRITEENABLE, TRUE);
} }
else else
pID3DDevice->SetRenderState( D3DRS_ZWRITEENABLE, FALSE); {
pID3DDevice->SetRenderState(D3DRS_ZWRITEENABLE, FALSE);
} }
// back face culling // back face culling
......
...@@ -725,6 +725,26 @@ namespace video ...@@ -725,6 +725,26 @@ namespace video
return (f32) getAverage ( p[(y * pitch) + x] ); return (f32) getAverage ( p[(y * pitch) + x] );
} }
inline bool getWriteZBuffer(const SMaterial&material) const
{
if (material.ZWriteEnable)
{
if (!AllowZWriteOnTransparent)
{
switch (material.ZWriteFineControl)
{
case EZI_ONLY_NON_TRANSPARENT:
return !material.isTransparent();
case EZI_ZBUFFER_FLAG:
return true;
}
}
else
return true;
}
return false;
}
struct SSurface struct SSurface
{ {
video::ITexture* Surface; video::ITexture* Surface;
......
...@@ -2964,8 +2964,7 @@ void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMater ...@@ -2964,8 +2964,7 @@ void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMater
} }
// ZWrite // ZWrite
if (material.ZWriteEnable && (AllowZWriteOnTransparent || (material.BlendOperation == EBO_NONE && if (getWriteZBuffer(material))
!MaterialRenderers[material.MaterialType].Renderer->isTransparent())))
{ {
BridgeCalls->setDepthMask(true); BridgeCalls->setDepthMask(true);
} }
......
...@@ -178,8 +178,7 @@ void CBurningVideoDriver::setCurrentShader() ...@@ -178,8 +178,7 @@ void CBurningVideoDriver::setCurrentShader()
bool zMaterialTest = Material.org.ZBuffer != ECFN_DISABLED && bool zMaterialTest = Material.org.ZBuffer != ECFN_DISABLED &&
Material.org.ZWriteEnable && Material.org.ZWriteEnable &&
( AllowZWriteOnTransparent || (!Material.org.isTransparent() && getWriteZBuffer(Material.org);
!MaterialRenderers[Material.org.MaterialType].Renderer->isTransparent()) );
EBurningFFShader shader = zMaterialTest ? ETR_TEXTURE_GOURAUD : ETR_TEXTURE_GOURAUD_NOZ; EBurningFFShader shader = zMaterialTest ? ETR_TEXTURE_GOURAUD : ETR_TEXTURE_GOURAUD_NOZ;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment