Changeset 336


Ignore:
Timestamp:
Mar 16, 2012, 9:53:30 PM (7 years ago)
Author:
Torben Dannhauer
Message:
 
Location:
experimental/distortionNG
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • experimental/distortionNG/extViewer.cpp

    r335 r336  
    3333}
    3434
    35 static osg::Texture* loadTexture( const std::string& fileName )
     35static osg::Texture2D* loadTexture( const std::string& fileName )
    3636{
    3737    std::string foundFileName = osgDB::findDataFile(fileName);
     
    4444                        osg::Texture2D* texture = new osg::Texture2D;
    4545            texture->setImage(image);
    46             texture->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::NEAREST);
    47             texture->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::NEAREST);
     46            //texture->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::NEAREST);
     47            //texture->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::NEAREST);
     48            //texture->setWrap(osg::Texture2D::WRAP_S, osg::Texture2D::CLAMP_TO_EDGE);
     49            //texture->setWrap(osg::Texture2D::WRAP_T, osg::Texture2D::CLAMP_TO_EDGE);
     50                        texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR);
     51                        texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR);
     52                        texture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_EDGE);
     53                        texture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE);
     54            return texture;
     55        }
     56    }
     57
     58    OSG_NOTIFY(osg::WARN) << "File \"" << fileName << "\" not found." << std::endl;
     59
     60    return NULL;
     61}
     62
     63static osg::TextureRectangle* loadTextureRect( const std::string& fileName )
     64{
     65    std::string foundFileName = osgDB::findDataFile(fileName);
     66    if (foundFileName.length() != 0 )
     67    {
     68        // load distortion map texture file
     69        osg::Image* image = osgDB::readImageFile(foundFileName);
     70        if (image)
     71        {
     72                        osg::TextureRectangle* texture = new osg::TextureRectangle;
     73            texture->setImage(image);
     74            texture->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR);
     75            texture->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR);
    4876            texture->setWrap(osg::Texture2D::WRAP_S, osg::Texture2D::CLAMP_TO_EDGE);
    4977            texture->setWrap(osg::Texture2D::WRAP_T, osg::Texture2D::CLAMP_TO_EDGE);
     
    135163                geom->addPrimitiveSet( de.get() );
    136164        }
    137 
    138         //if (intensityMap && !applyIntensityMapAsColours)
    139         //{
    140         //      // create shaders for distortion
    141         //      osg::Program* distortProgram = new osg::Program;
    142         //      distortProgram->setName( "distortion" );
    143         //      osg::Shader* vShader = osg::Shader::readShaderFile( osg::Shader::VERTEX, "shader.vert" );
    144         //      vShader->setName("intensityMapVertShader");
    145         //      osg::Shader* fShader = osg::Shader::readShaderFile( osg::Shader::FRAGMENT, "shader.frag" );
    146         //      fShader->setName("intensityMapFragShader");
    147 
    148         //      if ( vShader && fShader )
    149         //      {
    150         //              //distortProgram->addShader( vShader );
    151         //              distortProgram->addShader( fShader );
    152         //              geom->getOrCreateStateSet()->addUniform( new osg::Uniform("sceneTexture", 0) );
    153         //              geom->getOrCreateStateSet()->addUniform( new osg::Uniform("intensityMapTexture", 1) );
    154         //              geom->getOrCreateStateSet()->setAttributeAndModes(distortProgram, osg::StateAttribute::ON);
    155         //      }
    156         //}
    157165
    158166        return geom.release();
     
    261269                // new we need to add the scene texture to the mesh, we do so by creating a
    262270        // StateSet to contain the Texture StateAttribute.
    263         osg::StateSet* stateset = geode->getOrCreateStateSet();
    264         //stateset->setTextureAttributeAndModes(0, sceneTexture,osg::StateAttribute::ON);
    265         //stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
    266 
    267                 //osg::TexMat* texmat = new osg::TexMat;
    268   //      texmat->setScaleByTextureRectangleSize(true);
    269   //      stateset->setTextureAttributeAndModes(0, texmat, osg::StateAttribute::ON);
     271            osg::StateSet* stateset = geode->getOrCreateStateSet();
     272        stateset->setTextureAttributeAndModes(0, sceneTexture,osg::StateAttribute::ON);
     273        stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
     274
     275                osg::TexMat* texmat = new osg::TexMat;
     276        texmat->setScaleByTextureRectangleSize(true);
     277        stateset->setTextureAttributeAndModes(0, texmat, osg::StateAttribute::ON);
    270278
    271279                // If the intensityMap is used but not applyIntensityMapAsColours: Apply intensityMap as intensityMapTexture on unit 1
    272280                if (!applyIntensityMapAsColours && intensityMap)
    273281        {
    274                         osg::Texture2D* intensityMapTexture = new osg::Texture2D(intensityMap);
    275             intensityMapTexture->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::NEAREST);
    276             intensityMapTexture->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::NEAREST);
    277             intensityMapTexture->setWrap(osg::Texture2D::WRAP_S, osg::Texture2D::CLAMP_TO_EDGE);
    278             intensityMapTexture->setWrap(osg::Texture2D::WRAP_T, osg::Texture2D::CLAMP_TO_EDGE);
     282                        osg::TextureRectangle* intensityMapTexture = new osg::TextureRectangle(intensityMap);
     283                        intensityMapTexture->setTextureSize(tex_width, tex_height);
     284                        //intensityMapTexture->setInternalFormat(GL_RGB);
     285                 //   intensityMapTexture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR);
     286                        //intensityMapTexture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR);
     287                        intensityMapTexture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_EDGE);
     288                        intensityMapTexture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE);
    279289
    280290            stateset->setTextureAttributeAndModes(1, intensityMapTexture, osg::StateAttribute::ON);
    281291
    282                         osg::Texture* tmp = loadTexture( "test.jpg" );
    283                         if(tmp)
    284                         {
    285                                 stateset->setTextureAttributeAndModes(0, tmp,osg::StateAttribute::ON);
    286 
    287                                 osg::TexMat* texmat = new osg::TexMat;
    288                                 texmat->setScaleByTextureRectangleSize(true);
    289                                 stateset->setTextureAttributeAndModes(0, texmat, osg::StateAttribute::ON);
    290                         }
    291 
     292                        //osg::TexMat* texmat1 = new osg::TexMat;
     293                        //texmat1->setScaleByTextureRectangleSize(true);
     294                        //stateset->setTextureAttributeAndModes(1, texmat1, osg::StateAttribute::ON);
    292295        }
    293296
     
    319322        camera->setGraphicsContext(gc.get());
    320323        camera->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT );
    321         camera->setClearColor( osg::Vec4(0.0,1.0,0.0,1.0) );
     324        camera->setClearColor( osg::Vec4(0.0,0.0,0.0,1.0) );
    322325        camera->setViewport(new osg::Viewport(0, 0, width, height));
    323326        GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
  • experimental/distortionNG/shader.frag

    r335 r336  
    1 uniform sampler2D sceneTexture;
    2 uniform sampler2D intensityMapTexture;
     1uniform sampler2DRect sceneTexture;
     2uniform sampler2DRect intensityMapTexture;
    33in varying vec2 texcoord_scene;
    44in varying vec2 texcoord_intensityMap;
     
    99        vec4 blendColor;
    1010
    11         sceneColor = texture2D(sceneTexture, texcoord_scene);
    12         blendColor = texture2D(intensityMapTexture, gl_FragCoord);
    13         //gl_FragColor = vec4( 1.,1.,1.,1.);
    14         gl_FragColor = sceneColor;
     11        //sceneColor = texture2DRect(sceneTexture, texcoord_scene);
     12        sceneColor = texture2DRect(sceneTexture, gl_FragCoord);
     13        blendColor = texture2DRect(intensityMapTexture, gl_FragCoord);
     14        gl_FragColor = sceneColor * blendColor;
    1515}
Note: See TracChangeset for help on using the changeset viewer.