Changeset 334
- Timestamp:
- Mar 12, 2012, 10:11:01 AM (13 years ago)
- Location:
- experimental/distortionNG
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
experimental/distortionNG/distortionNG.vcproj
r310 r334 210 210 > 211 211 </Filter> 212 <File 213 RelativePath=".\shader.frag" 214 > 215 </File> 216 <File 217 RelativePath=".\shader.vert" 218 > 219 </File> 212 220 </Files> 213 221 <Globals> -
experimental/distortionNG/extViewer.cpp
r333 r334 3 3 4 4 #include <osg/PolygonOffset> 5 #include<osg/Texture2D> 6 #include<osg/TextureRectangle> 7 #include<osg/TexMat> 8 #include<osg/ComputeBoundsVisitor> 9 #include<osg/Vec2> 10 11 #include<osgDB/ReadFile> 5 #include <osg/Texture2D> 6 #include <osg/TextureRectangle> 7 #include <osg/TexMat> 8 #include <osg/ComputeBoundsVisitor> 9 #include <osg/Vec2> 10 11 #include <osgDB/ReadFile> 12 #include <osgDB/FileUtils> 12 13 13 14 #include <osgUtil/SmoothingVisitor> … … 30 31 { 31 32 32 }33 34 static void configureShaders( osg::StateSet* stateSet )35 {36 // Create Shaders37 const std::string vertexSource =38 "uniform sampler2D sceneTexture;\n"39 "uniform sampler2D intensityMapTexture;\n"40 "uniform mat4 osg_ModelViewProjectionMatrix; \n"41 //"uniform vec3 ecLightDir; \n"42 " \n"43 "in vec4 osg_Vertex; \n"44 "in vec4 osg_Color; \n"45 " \n"46 "void main() \n"47 "{ \n"48 //" gl_Position = osg_ModelViewProjectionMatrix * osg_Vertex; \n"49 " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; \n"50 " gl_FrontColor = gl_Color;\n"51 " gl_TexCoord[0] = gl_MultiTexCoord0; \n"52 // " gl_TexCoord[1] = gl_MultiTexCoord1; \n"53 ""54 " \n"55 "} \n";56 57 osg::Shader* vShader = new osg::Shader( osg::Shader::VERTEX, vertexSource );58 vShader->setName("intensityMapVertShader");59 60 const std::string fragmentSource =61 "uniform sampler2D sceneTexture;\n"62 "uniform sampler2D intensityMapTexture;\n"63 "varying vec2 texcoord;\n"64 "\n"65 "void main(void) \n"66 "{\n"67 " vec4 distortColor; \n"68 " vec4 blendColor; \n"69 "\n"70 " distortColor = texture2D(sceneTexture, gl_TexCoord[0]); \n"71 //" blendColor = texture2D(intensityMapTexture, gl_TexCoord[1].st); \n"72 " blendColor = texture2D(intensityMapTexture, gl_FragCoord); \n"73 //" gl_FragColor = vec4( 1.,1.,1.,1.); \n"74 "gl_FragColor = blendColor; \n"75 "}\n";76 osg::Shader* fShader = new osg::Shader( osg::Shader::FRAGMENT, fragmentSource );77 fShader->setName("intensityMapFragShader");78 79 // Create Programm80 osg::Program* program = new osg::Program;81 program->addShader( vShader );82 program->addShader( fShader );83 program->setName("intensityMapFragProgramm");84 stateSet->setAttribute( program );85 86 osg::Uniform* sceneTextureSampler = new osg::Uniform("sceneTexture",0);87 stateSet->addUniform(sceneTextureSampler);88 osg::Uniform* intensityMapTextureSampler = new osg::Uniform("intensityMapTexture",1);89 stateSet->addUniform(intensityMapTextureSampler);90 91 92 /*osg::Vec3f lightDir( 0., 0.5, 1. );93 lightDir.normalize();94 stateSet->addUniform( new osg::Uniform( "ecLightDir", lightDir ) );*/95 33 } 96 34 … … 178 116 if (intensityMap && !applyIntensityMapAsColours) 179 117 { 180 configureShaders( geom->getOrCreateStateSet() ); 118 // create shaders for distortion 119 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 } 181 134 } 182 135 … … 245 198 int camera_height = tex_height; 246 199 247 osg::TextureRectangle* texture = new osg::TextureRectangle;248 249 texture->setTextureSize(tex_width, tex_height);250 texture->setInternalFormat(GL_RGB);251 texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR);252 texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR);253 texture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_EDGE);254 texture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE);200 osg::TextureRectangle* sceneTexture = new osg::TextureRectangle; 201 202 sceneTexture->setTextureSize(tex_width, tex_height); 203 sceneTexture->setInternalFormat(GL_RGB); 204 sceneTexture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); 205 sceneTexture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR); 206 sceneTexture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_EDGE); 207 sceneTexture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE); 255 208 256 209 … … 274 227 // tell the camera to use OpenGL frame buffer object where supported. 275 228 camera->setRenderTargetImplementation(renderTargetImplementation); 276 277 229 // attach the texture and use it as the color buffer. 278 camera->attach(osg::Camera::COLOR_BUFFER, texture);230 camera->attach(osg::Camera::COLOR_BUFFER, sceneTexture); 279 231 280 232 addSlave(camera.get(), osg::Matrixd(), osg::Matrixd()); … … 288 240 // StateSet to contain the Texture StateAttribute. 289 241 osg::StateSet* stateset = geode->getOrCreateStateSet(); 290 stateset->setTextureAttributeAndModes(0, texture,osg::StateAttribute::ON);242 stateset->setTextureAttributeAndModes(0, sceneTexture,osg::StateAttribute::ON); 291 243 stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF); 292 244 … … 298 250 if (!applyIntensityMapAsColours && intensityMap) 299 251 { 300 stateset->setTextureAttributeAndModes(1, new osg::Texture2D(intensityMap), osg::StateAttribute::ON); 252 osg::Texture2D* intensityMapTexture = new osg::Texture2D(intensityMap); 253 intensityMapTexture->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::NEAREST); 254 intensityMapTexture->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::NEAREST); 255 intensityMapTexture->setWrap(osg::Texture2D::WRAP_S, osg::Texture2D::CLAMP_TO_EDGE); 256 intensityMapTexture->setWrap(osg::Texture2D::WRAP_T, osg::Texture2D::CLAMP_TO_EDGE); 257 258 stateset->setTextureAttributeAndModes(1, intensityMapTexture, osg::StateAttribute::ON); 301 259 } 302 260 303 //geode->addDrawable(createParoramicSphericalDisplayDistortionMesh(osg::Vec3(0.0f,0.0f,0.0f), osg::Vec3(width,0.0f,0.0f), osg::Vec3(0.0f,height,0.0f), 1, 0.45, intensityMap, projectorMatrix));304 261 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); 305 262 geode->addDrawable(distortionMesh); … … 309 266 camera->setGraphicsContext(gc.get()); 310 267 camera->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT ); 311 camera->setClearColor( osg::Vec4(0.0, 0.0,0.0,1.0) );268 camera->setClearColor( osg::Vec4(0.0,1.0,0.0,1.0) ); 312 269 camera->setViewport(new osg::Viewport(0, 0, width, height)); 313 270 GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
Note: See TracChangeset
for help on using the changeset viewer.