Commit 9982e8cf authored by hybrid's avatar hybrid

Added two currently disabled OpenGL improvements for shadow volumes. Due to...

Added two currently disabled OpenGL improvements for shadow volumes. Due to incompatible shadow volumes the extensions are not yet working.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@752 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 9b3c67fe
......@@ -1725,39 +1725,106 @@ void COpenGLDriver::drawStencilShadowVolume(const core::vector3df* triangles, s3
glDisable(GL_LIGHTING);
glDisable(GL_FOG);
glDepthMask(GL_FALSE); // no depth buffer writing
glDepthFunc(GL_LEQUAL);
glDepthMask(GL_FALSE); // no depth buffer writing
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE ); // no color buffer drawing
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_ALWAYS, 0, 0);
glEnable(GL_CULL_FACE);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3,GL_FLOAT,sizeof(core::vector3df),&triangles[0]);
glStencilMask(~0);
glStencilFunc(GL_ALWAYS, 0, ~0);
if (!zfail)
// The first parts are not correctly working, yet.
#if 0
if (FeatureAvailable[IRR_EXT_stencil_two_side] && FeatureAvailable[IRR_EXT_stencil_wrap])
{
// ZPASS Method
glEnable(GL_STENCIL_TEST_TWO_SIDE_EXT);
glEnable(GL_DEPTH_CLAMP_NV);
glDisable(GL_CULL_FACE);
if (!zfail)
{
// ZPASS Method
glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
glCullFace(GL_BACK);
glDrawArrays(GL_TRIANGLES,0,count);
extGlActiveStencilFace(GL_BACK);
glStencilOp(GL_KEEP, GL_KEEP, GL_DECR_WRAP_EXT);
extGlActiveStencilFace(GL_FRONT);
glStencilOp(GL_KEEP, GL_KEEP, GL_INCR_WRAP_EXT);
glStencilMask(~0);
glStencilFunc(GL_ALWAYS, 0, ~0);
glDrawArrays(GL_TRIANGLES,0,count);
}
else
{
// ZFAIL Method
extGlActiveStencilFace(GL_BACK);
glStencilOp(GL_KEEP, GL_INCR_WRAP_EXT, GL_KEEP);
glStencilMask(~0);
glStencilFunc(GL_ALWAYS, 0, ~0);
extGlActiveStencilFace(GL_FRONT);
glStencilOp(GL_KEEP, GL_DECR_WRAP_EXT, GL_KEEP);
glStencilMask(~0);
glStencilFunc(GL_ALWAYS, 0, ~0);
glDrawArrays(GL_TRIANGLES,0,count);
}
}
else if (FeatureAvailable[IRR_ATI_separate_stencil])
{
glDisable(GL_CULL_FACE);
if (!zfail)
{
// ZPASS Method
glStencilOp(GL_KEEP, GL_KEEP, GL_DECR);
glCullFace(GL_FRONT);
glDrawArrays(GL_TRIANGLES,0,count);
extGlStencilOpSeparate(GL_BACK, GL_KEEP, GL_KEEP, GL_DECR);
extGlStencilOpSeparate(GL_FRONT, GL_KEEP, GL_KEEP, GL_INCR);
extGlStencilFuncSeparate(GL_FRONT_AND_BACK, GL_ALWAYS, 0, ~0);
glDrawArrays(GL_TRIANGLES,0,count);
}
else
{
// ZFAIL Method
extGlStencilOpSeparate(GL_BACK, GL_KEEP, GL_INCR, GL_KEEP);
extGlStencilOpSeparate(GL_FRONT, GL_KEEP, GL_DECR, GL_KEEP);
extGlStencilFuncSeparate(GL_FRONT_AND_BACK, GL_ALWAYS, 0, ~0);
glDrawArrays(GL_TRIANGLES,0,count);
}
}
else
#endif
{
// ZFAIL Method
glEnable(GL_CULL_FACE);
if (!zfail)
{
// ZPASS Method
glStencilOp(GL_KEEP, GL_INCR, GL_KEEP);
glCullFace(GL_FRONT);
glDrawArrays(GL_TRIANGLES,0,count);
glCullFace(GL_BACK);
glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
glDrawArrays(GL_TRIANGLES,0,count);
glStencilOp(GL_KEEP, GL_DECR, GL_KEEP);
glCullFace(GL_BACK);
glDrawArrays(GL_TRIANGLES,0,count);
glCullFace(GL_FRONT);
glStencilOp(GL_KEEP, GL_KEEP, GL_DECR);
glDrawArrays(GL_TRIANGLES,0,count);
}
else
{
// ZFAIL Method
glStencilOp(GL_KEEP, GL_INCR, GL_KEEP);
glCullFace(GL_FRONT);
glDrawArrays(GL_TRIANGLES,0,count);
glStencilOp(GL_KEEP, GL_DECR, GL_KEEP);
glCullFace(GL_BACK);
glDrawArrays(GL_TRIANGLES,0,count);
}
}
glDisableClientState(GL_VERTEX_ARRAY); //not stored on stack
......@@ -1780,7 +1847,6 @@ void COpenGLDriver::drawStencilShadow(bool clearStencilBuffer, video::SColor lef
glDisable( GL_LIGHTING );
glDisable(GL_FOG);
glDepthMask(GL_FALSE);
glDepthFunc( GL_LEQUAL );
glShadeModel( GL_FLAT );
glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
......@@ -1789,7 +1855,7 @@ void COpenGLDriver::drawStencilShadow(bool clearStencilBuffer, video::SColor lef
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable( GL_STENCIL_TEST );
glStencilFunc(GL_NOTEQUAL, 0, 0xFFFFFFFFL);
glStencilFunc(GL_NOTEQUAL, 0, ~0);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
// draw a shadow rectangle covering the entire screen using stencil buffer
......
......@@ -36,8 +36,7 @@ CShadowVolumeSceneNode::CShadowVolumeSceneNode(ISceneNode* parent,
//! destructor
CShadowVolumeSceneNode::~CShadowVolumeSceneNode()
{
if (Edges)
delete [] Edges;
delete [] Edges;
for (u32 i=0; i<ShadowVolumes.size(); ++i)
delete [] ShadowVolumes[i].vertices;
......@@ -97,10 +96,10 @@ void CShadowVolumeSceneNode::createShadowVolume(const core::vector3df& light)
s32 numEdges = 0;
core::vector3df ls = light * Infinity; // light scaled
//if (!UseZFailMethod)
// createZPassVolume(faceCount, numEdges, light, svp);
//else
//if (UseZFailMethod)
// createZFailVolume(faceCount, numEdges, light, svp);
//else
// createZPassVolume(faceCount, numEdges, light, svp, false);
// the createZFailVolume does currently not work 100% correctly,
// so we create createZPassVolume with caps if the zfail method
......@@ -144,13 +143,11 @@ void CShadowVolumeSceneNode::createZFailVolume(s32 faceCount, s32& numEdges,
wFace1 = Indices[3*i+1];
wFace2 = Indices[3*i+2];
core::vector3df v0 = Vertices[wFace0];
core::vector3df v1 = Vertices[wFace1];
core::vector3df v2 = Vertices[wFace2];
const core::vector3df v0 = Vertices[wFace0];
const core::vector3df v1 = Vertices[wFace1];
const core::vector3df v2 = Vertices[wFace2];
core::vector3df normal = (v2-v1).crossProduct(v1-v0);
if(normal.dotProduct(light) >= 0.0f )
if (core::triangle3df(v0,v1,v2).isFrontFacing(light))
{
FaceData[i] = false; // it's a back facing face
......@@ -213,15 +210,13 @@ void CShadowVolumeSceneNode::createZFailVolume(s32 faceCount, s32& numEdges,
void CShadowVolumeSceneNode::createZPassVolume(s32 faceCount,
s32& numEdges,
const core::vector3df& lightsource,
core::vector3df light,
SShadowVolume* svp, bool caps)
{
core::vector3df light(lightsource);
light *= Infinity;
if (light == core::vector3df(0,0,0))
light = core::vector3df(0.0001f,0.0001f,0.0001f);
core::vector3df normal;
u16 wFace0, wFace1, wFace2;
for (s32 i=0; i<faceCount; ++i)
......@@ -230,12 +225,7 @@ void CShadowVolumeSceneNode::createZPassVolume(s32 faceCount,
wFace1 = Indices[3*i+1];
wFace2 = Indices[3*i+2];
core::vector3df v0(Vertices[wFace2] - Vertices[wFace1]);
core::vector3df v1(Vertices[wFace1] - Vertices[wFace0]);
normal = v0.crossProduct(v1);
if (normal.dotProduct(light) >= 0.0f)
if (core::triangle3df(Vertices[wFace0],Vertices[wFace1],Vertices[wFace2]).isFrontFacing(light))
{
Edges[2*numEdges+0] = wFace0;
Edges[2*numEdges+1] = wFace1;
......@@ -292,7 +282,7 @@ void CShadowVolumeSceneNode::setMeshToRenderFrom(IMesh* mesh)
totalVertices += b->getVertexCount();
}
// allocate memory if nececcary
// allocate memory if necessary
if (totalVertices > VertexCountAllocated)
{
......
......@@ -55,7 +55,7 @@ namespace scene
};
void createShadowVolume(const core::vector3df& pos);
void createZPassVolume(s32 faceCount, s32& numEdges, const core::vector3df& light, SShadowVolume* svp, bool caps);
void createZPassVolume(s32 faceCount, s32& numEdges, core::vector3df light, SShadowVolume* svp, bool caps);
void createZFailVolume(s32 faceCount, s32& numEdges, const core::vector3df& light, SShadowVolume* svp);
void addEdge(s32& numEdges, u16 v0, u16 v1);
......
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