Commit 0c0ee8be authored by hybrid's avatar hybrid

Add debug data switch for shadow scene nodes. With EDS_SKELETON and...

Add debug data switch for shadow scene nodes. With EDS_SKELETON and EDS_MESH_WIRE_OVERLAY one can draw the whole shadow volume (or just the wireframe of it) instead of just the shadow. Currently only implemented in the hw drivers.
Also fixed a somewhat slow way of not writing to color planes from alphablend(1,0) to proper colormask settings in d3d driver.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@3964 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 197ddb57
...@@ -984,7 +984,7 @@ namespace video ...@@ -984,7 +984,7 @@ namespace video
\param count Amount of triangles in the array. \param count Amount of triangles in the array.
\param zfail If set to true, zfail method is used, otherwise \param zfail If set to true, zfail method is used, otherwise
zpass. */ zpass. */
virtual void drawStencilShadowVolume(const core::array<core::vector3df>& triangles, bool zfail=true) =0; virtual void drawStencilShadowVolume(const core::array<core::vector3df>& triangles, bool zfail=true, u32 debugDataVisible=0) =0;
//! Fills the stencil shadow with color. //! Fills the stencil shadow with color.
/** After the shadow volume has been drawn into the stencil /** After the shadow volume has been drawn into the stencil
......
...@@ -1672,12 +1672,19 @@ void CD3D8Driver::setBasicRenderStates(const SMaterial& material, const SMateria ...@@ -1672,12 +1672,19 @@ void CD3D8Driver::setBasicRenderStates(const SMaterial& material, const SMateria
//! sets the needed renderstates //! sets the needed renderstates
void CD3D8Driver::setRenderStatesStencilShadowMode(bool zfail) void CD3D8Driver::setRenderStatesStencilShadowMode(bool zfail, u32 debugDataVisible)
{ {
if ((CurrentRenderMode != ERM_SHADOW_VOLUME_ZFAIL && if ((CurrentRenderMode != ERM_SHADOW_VOLUME_ZFAIL &&
CurrentRenderMode != ERM_SHADOW_VOLUME_ZPASS) || CurrentRenderMode != ERM_SHADOW_VOLUME_ZPASS) ||
Transformation3DChanged) Transformation3DChanged)
{ {
// unset last 3d material
if (CurrentRenderMode == ERM_3D &&
static_cast<u32>(Material.MaterialType) < MaterialRenderers.size())
{
MaterialRenderers[Material.MaterialType].Renderer->OnUnsetMaterial();
ResetRenderStates = true;
}
// switch back the matrices // switch back the matrices
pID3DDevice->SetTransform(D3DTS_VIEW, (D3DMATRIX*)((void*)&Matrices[ETS_VIEW])); pID3DDevice->SetTransform(D3DTS_VIEW, (D3DMATRIX*)((void*)&Matrices[ETS_VIEW]));
pID3DDevice->SetTransform(D3DTS_WORLD, (D3DMATRIX*)((void*)&Matrices[ETS_WORLD])); pID3DDevice->SetTransform(D3DTS_WORLD, (D3DMATRIX*)((void*)&Matrices[ETS_WORLD]));
...@@ -1691,63 +1698,40 @@ void CD3D8Driver::setRenderStatesStencilShadowMode(bool zfail) ...@@ -1691,63 +1698,40 @@ void CD3D8Driver::setRenderStatesStencilShadowMode(bool zfail)
setActiveTexture(3,0); setActiveTexture(3,0);
pID3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_DISABLE); pID3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_DISABLE);
pID3DDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
pID3DDevice->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
pID3DDevice->SetTextureStageState(2, D3DTSS_COLOROP, D3DTOP_DISABLE);
pID3DDevice->SetTextureStageState(2, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
pID3DDevice->SetTextureStageState(3, D3DTSS_COLOROP, D3DTOP_DISABLE);
pID3DDevice->SetTextureStageState(3, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
pID3DDevice->SetVertexShader(D3DFVF_XYZ); pID3DDevice->SetVertexShader(D3DFVF_XYZ);
LastVertexType = (video::E_VERTEX_TYPE)(-1); LastVertexType = (video::E_VERTEX_TYPE)(-1);
pID3DDevice->SetRenderState( D3DRS_ZWRITEENABLE, FALSE ); pID3DDevice->SetRenderState(D3DRS_ZWRITEENABLE, FALSE);
pID3DDevice->SetRenderState( D3DRS_STENCILENABLE, TRUE ); pID3DDevice->SetRenderState(D3DRS_STENCILENABLE, TRUE);
pID3DDevice->SetRenderState( D3DRS_SHADEMODE, D3DSHADE_FLAT); pID3DDevice->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_FLAT);
//pID3DDevice->SetRenderState(D3DRS_FOGENABLE, FALSE); //pID3DDevice->SetRenderState(D3DRS_FOGENABLE, FALSE);
//pID3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE); //pID3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);
// unset last 3d material pID3DDevice->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_ALWAYS);
if (CurrentRenderMode == ERM_3D && pID3DDevice->SetRenderState(D3DRS_STENCILREF, 0x0);
Material.MaterialType >= 0 && Material.MaterialType < (s32)MaterialRenderers.size()) pID3DDevice->SetRenderState(D3DRS_STENCILMASK, 0xffffffff);
MaterialRenderers[Material.MaterialType].Renderer->OnUnsetMaterial(); pID3DDevice->SetRenderState(D3DRS_STENCILWRITEMASK, 0xffffffff);
if (!(debugDataVisible & (scene::EDS_SKELETON|scene::EDS_MESH_WIRE_OVERLAY)))
pID3DDevice->SetRenderState(D3DRS_COLORWRITEENABLE, 0);
if ((debugDataVisible & scene::EDS_MESH_WIRE_OVERLAY))
pID3DDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);
} }
if (CurrentRenderMode != ERM_SHADOW_VOLUME_ZPASS && !zfail) if (CurrentRenderMode != ERM_SHADOW_VOLUME_ZPASS && !zfail)
{ {
// USE THE ZPASS METHOD // USE THE ZPASS METHOD
pID3DDevice->SetRenderState(D3DRS_STENCILFAIL, D3DSTENCILOP_KEEP);
pID3DDevice->SetRenderState( D3DRS_STENCILFUNC, D3DCMP_ALWAYS ); pID3DDevice->SetRenderState(D3DRS_STENCILZFAIL, D3DSTENCILOP_KEEP);
pID3DDevice->SetRenderState( D3DRS_STENCILZFAIL, D3DSTENCILOP_KEEP ); pID3DDevice->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_INCR);
pID3DDevice->SetRenderState( D3DRS_STENCILFAIL, D3DSTENCILOP_KEEP );
pID3DDevice->SetRenderState( D3DRS_STENCILREF, 0x1 );
pID3DDevice->SetRenderState( D3DRS_STENCILMASK, 0xffffffff );
pID3DDevice->SetRenderState( D3DRS_STENCILWRITEMASK, 0xffffffff );
pID3DDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE);
pID3DDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ZERO );
pID3DDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE );
} }
else else
if (CurrentRenderMode != ERM_SHADOW_VOLUME_ZFAIL && zfail) if (CurrentRenderMode != ERM_SHADOW_VOLUME_ZFAIL && zfail)
{ {
// USE THE ZFAIL METHOD // USE THE ZFAIL METHOD
pID3DDevice->SetRenderState(D3DRS_STENCILFAIL, D3DSTENCILOP_KEEP);
pID3DDevice->SetRenderState( D3DRS_STENCILFUNC, D3DCMP_ALWAYS ); pID3DDevice->SetRenderState(D3DRS_STENCILZFAIL, D3DSTENCILOP_INCR);
pID3DDevice->SetRenderState( D3DRS_STENCILZFAIL, D3DSTENCILOP_KEEP ); pID3DDevice->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_KEEP);
pID3DDevice->SetRenderState( D3DRS_STENCILFAIL, D3DSTENCILOP_KEEP );
pID3DDevice->SetRenderState( D3DRS_STENCILPASS, D3DSTENCILOP_KEEP );
pID3DDevice->SetRenderState( D3DRS_STENCILREF, 0x0 );
pID3DDevice->SetRenderState( D3DRS_STENCILMASK, 0xffffffff );
pID3DDevice->SetRenderState( D3DRS_STENCILWRITEMASK, 0xffffffff );
pID3DDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
pID3DDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ZERO );
pID3DDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE );
} }
CurrentRenderMode = zfail ? ERM_SHADOW_VOLUME_ZFAIL : ERM_SHADOW_VOLUME_ZPASS; CurrentRenderMode = zfail ? ERM_SHADOW_VOLUME_ZFAIL : ERM_SHADOW_VOLUME_ZPASS;
...@@ -2015,21 +1999,21 @@ const wchar_t* CD3D8Driver::getName() const ...@@ -2015,21 +1999,21 @@ const wchar_t* CD3D8Driver::getName() const
//! Draws a shadow volume into the stencil buffer. To draw a stencil shadow, do //! Draws a shadow volume into the stencil buffer. To draw a stencil shadow, do
//! this: Frist, draw all geometry. Then use this method, to draw the shadow //! this: First, draw all geometry. Then use this method, to draw the shadow
//! volume. Then, use IVideoDriver::drawStencilShadow() to visualize the shadow. //! volume. Then, use IVideoDriver::drawStencilShadow() to visualize the shadow.
void CD3D8Driver::drawStencilShadowVolume(const core::array<core::vector3df>& triangles, bool zfail) void CD3D8Driver::drawStencilShadowVolume(const core::array<core::vector3df>& triangles, bool zfail, u32 debugDataVisible)
{ {
const u32 count = triangles.size(); const u32 count = triangles.size();
if (!StencilBuffer || !count) if (!StencilBuffer || !count)
return; return;
setRenderStatesStencilShadowMode(zfail); setRenderStatesStencilShadowMode(zfail, debugDataVisible);
if (!zfail) if (!zfail)
{ {
// ZPASS Method // ZPASS Method
// Draw front-side of shadow volume in stencil/z only // Draw front-side of shadow volume in stencil only
pID3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW ); pID3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW );
pID3DDevice->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_INCRSAT); pID3DDevice->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_INCRSAT);
pID3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLELIST, count / 3, triangles.const_pointer(), sizeof(core::vector3df)); pID3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLELIST, count / 3, triangles.const_pointer(), sizeof(core::vector3df));
...@@ -2043,7 +2027,7 @@ void CD3D8Driver::drawStencilShadowVolume(const core::array<core::vector3df>& tr ...@@ -2043,7 +2027,7 @@ void CD3D8Driver::drawStencilShadowVolume(const core::array<core::vector3df>& tr
{ {
// ZFAIL Method // ZFAIL Method
// Draw front-side of shadow volume in stencil/z only // Draw front-side of shadow volume in stencil only
pID3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW ); pID3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW );
pID3DDevice->SetRenderState(D3DRS_STENCILZFAIL, D3DSTENCILOP_INCRSAT ); pID3DDevice->SetRenderState(D3DRS_STENCILZFAIL, D3DSTENCILOP_INCRSAT );
pID3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLELIST, count / 3, triangles.const_pointer(), sizeof(core::vector3df)); pID3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLELIST, count / 3, triangles.const_pointer(), sizeof(core::vector3df));
......
...@@ -138,7 +138,7 @@ namespace video ...@@ -138,7 +138,7 @@ namespace video
//! Draws a shadow volume into the stencil buffer. To draw a stencil shadow, do //! Draws a shadow volume into the stencil buffer. To draw a stencil shadow, do
//! this: Frist, draw all geometry. Then use this method, to draw the shadow //! this: Frist, draw all geometry. Then use this method, to draw the shadow
//! volume. Then, use IVideoDriver::drawStencilShadow() to visualize the shadow. //! volume. Then, use IVideoDriver::drawStencilShadow() to visualize the shadow.
virtual void drawStencilShadowVolume(const core::array<core::vector3df>& triangles, bool zfail); virtual void drawStencilShadowVolume(const core::array<core::vector3df>& triangles, bool zfail=true, u32 debugDataVisible=0);
//! Fills the stencil shadow with color. After the shadow volume has been drawn //! Fills the stencil shadow with color. After the shadow volume has been drawn
//! into the stencil buffer using IVideoDriver::drawStencilShadowVolume(), use this //! into the stencil buffer using IVideoDriver::drawStencilShadowVolume(), use this
...@@ -244,7 +244,7 @@ namespace video ...@@ -244,7 +244,7 @@ namespace video
void setRenderStatesStencilFillMode(bool alpha); void setRenderStatesStencilFillMode(bool alpha);
//! sets the needed renderstates //! sets the needed renderstates
void setRenderStatesStencilShadowMode(bool zfail); void setRenderStatesStencilShadowMode(bool zfail, u32 debugDataVisible);
//! sets the current Texture //! sets the current Texture
bool setActiveTexture(u32 stage, const video::ITexture* texture); bool setActiveTexture(u32 stage, const video::ITexture* texture);
......
...@@ -2414,12 +2414,19 @@ void CD3D9Driver::setBasicRenderStates(const SMaterial& material, const SMateria ...@@ -2414,12 +2414,19 @@ void CD3D9Driver::setBasicRenderStates(const SMaterial& material, const SMateria
//! sets the needed renderstates //! sets the needed renderstates
void CD3D9Driver::setRenderStatesStencilShadowMode(bool zfail) void CD3D9Driver::setRenderStatesStencilShadowMode(bool zfail, u32 debugDataVisible)
{ {
if ((CurrentRenderMode != ERM_SHADOW_VOLUME_ZFAIL && if ((CurrentRenderMode != ERM_SHADOW_VOLUME_ZFAIL &&
CurrentRenderMode != ERM_SHADOW_VOLUME_ZPASS) || CurrentRenderMode != ERM_SHADOW_VOLUME_ZPASS) ||
Transformation3DChanged) Transformation3DChanged)
{ {
// unset last 3d material
if (CurrentRenderMode == ERM_3D &&
static_cast<u32>(Material.MaterialType) < MaterialRenderers.size())
{
MaterialRenderers[Material.MaterialType].Renderer->OnUnsetMaterial();
ResetRenderStates = true;
}
// switch back the matrices // switch back the matrices
pID3DDevice->SetTransform(D3DTS_VIEW, (D3DMATRIX*)((void*)&Matrices[ETS_VIEW])); pID3DDevice->SetTransform(D3DTS_VIEW, (D3DMATRIX*)((void*)&Matrices[ETS_VIEW]));
pID3DDevice->SetTransform(D3DTS_WORLD, (D3DMATRIX*)((void*)&Matrices[ETS_WORLD])); pID3DDevice->SetTransform(D3DTS_WORLD, (D3DMATRIX*)((void*)&Matrices[ETS_WORLD]));
...@@ -2437,53 +2444,37 @@ void CD3D9Driver::setRenderStatesStencilShadowMode(bool zfail) ...@@ -2437,53 +2444,37 @@ void CD3D9Driver::setRenderStatesStencilShadowMode(bool zfail)
pID3DDevice->SetFVF(D3DFVF_XYZ); pID3DDevice->SetFVF(D3DFVF_XYZ);
LastVertexType = (video::E_VERTEX_TYPE)(-1); LastVertexType = (video::E_VERTEX_TYPE)(-1);
pID3DDevice->SetRenderState( D3DRS_ZWRITEENABLE, FALSE ); pID3DDevice->SetRenderState(D3DRS_ZWRITEENABLE, FALSE);
pID3DDevice->SetRenderState( D3DRS_STENCILENABLE, TRUE ); pID3DDevice->SetRenderState(D3DRS_STENCILENABLE, TRUE);
pID3DDevice->SetRenderState( D3DRS_SHADEMODE, D3DSHADE_FLAT); pID3DDevice->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_FLAT);
// unset last 3d material
if (CurrentRenderMode == ERM_3D &&
Material.MaterialType >= 0 && Material.MaterialType < (s32)MaterialRenderers.size())
MaterialRenderers[Material.MaterialType].Renderer->OnUnsetMaterial();
//pID3DDevice->SetRenderState(D3DRS_FOGENABLE, FALSE); //pID3DDevice->SetRenderState(D3DRS_FOGENABLE, FALSE);
//pID3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE); //pID3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);
pID3DDevice->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_ALWAYS);
pID3DDevice->SetRenderState(D3DRS_STENCILREF, 0x0);
pID3DDevice->SetRenderState(D3DRS_STENCILMASK, 0xffffffff);
pID3DDevice->SetRenderState(D3DRS_STENCILWRITEMASK, 0xffffffff);
if (!(debugDataVisible & (scene::EDS_SKELETON|scene::EDS_MESH_WIRE_OVERLAY)))
pID3DDevice->SetRenderState(D3DRS_COLORWRITEENABLE, 0);
if ((debugDataVisible & scene::EDS_MESH_WIRE_OVERLAY))
pID3DDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);
} }
if (CurrentRenderMode != ERM_SHADOW_VOLUME_ZPASS && !zfail) if (CurrentRenderMode != ERM_SHADOW_VOLUME_ZPASS && !zfail)
{ {
// USE THE ZPASS METHOD // USE THE ZPASS METHOD
pID3DDevice->SetRenderState(D3DRS_STENCILFAIL, D3DSTENCILOP_KEEP);
pID3DDevice->SetRenderState( D3DRS_STENCILFUNC, D3DCMP_ALWAYS ); pID3DDevice->SetRenderState(D3DRS_STENCILZFAIL, D3DSTENCILOP_KEEP);
pID3DDevice->SetRenderState( D3DRS_STENCILFAIL, D3DSTENCILOP_KEEP ); pID3DDevice->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_INCR);
pID3DDevice->SetRenderState( D3DRS_STENCILZFAIL, D3DSTENCILOP_KEEP );
pID3DDevice->SetRenderState( D3DRS_STENCILPASS, D3DSTENCILOP_INCR );
pID3DDevice->SetRenderState( D3DRS_STENCILREF, 0x0 );
pID3DDevice->SetRenderState( D3DRS_STENCILMASK, 0xffffffff );
pID3DDevice->SetRenderState( D3DRS_STENCILWRITEMASK, 0xffffffff );
pID3DDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE);
pID3DDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ZERO );
pID3DDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE );
} }
else else
if (CurrentRenderMode != ERM_SHADOW_VOLUME_ZFAIL && zfail) if (CurrentRenderMode != ERM_SHADOW_VOLUME_ZFAIL && zfail)
{ {
// USE THE ZFAIL METHOD // USE THE ZFAIL METHOD
pID3DDevice->SetRenderState(D3DRS_STENCILFAIL, D3DSTENCILOP_KEEP);
pID3DDevice->SetRenderState( D3DRS_STENCILFUNC, D3DCMP_ALWAYS ); pID3DDevice->SetRenderState(D3DRS_STENCILZFAIL, D3DSTENCILOP_INCR);
pID3DDevice->SetRenderState( D3DRS_STENCILFAIL, D3DSTENCILOP_KEEP ); pID3DDevice->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_KEEP);
pID3DDevice->SetRenderState( D3DRS_STENCILZFAIL, D3DSTENCILOP_INCR );
pID3DDevice->SetRenderState( D3DRS_STENCILPASS, D3DSTENCILOP_KEEP );
pID3DDevice->SetRenderState( D3DRS_STENCILREF, 0x0 );
pID3DDevice->SetRenderState( D3DRS_STENCILMASK, 0xffffffff );
pID3DDevice->SetRenderState( D3DRS_STENCILWRITEMASK, 0xffffffff );
pID3DDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
pID3DDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ZERO );
pID3DDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE );
} }
CurrentRenderMode = zfail ? ERM_SHADOW_VOLUME_ZFAIL : ERM_SHADOW_VOLUME_ZPASS; CurrentRenderMode = zfail ? ERM_SHADOW_VOLUME_ZFAIL : ERM_SHADOW_VOLUME_ZPASS;
...@@ -2509,11 +2500,11 @@ void CD3D9Driver::setRenderStatesStencilFillMode(bool alpha) ...@@ -2509,11 +2500,11 @@ void CD3D9Driver::setRenderStatesStencilFillMode(bool alpha)
pID3DDevice->SetRenderState(D3DRS_STENCILREF, 0x1); pID3DDevice->SetRenderState(D3DRS_STENCILREF, 0x1);
pID3DDevice->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_LESSEQUAL); pID3DDevice->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_LESSEQUAL);
//pID3DDevice->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_GREATEREQUAL); //pID3DDevice->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_GREATEREQUAL);
pID3DDevice->SetRenderState(D3DRS_STENCILFAIL, D3DSTENCILOP_KEEP ); pID3DDevice->SetRenderState(D3DRS_STENCILFAIL, D3DSTENCILOP_KEEP);
pID3DDevice->SetRenderState(D3DRS_STENCILZFAIL, D3DSTENCILOP_KEEP ); pID3DDevice->SetRenderState(D3DRS_STENCILZFAIL, D3DSTENCILOP_KEEP);
pID3DDevice->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_KEEP ); pID3DDevice->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_KEEP);
pID3DDevice->SetRenderState(D3DRS_STENCILMASK, 0xffffffff ); pID3DDevice->SetRenderState(D3DRS_STENCILMASK, 0xffffffff);
pID3DDevice->SetRenderState(D3DRS_STENCILWRITEMASK, 0xffffffff ); pID3DDevice->SetRenderState(D3DRS_STENCILWRITEMASK, 0xffffffff);
pID3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW); pID3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);
...@@ -2528,7 +2519,7 @@ void CD3D9Driver::setRenderStatesStencilFillMode(bool alpha) ...@@ -2528,7 +2519,7 @@ void CD3D9Driver::setRenderStatesStencilFillMode(bool alpha)
{ {
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
pID3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); pID3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
pID3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA ); pID3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
} }
else else
{ {
...@@ -2758,21 +2749,21 @@ const wchar_t* CD3D9Driver::getName() const ...@@ -2758,21 +2749,21 @@ const wchar_t* CD3D9Driver::getName() const
//! Draws a shadow volume into the stencil buffer. To draw a stencil shadow, do //! Draws a shadow volume into the stencil buffer. To draw a stencil shadow, do
//! this: Frist, draw all geometry. Then use this method, to draw the shadow //! this: First, draw all geometry. Then use this method, to draw the shadow
//! volume. Then, use IVideoDriver::drawStencilShadow() to visualize the shadow. //! volume. Then, use IVideoDriver::drawStencilShadow() to visualize the shadow.
void CD3D9Driver::drawStencilShadowVolume(const core::array<core::vector3df>& triangles, bool zfail) void CD3D9Driver::drawStencilShadowVolume(const core::array<core::vector3df>& triangles, bool zfail, u32 debugDataVisible)
{ {
const u32 count = triangles.size(); const u32 count = triangles.size();
if (!Params.Stencilbuffer || !count) if (!Params.Stencilbuffer || !count)
return; return;
setRenderStatesStencilShadowMode(zfail); setRenderStatesStencilShadowMode(zfail, debugDataVisible);
if (!zfail) if (!zfail)
{ {
// ZPASS Method // ZPASS Method
// Draw front-side of shadow volume in stencil/z only // Draw front-side of shadow volume in stencil only
pID3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW); pID3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);
pID3DDevice->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_INCR); pID3DDevice->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_INCR);
pID3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLELIST, count / 3, triangles.const_pointer(), sizeof(core::vector3df)); pID3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLELIST, count / 3, triangles.const_pointer(), sizeof(core::vector3df));
...@@ -2786,7 +2777,7 @@ void CD3D9Driver::drawStencilShadowVolume(const core::array<core::vector3df>& tr ...@@ -2786,7 +2777,7 @@ void CD3D9Driver::drawStencilShadowVolume(const core::array<core::vector3df>& tr
{ {
// ZFAIL Method // ZFAIL Method
// Draw front-side of shadow volume in stencil/z only // Draw front-side of shadow volume in stencil only
pID3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW); pID3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW);
pID3DDevice->SetRenderState(D3DRS_STENCILZFAIL, D3DSTENCILOP_INCR); pID3DDevice->SetRenderState(D3DRS_STENCILZFAIL, D3DSTENCILOP_INCR);
pID3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLELIST, count / 3, triangles.const_pointer(), sizeof(core::vector3df)); pID3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLELIST, count / 3, triangles.const_pointer(), sizeof(core::vector3df));
......
...@@ -219,7 +219,7 @@ namespace video ...@@ -219,7 +219,7 @@ namespace video
virtual void setAmbientLight(const SColorf& color); virtual void setAmbientLight(const SColorf& color);
//! Draws a shadow volume into the stencil buffer. //! Draws a shadow volume into the stencil buffer.
virtual void drawStencilShadowVolume(const core::array<core::vector3df>& triangles, bool zfail); virtual void drawStencilShadowVolume(const core::array<core::vector3df>& triangles, bool zfail=true, u32 debugDataVisible=0);
//! Fills the stencil shadow with color. //! Fills the stencil shadow with color.
virtual void drawStencilShadow(bool clearStencilBuffer=false, virtual void drawStencilShadow(bool clearStencilBuffer=false,
...@@ -341,7 +341,7 @@ namespace video ...@@ -341,7 +341,7 @@ namespace video
void setRenderStatesStencilFillMode(bool alpha); void setRenderStatesStencilFillMode(bool alpha);
//! sets the needed renderstates //! sets the needed renderstates
void setRenderStatesStencilShadowMode(bool zfail); void setRenderStatesStencilShadowMode(bool zfail, u32 debugDataVisible);
//! sets the current Texture //! sets the current Texture
bool setActiveTexture(u32 stage, const video::ITexture* texture); bool setActiveTexture(u32 stage, const video::ITexture* texture);
......
...@@ -915,7 +915,7 @@ const wchar_t* CNullDriver::getName() const ...@@ -915,7 +915,7 @@ const wchar_t* CNullDriver::getName() const
//! Draws a shadow volume into the stencil buffer. To draw a stencil shadow, do //! Draws a shadow volume into the stencil buffer. To draw a stencil shadow, do
//! this: Frist, draw all geometry. Then use this method, to draw the shadow //! this: Frist, draw all geometry. Then use this method, to draw the shadow
//! volume. Then, use IVideoDriver::drawStencilShadow() to visualize the shadow. //! volume. Then, use IVideoDriver::drawStencilShadow() to visualize the shadow.
void CNullDriver::drawStencilShadowVolume(const core::array<core::vector3df>& triangles, bool zfail) void CNullDriver::drawStencilShadowVolume(const core::array<core::vector3df>& triangles, bool zfail, u32 debugDataVisible)
{ {
} }
......
...@@ -284,7 +284,7 @@ namespace video ...@@ -284,7 +284,7 @@ namespace video
//! Draws a shadow volume into the stencil buffer. To draw a stencil shadow, do //! Draws a shadow volume into the stencil buffer. To draw a stencil shadow, do
//! this: Frist, draw all geometry. Then use this method, to draw the shadow //! this: Frist, draw all geometry. Then use this method, to draw the shadow
//! volume. Then, use IVideoDriver::drawStencilShadow() to visualize the shadow. //! volume. Then, use IVideoDriver::drawStencilShadow() to visualize the shadow.
virtual void drawStencilShadowVolume(const core::array<core::vector3df>& triangles, bool zfail=true); virtual void drawStencilShadowVolume(const core::array<core::vector3df>& triangles, bool zfail=true, u32 debugDataVisible=0);
//! Fills the stencil shadow with color. After the shadow volume has been drawn //! Fills the stencil shadow with color. After the shadow volume has been drawn
//! into the stencil buffer using IVideoDriver::drawStencilShadowVolume(), use this //! into the stencil buffer using IVideoDriver::drawStencilShadowVolume(), use this
......
...@@ -3502,7 +3502,7 @@ void COpenGLDriver::setViewPort(const core::rect<s32>& area) ...@@ -3502,7 +3502,7 @@ void COpenGLDriver::setViewPort(const core::rect<s32>& area)
//! Draws a shadow volume into the stencil buffer. To draw a stencil shadow, do //! Draws a shadow volume into the stencil buffer. To draw a stencil shadow, do
//! this: First, draw all geometry. Then use this method, to draw the shadow //! this: First, draw all geometry. Then use this method, to draw the shadow
//! volume. Next use IVideoDriver::drawStencilShadow() to visualize the shadow. //! volume. Next use IVideoDriver::drawStencilShadow() to visualize the shadow.
void COpenGLDriver::drawStencilShadowVolume(const core::array<core::vector3df>& triangles, bool zfail) void COpenGLDriver::drawStencilShadowVolume(const core::array<core::vector3df>& triangles, bool zfail, u32 debugDataVisible)
{ {
const u32 count=triangles.size(); const u32 count=triangles.size();
if (!StencilBuffer || !count) if (!StencilBuffer || !count)
...@@ -3524,9 +3524,13 @@ void COpenGLDriver::drawStencilShadowVolume(const core::array<core::vector3df>& ...@@ -3524,9 +3524,13 @@ void COpenGLDriver::drawStencilShadowVolume(const core::array<core::vector3df>&
glDisable(GL_FOG); glDisable(GL_FOG);
glDepthFunc(GL_LEQUAL); glDepthFunc(GL_LEQUAL);
glDepthMask(GL_FALSE); // no depth buffer writing glDepthMask(GL_FALSE); // no depth buffer writing
// glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); if (debugDataVisible & scene::EDS_MESH_WIRE_OVERLAY)
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); // no color buffer drawing glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
glEnable(GL_STENCIL_TEST); if (!(debugDataVisible & (scene::EDS_SKELETON|scene::EDS_MESH_WIRE_OVERLAY)))
{
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); // no color buffer drawing
glEnable(GL_STENCIL_TEST);
}
glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3,GL_FLOAT,sizeof(core::vector3df),triangles.const_pointer()); glVertexPointer(3,GL_FLOAT,sizeof(core::vector3df),triangles.const_pointer());
......
...@@ -238,7 +238,7 @@ namespace video ...@@ -238,7 +238,7 @@ namespace video
//! Draws a shadow volume into the stencil buffer. To draw a stencil shadow, do //! Draws a shadow volume into the stencil buffer. To draw a stencil shadow, do
//! this: First, draw all geometry. Then use this method, to draw the shadow //! this: First, draw all geometry. Then use this method, to draw the shadow
//! volume. Then, use IVideoDriver::drawStencilShadow() to visualize the shadow. //! volume. Then, use IVideoDriver::drawStencilShadow() to visualize the shadow.
virtual void drawStencilShadowVolume(const core::array<core::vector3df>& triangles, bool zfail); virtual void drawStencilShadowVolume(const core::array<core::vector3df>& triangles, bool zfail, u32 debugDataVisible=0);
//! Fills the stencil shadow with color. After the shadow volume has been drawn //! Fills the stencil shadow with color. After the shadow volume has been drawn
//! into the stencil buffer using IVideoDriver::drawStencilShadowVolume(), use this //! into the stencil buffer using IVideoDriver::drawStencilShadowVolume(), use this
......
...@@ -292,7 +292,7 @@ void CShadowVolumeSceneNode::render() ...@@ -292,7 +292,7 @@ void CShadowVolumeSceneNode::render()
for (u32 i=0; i<ShadowVolumesUsed; ++i) for (u32 i=0; i<ShadowVolumesUsed; ++i)
{ {
driver->drawStencilShadowVolume(ShadowVolumes[i], UseZFailMethod); driver->drawStencilShadowVolume(ShadowVolumes[i], UseZFailMethod, DebugDataVisible);
} }
} }
......
...@@ -2625,7 +2625,7 @@ u32 CBurningVideoDriver::getMaximalPrimitiveCount() const ...@@ -2625,7 +2625,7 @@ u32 CBurningVideoDriver::getMaximalPrimitiveCount() const
//! Draws a shadow volume into the stencil buffer. To draw a stencil shadow, do //! Draws a shadow volume into the stencil buffer. To draw a stencil shadow, do
//! this: First, draw all geometry. Then use this method, to draw the shadow //! this: First, draw all geometry. Then use this method, to draw the shadow
//! volume. Next use IVideoDriver::drawStencilShadow() to visualize the shadow. //! volume. Next use IVideoDriver::drawStencilShadow() to visualize the shadow.
void CBurningVideoDriver::drawStencilShadowVolume(const core::array<core::vector3df>& triangles, bool zfail) void CBurningVideoDriver::drawStencilShadowVolume(const core::array<core::vector3df>& triangles, bool zfail, u32 debugDataVisible)
{ {
const u32 count = triangles.size(); const u32 count = triangles.size();
IBurningShader *shader = BurningShader [ ETR_STENCIL_SHADOW ]; IBurningShader *shader = BurningShader [ ETR_STENCIL_SHADOW ];
......
...@@ -146,7 +146,7 @@ namespace video ...@@ -146,7 +146,7 @@ namespace video
//! Draws a shadow volume into the stencil buffer. To draw a stencil shadow, do //! Draws a shadow volume into the stencil buffer. To draw a stencil shadow, do
//! this: First, draw all geometry. Then use this method, to draw the shadow //! this: First, draw all geometry. Then use this method, to draw the shadow
//! volume. Then, use IVideoDriver::drawStencilShadow() to visualize the shadow. //! volume. Then, use IVideoDriver::drawStencilShadow() to visualize the shadow.
virtual void drawStencilShadowVolume(const core::array<core::vector3df>& triangles, bool zfail); virtual void drawStencilShadowVolume(const core::array<core::vector3df>& triangles, bool zfail=true, u32 debugDataVisible=0);
//! Fills the stencil shadow with color. After the shadow volume has been drawn //! Fills the stencil shadow with color. After the shadow volume has been drawn
//! into the stencil buffer using IVideoDriver::drawStencilShadowVolume(), use this //! into the stencil buffer using IVideoDriver::drawStencilShadowVolume(), use this
......
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