Add world viewer position in cartesian and geodesic coordinate as shader uniforms
This commit is contained in:
parent
a5dff11f13
commit
3e7b8e57b6
3 changed files with 20 additions and 3 deletions
|
@ -274,8 +274,13 @@ int CameraInfo::getMainSlaveIndex() const
|
||||||
void CameraInfo::setMatrices(osg::Camera* c)
|
void CameraInfo::setMatrices(osg::Camera* c)
|
||||||
{
|
{
|
||||||
view->set( c->getViewMatrix() );
|
view->set( c->getViewMatrix() );
|
||||||
viewInverse->set( osg::Matrix::inverse( c->getViewMatrix() ) );
|
osg::Matrixd vi = c->getInverseViewMatrix();
|
||||||
|
viewInverse->set( vi );
|
||||||
projInverse->set( osg::Matrix::inverse( c->getProjectionMatrix() ) );
|
projInverse->set( osg::Matrix::inverse( c->getProjectionMatrix() ) );
|
||||||
|
osg::Vec4d pos = osg::Vec4d(0., 0., 0., 1.) * vi;
|
||||||
|
worldPosCart->set( osg::Vec3f( pos.x(), pos.y(), pos.z() ) );
|
||||||
|
SGGeod pos2 = SGGeod::fromCart( SGVec3d( pos.x(), pos.y(), pos.z() ) );
|
||||||
|
worldPosGeod->set( osg::Vec3f( pos2.getLongitudeRad(), pos2.getLatitudeRad(), pos2.getElevationM() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void CameraGroup::update(const osg::Vec3d& position,
|
void CameraGroup::update(const osg::Vec3d& position,
|
||||||
|
|
|
@ -94,6 +94,8 @@ struct CameraInfo : public osg::Referenced
|
||||||
bufferSize( new osg::Uniform("fg_BufferSize", osg::Vec2f() ) ),
|
bufferSize( new osg::Uniform("fg_BufferSize", osg::Vec2f() ) ),
|
||||||
projInverse( new osg::Uniform( "fg_ProjectionMatrixInverse", osg::Matrixf() ) ),
|
projInverse( new osg::Uniform( "fg_ProjectionMatrixInverse", osg::Matrixf() ) ),
|
||||||
viewInverse( new osg::Uniform( "fg_ViewMatrixInverse",osg::Matrixf() ) ),
|
viewInverse( new osg::Uniform( "fg_ViewMatrixInverse",osg::Matrixf() ) ),
|
||||||
|
worldPosCart( new osg::Uniform( "fg_CameraPositionCart", osg::Vec3f() ) ),
|
||||||
|
worldPosGeod( new osg::Uniform( "fg_CameraPositionGeod", osg::Vec3f() ) ),
|
||||||
view( new osg::Uniform( "fg_ViewMatrix",osg::Matrixf() ) ),
|
view( new osg::Uniform( "fg_ViewMatrix",osg::Matrixf() ) ),
|
||||||
du( new osg::Uniform( "fg_du",osg::Vec4() ) ),
|
du( new osg::Uniform( "fg_du",osg::Vec4() ) ),
|
||||||
dv( new osg::Uniform( "fg_dv",osg::Vec4() ) )
|
dv( new osg::Uniform( "fg_dv",osg::Vec4() ) )
|
||||||
|
@ -152,6 +154,8 @@ struct CameraInfo : public osg::Referenced
|
||||||
osg::ref_ptr<osg::Uniform> projInverse;
|
osg::ref_ptr<osg::Uniform> projInverse;
|
||||||
osg::ref_ptr<osg::Uniform> viewInverse;
|
osg::ref_ptr<osg::Uniform> viewInverse;
|
||||||
osg::ref_ptr<osg::Uniform> view;
|
osg::ref_ptr<osg::Uniform> view;
|
||||||
|
osg::ref_ptr<osg::Uniform> worldPosCart;
|
||||||
|
osg::ref_ptr<osg::Uniform> worldPosGeod;
|
||||||
osg::ref_ptr<osg::Uniform> du;
|
osg::ref_ptr<osg::Uniform> du;
|
||||||
osg::ref_ptr<osg::Uniform> dv;
|
osg::ref_ptr<osg::Uniform> dv;
|
||||||
|
|
||||||
|
|
|
@ -1091,10 +1091,13 @@ osg::Camera* FGRenderer::buildDeferredLightingCamera( CameraInfo* info, osg::Gra
|
||||||
quadCam1->setProjectionMatrixAsOrtho2D(-1,1,-1,1);
|
quadCam1->setProjectionMatrixAsOrtho2D(-1,1,-1,1);
|
||||||
quadCam1->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
|
quadCam1->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
|
||||||
ss = quadCam1->getOrCreateStateSet();
|
ss = quadCam1->getOrCreateStateSet();
|
||||||
ss->addUniform( _ambientFactor );
|
|
||||||
ss->addUniform( info->projInverse );
|
ss->addUniform( info->projInverse );
|
||||||
ss->addUniform( info->viewInverse );
|
ss->addUniform( info->viewInverse );
|
||||||
ss->addUniform( info->view );
|
ss->addUniform( info->view );
|
||||||
|
ss->addUniform( info->bufferSize );
|
||||||
|
ss->addUniform( info->worldPosCart );
|
||||||
|
ss->addUniform( info->worldPosGeod );
|
||||||
|
ss->addUniform( _ambientFactor );
|
||||||
ss->addUniform( _sunDiffuse );
|
ss->addUniform( _sunDiffuse );
|
||||||
ss->addUniform( _sunSpecular );
|
ss->addUniform( _sunSpecular );
|
||||||
ss->addUniform( _sunDirection );
|
ss->addUniform( _sunDirection );
|
||||||
|
@ -1159,10 +1162,13 @@ osg::Camera* FGRenderer::buildDeferredLightingCamera( CameraInfo* info, osg::Gra
|
||||||
quadCam2->setProjectionMatrixAsOrtho2D(-1,1,-1,1);
|
quadCam2->setProjectionMatrixAsOrtho2D(-1,1,-1,1);
|
||||||
quadCam2->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
|
quadCam2->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
|
||||||
ss = quadCam2->getOrCreateStateSet();
|
ss = quadCam2->getOrCreateStateSet();
|
||||||
ss->addUniform( _ambientFactor );
|
|
||||||
ss->addUniform( info->projInverse );
|
ss->addUniform( info->projInverse );
|
||||||
ss->addUniform( info->viewInverse );
|
ss->addUniform( info->viewInverse );
|
||||||
ss->addUniform( info->view );
|
ss->addUniform( info->view );
|
||||||
|
ss->addUniform( info->bufferSize );
|
||||||
|
ss->addUniform( info->worldPosCart );
|
||||||
|
ss->addUniform( info->worldPosGeod );
|
||||||
|
ss->addUniform( _ambientFactor );
|
||||||
ss->addUniform( _sunDiffuse );
|
ss->addUniform( _sunDiffuse );
|
||||||
ss->addUniform( _sunSpecular );
|
ss->addUniform( _sunSpecular );
|
||||||
ss->addUniform( _sunDirection );
|
ss->addUniform( _sunDirection );
|
||||||
|
@ -1262,6 +1268,8 @@ FGRenderer::buildDeferredFullscreenCamera( flightgear::CameraInfo* info, const F
|
||||||
ss->addUniform( info->viewInverse );
|
ss->addUniform( info->viewInverse );
|
||||||
ss->addUniform( info->view );
|
ss->addUniform( info->view );
|
||||||
ss->addUniform( info->bufferSize );
|
ss->addUniform( info->bufferSize );
|
||||||
|
ss->addUniform( info->worldPosCart );
|
||||||
|
ss->addUniform( info->worldPosGeod );
|
||||||
ss->addUniform( _ambientFactor );
|
ss->addUniform( _ambientFactor );
|
||||||
ss->addUniform( _sunDiffuse );
|
ss->addUniform( _sunDiffuse );
|
||||||
ss->addUniform( _sunSpecular );
|
ss->addUniform( _sunSpecular );
|
||||||
|
|
Loading…
Add table
Reference in a new issue