OSG : working on reflectionMapping

git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@5498 30fe4595-0a0c-4342-8851-515496e4dcbd

Former-commit-id: 3745836c7e189572d1699fdef1d56e6b9229436f
Former-commit-id: ff097b5b7f4454087585ca632787d0719859cf54
This commit is contained in:
rvlander 2013-06-09 14:07:00 +00:00
parent 77f4700705
commit d4253f1311
5 changed files with 60 additions and 29 deletions

View file

@ -34,31 +34,44 @@ SDReflectionMapping::SDReflectionMapping(SDScreens *s, osg::ref_ptr<osg::Node> m
screens=s;
map = new osg::Texture2D;
map->setTextureSize( 256, 256 );
map->setInternalFormat( GL_RGB );
reflectionMap = new osg::TextureCubeMap;
reflectionMap->setTextureSize( 256, 256 );
reflectionMap->setInternalFormat( GL_RGB );
camera = new osg::Camera;
camera->setViewport( 0, 0, 256, 256 );
camera->setClearColor( osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f) );
camera->setClearMask( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT );
camerasRoot = new osg::Group;
camera->setRenderOrder( osg::Camera::PRE_RENDER );
camera->setRenderTargetImplementation(
osg::Camera::FRAME_BUFFER_OBJECT );
camera->attach( osg::Camera::COLOR_BUFFER, map.get() );
camera->setReferenceFrame( osg::Camera::ABSOLUTE_RF );
camera->addChild( m_sceneroot );
for(int i=0;i<6;i++){
map = new osg::Texture2D;
map->setTextureSize( 256, 256 );
map->setInternalFormat( GL_RGB );
//camera->setProjectionMatrixAsOrtho(-1,1,-1,1,0,1000000);
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
camera->setViewport( 0, 0, 256, 256 );
camera->setClearColor( osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f) );
camera->setClearMask( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT );
camera->setRenderOrder( osg::Camera::PRE_RENDER );
camera->setRenderTargetImplementation(
osg::Camera::FRAME_BUFFER_OBJECT );
camera->attach( osg::Camera::COLOR_BUFFER, reflectionMap,0,i );
camera->setReferenceFrame( osg::Camera::ABSOLUTE_RF );
camera->addChild( m_sceneroot );
//camera->setProjectionMatrixAsOrtho(-1,1,-1,1,0,1000000);
camera->setProjectionMatrixAsPerspective(45.0,1.0,1.0,1000000.0);
camerasRoot->addChild(camera);
cameras.push_back(camera);
reflectionMap->setImage(i,map->getImage());
}
camera->setProjectionMatrixAsPerspective(45.0,1.0,1.0,1000000.0);
cameras = new osg::Group;
cameras->addChild(camera);
}
@ -93,10 +106,9 @@ void SDReflectionMapping::update(){
up[1] = car->_posMat[2][1];
up[2] = car->_posMat[2][2];
camera->setViewMatrixAsLookAt(eye,center,up);
for(uint i=0;i<cameras.size();i++){
cameras[i]->setViewMatrixAsLookAt(eye,center,up);
}
}
SDReflectionMapping::~SDReflectionMapping(){

View file

@ -19,22 +19,28 @@
#ifndef _OSGREFLECTIONMAPPING_H_
#define _OSGREFLECTIONMAPPING_H_
#include <osg/TextureCubeMap>
#include <osg/Texture2D>
class SDReflectionMapping
{
private:
osg::ref_ptr<osg::Group> cameras;
osg::ref_ptr<osg::Camera> camera;
osg::ref_ptr<osg::Texture2D> map;
osg::ref_ptr<osg::Group> camerasRoot;
std::vector< osg::ref_ptr<osg::Camera> > cameras;
osg::ref_ptr<osg::TextureCubeMap> reflectionMap;
SDScreens * screens;
osg::ref_ptr<osg::Texture2D> map;
public:
SDReflectionMapping(SDScreens *s, osg::ref_ptr<osg::Node> m_sceneroot);
inline osg::ref_ptr<osg::Group> getCameras(){
return cameras;
inline osg::ref_ptr<osg::Group> getCamerasRoot(){
return camerasRoot;
}
inline osg::ref_ptr<osg::Texture2D> getReflectionMap(){
inline osg::ref_ptr<osg::TextureCubeMap> getReflectionMap(){
return reflectionMap;
}
inline osg::ref_ptr<osg::Texture2D> getMap(){
return map;
}

View file

@ -3,6 +3,7 @@
#include <osg/Geometry>
#include <osg/Geode>
#include <osg/Texture2D>
#include <osg/TextureCubeMap>
#include "OsgDebugHUD.h"
@ -30,6 +31,16 @@ void SDDebugHUD::setTexture(osg::ref_ptr<osg::Texture2D> map){
stateset->setTextureAttributeAndModes( 0,map);
}
void SDDebugHUD::setTexture(osg::ref_ptr<osg::TextureCubeMap> map){
osg::StateSet* stateset = HUD_camera->getOrCreateStateSet();
osg::ref_ptr<osg::Texture2D> lm = new osg::Texture2D;
lm->setTextureSize( 256, 256 );
lm->setInternalFormat( GL_RGB );
lm->setDataVariance(osg::Object::DYNAMIC);
lm->setImage(map->getImage(3));
stateset->setTextureAttributeAndModes( 0,lm);
}
void SDDebugHUD::toggleHUD(){
HUD_camera->setNodeMask(1-HUD_camera->getNodeMask());
}

View file

@ -27,6 +27,7 @@ class SDDebugHUD
public:
void toggleHUD();
void setTexture(osg::ref_ptr<osg::TextureCubeMap> map);
void setTexture(osg::ref_ptr<osg::Texture2D> map);
SDDebugHUD();
~SDDebugHUD();

View file

@ -116,7 +116,8 @@ void SDScreens::Init(int x,int y, int width, int height, osg::ref_ptr<osg::Node>
}
root->addChild(reflectionMapping->getCameras());
root->addChild(reflectionMapping->getCamerasRoot());
//debugHUD->setTexture(reflectionMapping->getMap());
debugHUD->setTexture(reflectionMapping->getReflectionMap());
root->addChild(debugHUD->getRootCamera());