Changeset 335
- Timestamp:
- Mar 12, 2012, 10:55:32 AM (13 years ago)
- Location:
- experimental/distortionNG
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
experimental/distortionNG/extViewer.cpp
r334 r335 31 31 { 32 32 33 } 34 35 static osg::Texture* loadTexture( const std::string& fileName ) 36 { 37 std::string foundFileName = osgDB::findDataFile(fileName); 38 if (foundFileName.length() != 0 ) 39 { 40 // load distortion map texture file 41 osg::Image* image = osgDB::readImageFile(foundFileName); 42 if (image) 43 { 44 osg::Texture2D* texture = new osg::Texture2D; 45 texture->setImage(image); 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 return texture; 51 } 52 } 53 54 OSG_NOTIFY(osg::WARN) << "File \"" << fileName << "\" not found." << std::endl; 55 56 return NULL; 33 57 } 34 58 … … 100 124 geom->setTexCoordArray(1,texcoords1); 101 125 102 // osg::DrawElementsUShort* elements = new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLES);103 // geometry->addPrimitiveSet(elements);104 126 105 127 for ( unsigned int row=0; row<rows-1; row++ ) // each strip consists of two affected vertex rows, so we need only row-1 strips. … … 114 136 } 115 137 116 if (intensityMap && !applyIntensityMapAsColours)117 {118 // create shaders for distortion119 osg::Program* distortProgram = new osg::Program;120 distortProgram->setName( "distortion" );121 osg::Shader* vShader = osg::Shader::readShaderFile( osg::Shader::VERTEX, "shader.vert" );122 vShader->setName("intensityMapVertShader");123 osg::Shader* fShader = osg::Shader::readShaderFile( osg::Shader::FRAGMENT, "shader.frag" );124 fShader->setName("intensityMapFragShader");125 126 if ( vShader && fShader )127 {128 //distortProgram->addShader( vShader );129 distortProgram->addShader( fShader );130 geom->getOrCreateStateSet()->addUniform( new osg::Uniform("sceneTexture", 0) );131 geom->getOrCreateStateSet()->addUniform( new osg::Uniform("intensityMapTexture", 1) );132 geom->getOrCreateStateSet()->setAttributeAndModes(distortProgram, osg::StateAttribute::ON);133 }134 }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 //} 135 157 136 158 return geom.release(); … … 240 262 // StateSet to contain the Texture StateAttribute. 241 263 osg::StateSet* stateset = geode->getOrCreateStateSet(); 242 stateset->setTextureAttributeAndModes(0, sceneTexture,osg::StateAttribute::ON);243 stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);244 245 osg::TexMat* texmat = new osg::TexMat;246 texmat->setScaleByTextureRectangleSize(true);247 stateset->setTextureAttributeAndModes(0, texmat, osg::StateAttribute::ON);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); 248 270 249 271 // If the intensityMap is used but not applyIntensityMapAsColours: Apply intensityMap as intensityMapTexture on unit 1 … … 257 279 258 280 stateset->setTextureAttributeAndModes(1, intensityMapTexture, osg::StateAttribute::ON); 281 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 259 292 } 260 293 261 294 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); 262 295 geode->addDrawable(distortionMesh); 296 297 if (intensityMap && !applyIntensityMapAsColours) 298 { 299 // create shaders for distortion 300 osg::Program* distortProgram = new osg::Program; 301 distortProgram->setName( "distortion" ); 302 osg::Shader* vShader = osg::Shader::readShaderFile( osg::Shader::VERTEX, "shader.vert" ); 303 vShader->setName("intensityMapVertShader"); 304 osg::Shader* fShader = osg::Shader::readShaderFile( osg::Shader::FRAGMENT, "shader.frag" ); 305 fShader->setName("intensityMapFragShader"); 306 307 if ( vShader && fShader ) 308 { 309 //distortProgram->addShader( vShader ); 310 distortProgram->addShader( fShader ); 311 stateset->addUniform( new osg::Uniform("sceneTexture", 0) ); 312 stateset->addUniform( new osg::Uniform("intensityMapTexture", 1) ); 313 stateset->setAttributeAndModes(distortProgram, osg::StateAttribute::ON); 314 } 315 } 263 316 264 317 -
experimental/distortionNG/shader.frag
r334 r335 1 1 uniform sampler2D sceneTexture; 2 2 uniform sampler2D intensityMapTexture; 3 varying vec2 texcoord_scene;4 varying vec2 texcoord_intensityMap;3 in varying vec2 texcoord_scene; 4 in varying vec2 texcoord_intensityMap; 5 5 6 6 void main(void) -
experimental/distortionNG/shader.vert
r334 r335 1 varying vec2 texcoord_scene;2 varying vec2 texcoord_intensityMap;1 out varying vec2 texcoord_scene; 2 out varying vec2 texcoord_intensityMap; 3 3 4 4 void main() 5 5 { 6 6 gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; 7 gl_FrontColor = gl_Color;8 7 texcoord_scene = vec2(gl_MultiTexCoord0); 9 8 texcoord_intensityMap = vec2(gl_MultiTexCoord1);
Note: See TracChangeset
for help on using the changeset viewer.