Basic shadow volume alogirthm implemented in example.

This commit is contained in:
Robert Osfield
2006-11-30 16:30:24 +00:00
parent 808047ee1b
commit a9d18d01db
3 changed files with 130 additions and 48 deletions

View File

@@ -962,7 +962,7 @@ void DrawShapeVisitor::apply(const HeightField& field)
// draw skirt at begining if required.
if (field.getSkirtHeight()!=0.0f)
{
vertTop.set(0.0f,dy*(float)row+dy,field.getHeight(0,row+1)-field.getSkirtHeight());
vertTop.set(0.0f,dy*(float)(row+1),field.getHeight(0,row+1)-field.getSkirtHeight());
normTop.set(field.getNormal(0,row+1));
vertBase.set(0.0f,dy*(float)row,field.getHeight(0,row)-field.getSkirtHeight());
@@ -979,7 +979,7 @@ void DrawShapeVisitor::apply(const HeightField& field)
for(unsigned int col=0;col<field.getNumColumns();++col,u+=du)
{
vertTop.set(dx*(float)col,dy*(float)row+dy,field.getHeight(col,row+1));
vertTop.set(dx*(float)col,dy*(float)(row+1),field.getHeight(col,row+1));
normTop.set(field.getNormal(col,row+1));
vertBase.set(dx*(float)col,dy*(float)row,field.getHeight(col,row));
@@ -1334,6 +1334,15 @@ void PrimitiveShapeVisitor::apply(const Sphere& sphere)
unsigned int numSegments = 40;
unsigned int numRows = 20;
float ratio = (_hints ? _hints->getDetailRatio() : 1.0f);
if (ratio > 0.0f && ratio != 1.0f) {
numRows = (unsigned int) (numRows * ratio);
if (numRows < MIN_NUM_ROWS)
numRows = MIN_NUM_ROWS;
numSegments = (unsigned int) (numSegments * ratio);
if (numSegments < MIN_NUM_SEGMENTS)
numSegments = MIN_NUM_SEGMENTS;
}
float lDelta = osg::PI/(float)numRows;
float vDelta = 1.0f/(float)numRows;
@@ -1708,7 +1717,7 @@ void PrimitiveShapeVisitor::apply(const HeightField& field)
for(unsigned int col=0;col<field.getNumColumns();++col)
{
Vec3 vertTop(dx*(float)col,dy*(float)row+dy,field.getHeight(col,row+1));
Vec3 vertTop(dx*(float)col,dy*(float)(row+1),field.getHeight(col,row+1));
Vec3 vertBase(dx*(float)col,dy*(float)row,field.getHeight(col,row));
_functor.vertex(vertTop*matrix);

View File

@@ -350,17 +350,21 @@ struct IndexVec3PtrPair
inline bool operator == (const IndexVec3PtrPair& rhs) const
{
return *vec == *rhs.vec;
// return (*vec - *rhs.vec).length2() < 1e-2;
}
const osg::Vec3* vec;
unsigned int index;
};
void OccluderGeometry::removeDuplicateVertices()
{
if (_vertices.empty()) return;
// osg::notify(osg::NOTICE)<<"OccluderGeometry::removeDuplicates() before = "<<_vertices.size()<<std::endl;
osg::notify(osg::NOTICE)<<"OccluderGeometry::removeDuplicates() before = "<<_vertices.size()<<std::endl;
typedef std::vector<IndexVec3PtrPair> IndexVec3PtrPairs;
IndexVec3PtrPairs indexVec3PtrPairs;
@@ -386,7 +390,7 @@ void OccluderGeometry::removeDuplicateVertices()
for(; curr != indexVec3PtrPairs.end(); ++curr)
{
if (*prev==*curr)
if (*prev==*curr)
{
++numDuplicates;
}
@@ -397,8 +401,8 @@ void OccluderGeometry::removeDuplicateVertices()
}
}
// osg::notify(osg::NOTICE)<<"Num diplicates = "<<numDuplicates<<std::endl;
// osg::notify(osg::NOTICE)<<"Num unique = "<<numUnique<<std::endl;
osg::notify(osg::NOTICE)<<"Num diplicates = "<<numDuplicates<<std::endl;
osg::notify(osg::NOTICE)<<"Num unique = "<<numUnique<<std::endl;
if (numDuplicates==0) return;
@@ -689,7 +693,7 @@ void OccluderGeometry::computeLightDirectionSlihouetteEdges(const osg::Vec3& lig
const osg::Vec3& v1 = _vertices[edge._p1];
const osg::Vec3& v2 = _vertices[edge._p2];
osg::Vec3 normal = (v2-v1) ^ lightdirection;
if (normal * edge._normal < 0.0)
if (normal * edge._normal > 0.0)
{
silhouetteIndices.push_back(edge._p1);
silhouetteIndices.push_back(edge._p2);
@@ -717,7 +721,7 @@ void OccluderGeometry::computeLightPositionSlihouetteEdges(const osg::Vec3& ligh
const osg::Vec3& v1 = _vertices[edge._p1];
const osg::Vec3& v2 = _vertices[edge._p2];
osg::Vec3 normal = (v2-v1) ^ (v1-lightpos);
if (normal * edge._normal < 0.0)
if (normal * edge._normal > 0.0)
{
silhouetteIndices.push_back(edge._p1);
silhouetteIndices.push_back(edge._p2);
@@ -801,7 +805,7 @@ void OccluderGeometry::comptueShadowVolumeGeometry(const osg::Vec4& lightpos, Sh
shadowVertices.push_back( v2_projected);
shadowVertices.push_back( v2);
osg::Vec3 normal = (v2-v1) ^ lightdirection;
osg::Vec3 normal = lightdirection ^ (v2-v1);
normal.normalize();
shadowNormals.push_back(normal);
shadowNormals.push_back(normal);
@@ -862,7 +866,7 @@ void OccluderGeometry::comptueShadowVolumeGeometry(const osg::Vec4& lightpos, Sh
shadowVertices.push_back( v2_projected);
shadowVertices.push_back( v2);
osg::Vec3 normal = (v2-v1) ^ d1;
osg::Vec3 normal = d1 ^ (v2-v1);
normal.normalize();
shadowNormals.push_back(normal);
shadowNormals.push_back(normal);