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
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;
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 );
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
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();
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 );