Changeset 336 for experimental
- Timestamp:
- Mar 16, 2012, 9:53:30 PM (13 years ago)
- Location:
- experimental/distortionNG
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
experimental/distortionNG/extViewer.cpp
r335 r336 33 33 } 34 34 35 static osg::Texture * loadTexture( const std::string& fileName )35 static osg::Texture2D* loadTexture( const std::string& fileName ) 36 36 { 37 37 std::string foundFileName = osgDB::findDataFile(fileName); … … 44 44 osg::Texture2D* texture = new osg::Texture2D; 45 45 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 63 static 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); 48 76 texture->setWrap(osg::Texture2D::WRAP_S, osg::Texture2D::CLAMP_TO_EDGE); 49 77 texture->setWrap(osg::Texture2D::WRAP_T, osg::Texture2D::CLAMP_TO_EDGE); … … 135 163 geom->addPrimitiveSet( de.get() ); 136 164 } 137 138 //if (intensityMap && !applyIntensityMapAsColours)139 //{140 // // create shaders for distortion141 // 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 //}157 165 158 166 return geom.release(); … … 261 269 // new we need to add the scene texture to the mesh, we do so by creating a 262 270 // StateSet to contain the Texture StateAttribute. 263 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); 270 278 271 279 // If the intensityMap is used but not applyIntensityMapAsColours: Apply intensityMap as intensityMapTexture on unit 1 272 280 if (!applyIntensityMapAsColours && intensityMap) 273 281 { 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); 279 289 280 290 stateset->setTextureAttributeAndModes(1, intensityMapTexture, osg::StateAttribute::ON); 281 291 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); 292 295 } 293 296 … … 319 322 camera->setGraphicsContext(gc.get()); 320 323 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) ); 322 325 camera->setViewport(new osg::Viewport(0, 0, width, height)); 323 326 GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT; -
experimental/distortionNG/shader.frag
r335 r336 1 uniform sampler2D sceneTexture;2 uniform sampler2D intensityMapTexture;1 uniform sampler2DRect sceneTexture; 2 uniform sampler2DRect intensityMapTexture; 3 3 in varying vec2 texcoord_scene; 4 4 in varying vec2 texcoord_intensityMap; … … 9 9 vec4 blendColor; 10 10 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; 15 15 }
Note: See TracChangeset
for help on using the changeset viewer.