Commit be047b48 authored by Nadro's avatar Nadro

- Backward shift shadow pass as the last render pass (it was changed rev4312).

- Fixed reset material issues in D3D9 driver which solve shadow bug issue visible in example no. 8 (small, movable shadow bug still exist).

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@4314 dfc29bdd-3216-0410-991c-e03cc46cb475
parent f84412dc
...@@ -111,6 +111,8 @@ public: ...@@ -111,6 +111,8 @@ public:
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services) bool resetAllRenderstates, IMaterialRendererServices* services)
{ {
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{ {
setTextureColorStage(pID3DDevice, 0, setTextureColorStage(pID3DDevice, 0,
...@@ -119,8 +121,6 @@ public: ...@@ -119,8 +121,6 @@ public:
pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE); pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
} }
}; };
...@@ -135,6 +135,8 @@ public: ...@@ -135,6 +135,8 @@ public:
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services) bool resetAllRenderstates, IMaterialRendererServices* services)
{ {
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || if (material.MaterialType != lastMaterial.MaterialType ||
material.MaterialTypeParam != lastMaterial.MaterialTypeParam || material.MaterialTypeParam != lastMaterial.MaterialTypeParam ||
resetAllRenderstates) resetAllRenderstates)
...@@ -179,9 +181,6 @@ public: ...@@ -179,9 +181,6 @@ public:
pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE); pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
} }
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
} }
//! Returns if the material is transparent. //! Returns if the material is transparent.
...@@ -245,6 +244,8 @@ public: ...@@ -245,6 +244,8 @@ public:
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services) bool resetAllRenderstates, IMaterialRendererServices* services)
{ {
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{ {
setTextureColorStage(pID3DDevice, 0, D3DTA_TEXTURE); setTextureColorStage(pID3DDevice, 0, D3DTA_TEXTURE);
...@@ -254,8 +255,6 @@ public: ...@@ -254,8 +255,6 @@ public:
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
} }
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
} }
}; };
...@@ -271,6 +270,8 @@ public: ...@@ -271,6 +270,8 @@ public:
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services) bool resetAllRenderstates, IMaterialRendererServices* services)
{ {
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{ {
setTextureColorStage(pID3DDevice, 0, setTextureColorStage(pID3DDevice, 0,
...@@ -281,8 +282,6 @@ public: ...@@ -281,8 +282,6 @@ public:
pID3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE); pID3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
pID3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCCOLOR); pID3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCCOLOR);
} }
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
} }
//! Returns if the material is transparent. The scene management needs to know this //! Returns if the material is transparent. The scene management needs to know this
...@@ -305,6 +304,8 @@ public: ...@@ -305,6 +304,8 @@ public:
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services) bool resetAllRenderstates, IMaterialRendererServices* services)
{ {
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{ {
setTextureColorStage(pID3DDevice, 0, setTextureColorStage(pID3DDevice, 0,
...@@ -316,8 +317,6 @@ public: ...@@ -316,8 +317,6 @@ public:
pID3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); pID3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
pID3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); pID3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
} }
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
} }
//! Returns if the material is transparent. The scene managment needs to know this //! Returns if the material is transparent. The scene managment needs to know this
...@@ -340,6 +339,8 @@ public: ...@@ -340,6 +339,8 @@ public:
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services) bool resetAllRenderstates, IMaterialRendererServices* services)
{ {
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates
|| material.MaterialTypeParam != lastMaterial.MaterialTypeParam ) || material.MaterialTypeParam != lastMaterial.MaterialTypeParam )
{ {
...@@ -356,8 +357,6 @@ public: ...@@ -356,8 +357,6 @@ public:
pID3DDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL); pID3DDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL);
pID3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE); pID3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE);
} }
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
} }
virtual void OnUnsetMaterial() virtual void OnUnsetMaterial()
...@@ -386,6 +385,8 @@ public: ...@@ -386,6 +385,8 @@ public:
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services) bool resetAllRenderstates, IMaterialRendererServices* services)
{ {
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{ {
setTextureColorStage(pID3DDevice, 0, setTextureColorStage(pID3DDevice, 0,
...@@ -401,8 +402,6 @@ public: ...@@ -401,8 +402,6 @@ public:
pID3DDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL); pID3DDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL);
pID3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE); pID3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE);
} }
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
} }
virtual void OnUnsetMaterial() virtual void OnUnsetMaterial()
...@@ -430,6 +429,8 @@ public: ...@@ -430,6 +429,8 @@ public:
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services) bool resetAllRenderstates, IMaterialRendererServices* services)
{ {
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{ {
if (material.MaterialType >= EMT_LIGHTMAP_LIGHTING) if (material.MaterialType >= EMT_LIGHTMAP_LIGHTING)
...@@ -458,8 +459,6 @@ public: ...@@ -458,8 +459,6 @@ public:
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
} }
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
} }
}; };
...@@ -476,6 +475,8 @@ public: ...@@ -476,6 +475,8 @@ public:
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services) bool resetAllRenderstates, IMaterialRendererServices* services)
{ {
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{ {
setTextureColorStage(pID3DDevice, 0, setTextureColorStage(pID3DDevice, 0,
...@@ -485,8 +486,6 @@ public: ...@@ -485,8 +486,6 @@ public:
pID3DDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1); pID3DDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1);
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
} }
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
} }
}; };
...@@ -502,6 +501,8 @@ public: ...@@ -502,6 +501,8 @@ public:
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services) bool resetAllRenderstates, IMaterialRendererServices* services)
{ {
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{ {
setTextureColorStage(pID3DDevice, 0, setTextureColorStage(pID3DDevice, 0,
...@@ -514,8 +515,6 @@ public: ...@@ -514,8 +515,6 @@ public:
pID3DDevice->SetTextureStageState( 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 ); pID3DDevice->SetTextureStageState( 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 );
pID3DDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACENORMAL ); pID3DDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACENORMAL );
} }
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
} }
virtual void OnUnsetMaterial() virtual void OnUnsetMaterial()
...@@ -538,6 +537,8 @@ public: ...@@ -538,6 +537,8 @@ public:
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services) bool resetAllRenderstates, IMaterialRendererServices* services)
{ {
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{ {
setTextureColorStage(pID3DDevice, 0, setTextureColorStage(pID3DDevice, 0,
...@@ -551,8 +552,6 @@ public: ...@@ -551,8 +552,6 @@ public:
pID3DDevice->SetTextureStageState( 1, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR); pID3DDevice->SetTextureStageState( 1, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR);
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
} }
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
} }
virtual void OnUnsetMaterial() virtual void OnUnsetMaterial()
...@@ -575,6 +574,8 @@ public: ...@@ -575,6 +574,8 @@ public:
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services) bool resetAllRenderstates, IMaterialRendererServices* services)
{ {
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{ {
setTextureColorStage(pID3DDevice, 0, setTextureColorStage(pID3DDevice, 0,
...@@ -592,8 +593,6 @@ public: ...@@ -592,8 +593,6 @@ public:
pID3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); pID3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
pID3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); pID3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
} }
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
} }
virtual void OnUnsetMaterial() virtual void OnUnsetMaterial()
......
...@@ -1507,19 +1507,17 @@ void CSceneManager::drawAll() ...@@ -1507,19 +1507,17 @@ void CSceneManager::drawAll()
LightManager->OnRenderPassPostRender(CurrentRendertime); LightManager->OnRenderPassPostRender(CurrentRendertime);
} }
// render transparent objects. // render shadows
{ {
CurrentRendertime = ESNRP_TRANSPARENT; CurrentRendertime = ESNRP_SHADOW;
Driver->getOverrideMaterial().Enabled = ((Driver->getOverrideMaterial().EnablePasses & CurrentRendertime) != 0); Driver->getOverrideMaterial().Enabled = ((Driver->getOverrideMaterial().EnablePasses & CurrentRendertime) != 0);
TransparentNodeList.sort(); // sort by distance from camera
if (LightManager) if (LightManager)
{ {
LightManager->OnRenderPassPreRender(CurrentRendertime); LightManager->OnRenderPassPreRender(CurrentRendertime);
for (i=0; i<ShadowNodeList.size(); ++i)
for (i=0; i<TransparentNodeList.size(); ++i)
{ {
ISceneNode* node = TransparentNodeList[i].Node; ISceneNode* node = ShadowNodeList[i];
LightManager->OnNodePreRender(node); LightManager->OnNodePreRender(node);
node->render(); node->render();
LightManager->OnNodePostRender(node); LightManager->OnNodePostRender(node);
...@@ -1527,28 +1525,33 @@ void CSceneManager::drawAll() ...@@ -1527,28 +1525,33 @@ void CSceneManager::drawAll()
} }
else else
{ {
for (i=0; i<TransparentNodeList.size(); ++i) for (i=0; i<ShadowNodeList.size(); ++i)
TransparentNodeList[i].Node->render(); ShadowNodeList[i]->render();
} }
Parameters.setAttribute ( "drawn_transparent", (s32) TransparentNodeList.size() ); if (!ShadowNodeList.empty())
TransparentNodeList.set_used(0); Driver->drawStencilShadow(true,ShadowColor, ShadowColor,
ShadowColor, ShadowColor);
ShadowNodeList.set_used(0);
if (LightManager) if (LightManager)
LightManager->OnRenderPassPostRender(CurrentRendertime); LightManager->OnRenderPassPostRender(CurrentRendertime);
} }
// render shadows // render transparent objects.
{ {
CurrentRendertime = ESNRP_SHADOW; CurrentRendertime = ESNRP_TRANSPARENT;
Driver->getOverrideMaterial().Enabled = ((Driver->getOverrideMaterial().EnablePasses & CurrentRendertime) != 0); Driver->getOverrideMaterial().Enabled = ((Driver->getOverrideMaterial().EnablePasses & CurrentRendertime) != 0);
TransparentNodeList.sort(); // sort by distance from camera
if (LightManager) if (LightManager)
{ {
LightManager->OnRenderPassPreRender(CurrentRendertime); LightManager->OnRenderPassPreRender(CurrentRendertime);
for (i=0; i<ShadowNodeList.size(); ++i)
for (i=0; i<TransparentNodeList.size(); ++i)
{ {
ISceneNode* node = ShadowNodeList[i]; ISceneNode* node = TransparentNodeList[i].Node;
LightManager->OnNodePreRender(node); LightManager->OnNodePreRender(node);
node->render(); node->render();
LightManager->OnNodePostRender(node); LightManager->OnNodePostRender(node);
...@@ -1556,15 +1559,12 @@ void CSceneManager::drawAll() ...@@ -1556,15 +1559,12 @@ void CSceneManager::drawAll()
} }
else else
{ {
for (i=0; i<ShadowNodeList.size(); ++i) for (i=0; i<TransparentNodeList.size(); ++i)
ShadowNodeList[i]->render(); TransparentNodeList[i].Node->render();
} }
if (!ShadowNodeList.empty()) Parameters.setAttribute ( "drawn_transparent", (s32) TransparentNodeList.size() );
Driver->drawStencilShadow(true,ShadowColor, ShadowColor, TransparentNodeList.set_used(0);
ShadowColor, ShadowColor);
ShadowNodeList.set_used(0);
if (LightManager) if (LightManager)
LightManager->OnRenderPassPostRender(CurrentRendertime); LightManager->OnRenderPassPostRender(CurrentRendertime);
......
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