[346] | 1 | /* osgVisual test. distortionNG, experimental. |
---|
| 2 | * |
---|
| 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
---|
| 4 | * of this software and associated documentation files (the "Software"), to deal |
---|
| 5 | * in the Software without restriction, including without limitation the rights |
---|
| 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
---|
| 7 | * copies of the Software, and to permit persons to whom the Software is |
---|
| 8 | * furnished to do so, subject to the following conditions: |
---|
| 9 | * |
---|
| 10 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
| 11 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
| 12 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
---|
| 13 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
| 14 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
---|
| 15 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
---|
| 16 | * THE SOFTWARE. |
---|
| 17 | */ |
---|
| 18 | |
---|
[310] | 19 | #include "extViewer.h" |
---|
| 20 | |
---|
[353] | 21 | #include <osg/Switch> |
---|
[329] | 22 | #include <osg/PolygonOffset> |
---|
[362] | 23 | #include <osg/PolygonMode> |
---|
[334] | 24 | #include <osg/Texture2D> |
---|
| 25 | #include <osg/TextureRectangle> |
---|
| 26 | #include <osg/TexMat> |
---|
| 27 | #include <osg/ComputeBoundsVisitor> |
---|
| 28 | #include <osg/Vec2> |
---|
[313] | 29 | |
---|
[334] | 30 | #include <osgDB/ReadFile> |
---|
| 31 | #include <osgDB/FileUtils> |
---|
[313] | 32 | |
---|
| 33 | #include <osgUtil/SmoothingVisitor> |
---|
| 34 | |
---|
[346] | 35 | |
---|
[311] | 36 | extViewer::extViewer() : Viewer() |
---|
[310] | 37 | { |
---|
| 38 | } |
---|
| 39 | |
---|
[311] | 40 | extViewer::extViewer(osg::ArgumentParser& arguments) : Viewer(arguments) |
---|
[310] | 41 | { |
---|
[346] | 42 | // Add help for command-line options here |
---|
[342] | 43 | arguments.getApplicationUsage()->addCommandLineOption("--distort","load distortion file and set up geometrical distortion for viewer. This includes blending"); |
---|
[361] | 44 | arguments.getApplicationUsage()->addCommandLineOption("--blend","Set up viewer for simple intensity map blending."); |
---|
[345] | 45 | |
---|
[361] | 46 | std::string distortionSetFilename = ""; |
---|
| 47 | std::string intensityMapFilename = ""; |
---|
| 48 | while( arguments.read("--blend",intensityMapFilename) ) {} |
---|
| 49 | while( arguments.read("--distort",distortionSetFilename) ) {} |
---|
| 50 | |
---|
| 51 | if( !intensityMapFilename.empty() ) |
---|
| 52 | { |
---|
| 53 | OSG_ALWAYS<<"Pure blendmap setup with : "<<intensityMapFilename<<std::endl; |
---|
| 54 | setUpIntensityMapBlending(intensityMapFilename); |
---|
| 55 | } |
---|
| 56 | else if( !distortionSetFilename.empty() ) |
---|
| 57 | { |
---|
| 58 | OSG_ALWAYS<<"Set up distortion by loaded distortionSet: "<<distortionSetFilename<<std::endl; |
---|
| 59 | |
---|
| 60 | osg::Object* distSet = osgDB::readObjectFile( distortionSetFilename ); |
---|
| 61 | if( distSet != NULL ) |
---|
| 62 | { |
---|
| 63 | OSG_ALWAYS<<"read distortionSet success"<<std::endl; |
---|
| 64 | setUpViewForManualDistortion(static_cast<osgViewer::DistortionSet*>(distSet)); |
---|
| 65 | } |
---|
| 66 | else |
---|
| 67 | { |
---|
| 68 | OSG_ALWAYS<<"read distortionSet failed"<<std::endl; |
---|
| 69 | } |
---|
| 70 | } |
---|
| 71 | |
---|
[310] | 72 | } |
---|
[311] | 73 | |
---|
| 74 | extViewer::extViewer(const osgViewer::Viewer& viewer, const osg::CopyOp& copyop) : Viewer(viewer, copyop) |
---|
| 75 | { |
---|
| 76 | |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | extViewer::~extViewer() |
---|
| 80 | { |
---|
| 81 | |
---|
| 82 | } |
---|
| 83 | |
---|
[351] | 84 | static osg::Geometry* createMesh(const osg::Vec3& origin, const osg::Vec3& widthVector, const osg::Vec3& heightVector, unsigned int columns, unsigned int rows, const osg::Matrix& projectorMatrix) |
---|
[332] | 85 | { |
---|
[331] | 86 | // Create Quad to render on |
---|
| 87 | osg::ref_ptr<osg::Geometry> geom = new osg::Geometry; |
---|
| 88 | |
---|
| 89 | geom->setUseDisplayList( false ); |
---|
| 90 | |
---|
| 91 | osg::Vec3 xAxis(widthVector); |
---|
| 92 | float width = widthVector.length(); |
---|
| 93 | xAxis /= width; |
---|
| 94 | |
---|
| 95 | osg::Vec3 yAxis(heightVector); |
---|
| 96 | float height = heightVector.length(); |
---|
| 97 | yAxis /= height; |
---|
| 98 | |
---|
| 99 | osg::Vec3 dx = xAxis*(width/((float)(columns-1))); |
---|
| 100 | osg::Vec3 dy = yAxis*(height/((float)(rows-1))); |
---|
| 101 | |
---|
| 102 | // Create vertices and coordinates |
---|
| 103 | osg::Vec3Array* vertices = new osg::Vec3Array; |
---|
| 104 | osg::Vec2Array* texcoords0 = new osg::Vec2Array; |
---|
| 105 | osg::Vec4Array* colors = new osg::Vec4Array; |
---|
| 106 | |
---|
| 107 | geom->getOrCreateStateSet()->setMode(GL_CULL_FACE, osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED); |
---|
| 108 | |
---|
| 109 | for ( unsigned int row=0; row<rows; row++ ) |
---|
| 110 | { |
---|
| 111 | for ( unsigned int col=0; col<columns; col++ ) |
---|
| 112 | { |
---|
[394] | 113 | osg::Vec3 vertex = origin+dy*row+dx*col; |
---|
| 114 | |
---|
[331] | 115 | // Create coordinates of the mesh node (geometry). |
---|
[394] | 116 | vertices->push_back( vertex ); |
---|
[331] | 117 | |
---|
| 118 | // Set Coordinates for RTT-Texture (scene rendering) |
---|
[394] | 119 | texcoords0->push_back( osg::Vec2( vertex.x(), vertex.y()) ); |
---|
[331] | 120 | |
---|
| 121 | // Set Color of the mesh node |
---|
[351] | 122 | colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); |
---|
[331] | 123 | } |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | // Pass the created vertex array to the points geometry object. |
---|
| 127 | geom->setUseVertexBufferObjects( true ); |
---|
| 128 | geom->setVertexArray(vertices); |
---|
| 129 | |
---|
| 130 | geom->setColorArray(colors); |
---|
| 131 | geom->setColorBinding(osg::Geometry::BIND_PER_VERTEX); |
---|
| 132 | |
---|
| 133 | geom->setTexCoordArray(0,texcoords0); |
---|
| 134 | |
---|
[340] | 135 | // Quads grid |
---|
| 136 | for ( unsigned int row=0; row<rows-1; row++ ) // each strip consists of two affected vertex rows, so we need only row-1 strips. |
---|
| 137 | { |
---|
[345] | 138 | osg::ref_ptr<osg::DrawElementsUInt> de = new osg::DrawElementsUInt(osg::PrimitiveSet::QUAD_STRIP, columns*2); // columns*2 = number of involved vertices for this strip. |
---|
[340] | 139 | for ( unsigned int col=0; col<columns; col++ ) |
---|
| 140 | { |
---|
| 141 | (*de)[col*2 + 0] = row*columns + col; |
---|
| 142 | (*de)[col*2 + 1] = (row+1)*columns + col; |
---|
| 143 | } |
---|
| 144 | geom->addPrimitiveSet( de.get() ); |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | //// Triangle grid |
---|
[339] | 148 | //for ( unsigned int row=0; row<rows-1; row++ ) // each strip consists of two affected vertex rows, so we need only row-1 strips. |
---|
| 149 | //{ |
---|
[340] | 150 | // osg::ref_ptr<osg::DrawElementsUInt> de = new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLE_STRIP, columns * 2 ); |
---|
[339] | 151 | // for ( unsigned int col=0; col<columns; col++ ) |
---|
| 152 | // { |
---|
| 153 | // (*de)[col*2 + 0] = row*columns + col; |
---|
| 154 | // (*de)[col*2 + 1] = (row+1)*columns + col; |
---|
| 155 | // } |
---|
| 156 | // geom->addPrimitiveSet( de.get() ); |
---|
| 157 | //} |
---|
[331] | 158 | |
---|
| 159 | return geom.release(); |
---|
| 160 | } |
---|
| 161 | |
---|
[350] | 162 | |
---|
[352] | 163 | void extViewer::setUpViewForManualDistortion(osgViewer::DistortionSet* distSet, unsigned int screenNum, const osg::Matrixd& projectorMatrix) |
---|
[311] | 164 | { |
---|
[350] | 165 | OSG_INFO<<"View::setUpViewForManualDistortion(sn="<<screenNum<<")"<<std::endl; |
---|
[313] | 166 | |
---|
[352] | 167 | if(distSet == NULL) |
---|
| 168 | { |
---|
| 169 | OSG_NOTICE<<"Error, no DistortionSet specified, cannot setup distortion."<<std::endl; |
---|
| 170 | return; |
---|
| 171 | } |
---|
| 172 | _distortionSet = distSet; |
---|
[350] | 173 | |
---|
[311] | 174 | osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface(); |
---|
| 175 | if (!wsi) |
---|
| 176 | { |
---|
| 177 | OSG_NOTICE<<"Error, no WindowSystemInterface available, cannot create windows."<<std::endl; |
---|
| 178 | return; |
---|
| 179 | } |
---|
| 180 | |
---|
[313] | 181 | osg::GraphicsContext::ScreenIdentifier si; |
---|
[311] | 182 | si.readDISPLAY(); |
---|
| 183 | |
---|
| 184 | // displayNum has not been set so reset it to 0. |
---|
| 185 | if (si.displayNum<0) si.displayNum = 0; |
---|
| 186 | |
---|
| 187 | si.screenNum = screenNum; |
---|
| 188 | |
---|
| 189 | unsigned int width, height; |
---|
| 190 | wsi->getScreenResolution(si, width, height); |
---|
| 191 | |
---|
| 192 | osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits; |
---|
| 193 | traits->hostName = si.hostName; |
---|
| 194 | traits->displayNum = si.displayNum; |
---|
| 195 | traits->screenNum = si.screenNum; |
---|
| 196 | traits->x = 0; |
---|
| 197 | traits->y = 0; |
---|
| 198 | traits->width = width; |
---|
| 199 | traits->height = height; |
---|
| 200 | traits->windowDecoration = false; |
---|
| 201 | traits->doubleBuffer = true; |
---|
| 202 | traits->sharedContext = 0; |
---|
| 203 | |
---|
[313] | 204 | osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get()); |
---|
[311] | 205 | if (!gc) |
---|
| 206 | { |
---|
| 207 | OSG_NOTICE<<"GraphicsWindow has not been created successfully."<<std::endl; |
---|
| 208 | return; |
---|
| 209 | } |
---|
[333] | 210 | |
---|
[328] | 211 | // Set up projection Matrix as it is done in View::setUpViewOnSingleScreen( |
---|
| 212 | double fovy, aspectRatio, zNear, zFar; |
---|
| 213 | _camera->getProjectionMatrixAsPerspective(fovy, aspectRatio, zNear, zFar); |
---|
[313] | 214 | |
---|
[328] | 215 | double newAspectRatio = double(traits->width) / double(traits->height); |
---|
| 216 | double aspectRatioChange = newAspectRatio / aspectRatio; |
---|
| 217 | if (aspectRatioChange != 1.0) |
---|
| 218 | { |
---|
| 219 | _camera->getProjectionMatrix() *= osg::Matrix::scale(1.0/aspectRatioChange,1.0,1.0); |
---|
| 220 | } |
---|
| 221 | |
---|
| 222 | |
---|
[313] | 223 | int tex_width = width; |
---|
| 224 | int tex_height = height; |
---|
| 225 | |
---|
| 226 | int camera_width = tex_width; |
---|
| 227 | int camera_height = tex_height; |
---|
| 228 | |
---|
[334] | 229 | osg::TextureRectangle* sceneTexture = new osg::TextureRectangle; |
---|
[313] | 230 | |
---|
[334] | 231 | sceneTexture->setTextureSize(tex_width, tex_height); |
---|
| 232 | sceneTexture->setInternalFormat(GL_RGB); |
---|
| 233 | sceneTexture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); |
---|
| 234 | sceneTexture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR); |
---|
| 235 | sceneTexture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_EDGE); |
---|
| 236 | sceneTexture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE); |
---|
[313] | 237 | |
---|
| 238 | |
---|
| 239 | #if 0 |
---|
| 240 | osg::Camera::RenderTargetImplementation renderTargetImplementation = osg::Camera::SEPERATE_WINDOW; |
---|
| 241 | GLenum buffer = GL_FRONT; |
---|
| 242 | #else |
---|
| 243 | osg::Camera::RenderTargetImplementation renderTargetImplementation = osg::Camera::FRAME_BUFFER_OBJECT; |
---|
| 244 | GLenum buffer = GL_FRONT; |
---|
| 245 | #endif |
---|
| 246 | |
---|
| 247 | // Scene camera |
---|
| 248 | { |
---|
| 249 | osg::ref_ptr<osg::Camera> camera = new osg::Camera; |
---|
[315] | 250 | camera->setName("Scene cam"); |
---|
[313] | 251 | camera->setGraphicsContext(gc.get()); |
---|
| 252 | camera->setViewport(new osg::Viewport(0,0,camera_width, camera_height)); |
---|
| 253 | camera->setDrawBuffer(buffer); |
---|
| 254 | camera->setReadBuffer(buffer); |
---|
| 255 | camera->setAllowEventFocus(false); |
---|
| 256 | // tell the camera to use OpenGL frame buffer object where supported. |
---|
| 257 | camera->setRenderTargetImplementation(renderTargetImplementation); |
---|
| 258 | // attach the texture and use it as the color buffer. |
---|
[334] | 259 | camera->attach(osg::Camera::COLOR_BUFFER, sceneTexture); |
---|
[313] | 260 | |
---|
[398] | 261 | _distortionSet->setSceneCamera( camera ); |
---|
| 262 | |
---|
[352] | 263 | addSlave(camera.get(), _distortionSet->getProjectionOffset(), _distortionSet->getViewOffset() ); |
---|
[361] | 264 | |
---|
[313] | 265 | } |
---|
| 266 | |
---|
| 267 | // distortion correction set up. |
---|
| 268 | { |
---|
[359] | 269 | osg::ref_ptr<osg::Switch> root = _distortionSet->getDistortionInternals(); |
---|
| 270 | osg::Geode* meshGeode = new osg::Geode(); |
---|
| 271 | root->addChild(meshGeode, true); // Child #0 (adds mesh,shader,.. so camera renders mesh (and thus render the scene)) |
---|
[313] | 272 | |
---|
[333] | 273 | // new we need to add the scene texture to the mesh, we do so by creating a |
---|
[362] | 274 | // Modify StateSet to contain the Texture StateAttribute. |
---|
[359] | 275 | osg::StateSet* stateset = meshGeode->getOrCreateStateSet(); |
---|
[350] | 276 | stateset->setTextureAttributeAndModes(_distortionSet->getTexUnitScene(), sceneTexture,osg::StateAttribute::ON); |
---|
[336] | 277 | stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF); |
---|
[370] | 278 | // Modify StateSet to protectit against state changes by the stateset Manipulator |
---|
[362] | 279 | osg::PolygonMode* polyModeObj = new osg::PolygonMode; |
---|
| 280 | stateset->setAttribute(polyModeObj, osg::StateAttribute::PROTECTED|osg::StateAttribute::ON); |
---|
[313] | 281 | |
---|
[336] | 282 | osg::TexMat* texmat = new osg::TexMat; |
---|
[337] | 283 | texmat->setScaleByTextureRectangleSize(true); |
---|
[359] | 284 | stateset->setTextureAttributeAndModes(_distortionSet->getTexUnitScene(), texmat, osg::StateAttribute::ON); |
---|
[313] | 285 | |
---|
[360] | 286 | 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), _distortionSet->getDistortionMeshColumns(), _distortionSet->getDistortionMeshColumns(), projectorMatrix); |
---|
[359] | 287 | meshGeode->addDrawable(distortionMesh); |
---|
[337] | 288 | |
---|
[359] | 289 | setUpIntensityMapBlending(_distortionSet, screenNum); |
---|
| 290 | |
---|
[313] | 291 | osg::ref_ptr<osg::Camera> camera = new osg::Camera; |
---|
| 292 | camera->setGraphicsContext(gc.get()); |
---|
| 293 | camera->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT ); |
---|
[336] | 294 | camera->setClearColor( osg::Vec4(0.0,0.0,0.0,1.0) ); |
---|
[313] | 295 | camera->setViewport(new osg::Viewport(0, 0, width, height)); |
---|
| 296 | GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT; |
---|
| 297 | camera->setDrawBuffer(buffer); |
---|
| 298 | camera->setReadBuffer(buffer); |
---|
| 299 | camera->setReferenceFrame(osg::Camera::ABSOLUTE_RF); |
---|
| 300 | camera->setAllowEventFocus(false); |
---|
| 301 | camera->setInheritanceMask(camera->getInheritanceMask() & ~osg::CullSettings::CLEAR_COLOR & ~osg::CullSettings::COMPUTE_NEAR_FAR_MODE); |
---|
| 302 | //camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR); |
---|
| 303 | |
---|
| 304 | camera->setProjectionMatrixAsOrtho2D(0,width,0,height); |
---|
| 305 | camera->setViewMatrix(osg::Matrix::identity()); |
---|
| 306 | |
---|
[329] | 307 | camera->addChild(root); |
---|
[353] | 308 | _distortionSet->setDistortionCamera( camera ); |
---|
| 309 | |
---|
| 310 | // Ensure selector is visible: |
---|
[359] | 311 | meshGeode->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF ); |
---|
| 312 | meshGeode->getOrCreateStateSet()->setAttributeAndModes( new osg::PolygonOffset(1.0f, 1.0f) ); |
---|
[352] | 313 | |
---|
[320] | 314 | camera->setName("Dist Cam"); |
---|
[313] | 315 | |
---|
| 316 | addSlave(camera.get(), osg::Matrixd(), osg::Matrixd(), false); |
---|
| 317 | } |
---|
[341] | 318 | } |
---|
| 319 | |
---|
[359] | 320 | void extViewer::setUpIntensityMapBlending(osgViewer::DistortionSet* distSet, unsigned int screenNum) |
---|
[341] | 321 | { |
---|
[350] | 322 | osg::Image* intensityMap = _distortionSet->getIntensityMap(); |
---|
[359] | 323 | osg::StateSet* stateset = _distortionSet->getDistortionInternals()->getChild(osgViewer::DistortionSet::MESH)->getOrCreateStateSet(); |
---|
| 324 | |
---|
[350] | 325 | if(intensityMap == NULL) return; |
---|
| 326 | |
---|
| 327 | if(stateset == NULL) |
---|
[341] | 328 | { |
---|
| 329 | OSG_NOTICE<<"Error, no intensityMap or stateset for intensityMapBlending specified."<<std::endl; |
---|
| 330 | return; |
---|
| 331 | } |
---|
| 332 | |
---|
| 333 | osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface(); |
---|
| 334 | if (!wsi) |
---|
| 335 | { |
---|
| 336 | OSG_NOTICE<<"Error, no WindowSystemInterface available, cannot create windows."<<std::endl; |
---|
| 337 | return; |
---|
| 338 | } |
---|
| 339 | |
---|
| 340 | osg::GraphicsContext::ScreenIdentifier si; |
---|
| 341 | si.readDISPLAY(); |
---|
| 342 | |
---|
| 343 | // displayNum has not been set so reset it to 0. |
---|
| 344 | if (si.displayNum<0) si.displayNum = 0; |
---|
| 345 | |
---|
| 346 | si.screenNum = screenNum; |
---|
| 347 | |
---|
| 348 | unsigned int width, height; |
---|
| 349 | wsi->getScreenResolution(si, width, height); |
---|
| 350 | |
---|
| 351 | // Resize intensityMap if the dimensions are wrong |
---|
| 352 | if(intensityMap->s()!=width || intensityMap->t()!=height) |
---|
| 353 | intensityMap->scaleImage(width, height, intensityMap->r()); |
---|
| 354 | |
---|
| 355 | osg::TextureRectangle* intensityMapTexture = new osg::TextureRectangle(intensityMap); |
---|
| 356 | intensityMapTexture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); |
---|
| 357 | intensityMapTexture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR); |
---|
| 358 | intensityMapTexture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_EDGE); |
---|
| 359 | intensityMapTexture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE); |
---|
| 360 | |
---|
[350] | 361 | stateset->setTextureAttributeAndModes(_distortionSet->getTexUnitIntensityMap(), intensityMapTexture, osg::StateAttribute::ON); |
---|
[341] | 362 | |
---|
[361] | 363 | // create shader for blending |
---|
[360] | 364 | osg::Program* IntensityMapProgram = new osg::Program; |
---|
| 365 | IntensityMapProgram->setName( "intensityMapBlending" ); |
---|
[392] | 366 | osg::Shader* shaderVert = osg::Shader::readShaderFile( osg::Shader::VERTEX, "shader.vert" ); |
---|
| 367 | shaderVert->setName("shaderVert"); |
---|
[361] | 368 | osg::Shader* shaderIntensityMap = osg::Shader::readShaderFile( osg::Shader::FRAGMENT, "shaderIntensityMap.frag" ); |
---|
| 369 | shaderIntensityMap->setName("shaderIntensityMap"); |
---|
[392] | 370 | |
---|
[361] | 371 | _distortionSet->setShaderIntensityMap( shaderIntensityMap ); |
---|
[341] | 372 | |
---|
[392] | 373 | if ( shaderVert && shaderIntensityMap ) |
---|
[341] | 374 | { |
---|
[392] | 375 | IntensityMapProgram->addShader( shaderVert ); |
---|
[361] | 376 | IntensityMapProgram->addShader( shaderIntensityMap ); |
---|
[351] | 377 | stateset->addUniform( new osg::Uniform("sceneTexture", (int)_distortionSet->getTexUnitScene()) ); |
---|
| 378 | stateset->addUniform( new osg::Uniform("intensityMapTexture", (int)_distortionSet->getTexUnitIntensityMap()) ); |
---|
[360] | 379 | stateset->setAttributeAndModes(IntensityMapProgram, osg::StateAttribute::ON); |
---|
[341] | 380 | } |
---|
[350] | 381 | } |
---|
| 382 | |
---|
| 383 | void extViewer::setUpIntensityMapBlending(std::string intensityMap) |
---|
| 384 | { |
---|
| 385 | // Try to load intensityMap |
---|
| 386 | osg::Image* intMap = osgDB::readImageFile(intensityMap); |
---|
| 387 | if (!intMap) |
---|
| 388 | { |
---|
| 389 | osg::notify(osg::WARN) << "Quitting, couldn't find intensity map: " << intensityMap << std::endl; |
---|
| 390 | return; |
---|
| 391 | } |
---|
| 392 | |
---|
| 393 | // Create DistortionSet |
---|
[360] | 394 | osgViewer::DistortionSet* ds = new osgViewer::DistortionSet(); |
---|
| 395 | ds->setIntensityMap( intMap ); |
---|
| 396 | ds->setDistortionMeshRows( 2 ); |
---|
| 397 | ds->setDistortionMeshColumns( 2 ); |
---|
| 398 | ds->setTexUnitScene( 0 ); |
---|
| 399 | ds->setTexUnitIntensityMap( 1 ); |
---|
[350] | 400 | |
---|
[360] | 401 | setUpViewForManualDistortion(ds); |
---|
[325] | 402 | } |
---|