|
请教场景水面倒影问题。我的程序是基于osgearth开发的场景,在地形上绘制了一个水面,在水面上反射了天空纹理。但是对于地面上的建筑物倒影是错误的,而且建筑物倒影会随着场景视点的变化而移动,以致消失。如下图:
建筑物倒影问题
我的RTT相机设置如下:
//相机设置
setClearColor( osg::Vec4(0.0,0.0,0.0,0.0) );
setClearMask( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT );
setRenderTargetImplementation( osg::Camera::FRAME_BUFFER_OBJECT );
setReferenceFrame(osg::Transform::ReferenceFrame::ABSOLUTE_RF);
setRenderOrder( osg::Camera:RE_RENDER );
//RTT相机输出的纹理
m_pTexture=new osg::Texture2D;
m_pTexture->setWrap(osg::Texture2D::WRAP_S,osg::Texture2D::REPEAT);
m_pTexture->setWrap(osg::Texture2D::WRAP_T,osg::Texture2D::REPEAT);
m_pTexture->setFilter( osg::Texture::MIN_FILTER, osg::Texture:INEAR );
m_pTexture->setFilter( osg::Texture::MAG_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR );
m_pTexture->setInternalFormat( GL_RGBA );
m_pTexture->setTextureSize(1024,1024);
attach( osg::Camera::COLOR_BUFFER,m_pTexture.get() );
下面是RTT相机的回调函数
void RefCameraCallBack:perator() (osg::Node *node, osg::NodeVisitor *nv)
{
//_cankaoCamera是场景主相机
_RttCamera=dynamic_cast<osg::Camera *>(node);
//if(_RttCamera==NULL)
//osg::ref_ptr<osg::GraphicsContext::WindowingSystemInterface> wsi=osg::GraphicsContext::getWindowingSystemInterface();
//if(!wsi) return;
//osg::GraphicsContext::ScreenIdentifier screen(0);
//wsi->getScreenResolution(screen,width,height);
const osg::GraphicsContext::Traits * traits=_cankaoCamera->getGraphicsContext()->getTraits();
w_h=traits->width/traits->height;
_time=_cankaoCamera->getView()->getFrameStamp()->getSimulationTime();
//_cankaoCamera->getViewMatrixAsLookAt(_eye_Positon,_eye_Center,_eye_Up);
//_RttCamera->setViewMatrixAsLookAt(_eye_Positon,_eye_Center,_eye_Up);
double aspectRatio,zNear, zFar;
_cankaoCamera->getProjectionMatrixAsPerspective(fovy,aspectRatio,zNear,zFar);
w_h=float(aspectRatio);
double newAspect=traits->width/traits->height;
double yizi=newAspect/aspectRatio;
//_RttCamera->setProjectionMatrix(_cankaoCamera->getProjectionMatrix()*osg::Matrix::scale(1.0/yizi,1.0,1.0));
_RttCamera->setViewMatrix(_cankaoCamera->getViewMatrix());
//_RttCamera->setProjectionMatrixAsPerspective(fovy,1.0/yizi,zNear,zFar);
_RttCamera->setProjectionMatrix(_cankaoCamera->getProjectionMatrix());
//_RttCamera->setViewMatrixAsLookAt(_eye_Positon,_eye_Center,_eye_Up);
}
下面是将建筑物添加到RTT相机
void SetupReflectionNode(osg::Node* pRefNode)
{
osg::MatrixTransform* reverseMatrix = new osg::MatrixTransform;
osg::Matrix mat = pModemat->getMatrix();
reverseMatrix->setReferenceFrame(osg::Transform::ReferenceFrame::RELATIVE_RF);
reverseMatrix->preMult(
osg::Matrix::scale(1.0f,1.0f,-1.0f)*
osg::Matrix::translate(0.0f,0.0f,-waterHeight));
m_pWaterRTTCamera->setClearColor(osg::Vec4(0.0,0.0,0.0,0.0));
reverseMatrix->addChild(pRefNode);
m_pWaterRTTCamera->addChild(reverseMatrix);
}
这个问题是不是相机的矩阵设置错误?? |
|