Changeset 341 for experimental


Ignore:
Timestamp:
Apr 12, 2012, 5:55:57 PM (13 years ago)
Author:
Torben Dannhauer
Message:

intensityBlending is now supported. Code refactored to have a single setup method

Location:
experimental/distortionNG
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • experimental/distortionNG/extViewer.cpp

    r340 r341  
    287287                // If the intensityMap is used but not applyIntensityMapAsColours: Apply intensityMap as intensityMapTexture on unit 1
    288288                if (!applyIntensityMapAsColours && intensityMap)
    289         {
    290                         // Resize intensityMap if the dimensions are wrong
    291                         if(intensityMap->s()!=tex_width || intensityMap->t()!=tex_height)
    292                                 intensityMap->scaleImage(tex_width, tex_height, intensityMap->r());
    293 
    294                         osg::TextureRectangle* intensityMapTexture = new osg::TextureRectangle(intensityMap);
    295                         intensityMapTexture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR);
    296                         intensityMapTexture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR);
    297                         intensityMapTexture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_EDGE);
    298                         intensityMapTexture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE);
    299 
    300             stateset->setTextureAttributeAndModes(1, intensityMapTexture, osg::StateAttribute::ON);
    301 
    302                         // create shaders for distortion
    303                         osg::Program* distortProgram = new osg::Program;
    304                         distortProgram->setName( "distortion" );
    305                         osg::Shader* vShader = osg::Shader::readShaderFile( osg::Shader::VERTEX, "shader.vert" );
    306                         vShader->setName("intensityMapVertShader");
    307                         osg::Shader* fShader = osg::Shader::readShaderFile( osg::Shader::FRAGMENT, "shader.frag" );
    308                         fShader->setName("intensityMapFragShader");
    309 
    310                         if ( vShader && fShader )
    311                         {
    312                                 //distortProgram->addShader( vShader );
    313                                 distortProgram->addShader( fShader );
    314                                 stateset->addUniform( new osg::Uniform("sceneTexture", 0) );
    315                                 stateset->addUniform( new osg::Uniform("intensityMapTexture", 1) );
    316                                 stateset->setAttributeAndModes(distortProgram, osg::StateAttribute::ON);
    317                         }
    318         }
     289                        setUpIntensityMapBlending(stateset, intensityMap, screenNum, 0, 1);     
    319290
    320291                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);
     
    358329    }
    359330}
     331
     332void extViewer::setUpIntensityMapBlending(osg::StateSet* stateset, osg::Image* intensityMap, unsigned int screenNum, int rttSceneTextureUnit, int intensityMapTextureUnit)
     333{
     334        if(stateset == NULL || intensityMap == NULL)
     335        {
     336                OSG_NOTICE<<"Error, no intensityMap or stateset for intensityMapBlending specified."<<std::endl;
     337                return;
     338        }
     339
     340        osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface();
     341    if (!wsi)
     342    {
     343        OSG_NOTICE<<"Error, no WindowSystemInterface available, cannot create windows."<<std::endl;
     344        return;
     345    }
     346
     347        osg::GraphicsContext::ScreenIdentifier si;
     348    si.readDISPLAY();
     349
     350    // displayNum has not been set so reset it to 0.
     351    if (si.displayNum<0) si.displayNum = 0;
     352
     353    si.screenNum = screenNum;
     354
     355    unsigned int width, height;
     356    wsi->getScreenResolution(si, width, height);
     357
     358        // Resize intensityMap if the dimensions are wrong
     359        if(intensityMap->s()!=width || intensityMap->t()!=height)
     360                intensityMap->scaleImage(width, height, intensityMap->r());
     361
     362        osg::TextureRectangle* intensityMapTexture = new osg::TextureRectangle(intensityMap);
     363        intensityMapTexture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR);
     364        intensityMapTexture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR);
     365        intensityMapTexture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_EDGE);
     366        intensityMapTexture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE);
     367
     368    stateset->setTextureAttributeAndModes(intensityMapTextureUnit, intensityMapTexture, osg::StateAttribute::ON);
     369
     370        // create shaders for blending
     371        osg::Program* distortProgram = new osg::Program;
     372        distortProgram->setName( "intensityMapBlending" );
     373        osg::Shader* fShader = osg::Shader::readShaderFile( osg::Shader::FRAGMENT, "shader.frag" );
     374        fShader->setName("intensityMapFragShader");
     375
     376        if ( fShader )
     377        {
     378                distortProgram->addShader( fShader );
     379                stateset->addUniform( new osg::Uniform("sceneTexture", rttSceneTextureUnit) );
     380                stateset->addUniform( new osg::Uniform("intensityMapTexture", intensityMapTextureUnit) );
     381                stateset->setAttributeAndModes(distortProgram, osg::StateAttribute::ON);
     382        }
     383}
  • experimental/distortionNG/extViewer.h

    r331 r341  
    1515                /** Convenience method for projection on curved screens using a slave camera rendering scene and a second camera doing distortion correction to present on a nonplaner display.*/
    1616        void setUpViewForManualDistortion(unsigned int screenNum=0, osg::Image* intensityMap=0, const osg::Matrixd& projectorMatrix = osg::Matrixd());
     17
     18                void setUpIntensityMapBlending(osg::StateSet* stateset, osg::Image* intensityMap, unsigned int screenNum=0, int rttSceneTextureUnit=0, int intensityMapTextureUnit=1);
    1719};
  • experimental/distortionNG/main.cpp

    r340 r341  
    4242    extViewer viewer(arguments);
    4343
    44         osg::Image* intMap = osgDB::readImageFile("intensitymap.png");
     44        osg::Image* intMap = osgDB::readImageFile("intensitymap2.png");
    4545        if (!intMap)
    4646        {
  • experimental/distortionNG/shader.frag

    r338 r341  
    99        vec4 blendColor;
    1010
    11         //sceneColor = texture2DRect(sceneTexture, texcoord_scene);
    1211        sceneColor = texture2DRect(sceneTexture, gl_FragCoord);
    1312        blendColor = texture2DRect(intensityMapTexture, gl_FragCoord);
Note: See TracChangeset for help on using the changeset viewer.