Converted tabs to four spaces
This commit is contained in:
parent
236832f669
commit
45085f3eea
@ -1245,7 +1245,7 @@ void ConvexPolyhedron::cut(const osg::Plane& plane, const std::string& name)
|
||||
if( plane.ptr()[0] ) == itr->plane.ptr()[0] &&
|
||||
plane.ptr()[1] ) == itr->plane.ptr()[1] &&
|
||||
plane.ptr()[2] ) == itr->plane.ptr()[2] &&
|
||||
#else // check plane using less precise float values
|
||||
#else // check plane using less precise float values
|
||||
if( float( plane.ptr()[0] ) == float( itr->plane.ptr()[0] ) &&
|
||||
float( plane.ptr()[1] ) == float( itr->plane.ptr()[1] ) &&
|
||||
float( plane.ptr()[2] ) == float( itr->plane.ptr()[2] ) &&
|
||||
|
@ -64,7 +64,7 @@ DebugShadowMap::DebugShadowMap():
|
||||
"{ \n"
|
||||
" float f = texture2D( texture, vec3( gl_TexCoord[0].xy, 1.0).xy ).r; \n"
|
||||
" gl_FragColor = vec4( 0.0, 1.0 - f, 0.5 - f, 0.5 ); \n"
|
||||
"} \n"
|
||||
"} \n"
|
||||
#else
|
||||
"uniform sampler2D texture; \n"
|
||||
" \n"
|
||||
@ -136,7 +136,7 @@ bool DebugShadowMap::ViewData::DebugBoundingBox
|
||||
( const osg::BoundingBox & bb, const char * name )
|
||||
{
|
||||
bool result = false;
|
||||
#if defined( _DEBUG ) || defined( DEBUG )
|
||||
#if defined( _DEBUG ) || defined( DEBUG )
|
||||
if( !name ) name = "";
|
||||
|
||||
osg::BoundingBox & bb_prev = _boundingBoxMap[ std::string( name ) ];
|
||||
@ -161,7 +161,7 @@ bool DebugShadowMap::ViewData::DebugPolytope
|
||||
( const osg::Polytope & p, const char * name )
|
||||
{
|
||||
bool result = false;
|
||||
#if defined( _DEBUG ) || defined( DEBUG )
|
||||
#if defined( _DEBUG ) || defined( DEBUG )
|
||||
if( !name ) name = "";
|
||||
|
||||
osg::Polytope & p_prev = _polytopeMap[ std::string( name ) ];
|
||||
@ -199,7 +199,7 @@ bool DebugShadowMap::ViewData::DebugMatrix
|
||||
( const osg::Matrix & m, const char * name )
|
||||
{
|
||||
bool result = false;
|
||||
#if defined( _DEBUG ) || defined( DEBUG )
|
||||
#if defined( _DEBUG ) || defined( DEBUG )
|
||||
if( !name ) name = "";
|
||||
|
||||
osg::Matrix & m_prev = _matrixMap[ std::string( name ) ];
|
||||
@ -276,7 +276,7 @@ void DebugShadowMap::ViewData::updateDebugGeometry
|
||||
|
||||
const osg::Camera *camera[2] = { viewCam, shadowCam };
|
||||
|
||||
osg::Matrix
|
||||
osg::Matrix
|
||||
transform[ num ] =
|
||||
{ viewCam->getViewMatrix() *
|
||||
// use near far clamped projection ( precomputed in cullDebugGeometry )
|
||||
@ -321,7 +321,7 @@ void DebugShadowMap::ViewData::updateDebugGeometry
|
||||
for( int i = 0; i < num ; i++ )
|
||||
{
|
||||
|
||||
ConvexPolyhedron cp( pg._polytope );
|
||||
ConvexPolyhedron cp( pg._polytope );
|
||||
cp.cut( frustum[i] );
|
||||
cp.transform( transform[i], inverse[i] );
|
||||
|
||||
@ -455,7 +455,7 @@ void DebugShadowMap::ViewData::createDebugHUD( )
|
||||
if( _orthoSize[1] <= 0 ) _orthoSize[1] = _viewportSize[1];
|
||||
}
|
||||
|
||||
{ // Initialize hud camera
|
||||
{ // Initialize hud camera
|
||||
osg::Camera * camera = _cameraDebugHUD.get();
|
||||
camera->setComputeNearFarMode(osg::Camera::DO_NOT_COMPUTE_NEAR_FAR);
|
||||
camera->setReferenceFrame(osg::Camera::ABSOLUTE_RF);
|
||||
|
@ -114,11 +114,11 @@ void calcLispSMMtx(struct VecPoint* B) {
|
||||
|
||||
//one possibility for a simple perspective transformation matrix
|
||||
//with the two parameters n(near) and f(far) in y direction
|
||||
copyMatrix(lispMtx,IDENTITY); // a = (f+n)/(f-n); b = -2*f*n/(f-n);
|
||||
lispMtx[ 5] = (f+n)/(f-n); // [ 1 0 0 0]
|
||||
lispMtx[13] = -2*f*n/(f-n); // [ 0 a 0 b]
|
||||
lispMtx[ 7] = 1; // [ 0 0 1 0]
|
||||
lispMtx[15] = 0; // [ 0 1 0 0]
|
||||
copyMatrix(lispMtx,IDENTITY); // a = (f+n)/(f-n); b = -2*f*n/(f-n);
|
||||
lispMtx[ 5] = (f+n)/(f-n); // [ 1 0 0 0]
|
||||
lispMtx[13] = -2*f*n/(f-n); // [ 0 a 0 b]
|
||||
lispMtx[ 7] = 1; // [ 0 0 1 0]
|
||||
lispMtx[15] = 0; // [ 0 1 0 0]
|
||||
|
||||
//temporal arrangement for the transformation of the points to post-perspective space
|
||||
mult(lightProjection,lispMtx,lightView); // ligthProjection = lispMtx*lightView
|
||||
@ -322,7 +322,7 @@ void LightSpacePerspectiveShadowMapAlgorithm::operator()
|
||||
// But since we want to pass it to std OpenGL right handed coordinate
|
||||
// makeLookAt function we compensate the effects by also using right
|
||||
// handed view forward vector (ie 0,0,-1) instead.
|
||||
// So in the end we get left handed makeLookAt behaviour (D3D like)...
|
||||
// So in the end we get left handed makeLookAt behaviour (D3D like)...
|
||||
// I agree this method is bizarre. But it works so I left it as is.
|
||||
// It sort of came out by itself through trial and error.
|
||||
// I later understoood why it works.
|
||||
@ -424,14 +424,14 @@ public:
|
||||
const double getN() const
|
||||
{ return _N; }
|
||||
|
||||
//for old LispSM formula from paper
|
||||
const double getNearDist() const
|
||||
//for old LispSM formula from paper
|
||||
const double getNearDist() const
|
||||
{ return _nearDist; }
|
||||
|
||||
void setNearDist( const double & nearDist )
|
||||
{ _nearDist = nearDist; }
|
||||
|
||||
const double getFarDist() const
|
||||
const double getFarDist() const
|
||||
{ return _farDist; }
|
||||
|
||||
void setFarDist( const double & farDist )
|
||||
@ -470,54 +470,54 @@ protected:
|
||||
double getN(const osg::Matrix lightSpace, const osg::BoundingBox& B_ls) const;
|
||||
|
||||
osg::Vec3d getNearCameraPointE() const;
|
||||
|
||||
|
||||
osg::Vec3d getZ0_ls
|
||||
(const osg::Matrix& lightSpace, const osg::Vec3d& e, const double& b_lsZmax, const osg::Vec3d& eyeDir) const;
|
||||
|
||||
double calcNoptGeneral
|
||||
double calcNoptGeneral
|
||||
(const osg::Matrix lightSpace, const osg::BoundingBox& B_ls) const;
|
||||
|
||||
double calcNoptOld
|
||||
double calcNoptOld
|
||||
( const double gamma_ = 999) const;
|
||||
|
||||
osg::Matrix getLispSmMtx
|
||||
(const osg::Matrix& lightSpace) const;
|
||||
|
||||
osg::Vec3d getProjViewDir_ls
|
||||
osg::Vec3d getProjViewDir_ls
|
||||
(const osg::Matrix& lightSpace) const;
|
||||
|
||||
void updateLightMtx
|
||||
void updateLightMtx
|
||||
(osg::Matrix& lightView, osg::Matrix& lightProj, const std::vector<osg::Vec3d>& B) const;
|
||||
|
||||
public:
|
||||
LispSM( ) : _useLiSPSM( true ), _useFormula( true ), _useOldFormula( false ), _N( 1 ), _nearDist( 1 ), _farDist( 10 ) { }
|
||||
|
||||
virtual void updateLightMtx( osg::Matrix& lightView, osg::Matrix& lightProj ) const;
|
||||
virtual void updateLightMtx( osg::Matrix& lightView, osg::Matrix& lightProj ) const;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
osg::Vec3d LispSM::getNearCameraPointE( ) const
|
||||
{
|
||||
const osg::Matrix& eyeView = getViewMatrix();
|
||||
const osg::Matrix& eyeView = getViewMatrix();
|
||||
|
||||
ConvexPolyhedron::Vertices LVS;
|
||||
_hull.getPoints( LVS );
|
||||
|
||||
//the LVS volume is always in front of the camera
|
||||
//the camera points along the neg z axis.
|
||||
//-> so the nearest point is the maximum
|
||||
//the LVS volume is always in front of the camera
|
||||
//the camera points along the neg z axis.
|
||||
//-> so the nearest point is the maximum
|
||||
|
||||
unsigned max = 0;
|
||||
for(unsigned i = 0; i < LVS.size(); i++) {
|
||||
unsigned max = 0;
|
||||
for(unsigned i = 0; i < LVS.size(); i++) {
|
||||
|
||||
LVS[i] = LVS[i] * eyeView;
|
||||
|
||||
if( LVS[max].z() < LVS[i].z() ) {
|
||||
max = i;
|
||||
}
|
||||
}
|
||||
//transform back to world space
|
||||
if( LVS[max].z() < LVS[i].z() ) {
|
||||
max = i;
|
||||
}
|
||||
}
|
||||
//transform back to world space
|
||||
return LVS[max] * osg::Matrix::inverse( eyeView );
|
||||
}
|
||||
|
||||
@ -526,16 +526,16 @@ osg::Vec3d LispSM::getNearCameraPointE( ) const
|
||||
osg::Vec3d LispSM::getZ0_ls
|
||||
(const osg::Matrix& lightSpace, const osg::Vec3d& e, const double& b_lsZmax, const osg::Vec3d& eyeDir) const
|
||||
{
|
||||
//to calculate the parallel plane to the near plane through e we
|
||||
//calculate the plane A with the three points
|
||||
//to calculate the parallel plane to the near plane through e we
|
||||
//calculate the plane A with the three points
|
||||
osg::Plane A(eyeDir,e);
|
||||
//to transform plane A into lightSpace
|
||||
A.transform( lightSpace );
|
||||
//transform to light space
|
||||
const osg::Vec3d e_ls = e * lightSpace;
|
||||
//to transform plane A into lightSpace
|
||||
A.transform( lightSpace );
|
||||
//transform to light space
|
||||
const osg::Vec3d e_ls = e * lightSpace;
|
||||
|
||||
//z_0 has the x coordinate of e, the z coord of B_lsZmax
|
||||
//and the y coord of the plane A and plane (z==B_lsZmax) intersection
|
||||
//z_0 has the x coordinate of e, the z coord of B_lsZmax
|
||||
//and the y coord of the plane A and plane (z==B_lsZmax) intersection
|
||||
#if 1
|
||||
osg::Vec3d v = osg::Vec3d(e_ls.x(),0,b_lsZmax);
|
||||
|
||||
@ -546,34 +546,34 @@ osg::Vec3d LispSM::getZ0_ls
|
||||
|
||||
v.y() = -A.distance( v ) / A.getNormal().y();
|
||||
#else
|
||||
//get the parameters of A from the plane equation n dot d = 0
|
||||
//get the parameters of A from the plane equation n dot d = 0
|
||||
const double d = A.asVec4()[3];
|
||||
const osg::Vec3d n = A.getNormal();
|
||||
osg::Vec3d v(e_ls.x(),(-d-n.z()*b_lsZmax-n.x()*e_ls.x())/n.y(),b_lsZmax);
|
||||
#endif
|
||||
|
||||
return v;
|
||||
return v;
|
||||
|
||||
}
|
||||
|
||||
double LispSM::calcNoptGeneral(const osg::Matrix lightSpace, const osg::BoundingBox& B_ls) const
|
||||
{
|
||||
const osg::Matrix& eyeView = getViewMatrix();
|
||||
const osg::Matrix& eyeView = getViewMatrix();
|
||||
const osg::Matrix invLightSpace = osg::Matrix::inverse( lightSpace );
|
||||
|
||||
const osg::Vec3d z0_ls = getZ0_ls(lightSpace, _E,B_ls.zMax(),getEyeDir());
|
||||
const osg::Vec3d z1_ls = osg::Vec3d(z0_ls.x(),z0_ls.y(),B_ls.zMin());
|
||||
|
||||
//to world
|
||||
const osg::Vec3d z0_ls = getZ0_ls(lightSpace, _E,B_ls.zMax(),getEyeDir());
|
||||
const osg::Vec3d z1_ls = osg::Vec3d(z0_ls.x(),z0_ls.y(),B_ls.zMin());
|
||||
|
||||
//to world
|
||||
const osg::Vec4d z0_ws = osg::Vec4d( z0_ls, 1 ) * invLightSpace;
|
||||
const osg::Vec4d z1_ws = osg::Vec4d( z1_ls, 1 ) * invLightSpace;
|
||||
const osg::Vec4d z1_ws = osg::Vec4d( z1_ls, 1 ) * invLightSpace;
|
||||
|
||||
//to eye
|
||||
const osg::Vec4d z0_cs = z0_ws * eyeView;
|
||||
const osg::Vec4d z1_cs = z1_ws * eyeView;
|
||||
//to eye
|
||||
const osg::Vec4d z0_cs = z0_ws * eyeView;
|
||||
const osg::Vec4d z1_cs = z1_ws * eyeView;
|
||||
|
||||
double z0 = -z0_cs.z() / z0_cs.w();
|
||||
double z1 = -z1_cs.z() / z1_cs.w();
|
||||
double z0 = -z0_cs.z() / z0_cs.w();
|
||||
double z1 = -z1_cs.z() / z1_cs.w();
|
||||
|
||||
if( z1 / z0 <= 1.0 ) {
|
||||
|
||||
@ -603,22 +603,22 @@ double LispSM::calcNoptGeneral(const osg::Matrix lightSpace, const osg::Bounding
|
||||
<< "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
|
||||
<< std::flush;
|
||||
#endif
|
||||
return N;
|
||||
return N;
|
||||
}
|
||||
|
||||
double LispSM::calcNoptOld( const double gamma_ ) const
|
||||
{
|
||||
const double& n = getNearDist();
|
||||
const double& f = getFarDist();
|
||||
const double d = abs(f-n);
|
||||
double sinGamma(0);
|
||||
if(999 == gamma_) {
|
||||
const double& n = getNearDist();
|
||||
const double& f = getFarDist();
|
||||
const double d = abs(f-n);
|
||||
double sinGamma(0);
|
||||
if(999 == gamma_) {
|
||||
double dot = getEyeDir() * getLightDir();
|
||||
sinGamma = sqrt( 1.0 - dot * dot );
|
||||
}
|
||||
else {
|
||||
sinGamma = sin(gamma_);
|
||||
}
|
||||
sinGamma = sqrt( 1.0 - dot * dot );
|
||||
}
|
||||
else {
|
||||
sinGamma = sin(gamma_);
|
||||
}
|
||||
|
||||
double N = (n+sqrt(n*(n+d*sinGamma)))/sinGamma;
|
||||
#if PRINT_COMPUTED_N_OPT
|
||||
@ -629,71 +629,71 @@ double LispSM::calcNoptOld( const double gamma_ ) const
|
||||
<< "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
|
||||
<< std::flush;
|
||||
#endif
|
||||
return N;
|
||||
return N;
|
||||
}
|
||||
|
||||
double LispSM::getN(const osg::Matrix lightSpace, const osg::BoundingBox& B_ls) const
|
||||
{
|
||||
if( getUseFormula()) {
|
||||
if( getUseFormula()) {
|
||||
if( getUseOldFormula() )
|
||||
return calcNoptOld();
|
||||
else
|
||||
return calcNoptGeneral(lightSpace,B_ls);
|
||||
}
|
||||
else {
|
||||
return getN();
|
||||
}
|
||||
return calcNoptGeneral(lightSpace,B_ls);
|
||||
}
|
||||
else {
|
||||
return getN();
|
||||
}
|
||||
}
|
||||
//this is the algorithm discussed in the article
|
||||
osg::Matrix LispSM::getLispSmMtx( const osg::Matrix& lightSpace ) const
|
||||
{
|
||||
const osg::BoundingBox B_ls = _hull.computeBoundingBox( lightSpace );
|
||||
|
||||
const double n = getN(lightSpace,B_ls);
|
||||
const double n = getN(lightSpace,B_ls);
|
||||
|
||||
//get the coordinates of the near camera point in light space
|
||||
const osg::Vec3d e_ls = _E * lightSpace;
|
||||
//c start has the x and y coordinate of e, the z coord of B.min()
|
||||
const osg::Vec3d Cstart_lp(e_ls.x(),e_ls.y(),B_ls.zMax());
|
||||
//get the coordinates of the near camera point in light space
|
||||
const osg::Vec3d e_ls = _E * lightSpace;
|
||||
//c start has the x and y coordinate of e, the z coord of B.min()
|
||||
const osg::Vec3d Cstart_lp(e_ls.x(),e_ls.y(),B_ls.zMax());
|
||||
|
||||
if( n >= INFINITY ) {
|
||||
//if n is inf. than we should do uniform shadow mapping
|
||||
return osg::Matrix::identity();
|
||||
}
|
||||
//calc C the projection center
|
||||
//new projection center C, n behind the near plane of P
|
||||
//we work along a negative axis so we transform +n*<the positive axis> == -n*<neg axis>
|
||||
const osg::Vec3d C( Cstart_lp + osg::Vec3d(0,0,1) * n );
|
||||
//construct a translation that moves to the projection center
|
||||
if( n >= INFINITY ) {
|
||||
//if n is inf. than we should do uniform shadow mapping
|
||||
return osg::Matrix::identity();
|
||||
}
|
||||
//calc C the projection center
|
||||
//new projection center C, n behind the near plane of P
|
||||
//we work along a negative axis so we transform +n*<the positive axis> == -n*<neg axis>
|
||||
const osg::Vec3d C( Cstart_lp + osg::Vec3d(0,0,1) * n );
|
||||
//construct a translation that moves to the projection center
|
||||
const osg::Matrix projectionCenter = osg::Matrix::translate( -C );
|
||||
|
||||
//calc d the perspective transform depth or light space y extents
|
||||
const double d = osg::absolute(B_ls.zMax()-B_ls.zMin());
|
||||
//calc d the perspective transform depth or light space y extents
|
||||
const double d = osg::absolute(B_ls.zMax()-B_ls.zMin());
|
||||
|
||||
//the lispsm perspective transformation
|
||||
//the lispsm perspective transformation
|
||||
|
||||
//here done with a standard frustum call that maps P onto the unit cube with
|
||||
//corner points [-1,-1,-1] and [1,1,1].
|
||||
//in directX you can use the same mapping and do a mapping to the directX post-perspective cube
|
||||
//with corner points [-1,-1,0] and [1,1,1] as the final step after all the shadow mapping.
|
||||
//here done with a standard frustum call that maps P onto the unit cube with
|
||||
//corner points [-1,-1,-1] and [1,1,1].
|
||||
//in directX you can use the same mapping and do a mapping to the directX post-perspective cube
|
||||
//with corner points [-1,-1,0] and [1,1,1] as the final step after all the shadow mapping.
|
||||
osg::Matrix P = osg::Matrix::frustum( -1.0,1.0,-1.0,1.0, n, n+d );
|
||||
|
||||
//invert the transform from right handed into left handed coordinate system for the ndc
|
||||
//done by the openGL style frustumGL call
|
||||
//so we stay in a right handed system
|
||||
//invert the transform from right handed into left handed coordinate system for the ndc
|
||||
//done by the openGL style frustumGL call
|
||||
//so we stay in a right handed system
|
||||
P = P * osg::Matrix::scale( 1.0,1.0,-1.0 );
|
||||
//return the lispsm frustum with the projection center
|
||||
return projectionCenter * P;
|
||||
//return the lispsm frustum with the projection center
|
||||
return projectionCenter * P;
|
||||
}
|
||||
|
||||
osg::Vec3d LispSM::getProjViewDir_ls(const osg::Matrix& lightSpace ) const {
|
||||
//get the point in the LVS volume that is nearest to the camera
|
||||
const osg::Vec3d e = _E;
|
||||
//construct edge to transform into light-space
|
||||
const osg::Vec3d b = e+getEyeDir();
|
||||
//transform to light-space
|
||||
//get the point in the LVS volume that is nearest to the camera
|
||||
const osg::Vec3d e = _E;
|
||||
//construct edge to transform into light-space
|
||||
const osg::Vec3d b = e+getEyeDir();
|
||||
//transform to light-space
|
||||
osg::Vec4d e_lp = osg::Vec4d( e, 1.0 ) * lightSpace;
|
||||
osg::Vec4d b_lp = osg::Vec4d( b, 1.0 ) * lightSpace;
|
||||
osg::Vec4d b_lp = osg::Vec4d( b, 1.0 ) * lightSpace;
|
||||
|
||||
if( e_lp[3] <= 0 )
|
||||
{
|
||||
@ -714,56 +714,56 @@ osg::Vec3d LispSM::getProjViewDir_ls(const osg::Matrix& lightSpace ) const {
|
||||
|
||||
projDir.normalize();
|
||||
|
||||
//project the view direction into the shadow map plane
|
||||
projDir.y() = 0.0;
|
||||
return projDir;
|
||||
//project the view direction into the shadow map plane
|
||||
projDir.y() = 0.0;
|
||||
return projDir;
|
||||
}
|
||||
|
||||
void LispSM::updateLightMtx
|
||||
( osg::Matrix& lightView, osg::Matrix& lightProj ) const
|
||||
{
|
||||
//calculate standard light space for spot or directional lights
|
||||
//this routine returns two matrices:
|
||||
//lightview contains the rotated translated frame
|
||||
//lightproj contains in the case of a spot light the spot light perspective transformation
|
||||
//in the case of a directional light a identity matrix
|
||||
// calcLightSpace(lightView,lightProj);
|
||||
//calculate standard light space for spot or directional lights
|
||||
//this routine returns two matrices:
|
||||
//lightview contains the rotated translated frame
|
||||
//lightproj contains in the case of a spot light the spot light perspective transformation
|
||||
//in the case of a directional light a identity matrix
|
||||
// calcLightSpace(lightView,lightProj);
|
||||
|
||||
if( _hull._faces.empty() ) {
|
||||
//debug() << "empty intersection body -> completely inside shadow\n";//debug output
|
||||
return;
|
||||
}
|
||||
//debug() << "empty intersection body -> completely inside shadow\n";//debug output
|
||||
return;
|
||||
}
|
||||
|
||||
_E = getNearCameraPointE();
|
||||
|
||||
lightProj = lightProj * osg::Matrix::scale( 1, 1, -1 );
|
||||
|
||||
//coordinate system change for calculations in the article
|
||||
//coordinate system change for calculations in the article
|
||||
osg::Matrix switchToArticle = osg::Matrix::identity();
|
||||
switchToArticle(1,1) = 0.0;
|
||||
switchToArticle(1,2) =-1.0; // y -> -z
|
||||
switchToArticle(2,1) = 1.0; // z -> y
|
||||
switchToArticle(2,2) = 0.0;
|
||||
//switch to the lightspace used in the article
|
||||
lightProj = lightProj * switchToArticle;
|
||||
switchToArticle(1,1) = 0.0;
|
||||
switchToArticle(1,2) =-1.0; // y -> -z
|
||||
switchToArticle(2,1) = 1.0; // z -> y
|
||||
switchToArticle(2,2) = 0.0;
|
||||
//switch to the lightspace used in the article
|
||||
lightProj = lightProj * switchToArticle;
|
||||
|
||||
osg::Matrix L = lightView * lightProj;
|
||||
osg::Matrix L = lightView * lightProj;
|
||||
|
||||
osg::Vec3d projViewDir = getProjViewDir_ls(L);
|
||||
osg::Vec3d projViewDir = getProjViewDir_ls(L);
|
||||
|
||||
if( getUseLiSPSM() /* && projViewDir.z() < 0*/ ) {
|
||||
//do Light Space Perspective shadow mapping
|
||||
//rotate the lightspace so that the proj light view always points upwards
|
||||
//calculate a frame matrix that uses the projViewDir[light-space] as up vector
|
||||
//look(from position, into the direction of the projected direction, with unchanged up-vector)
|
||||
lightProj = lightProj *
|
||||
if( getUseLiSPSM() /* && projViewDir.z() < 0*/ ) {
|
||||
//do Light Space Perspective shadow mapping
|
||||
//rotate the lightspace so that the proj light view always points upwards
|
||||
//calculate a frame matrix that uses the projViewDir[light-space] as up vector
|
||||
//look(from position, into the direction of the projected direction, with unchanged up-vector)
|
||||
lightProj = lightProj *
|
||||
osg::Matrix::lookAt( osg::Vec3d(0,0,0), projViewDir, osg::Vec3d(0,1,0) );
|
||||
|
||||
osg::Matrix lispsm = getLispSmMtx( lightView * lightProj );
|
||||
lightProj = lightProj * lispsm;
|
||||
}
|
||||
osg::Matrix lispsm = getLispSmMtx( lightView * lightProj );
|
||||
lightProj = lightProj * lispsm;
|
||||
}
|
||||
|
||||
const osg::Matrix PL = lightView * lightProj;
|
||||
const osg::Matrix PL = lightView * lightProj;
|
||||
|
||||
osg::BoundingBox bb = _hull.computeBoundingBox( PL );
|
||||
|
||||
@ -772,19 +772,19 @@ void LispSM::updateLightMtx
|
||||
bb._min[1], bb._max[1],
|
||||
-bb._max[2], -bb._min[2] );
|
||||
|
||||
//map to unit cube
|
||||
lightProj = lightProj * fitToUnitFrustum;
|
||||
//map to unit cube
|
||||
lightProj = lightProj * fitToUnitFrustum;
|
||||
|
||||
//coordinate system change for calculations in the article
|
||||
osg::Matrix switchToGL = osg::Matrix::identity();
|
||||
switchToGL(1,1) = 0.0;
|
||||
switchToGL(1,2) = 1.0; // y -> z
|
||||
switchToGL(2,1) = -1.0; // z -> -y
|
||||
switchToGL(2,2) = 0.0;
|
||||
//coordinate system change for calculations in the article
|
||||
osg::Matrix switchToGL = osg::Matrix::identity();
|
||||
switchToGL(1,1) = 0.0;
|
||||
switchToGL(1,2) = 1.0; // y -> z
|
||||
switchToGL(2,1) = -1.0; // z -> -y
|
||||
switchToGL(2,2) = 0.0;
|
||||
|
||||
//back to open gl coordinate system y <-> z
|
||||
lightProj = lightProj * switchToGL;
|
||||
//transform from right handed system into left handed ndc
|
||||
//back to open gl coordinate system y <-> z
|
||||
lightProj = lightProj * switchToGL;
|
||||
//transform from right handed system into left handed ndc
|
||||
lightProj = lightProj * osg::Matrix::scale(1.0,1.0,-1.0);
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ MinimalDrawBoundsShadowMap::~MinimalDrawBoundsShadowMap()
|
||||
}
|
||||
|
||||
void MinimalDrawBoundsShadowMap::ViewData::cullShadowReceivingScene( )
|
||||
{
|
||||
{
|
||||
BaseClass::ViewData::cullShadowReceivingScene( );
|
||||
ThisClass::ViewData::cullBoundAnalysisScene( );
|
||||
}
|
||||
@ -59,7 +59,7 @@ void MinimalDrawBoundsShadowMap::ViewData::cullBoundAnalysisScene( )
|
||||
_boundAnalysisCamera->setProjectionMatrix( _clampedProjection );
|
||||
|
||||
osg::Matrix::value_type l,r,b,t,n,f;
|
||||
_boundAnalysisCamera->getProjectionMatrixAsFrustum( l,r,b,t,n,f );
|
||||
_boundAnalysisCamera->getProjectionMatrixAsFrustum( l,r,b,t,n,f );
|
||||
|
||||
_mainCamera = _cv->getRenderStage()->getCamera();
|
||||
|
||||
@ -82,7 +82,7 @@ void MinimalDrawBoundsShadowMap::ViewData::cullBoundAnalysisScene( )
|
||||
|
||||
void MinimalDrawBoundsShadowMap::ViewData::createDebugHUD( )
|
||||
{
|
||||
// _hudSize[0] *= 2;
|
||||
// _hudSize[0] *= 2;
|
||||
_viewportSize[0] *= 2;
|
||||
_orthoSize[0] *= 2;
|
||||
|
||||
@ -119,10 +119,10 @@ osg::BoundingBox MinimalDrawBoundsShadowMap::ViewData::scanImage
|
||||
{
|
||||
osg::BoundingBox bb, bbProj;
|
||||
|
||||
int components = osg::Image::computeNumComponents( image->getPixelFormat() );
|
||||
int components = osg::Image::computeNumComponents( image->getPixelFormat() );
|
||||
|
||||
if( image->getDataType() == GL_FLOAT ) {
|
||||
float scale = 255.f / 254.f;
|
||||
float scale = 255.f / 254.f;
|
||||
float * pf = (float *)image->data();
|
||||
for( int y = 0; y < image->t(); y++ ) {
|
||||
float fY = ( 0.5f + y ) / image->t();
|
||||
@ -208,8 +208,8 @@ void MinimalDrawBoundsShadowMap::ViewData::performBoundAnalysis( const osg::Came
|
||||
if( getDebugDraw() ) {
|
||||
ConvexPolyhedron p;
|
||||
p.setToBoundingBox( bb );
|
||||
p.transform( *_modellingSpaceToWorldPtr,
|
||||
osg::Matrix::inverse( *_modellingSpaceToWorldPtr ) );
|
||||
p.transform( *_modellingSpaceToWorldPtr,
|
||||
osg::Matrix::inverse( *_modellingSpaceToWorldPtr ) );
|
||||
|
||||
setDebugPolytope( "scan", p,
|
||||
osg::Vec4( 0,0,0,1 ), osg::Vec4( 0,0,0,0.1 ) );
|
||||
@ -250,7 +250,7 @@ void MinimalDrawBoundsShadowMap::ViewData::recordShadowMapParams( )
|
||||
std::set< osg::ref_ptr< osg::RefMatrix > > projections;
|
||||
|
||||
MinimalShadowMap::GetRenderLeaves( , rll );
|
||||
for( unsigned i =0; i < rll.size(); i++ ) {
|
||||
for( unsigned i =0; i < rll.size(); i++ ) {
|
||||
if( rll[i]->_projection.get() != _projection.get() ) {
|
||||
osg::RefMatrix * projection = rll[i]->_projection.get();
|
||||
projections.insert( rll[i]->_projection );
|
||||
@ -286,7 +286,7 @@ void MinimalDrawBoundsShadowMap::ViewData::init
|
||||
_boundAnalysisSize[1], 1,
|
||||
GL_DEPTH_COMPONENT, GL_FLOAT );
|
||||
|
||||
_boundAnalysisTexture->setInternalFormat(GL_DEPTH_COMPONENT);
|
||||
_boundAnalysisTexture->setInternalFormat(GL_DEPTH_COMPONENT);
|
||||
// _boundAnalysisTexture->setShadowComparison(true);
|
||||
_boundAnalysisTexture->setShadowTextureMode(osg::Texture2D::LUMINANCE);
|
||||
|
||||
@ -330,7 +330,7 @@ void MinimalDrawBoundsShadowMap::ViewData::init
|
||||
_boundAnalysisCamera->setName( "AnalysisCamera" );
|
||||
|
||||
_boundAnalysisCamera->setCullCallback( new BaseClass::CameraCullCallback(st) );
|
||||
// _boundAnalysisCamera->setPreDrawCallback( _camera->getPreDrawCallback() );
|
||||
// _boundAnalysisCamera->setPreDrawCallback( _camera->getPreDrawCallback() );
|
||||
_boundAnalysisCamera->setPostDrawCallback( new CameraPostDrawCallback(this) );
|
||||
|
||||
_boundAnalysisCamera->setClearColor( osg::Vec4(1,1,1,1) );
|
||||
@ -355,8 +355,8 @@ void MinimalDrawBoundsShadowMap::ViewData::init
|
||||
stateset->setAttributeAndModes
|
||||
( new osg::Depth( osg::Depth::LESS, 0.0, 254.f/255.f ), OVERRIDE_ON );
|
||||
|
||||
// stateset->setAttributeAndModes
|
||||
// ( new osg::AlphaFunc( osg::AlphaFunc::EQUAL, 1.f ), OVERRIDE_ON );
|
||||
// stateset->setAttributeAndModes
|
||||
// ( new osg::AlphaFunc( osg::AlphaFunc::EQUAL, 1.f ), OVERRIDE_ON );
|
||||
|
||||
stateset->setRenderBinDetails( 0, "RenderBin",
|
||||
osg::StateSet::OVERRIDE_RENDERBIN_DETAILS );
|
||||
@ -373,7 +373,7 @@ void MinimalDrawBoundsShadowMap::ViewData::init
|
||||
" gl_FragColor = vec4( gl_FragCoord.z, \n"
|
||||
" 1.-gl_FragCoord.z, \n"
|
||||
" 1., \n"
|
||||
" texture2D( texture, gl_TexCoord[0].xy ).a ); \n"
|
||||
" texture2D( texture, gl_TexCoord[0].xy ).a ); \n"
|
||||
#endif
|
||||
"} \n"
|
||||
) ); // program->addShader Fragment
|
||||
@ -395,7 +395,7 @@ void MinimalDrawBoundsShadowMap::ViewData::init
|
||||
|
||||
stateset->setMode( GL_BLEND, OVERRIDE_OFF );
|
||||
#else
|
||||
// _boundAnalysisCamera->attach(osg::Camera::COLOR_BUFFER, _boundAnalysisTexture.get());
|
||||
// _boundAnalysisCamera->attach(osg::Camera::COLOR_BUFFER, _boundAnalysisTexture.get());
|
||||
_boundAnalysisCamera->attach(osg::Camera::COLOR_BUFFER, _boundAnalysisImage.get());
|
||||
|
||||
stateset->setAttributeAndModes
|
||||
|
@ -117,7 +117,7 @@ osg::BoundingBox MinimalShadowMap::ViewData::computeShadowReceivingCoarseBounds(
|
||||
void MinimalShadowMap::ViewData::aimShadowCastingCamera
|
||||
( const osg::Light *light, const osg::Vec4 &lightPos,
|
||||
const osg::Vec3 &lightDir, const osg::Vec3 &lightUp )
|
||||
{
|
||||
{
|
||||
osg::BoundingBox bb = computeScenePolytopeBounds();
|
||||
if( !bb.valid() ) { // empty scene or looking at the sky - substitute something
|
||||
bb.expandBy( osg::BoundingSphere( _cv->getEyePoint(), 1 ) );
|
||||
@ -175,8 +175,8 @@ void MinimalShadowMap::ViewData::frameShadowCastingCamera
|
||||
|
||||
// projection was trimmed above, need to recompute mvp
|
||||
if( bb.valid() && *_minLightMarginPtr > 0 ) {
|
||||
// bb._max += osg::Vec3( 1, 1, 1 );
|
||||
// bb._min -= osg::Vec3( 1, 1, 1 );
|
||||
// bb._max += osg::Vec3( 1, 1, 1 );
|
||||
// bb._min -= osg::Vec3( 1, 1, 1 );
|
||||
|
||||
osg::Matrix transform = osg::Matrix::inverse( mvp );
|
||||
|
||||
@ -219,7 +219,7 @@ void MinimalShadowMap::ViewData::frameShadowCastingCamera
|
||||
trimProjection( cameraShadow->getProjectionMatrix(), bb, 1|2|4|8|16|32 );
|
||||
|
||||
///// Debuging stuff //////////////////////////////////////////////////////////
|
||||
setDebugPolytope( "scene", _sceneReceivingShadowPolytope, osg::Vec4(0,1,0,1) );
|
||||
setDebugPolytope( "scene", _sceneReceivingShadowPolytope, osg::Vec4(0,1,0,1) );
|
||||
|
||||
|
||||
#if PRINT_SHADOW_TEXEL_TO_PIXEL_ERROR
|
||||
@ -260,7 +260,7 @@ void MinimalShadowMap::ViewData::cullShadowReceivingScene( )
|
||||
if( 0 < *_maxFarPlanePtr )
|
||||
clampProjection( _clampedProjection, 0.f, *_maxFarPlanePtr );
|
||||
|
||||
// Give derived classes chance to initialize _sceneReceivingShadowPolytope
|
||||
// Give derived classes chance to initialize _sceneReceivingShadowPolytope
|
||||
osg::BoundingBox bb = computeShadowReceivingCoarseBounds( );
|
||||
if( bb.valid() )
|
||||
_sceneReceivingShadowPolytope.setToBoundingBox( bb );
|
||||
@ -301,7 +301,7 @@ void MinimalShadowMap::ViewData::cutScenePolytope
|
||||
osg::Polytope polytope;
|
||||
polytope.setToBoundingBox( bb );
|
||||
polytope.transformProvidingInverse( inverse );
|
||||
_sceneReceivingShadowPolytope.cut( polytope );
|
||||
_sceneReceivingShadowPolytope.cut( polytope );
|
||||
_sceneReceivingShadowPolytope.getPoints
|
||||
( _sceneReceivingShadowPolytopePoints );
|
||||
} else
|
||||
@ -445,7 +445,7 @@ void MinimalShadowMap::ViewData::clampProjection
|
||||
if( perspective )
|
||||
projection.makeFrustum( l, r, b, t, n, f );
|
||||
else
|
||||
projection.makeOrtho( l, r, b, t, n, f );
|
||||
projection.makeOrtho( l, r, b, t, n, f );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -106,163 +106,163 @@ StandardShadowMap::StandardShadowMap():
|
||||
"const int NumEnabledLights = 1; \n"
|
||||
" \n"
|
||||
"void DynamicShadow( in vec4 ecPosition ); \n"
|
||||
" \n"
|
||||
" \n"
|
||||
"varying vec4 colorAmbientEmissive; \n"
|
||||
" \n"
|
||||
"void SpotLight(in int i, \n"
|
||||
" in vec3 eye, \n"
|
||||
" in vec3 ecPosition3, \n"
|
||||
" in vec3 normal, \n"
|
||||
" in vec3 eye, \n"
|
||||
" in vec3 ecPosition3, \n"
|
||||
" in vec3 normal, \n"
|
||||
" inout vec4 ambient, \n"
|
||||
" inout vec4 diffuse, \n"
|
||||
" inout vec4 specular) \n"
|
||||
"{ \n"
|
||||
" inout vec4 diffuse, \n"
|
||||
" inout vec4 specular) \n"
|
||||
"{ \n"
|
||||
" float nDotVP; // normal . light direction \n"
|
||||
" float nDotHV; // normal . light half vector \n"
|
||||
" float pf; // power factor \n"
|
||||
" float spotDot; // cosine of angle between spotlight \n"
|
||||
" float nDotHV; // normal . light half vector \n"
|
||||
" float pf; // power factor \n"
|
||||
" float spotDot; // cosine of angle between spotlight \n"
|
||||
" float spotAttenuation; // spotlight attenuation factor \n"
|
||||
" float attenuation; // computed attenuation factor \n"
|
||||
" float d; // distance from surface to light source \n"
|
||||
" float attenuation; // computed attenuation factor \n"
|
||||
" float d; // distance from surface to light source \n"
|
||||
" vec3 VP; // direction from surface to light position \n"
|
||||
" vec3 halfVector; // direction of maximum highlights \n"
|
||||
" \n"
|
||||
" // Compute vector from surface to light position \n"
|
||||
" VP = vec3(gl_LightSource[i].position) - ecPosition3; \n"
|
||||
" \n"
|
||||
" // Compute vector from surface to light position \n"
|
||||
" VP = vec3(gl_LightSource[i].position) - ecPosition3; \n"
|
||||
" \n"
|
||||
" // Compute distance between surface and light position \n"
|
||||
" d = length(VP); \n"
|
||||
" \n"
|
||||
" // Compute distance between surface and light position \n"
|
||||
" d = length(VP); \n"
|
||||
" \n"
|
||||
" // Normalize the vector from surface to light position \n"
|
||||
" VP = normalize(VP); \n"
|
||||
" \n"
|
||||
" // Compute attenuation \n"
|
||||
" VP = normalize(VP); \n"
|
||||
" \n"
|
||||
" // Compute attenuation \n"
|
||||
" attenuation = 1.0 / (gl_LightSource[i].constantAttenuation + \n"
|
||||
" gl_LightSource[i].linearAttenuation * d + \n"
|
||||
" gl_LightSource[i].linearAttenuation * d + \n"
|
||||
" gl_LightSource[i].quadraticAttenuation *d*d); \n"
|
||||
" \n"
|
||||
" \n"
|
||||
" // See if point on surface is inside cone of illumination \n"
|
||||
" spotDot = dot(-VP, normalize(gl_LightSource[i].spotDirection)); \n"
|
||||
" \n"
|
||||
" if (spotDot < gl_LightSource[i].spotCosCutoff) \n"
|
||||
" spotAttenuation = 0.0; // light adds no contribution \n"
|
||||
" else \n"
|
||||
" spotDot = dot(-VP, normalize(gl_LightSource[i].spotDirection)); \n"
|
||||
" \n"
|
||||
" if (spotDot < gl_LightSource[i].spotCosCutoff) \n"
|
||||
" spotAttenuation = 0.0; // light adds no contribution \n"
|
||||
" else \n"
|
||||
" spotAttenuation = pow(spotDot, gl_LightSource[i].spotExponent);\n"
|
||||
" \n"
|
||||
" // Combine the spotlight and distance attenuation. \n"
|
||||
" attenuation *= spotAttenuation; \n"
|
||||
" \n"
|
||||
" halfVector = normalize(VP + eye); \n"
|
||||
" \n"
|
||||
" nDotVP = max(0.0, dot(normal, VP)); \n"
|
||||
" nDotHV = max(0.0, dot(normal, halfVector)); \n"
|
||||
" \n"
|
||||
" \n"
|
||||
" // Combine the spotlight and distance attenuation. \n"
|
||||
" attenuation *= spotAttenuation; \n"
|
||||
" \n"
|
||||
" halfVector = normalize(VP + eye); \n"
|
||||
" \n"
|
||||
" nDotVP = max(0.0, dot(normal, VP)); \n"
|
||||
" nDotHV = max(0.0, dot(normal, halfVector)); \n"
|
||||
" \n"
|
||||
" if (nDotVP == 0.0) \n"
|
||||
" pf = 0.0; \n"
|
||||
" else \n"
|
||||
" pf = pow(nDotHV, gl_FrontMaterial.shininess); \n"
|
||||
" \n"
|
||||
" ambient += gl_LightSource[i].ambient * attenuation; \n"
|
||||
" diffuse += gl_LightSource[i].diffuse * nDotVP * attenuation; \n"
|
||||
" specular += gl_LightSource[i].specular * pf * attenuation; \n"
|
||||
"} \n"
|
||||
" \n"
|
||||
"void PointLight(in int i, \n"
|
||||
" in vec3 eye, \n"
|
||||
" in vec3 ecPosition3, \n"
|
||||
" in vec3 normal, \n"
|
||||
" inout vec4 ambient, \n"
|
||||
" inout vec4 diffuse, \n"
|
||||
" pf = 0.0; \n"
|
||||
" else \n"
|
||||
" pf = pow(nDotHV, gl_FrontMaterial.shininess); \n"
|
||||
" \n"
|
||||
" ambient += gl_LightSource[i].ambient * attenuation; \n"
|
||||
" diffuse += gl_LightSource[i].diffuse * nDotVP * attenuation; \n"
|
||||
" specular += gl_LightSource[i].specular * pf * attenuation; \n"
|
||||
"} \n"
|
||||
" \n"
|
||||
"void PointLight(in int i, \n"
|
||||
" in vec3 eye, \n"
|
||||
" in vec3 ecPosition3, \n"
|
||||
" in vec3 normal, \n"
|
||||
" inout vec4 ambient, \n"
|
||||
" inout vec4 diffuse, \n"
|
||||
" inout vec4 specular) \n"
|
||||
"{ \n"
|
||||
" float nDotVP; // normal . light direction \n"
|
||||
" float nDotHV; // normal . light half vector \n"
|
||||
" float pf; // power factor \n"
|
||||
" float attenuation; // computed attenuation factor \n"
|
||||
" float d; // distance from surface to light source \n"
|
||||
" vec3 VP; // direction from surface to light position \n"
|
||||
" vec3 halfVector; // direction of maximum highlights \n"
|
||||
" \n"
|
||||
" // Compute vector from surface to light position \n"
|
||||
" VP = vec3(gl_LightSource[i].position) - ecPosition3; \n"
|
||||
" \n"
|
||||
" // Compute distance between surface and light position \n"
|
||||
" d = length(VP); \n"
|
||||
" \n"
|
||||
"{ \n"
|
||||
" float nDotVP; // normal . light direction \n"
|
||||
" float nDotHV; // normal . light half vector \n"
|
||||
" float pf; // power factor \n"
|
||||
" float attenuation; // computed attenuation factor \n"
|
||||
" float d; // distance from surface to light source \n"
|
||||
" vec3 VP; // direction from surface to light position \n"
|
||||
" vec3 halfVector; // direction of maximum highlights \n"
|
||||
" \n"
|
||||
" // Compute vector from surface to light position \n"
|
||||
" VP = vec3(gl_LightSource[i].position) - ecPosition3; \n"
|
||||
" \n"
|
||||
" // Compute distance between surface and light position \n"
|
||||
" d = length(VP); \n"
|
||||
" \n"
|
||||
" // Normalize the vector from surface to light position \n"
|
||||
" VP = normalize(VP); \n"
|
||||
" \n"
|
||||
" // Compute attenuation \n"
|
||||
" attenuation = 1.0 / (gl_LightSource[i].constantAttenuation + \n"
|
||||
" gl_LightSource[i].linearAttenuation * d + \n"
|
||||
" VP = normalize(VP); \n"
|
||||
" \n"
|
||||
" // Compute attenuation \n"
|
||||
" attenuation = 1.0 / (gl_LightSource[i].constantAttenuation + \n"
|
||||
" gl_LightSource[i].linearAttenuation * d + \n"
|
||||
" gl_LightSource[i].quadraticAttenuation * d*d);\n"
|
||||
" \n"
|
||||
" halfVector = normalize(VP + eye); \n"
|
||||
" \n"
|
||||
" nDotVP = max(0.0, dot(normal, VP)); \n"
|
||||
" nDotHV = max(0.0, dot(normal, halfVector)); \n"
|
||||
" \n"
|
||||
" if (nDotVP == 0.0) \n"
|
||||
" pf = 0.0; \n"
|
||||
" else \n"
|
||||
" \n"
|
||||
" halfVector = normalize(VP + eye); \n"
|
||||
" \n"
|
||||
" nDotVP = max(0.0, dot(normal, VP)); \n"
|
||||
" nDotHV = max(0.0, dot(normal, halfVector)); \n"
|
||||
" \n"
|
||||
" if (nDotVP == 0.0) \n"
|
||||
" pf = 0.0; \n"
|
||||
" else \n"
|
||||
" pf = pow(nDotHV, gl_FrontMaterial.shininess); \n"
|
||||
" \n"
|
||||
" ambient += gl_LightSource[i].ambient * attenuation; \n"
|
||||
" diffuse += gl_LightSource[i].diffuse * nDotVP * attenuation; \n"
|
||||
" specular += gl_LightSource[i].specular * pf * attenuation; \n"
|
||||
"} \n"
|
||||
" \n"
|
||||
"void DirectionalLight(in int i, \n"
|
||||
" in vec3 normal, \n"
|
||||
" inout vec4 ambient, \n"
|
||||
" inout vec4 diffuse, \n"
|
||||
" inout vec4 specular) \n"
|
||||
"{ \n"
|
||||
" float nDotVP; // normal . light direction \n"
|
||||
" float nDotHV; // normal . light half vector \n"
|
||||
" float pf; // power factor \n"
|
||||
" \n"
|
||||
" nDotVP = max(0.0, dot(normal, \n"
|
||||
" normalize(vec3(gl_LightSource[i].position)))); \n"
|
||||
" nDotHV = max(0.0, dot(normal, \n"
|
||||
" vec3(gl_LightSource[i].halfVector))); \n"
|
||||
" \n"
|
||||
" if (nDotVP == 0.0) \n"
|
||||
" pf = 0.0; \n"
|
||||
" else \n"
|
||||
" pf = pow(nDotHV, gl_FrontMaterial.shininess); \n"
|
||||
" \n"
|
||||
" ambient += gl_LightSource[i].ambient; \n"
|
||||
" diffuse += gl_LightSource[i].diffuse * nDotVP; \n"
|
||||
" specular += gl_LightSource[i].specular * pf; \n"
|
||||
"} \n"
|
||||
" \n"
|
||||
"void main( ) \n"
|
||||
"{ \n"
|
||||
" // Transform vertex to clip space \n"
|
||||
" gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; \n"
|
||||
" vec3 normal = normalize( gl_NormalMatrix * gl_Normal ); \n"
|
||||
" \n"
|
||||
" vec4 ecPos = gl_ModelViewMatrix * gl_Vertex; \n"
|
||||
" \n"
|
||||
" ambient += gl_LightSource[i].ambient * attenuation; \n"
|
||||
" diffuse += gl_LightSource[i].diffuse * nDotVP * attenuation; \n"
|
||||
" specular += gl_LightSource[i].specular * pf * attenuation; \n"
|
||||
"} \n"
|
||||
" \n"
|
||||
"void DirectionalLight(in int i, \n"
|
||||
" in vec3 normal, \n"
|
||||
" inout vec4 ambient, \n"
|
||||
" inout vec4 diffuse, \n"
|
||||
" inout vec4 specular) \n"
|
||||
"{ \n"
|
||||
" float nDotVP; // normal . light direction \n"
|
||||
" float nDotHV; // normal . light half vector \n"
|
||||
" float pf; // power factor \n"
|
||||
" \n"
|
||||
" nDotVP = max(0.0, dot(normal, \n"
|
||||
" normalize(vec3(gl_LightSource[i].position)))); \n"
|
||||
" nDotHV = max(0.0, dot(normal, \n"
|
||||
" vec3(gl_LightSource[i].halfVector))); \n"
|
||||
" \n"
|
||||
" if (nDotVP == 0.0) \n"
|
||||
" pf = 0.0; \n"
|
||||
" else \n"
|
||||
" pf = pow(nDotHV, gl_FrontMaterial.shininess); \n"
|
||||
" \n"
|
||||
" ambient += gl_LightSource[i].ambient; \n"
|
||||
" diffuse += gl_LightSource[i].diffuse * nDotVP; \n"
|
||||
" specular += gl_LightSource[i].specular * pf; \n"
|
||||
"} \n"
|
||||
" \n"
|
||||
"void main( ) \n"
|
||||
"{ \n"
|
||||
" // Transform vertex to clip space \n"
|
||||
" gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; \n"
|
||||
" vec3 normal = normalize( gl_NormalMatrix * gl_Normal ); \n"
|
||||
" \n"
|
||||
" vec4 ecPos = gl_ModelViewMatrix * gl_Vertex; \n"
|
||||
" float ecLen = length( ecPos ); \n"
|
||||
" vec3 ecPosition3 = ecPos.xyz / ecPos.w; \n"
|
||||
" \n"
|
||||
" vec3 eye = vec3( 0.0, 0.0, 1.0 ); \n"
|
||||
" //vec3 eye = -normalize(ecPosition3); \n"
|
||||
" \n"
|
||||
" DynamicShadow( ecPos ); \n"
|
||||
" \n"
|
||||
" gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; \n"
|
||||
" \n"
|
||||
" // Front Face lighting \n"
|
||||
" \n"
|
||||
" // Clear the light intensity accumulators \n"
|
||||
" vec4 amb = vec4(0.0); \n"
|
||||
" vec4 diff = vec4(0.0); \n"
|
||||
" vec4 spec = vec4(0.0); \n"
|
||||
" \n"
|
||||
" // Loop through enabled lights, compute contribution from each \n"
|
||||
" for (int i = 0; i < NumEnabledLights; i++) \n"
|
||||
" DynamicShadow( ecPos ); \n"
|
||||
" \n"
|
||||
" gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; \n"
|
||||
" \n"
|
||||
" // Front Face lighting \n"
|
||||
" \n"
|
||||
" // Clear the light intensity accumulators \n"
|
||||
" vec4 amb = vec4(0.0); \n"
|
||||
" vec4 diff = vec4(0.0); \n"
|
||||
" vec4 spec = vec4(0.0); \n"
|
||||
" \n"
|
||||
" // Loop through enabled lights, compute contribution from each \n"
|
||||
" for (int i = 0; i < NumEnabledLights; i++) \n"
|
||||
" { \n"
|
||||
" if (gl_LightSource[i].position.w == 0.0) \n"
|
||||
" DirectionalLight(i, normal, amb, diff, spec); \n"
|
||||
@ -272,20 +272,20 @@ StandardShadowMap::StandardShadowMap():
|
||||
" SpotLight(i, eye, ecPosition3, normal, amb, diff, spec); \n"
|
||||
" } \n"
|
||||
" \n"
|
||||
" colorAmbientEmissive = gl_FrontLightModelProduct.sceneColor + \n"
|
||||
" colorAmbientEmissive = gl_FrontLightModelProduct.sceneColor + \n"
|
||||
" amb * gl_FrontMaterial.ambient; \n"
|
||||
" \n"
|
||||
" gl_FrontColor = colorAmbientEmissive + \n"
|
||||
" diff * gl_FrontMaterial.diffuse; \n"
|
||||
" \n"
|
||||
" gl_FrontSecondaryColor = vec4(spec*gl_FrontMaterial.specular); \n"
|
||||
" \n"
|
||||
" gl_BackColor = gl_FrontColor; \n"
|
||||
" gl_BackSecondaryColor = gl_FrontSecondaryColor; \n"
|
||||
" \n"
|
||||
" gl_FogFragCoord = ecLen; \n"
|
||||
"} \n" );
|
||||
}
|
||||
" \n"
|
||||
" gl_FrontSecondaryColor = vec4(spec*gl_FrontMaterial.specular); \n"
|
||||
" \n"
|
||||
" gl_BackColor = gl_FrontColor; \n"
|
||||
" gl_BackSecondaryColor = gl_FrontSecondaryColor; \n"
|
||||
" \n"
|
||||
" gl_FogFragCoord = ecLen; \n"
|
||||
"} \n" );
|
||||
}
|
||||
|
||||
StandardShadowMap::StandardShadowMap
|
||||
(const StandardShadowMap& copy, const osg::CopyOp& copyop) :
|
||||
@ -313,10 +313,10 @@ StandardShadowMap::StandardShadowMap
|
||||
( copy._shadowFragmentShader->clone(copyop) );
|
||||
}
|
||||
|
||||
StandardShadowMap::~StandardShadowMap(void)
|
||||
{
|
||||
StandardShadowMap::~StandardShadowMap(void)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void StandardShadowMap::updateTextureCoordIndices
|
||||
( unsigned int fromTextureCoordIndex, unsigned int toTextureCoordIndex )
|
||||
@ -455,10 +455,10 @@ void StandardShadowMap::ViewData::init( ThisClass *st, osgUtil::CullVisitor *cv
|
||||
_camera->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
|
||||
_camera->setClearColor( osg::Vec4(1.0f,1.0f,1.0f,1.0f) );
|
||||
#endif
|
||||
_camera->setComputeNearFarMode(osg::Camera::DO_NOT_COMPUTE_NEAR_FAR);
|
||||
_camera->setComputeNearFarMode(osg::Camera::DO_NOT_COMPUTE_NEAR_FAR);
|
||||
_camera->setViewport(0,0, st->_textureSize.x(), st->_textureSize.y() );
|
||||
_camera->setRenderOrder(osg::Camera::PRE_RENDER);
|
||||
_camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
|
||||
_camera->setRenderOrder(osg::Camera::PRE_RENDER);
|
||||
_camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
|
||||
_camera->attach(osg::Camera::DEPTH_BUFFER, _texture.get());
|
||||
}
|
||||
|
||||
@ -490,7 +490,7 @@ void StandardShadowMap::ViewData::init( ThisClass *st, osgUtil::CullVisitor *cv
|
||||
_stateset->setTextureMode(st->_shadowTextureUnit,GL_TEXTURE_GEN_Q,osg::StateAttribute::ON);
|
||||
}
|
||||
|
||||
{ // Setup shaders used in shadow casting
|
||||
{ // Setup shaders used in shadow casting
|
||||
osg::Program * program = new osg::Program();
|
||||
_stateset->setAttribute( program );
|
||||
|
||||
@ -558,7 +558,7 @@ void StandardShadowMap::ViewData::init( ThisClass *st, osgUtil::CullVisitor *cv
|
||||
#if 0
|
||||
stateset->setMode
|
||||
( GL_ALPHA_TEST, osg::StateAttribute::OVERRIDE | osg::StateAttribute::OFF );
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if 0 // fixed pipeline seems faster (at least on my 7800)
|
||||
program->addShader( new osg::Shader( osg::Shader::FRAGMENT,
|
||||
@ -625,7 +625,7 @@ const osg::Light* StandardShadowMap::ViewData::selectLight
|
||||
if( lightPos[3] == 0 )
|
||||
lightDir.set( -lightPos[0], -lightPos[1], -lightPos[2] );
|
||||
else
|
||||
lightDir = light->getDirection();
|
||||
lightDir = light->getDirection();
|
||||
|
||||
lightPos = lightPos * localToWorld;
|
||||
lightDir = osg::Matrix::transform3x3( lightDir, localToWorld );
|
||||
@ -731,7 +731,7 @@ void StandardShadowMap::ViewData::cullShadowReceivingScene( )
|
||||
}
|
||||
|
||||
void StandardShadowMap::ViewData::cullShadowCastingScene( )
|
||||
{
|
||||
{
|
||||
// record the traversal mask on entry so we can reapply it later.
|
||||
unsigned int traversalMask = _cv->getTraversalMask();
|
||||
|
||||
|
@ -43,10 +43,10 @@ void ViewDependentShadowTechnique::traverse(osg::NodeVisitor& nv)
|
||||
}
|
||||
|
||||
void ViewDependentShadowTechnique::dirty()
|
||||
{
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_viewDataMapMutex);
|
||||
|
||||
osgShadow::ShadowTechnique::_dirty = true;
|
||||
osgShadow::ShadowTechnique::_dirty = true;
|
||||
|
||||
for( ViewDataMap::iterator mitr = _viewDataMap.begin();
|
||||
mitr != _viewDataMap.end();
|
||||
@ -94,20 +94,20 @@ void ViewDependentShadowTechnique::cleanSceneGraph()
|
||||
|
||||
ViewDependentShadowTechnique::ViewData *
|
||||
ViewDependentShadowTechnique::getViewDependentData( osgUtil::CullVisitor * cv )
|
||||
{
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_viewDataMapMutex);
|
||||
return _viewDataMap[ cv ].get();
|
||||
}
|
||||
|
||||
void ViewDependentShadowTechnique::setViewDependentData
|
||||
( osgUtil::CullVisitor * cv, ViewData * data )
|
||||
{
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_viewDataMapMutex);
|
||||
_viewDataMap[ cv ] = data;
|
||||
}
|
||||
|
||||
void ViewDependentShadowTechnique::ViewData::dirty( bool flag )
|
||||
{
|
||||
void ViewDependentShadowTechnique::ViewData::dirty( bool flag )
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
|
||||
_dirty = flag;
|
||||
}
|
||||
@ -120,8 +120,8 @@ void ViewDependentShadowTechnique::ViewData::init
|
||||
dirty( false );
|
||||
}
|
||||
|
||||
void ViewDependentShadowTechnique::ViewData::cull( void )
|
||||
{
|
||||
void ViewDependentShadowTechnique::ViewData::cull( void )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user