1
0
Fork 0

Get rid of TexGen magic and do the projective texturing for shadow mapping ourself

This commit is contained in:
Frederic Bouvier 2012-06-27 19:37:38 +02:00
parent 432a0a8c5c
commit 6d0cacc0a3
2 changed files with 15 additions and 13 deletions

View file

@ -100,6 +100,10 @@ struct CameraInfo : public osg::Referenced
du( new osg::Uniform( "fg_du",osg::Vec4() ) ),
dv( new osg::Uniform( "fg_dv",osg::Vec4() ) )
{
shadowMatrix[0] = new osg::Uniform("fg_ShadowMatrix_0", osg::Matrixf());
shadowMatrix[1] = new osg::Uniform("fg_ShadowMatrix_1", osg::Matrixf());
shadowMatrix[2] = new osg::Uniform("fg_ShadowMatrix_2", osg::Matrixf());
shadowMatrix[3] = new osg::Uniform("fg_ShadowMatrix_3", osg::Matrixf());
}
/** Update and resize cameras
@ -147,10 +151,7 @@ struct CameraInfo : public osg::Referenced
void addBuffer(const std::string& k, osg::Texture2D* tex, float scale = 1.0 ) { buffers[k] = RenderBufferInfo(tex,scale); }
osg::Texture2D* getBuffer(const std::string& k) const;
osg::ref_ptr<osg::TexGen> shadowTexGen[4];
osg::ref_ptr<osg::Uniform> bufferSize;
//osg::ref_ptr<osg::Uniform> bloomOffset[2];
osg::ref_ptr<osg::Uniform> projInverse;
osg::ref_ptr<osg::Uniform> viewInverse;
osg::ref_ptr<osg::Uniform> view;
@ -158,6 +159,7 @@ struct CameraInfo : public osg::Referenced
osg::ref_ptr<osg::Uniform> worldPosGeod;
osg::ref_ptr<osg::Uniform> du;
osg::ref_ptr<osg::Uniform> dv;
osg::ref_ptr<osg::Uniform> shadowMatrix[4];
void setMatrices( osg::Camera* c );

View file

@ -719,18 +719,15 @@ public:
for (int i = 0; i < 4; ++i ) {
if (!grp->getValue(i))
continue;
osg::TexGen* shadowTexGen = info->shadowTexGen[i];
shadowTexGen->setMode(osg::TexGen::EYE_LINEAR);
osg::Camera* cascadeCam = static_cast<osg::Camera*>( grp->getChild(i) );
// compute the matrix which takes a vertex from view coords into tex coords
shadowTexGen->setPlanesFromMatrix( cascadeCam->getProjectionMatrix() *
osg::Matrix::translate(1.0,1.0,1.0) *
osg::Matrix::scale(0.5f,0.5f,0.5f) );
osg::Matrixf shadowMatrix = camera->getInverseViewMatrix() *
cascadeCam->getViewMatrix() *
cascadeCam->getProjectionMatrix() *
osg::Matrix::translate(1.0, 1.0, 1.0) *
osg::Matrix::scale(0.5f, 0.5f, 0.5f);
osg::RefMatrix * refMatrix = new osg::RefMatrix( cascadeCam->getInverseViewMatrix() * *cv->getModelViewMatrix() );
cv->getRenderStage()->getPositionalStateContainer()->addPositionedTextureAttribute( i+1, refMatrix, shadowTexGen );
info->shadowMatrix[i]->set( shadowMatrix );
}
}
// Render saved transparent render bins
@ -876,7 +873,6 @@ osg::Camera* FGRenderer::buildDeferredShadowCamera( CameraInfo* info, osg::Graph
osg::Camera* cascadeCam = createShadowCascadeCamera( i, _shadowMapSize/2 );
cascadeCam->addChild( mDeferredRealRoot.get() );
shadowSwitch->addChild( cascadeCam );
info->shadowTexGen[i] = new osg::TexGen;
}
if (fgGetBool("/sim/rendering/shadows/enabled", true))
shadowSwitch->setAllChildrenOn();
@ -1123,6 +1119,10 @@ FGRenderer::buildDeferredFullscreenCamera( flightgear::CameraInfo* info, const F
ss->addUniform( info->bufferSize );
ss->addUniform( info->worldPosCart );
ss->addUniform( info->worldPosGeod );
ss->addUniform( info->shadowMatrix[0] );
ss->addUniform( info->shadowMatrix[1] );
ss->addUniform( info->shadowMatrix[2] );
ss->addUniform( info->shadowMatrix[3] );
ss->addUniform( _ambientFactor );
ss->addUniform( _sunDiffuse );
ss->addUniform( _sunSpecular );