Commit ff51e313 authored by Nadro's avatar Nadro

- Fixed ZFail shadows problem related to second - unnecessary shadow on the...

- Fixed ZFail shadows problem related to second - unnecessary shadow on the scene (only minor problems related to less depth exist).

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@4315 dfc29bdd-3216-0410-991c-e03cc46cb475
parent be047b48
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "ISceneManager.h" #include "ISceneManager.h"
#include "IMesh.h" #include "IMesh.h"
#include "IVideoDriver.h" #include "IVideoDriver.h"
#include "ICameraScenenode.h"
#include "SLight.h" #include "SLight.h"
#include "os.h" #include "os.h"
...@@ -64,14 +65,13 @@ void CShadowVolumeSceneNode::createShadowVolume(const core::vector3df& light, bo ...@@ -64,14 +65,13 @@ void CShadowVolumeSceneNode::createShadowVolume(const core::vector3df& light, bo
numEdges=createEdgesAndCaps(light, svp); numEdges=createEdgesAndCaps(light, svp);
const core::vector3df ls = light * Infinity; // light scaled
// for all edges add the near->far quads // for all edges add the near->far quads
for (u32 i=0; i<numEdges; ++i) for (u32 i=0; i<numEdges; ++i)
{ {
const core::vector3df &v1 = Vertices[Edges[2*i+0]]; const core::vector3df &v1 = Vertices[Edges[2*i+0]];
const core::vector3df &v2 = Vertices[Edges[2*i+1]]; const core::vector3df &v2 = Vertices[Edges[2*i+1]];
const core::vector3df v3(v1 - ls); const core::vector3df v3(v1+(v1 - light).normalize()*Infinity);
const core::vector3df v4(v2 - ls); const core::vector3df v4(v2+(v2 - light).normalize()*Infinity);
// Add a quad (two triangles) to the vertex list // Add a quad (two triangles) to the vertex list
#ifdef _DEBUG #ifdef _DEBUG
...@@ -91,14 +91,11 @@ void CShadowVolumeSceneNode::createShadowVolume(const core::vector3df& light, bo ...@@ -91,14 +91,11 @@ void CShadowVolumeSceneNode::createShadowVolume(const core::vector3df& light, bo
#define IRR_USE_ADJACENCY #define IRR_USE_ADJACENCY
u32 CShadowVolumeSceneNode::createEdgesAndCaps(core::vector3df light, u32 CShadowVolumeSceneNode::createEdgesAndCaps(const core::vector3df& light,
SShadowVolume* svp) SShadowVolume* svp)
{ {
u32 numEdges=0; u32 numEdges=0;
const u32 faceCount = IndexCount / 3; const u32 faceCount = IndexCount / 3;
light *= Infinity;
if (light == core::vector3df(0,0,0))
light = core::vector3df(0.0001f,0.0001f,0.0001f);
// Check every face if it is front or back facing the light. // Check every face if it is front or back facing the light.
for (u32 i=0; i<faceCount; ++i) for (u32 i=0; i<faceCount; ++i)
...@@ -116,13 +113,13 @@ u32 CShadowVolumeSceneNode::createEdgesAndCaps(core::vector3df light, ...@@ -116,13 +113,13 @@ u32 CShadowVolumeSceneNode::createEdgesAndCaps(core::vector3df light,
#endif #endif
// add front cap from light-facing faces // add front cap from light-facing faces
svp->push_back(v0); svp->push_back(v0);
svp->push_back(v2);
svp->push_back(v1); svp->push_back(v1);
svp->push_back(v2);
// add back cap // add back cap
svp->push_back(v0-light); svp->push_back(v0+(v0-light).normalize()*Infinity);
svp->push_back(v1-light); svp->push_back(v1+(v1-light).normalize()*Infinity);
svp->push_back(v2-light); svp->push_back(v2+(v2-light).normalize()*Infinity);
} }
} }
...@@ -288,6 +285,19 @@ void CShadowVolumeSceneNode::render() ...@@ -288,6 +285,19 @@ void CShadowVolumeSceneNode::render()
if (!ShadowVolumesUsed || !driver) if (!ShadowVolumesUsed || !driver)
return; return;
if (UseZFailMethod && SceneManager->getActiveCamera())
{
core::matrix4 mat(core::matrix4::EM4CONST_NOTHING);
mat.buildProjectionMatrixPerspectiveFovInfinityLH(
SceneManager->getActiveCamera()->getFOV(),
SceneManager->getActiveCamera()->getAspectRatio(),
SceneManager->getActiveCamera()->getNearValue(),
core::ROUNDING_ERROR_f32);
driver->setTransform(video::ETS_PROJECTION, mat);
}
driver->setTransform(video::ETS_WORLD, Parent->getAbsoluteTransformation()); driver->setTransform(video::ETS_WORLD, Parent->getAbsoluteTransformation());
for (u32 i=0; i<ShadowVolumesUsed; ++i) for (u32 i=0; i<ShadowVolumesUsed; ++i)
......
...@@ -50,7 +50,7 @@ namespace scene ...@@ -50,7 +50,7 @@ namespace scene
typedef core::array<core::vector3df> SShadowVolume; typedef core::array<core::vector3df> SShadowVolume;
void createShadowVolume(const core::vector3df& pos, bool isDirectional=false); void createShadowVolume(const core::vector3df& pos, bool isDirectional=false);
u32 createEdgesAndCaps(core::vector3df light, SShadowVolume* svp); u32 createEdgesAndCaps(const core::vector3df& light, SShadowVolume* svp);
//! Generates adjacency information based on mesh indices. //! Generates adjacency information based on mesh indices.
void calculateAdjacency(); void calculateAdjacency();
......
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