Changeset 350 for experimental/distortionNG/extViewer.cpp
- Timestamp:
- Apr 21, 2012, 4:53:52 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
experimental/distortionNG/extViewer.cpp
r349 r350 57 57 } 58 58 59 //static osg::Texture2D* loadTexture( const std::string& fileName )60 //{61 // std::string foundFileName = osgDB::findDataFile(fileName);62 // if (foundFileName.length() != 0 )63 // {64 // // load distortion map texture file65 // osg::Image* image = osgDB::readImageFile(foundFileName);66 // if (image)67 // {68 // osg::Texture2D* texture = new osg::Texture2D;69 // texture->setImage(image);70 // texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR);71 // texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR);72 // texture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_EDGE);73 // texture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE);74 // return texture;75 // }76 // }77 //78 // OSG_NOTIFY(osg::WARN) << "File \"" << fileName << "\" not found." << std::endl;79 //80 // return NULL;81 //}82 83 //static osg::TextureRectangle* loadTextureRect( const std::string& fileName )84 //{85 // std::string foundFileName = osgDB::findDataFile(fileName);86 // if (foundFileName.length() != 0 )87 // {88 // // load distortion map texture file89 // osg::Image* image = osgDB::readImageFile(foundFileName);90 // if (image)91 // {92 // osg::TextureRectangle* texture = new osg::TextureRectangle;93 // texture->setImage(image);94 // texture->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR);95 // texture->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR);96 // texture->setWrap(osg::Texture2D::WRAP_S, osg::Texture2D::CLAMP_TO_EDGE);97 // texture->setWrap(osg::Texture2D::WRAP_T, osg::Texture2D::CLAMP_TO_EDGE);98 // return texture;99 // }100 // }101 //102 // OSG_NOTIFY(osg::WARN) << "File \"" << fileName << "\" not found." << std::endl;103 //104 // return NULL;105 //}106 107 59 static osg::Geometry* createMesh(const osg::Vec3& origin, const osg::Vec3& widthVector, const osg::Vec3& heightVector, unsigned int columns, unsigned int rows, osg::Image* intensityMap, bool applyIntensityMapAsColours, const osg::Matrix& projectorMatrix) 108 60 { … … 199 151 } 200 152 153 201 154 void extViewer::setUpViewForManualDistortion(unsigned int screenNum, osg::Image* intensityMap, const osg::Matrixd& projectorMatrix) 202 155 { 203 OSG_INFO<<"View::setUpViewForManualDistortion(sn="<<screenNum<<", im="<<intensityMap<<")"<<std::endl; 156 OSG_INFO<<"View::setUpViewForManualDistortion(sn="<<screenNum<<")"<<std::endl; 157 158 // Create DistortionSet 159 _distortionSet = new osgViewer::DistortionSet(); 160 _distortionSet->setIntensityMap( intensityMap ); 161 _distortionSet->setDistortionMeshRows( 20 ); 162 _distortionSet->setDistortionMeshColumns( 20 ); 163 164 165 204 166 205 167 osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface(); … … 233 195 traits->sharedContext = 0; 234 196 235 bool applyIntensityMapAsColours = false;236 237 197 osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get()); 238 198 if (!gc) … … 302 262 // StateSet to contain the Texture StateAttribute. 303 263 osg::StateSet* stateset = geode->getOrCreateStateSet(); 304 stateset->setTextureAttributeAndModes( 0, sceneTexture,osg::StateAttribute::ON);264 stateset->setTextureAttributeAndModes(_distortionSet->getTexUnitScene(), sceneTexture,osg::StateAttribute::ON); 305 265 stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF); 306 266 … … 309 269 stateset->setTextureAttributeAndModes(0, texmat, osg::StateAttribute::ON); 310 270 311 // If the intensityMap is used but not applyIntensityMapAsColours: Apply intensityMap as intensityMapTexture on unit 1 312 if (!applyIntensityMapAsColours && intensityMap) 313 setUpIntensityMapBlending(stateset, intensityMap, screenNum, 0, 1); 314 315 osg::Geometry* distortionMesh = createMesh(osg::Vec3(0.0f,0.0f,0.0f), osg::Vec3(width,0.0f,0.0f), osg::Vec3(0.0f,height,0.0f), 20, 20, intensityMap, applyIntensityMapAsColours, projectorMatrix); 271 setUpIntensityMapBlending(_distortionSet, stateset, screenNum); 272 273 osg::Geometry* distortionMesh = createMesh(osg::Vec3(0.0f,0.0f,0.0f), osg::Vec3(width,0.0f,0.0f), osg::Vec3(0.0f,height,0.0f), 20, 20, _distortionSet->getIntensityMap(), false, projectorMatrix); 316 274 geode->addDrawable(distortionMesh); 317 275 … … 347 305 camera->setCullingMode( mode & (~osg::CullSettings::SMALL_FEATURE_CULLING) ); 348 306 349 // Create DistortionSet350 _distortionSet = new osgViewer::DistortionSet();351 _distortionSet->setIntensityMap( intensityMap );352 353 354 307 // Add the distortionHandler 355 308 osgViewer::DistortionManipulator* distManip = new osgViewer::DistortionManipulator(); … … 364 317 } 365 318 366 void extViewer::setUpIntensityMapBlending(osg::StateSet* stateset, osg::Image* intensityMap, unsigned int screenNum, int rttSceneTextureUnit, int intensityMapTextureUnit) 367 { 368 if(stateset == NULL || intensityMap == NULL) 319 void extViewer::setUpIntensityMapBlending(osgViewer::DistortionSet* distSet, osg::StateSet* stateset, unsigned int screenNum) 320 { 321 osg::Image* intensityMap = _distortionSet->getIntensityMap(); 322 if(intensityMap == NULL) return; 323 324 if(stateset == NULL) 369 325 { 370 326 OSG_NOTICE<<"Error, no intensityMap or stateset for intensityMapBlending specified."<<std::endl; … … 400 356 intensityMapTexture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE); 401 357 402 stateset->setTextureAttributeAndModes( intensityMapTextureUnit, intensityMapTexture, osg::StateAttribute::ON);358 stateset->setTextureAttributeAndModes(_distortionSet->getTexUnitIntensityMap(), intensityMapTexture, osg::StateAttribute::ON); 403 359 404 360 // create shaders for blending … … 411 367 { 412 368 distortProgram->addShader( fShader ); 413 stateset->addUniform( new osg::Uniform("sceneTexture", rttSceneTextureUnit) ); 414 stateset->addUniform( new osg::Uniform("intensityMapTexture", intensityMapTextureUnit) ); 369 //stateset->addUniform( new osg::Uniform("sceneTexture", _distortionSet->getTexUnitScene()) ); 370 //stateset->addUniform( new osg::Uniform("intensityMapTexture", _distortionSet->getTexUnitIntensityMap()) ); 371 stateset->addUniform( new osg::Uniform("sceneTexture", 0 ) ); 372 stateset->addUniform( new osg::Uniform("intensityMapTexture", 1 ) ); 415 373 stateset->setAttributeAndModes(distortProgram, osg::StateAttribute::ON); 416 374 } 417 375 } 376 377 void extViewer::setUpIntensityMapBlending(std::string intensityMap) 378 { 379 // Try to load intensityMap 380 osg::Image* intMap = osgDB::readImageFile(intensityMap); 381 if (!intMap) 382 { 383 osg::notify(osg::WARN) << "Quitting, couldn't find intensity map: " << intensityMap << std::endl; 384 return; 385 } 386 387 // Create DistortionSet 388 _distortionSet = new osgViewer::DistortionSet(); 389 _distortionSet->setIntensityMap( intMap ); 390 _distortionSet->setDistortionMeshRows( 1 ); 391 _distortionSet->setDistortionMeshColumns( 1 ); 392 _distortionSet->setTexUnitScene( 0 ); 393 _distortionSet->setTexUnitIntensityMap( 1 ); 394 395 // Todo: call setupDistortion/Blendung to perform the blending 396 }
Note: See TracChangeset
for help on using the changeset viewer.