Re: [osg-users] GLSL shaders and projective texturing
I also struggled with this issue once and I believe osgspotlight suffers from exactly the same quadrant defect if you look closely. Would be really nice if somebody submitted a fix. /Per On 29 September 2011 01:59, Brad Colbert bcolb...@rscusa.com wrote: Glenn, ** ** Bingo! That was it. I wasn’t quite sure that would work with TexGen but there you go! ** ** Thanks! ** ** ** ** -B ** ** *From:* osg-users-boun...@lists.openscenegraph.org [mailto: osg-users-boun...@lists.openscenegraph.org] *On Behalf Of *Glenn Waldron *Sent:* Wednesday, September 28, 2011 4:40 PM *To:* OpenSceneGraph Users *Subject:* Re: [osg-users] GLSL shaders and projective texturing ** ** Brad, I once had the same issue; calcuating my texgen matrix like this worked:** ** ** ** texGenMat = modelViewMat * projectionMat * osg::Matrix::translate(1, 1, 1) * osg::Matrix::scale(0.5, 0.5, 0.5); ** ** Glenn Waldron / Pelican Mapping / @glennwaldron On Wed, Sep 28, 2011 at 7:34 PM, Brad Colbert bcolb...@rscusa.com wrote: Hi Chris, Thanks! I found that one too but it still doesn't help me figure out how to fix the coordinates so that my projected texture renders in the center of the projection frustum instead of the upper right quadrant. It's strange and I can't figure it out. -B -Original Message- From: osg-users-boun...@lists.openscenegraph.org [mailto: osg-users-boun...@lists.openscenegraph.org] On Behalf Of Chris 'Xenon' Hanson Sent: Wednesday, September 28, 2011 3:31 PM To: OpenSceneGraph Users Subject: Re: [osg-users] GLSL shaders and projective texturing On 9/27/2011 7:21 PM, Brad Colbert wrote: I am closer! Looks like the other example I have is FFP not GLSL. Here's a working GLSL implementation (not OSG) that should be relatively easy to feed with OSG uniforms and such: http://www.ozone3d.net/tutorials/glsl_texturing_p08.php#part_8 -- Chris 'Xenon' Hanson, omo sanza lettere. xe...@alphapixel.com http://www.alphapixel.com/ Digital Imaging. OpenGL. Scene Graphs. GIS. GPS. Training. Consulting. Contracting. There is no Truth. There is only Perception. To Perceive is to Exist. - Xen ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org* *** ** ** ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] GLSL shaders and projective texturing
I think Paul Martz did already. http://thread.gmane.org/gmane.comp.graphics.openscenegraph.cvs/9237/focus=9304 jp On 29/09/2011 13:46, Per Nordqvist wrote: I also struggled with this issue once and I believe osgspotlight suffers from exactly the same quadrant defect if you look closely. Would be really nice if somebody submitted a fix. /Per On 29 September 2011 01:59, Brad Colbert bcolb...@rscusa.com mailto:bcolb...@rscusa.com wrote: Glenn, __ __ Bingo! That was it. I wasn’t quite sure that would work with TexGen but there you go! __ __ Thanks! __ __ __ __ -B __ __ *From:*osg-users-boun...@lists.openscenegraph.org mailto:osg-users-boun...@lists.openscenegraph.org [mailto:osg-users-boun...@lists.openscenegraph.org mailto:osg-users-boun...@lists.openscenegraph.org] *On Behalf Of *Glenn Waldron *Sent:* Wednesday, September 28, 2011 4:40 PM *To:* OpenSceneGraph Users *Subject:* Re: [osg-users] GLSL shaders and projective texturing __ __ Brad, I once had the same issue; calcuating my texgen matrix like this worked: __ __ texGenMat = modelViewMat * projectionMat * osg::Matrix::translate(1, 1, 1) * osg::Matrix::scale(0.5, 0.5, 0.5); __ __ Glenn Waldron / Pelican Mapping / @glennwaldron On Wed, Sep 28, 2011 at 7:34 PM, Brad Colbert bcolb...@rscusa.com mailto:bcolb...@rscusa.com wrote: Hi Chris, Thanks! I found that one too but it still doesn't help me figure out how to fix the coordinates so that my projected texture renders in the center of the projection frustum instead of the upper right quadrant. It's strange and I can't figure it out. -B -Original Message- From: osg-users-boun...@lists.openscenegraph.org mailto:osg-users-boun...@lists.openscenegraph.org [mailto:osg-users-boun...@lists.openscenegraph.org mailto:osg-users-boun...@lists.openscenegraph.org] On Behalf Of Chris 'Xenon' Hanson Sent: Wednesday, September 28, 2011 3:31 PM To: OpenSceneGraph Users Subject: Re: [osg-users] GLSL shaders and projective texturing On 9/27/2011 7:21 PM, Brad Colbert wrote: I am closer! Looks like the other example I have is FFP not GLSL. Here's a working GLSL implementation (not OSG) that should be relatively easy to feed with OSG uniforms and such: http://www.ozone3d.net/tutorials/glsl_texturing_p08.php#part_8 -- Chris 'Xenon' Hanson, omo sanza lettere. xe...@alphapixel.com http://www.alphapixel.com/ Digital Imaging. OpenGL. Scene Graphs. GIS. GPS. Training. Consulting. Contracting. There is no Truth. There is only Perception. To Perceive is to Exist. - Xen ___ osg-users mailing list osg-users@lists.openscenegraph.org mailto:osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org mailto:osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org __ __ ___ osg-users mailing list osg-users@lists.openscenegraph.org mailto:osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org -- This message is subject to the CSIR's copyright terms and conditions, e-mail legal notice, and implemented Open Document Format (ODF) standard. The full disclaimer details can be found at http://www.csir.co.za/disclaimer.html. This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] GLSL shaders and projective texturing
Funny, I should have changed my search to just projective texture and I think this would have popped up. -B -Original Message- From: osg-users-boun...@lists.openscenegraph.org [mailto:osg-users-boun...@lists.openscenegraph.org] On Behalf Of J.P. Delport Sent: Thursday, September 29, 2011 5:19 AM To: OpenSceneGraph Users Subject: Re: [osg-users] GLSL shaders and projective texturing I think Paul Martz did already. http://thread.gmane.org/gmane.comp.graphics.openscenegraph.cvs/9237/focus=9304 jp On 29/09/2011 13:46, Per Nordqvist wrote: I also struggled with this issue once and I believe osgspotlight suffers from exactly the same quadrant defect if you look closely. Would be really nice if somebody submitted a fix. /Per On 29 September 2011 01:59, Brad Colbert bcolb...@rscusa.com mailto:bcolb...@rscusa.com wrote: Glenn, __ __ Bingo! That was it. I wasn't quite sure that would work with TexGen but there you go! __ __ Thanks! __ __ __ __ -B __ __ *From:*osg-users-boun...@lists.openscenegraph.org mailto:osg-users-boun...@lists.openscenegraph.org [mailto:osg-users-boun...@lists.openscenegraph.org mailto:osg-users-boun...@lists.openscenegraph.org] *On Behalf Of *Glenn Waldron *Sent:* Wednesday, September 28, 2011 4:40 PM *To:* OpenSceneGraph Users *Subject:* Re: [osg-users] GLSL shaders and projective texturing __ __ Brad, I once had the same issue; calcuating my texgen matrix like this worked: __ __ texGenMat = modelViewMat * projectionMat * osg::Matrix::translate(1, 1, 1) * osg::Matrix::scale(0.5, 0.5, 0.5); __ __ Glenn Waldron / Pelican Mapping / @glennwaldron On Wed, Sep 28, 2011 at 7:34 PM, Brad Colbert bcolb...@rscusa.com mailto:bcolb...@rscusa.com wrote: Hi Chris, Thanks! I found that one too but it still doesn't help me figure out how to fix the coordinates so that my projected texture renders in the center of the projection frustum instead of the upper right quadrant. It's strange and I can't figure it out. -B -Original Message- From: osg-users-boun...@lists.openscenegraph.org mailto:osg-users-boun...@lists.openscenegraph.org [mailto:osg-users-boun...@lists.openscenegraph.org mailto:osg-users-boun...@lists.openscenegraph.org] On Behalf Of Chris 'Xenon' Hanson Sent: Wednesday, September 28, 2011 3:31 PM To: OpenSceneGraph Users Subject: Re: [osg-users] GLSL shaders and projective texturing On 9/27/2011 7:21 PM, Brad Colbert wrote: I am closer! Looks like the other example I have is FFP not GLSL. Here's a working GLSL implementation (not OSG) that should be relatively easy to feed with OSG uniforms and such: http://www.ozone3d.net/tutorials/glsl_texturing_p08.php#part_8 -- Chris 'Xenon' Hanson, omo sanza lettere. xe...@alphapixel.com http://www.alphapixel.com/ Digital Imaging. OpenGL. Scene Graphs. GIS. GPS. Training. Consulting. Contracting. There is no Truth. There is only Perception. To Perceive is to Exist. - Xen ___ osg-users mailing list osg-users@lists.openscenegraph.org mailto:osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org mailto:osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org __ __ ___ osg-users mailing list osg-users@lists.openscenegraph.org mailto:osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org -- This message is subject to the CSIR's copyright terms and conditions, e-mail legal notice, and implemented Open Document Format (ODF) standard. The full disclaimer details can be found at http://www.csir.co.za/disclaimer.html. This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users
Re: [osg-users] GLSL shaders and projective texturing
On 9/27/2011 7:21 PM, Brad Colbert wrote: I am closer! Looks like the other example I have is FFP not GLSL. Here's a working GLSL implementation (not OSG) that should be relatively easy to feed with OSG uniforms and such: http://www.ozone3d.net/tutorials/glsl_texturing_p08.php#part_8 -- Chris 'Xenon' Hanson, omo sanza lettere. xe...@alphapixel.com http://www.alphapixel.com/ Digital Imaging. OpenGL. Scene Graphs. GIS. GPS. Training. Consulting. Contracting. There is no Truth. There is only Perception. To Perceive is to Exist. - Xen ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] GLSL shaders and projective texturing
Hi Chris, Thanks! I found that one too but it still doesn't help me figure out how to fix the coordinates so that my projected texture renders in the center of the projection frustum instead of the upper right quadrant. It's strange and I can't figure it out. -B -Original Message- From: osg-users-boun...@lists.openscenegraph.org [mailto:osg-users-boun...@lists.openscenegraph.org] On Behalf Of Chris 'Xenon' Hanson Sent: Wednesday, September 28, 2011 3:31 PM To: OpenSceneGraph Users Subject: Re: [osg-users] GLSL shaders and projective texturing On 9/27/2011 7:21 PM, Brad Colbert wrote: I am closer! Looks like the other example I have is FFP not GLSL. Here's a working GLSL implementation (not OSG) that should be relatively easy to feed with OSG uniforms and such: http://www.ozone3d.net/tutorials/glsl_texturing_p08.php#part_8 -- Chris 'Xenon' Hanson, omo sanza lettere. xe...@alphapixel.com http://www.alphapixel.com/ Digital Imaging. OpenGL. Scene Graphs. GIS. GPS. Training. Consulting. Contracting. There is no Truth. There is only Perception. To Perceive is to Exist. - Xen ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] GLSL shaders and projective texturing
Brad, I once had the same issue; calcuating my texgen matrix like this worked: texGenMat = modelViewMat * projectionMat * osg::Matrix::translate(1, 1, 1) * osg::Matrix::scale(0.5, 0.5, 0.5); Glenn Waldron / Pelican Mapping / @glennwaldron On Wed, Sep 28, 2011 at 7:34 PM, Brad Colbert bcolb...@rscusa.com wrote: Hi Chris, Thanks! I found that one too but it still doesn't help me figure out how to fix the coordinates so that my projected texture renders in the center of the projection frustum instead of the upper right quadrant. It's strange and I can't figure it out. -B -Original Message- From: osg-users-boun...@lists.openscenegraph.org [mailto: osg-users-boun...@lists.openscenegraph.org] On Behalf Of Chris 'Xenon' Hanson Sent: Wednesday, September 28, 2011 3:31 PM To: OpenSceneGraph Users Subject: Re: [osg-users] GLSL shaders and projective texturing On 9/27/2011 7:21 PM, Brad Colbert wrote: I am closer! Looks like the other example I have is FFP not GLSL. Here's a working GLSL implementation (not OSG) that should be relatively easy to feed with OSG uniforms and such: http://www.ozone3d.net/tutorials/glsl_texturing_p08.php#part_8 -- Chris 'Xenon' Hanson, omo sanza lettere. xe...@alphapixel.com http://www.alphapixel.com/ Digital Imaging. OpenGL. Scene Graphs. GIS. GPS. Training. Consulting. Contracting. There is no Truth. There is only Perception. To Perceive is to Exist. - Xen ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] GLSL shaders and projective texturing
On 9/27/2011 2:16 PM, Brad Colbert wrote: Hi folks, I'm looking for a complete example showing projective texturing with GLSL shaders in OSG. I'm simply trying to implement a spotlight just like the osgspotlight example. What I've found doesn't quite paint the whole picture for me. Anything would be helpful. This one seemed fairly complete. http://www.jotschi.de/?p=378 Ping me if you need help on the project. -- Chris 'Xenon' Hanson, omo sanza lettere. xe...@alphapixel.com http://www.alphapixel.com/ Digital Imaging. OpenGL. Scene Graphs. GIS. GPS. Training. Consulting. Contracting. There is no Truth. There is only Perception. To Perceive is to Exist. - Xen ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] GLSL shaders and projective texturing
Hi Chris, Thanks for the quick reply and the lead. I'm still fumbling around with that example and I think I've found an issue with it. It appears to be sensitive to the camera position (ie not the correct projection solution). This little bit in the shader makes me feel that it's suspect (+vec2(0.5,0.5)): vec4 color = texture2D(projectionMap,dividedCoord.st+vec2(0.5,0.5) ); Do embedded images come across in these emails: Startup: [cid:image001.png@01CC7D27.0D484B60] Moving in slide to the right (projection moves to the far right): [cid:image002.png@01CC7D27.5588D890] -B -Original Message- From: osg-users-boun...@lists.openscenegraph.org [mailto:osg-users-boun...@lists.openscenegraph.org] On Behalf Of Chris 'Xenon' Hanson Sent: Tuesday, September 27, 2011 1:44 PM To: OpenSceneGraph Users Subject: Re: [osg-users] GLSL shaders and projective texturing On 9/27/2011 2:16 PM, Brad Colbert wrote: Hi folks, I'm looking for a complete example showing projective texturing with GLSL shaders in OSG. I'm simply trying to implement a spotlight just like the osgspotlight example. What I've found doesn't quite paint the whole picture for me. Anything would be helpful. This one seemed fairly complete. http://www.jotschi.de/?p=378 Ping me if you need help on the project. -- Chris 'Xenon' Hanson, omo sanza lettere. xe...@alphapixel.com http://www.alphapixel.com/ Digital Imaging. OpenGL. Scene Graphs. GIS. GPS. Training. Consulting. Contracting. There is no Truth. There is only Perception. To Perceive is to Exist. - Xen ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org inline: image001.pnginline: image002.png___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] GLSL shaders and projective texturing
To add more to this: I've adapted this to where the camera is the projector (ie the image is projected from the viewpoint, well, at least that is the idea): http://www.jotschi.de/?p=378 and I would like to say I'm close, but I'm still a ways away from a solution. I do see the clock projected onto my model, but the movement is not properly coordinated with my camera, and I'm quite sure I see the reverse projection at times. I'm including my source below hoping someone can find what I've done wrong. // #include osg/Version #include osg/Camera #include osg/NodeVisitor #include osg/TexGenNode #include osg/TexMat #include osgSim/MultiSwitch #include osgDB/ReadFile #include osgDB/FileUtils #include osgDB/FileNameUtils #include osgDB/DatabasePager #include osgViewer/ViewerEventHandlers #include osgGA/TrackballManipulator #include osgGA/FlightManipulator #include osgGA/DriveManipulator #include osgGA/KeySwitchMatrixManipulator #include osgGA/StateSetManipulator #include osgGA/AnimationPathManipulator #include osgGA/TerrainManipulator #include osgGA/CameraManipulator #include iostream #include osg/Notify #include osg/MatrixTransform #include osg/ShapeDrawable #include osg/PositionAttitudeTransform #include osg/Geometry #include osgGA/TrackballManipulator #include osg/Texture2D #include osg/Geode #include osg/LightSource #include osg/TexGenNode #include osg/TexMat #include osgDB/WriteFile #include osgUtil/Optimizer #include osgDB/Registry #include osgDB/ReadFile #include osgViewer/Viewer #include osgViewer/CompositeViewer using namespace std; osgViewer::View* viewA = new osgViewer::View; osg::TexMat* texMat = new osg::TexMat; osg::Uniform* ViewMatInv = new osg::Uniform( osg::Uniform::FLOAT_MAT4, ViewMatInv ); osg::ref_ptrosg::Program addShader() { osg::ref_ptrosg::Program projProg(new osg::Program); osg::ref_ptrosg::Shader projvertexShader(osg::Shader::readShaderFile( osg::Shader::VERTEX, surface.main.vert.glsl)); osg::ref_ptrosg::Shader projfragShader(osg::Shader::readShaderFile( osg::Shader::FRAGMENT, surface.main.frag.glsl)); projProg-addShader(projvertexShader.get()); projProg-addShader(projfragShader.get()); return projProg; } void addProjectionInfoToState(osg::StateSet* stateset, string fn) { osg::Vec4 centerColour(1.0f,1.0f,1.0f,1.0f); osg::Vec4 ambientColour(0.05f,0.05f,0.05f,1.0f); /* 1. Load the texture that will be projected */ osg::Texture2D* texture = new osg::Texture2D(); texture-setImage( osgDB::readImageFile(fn) );//VTB::createSpotLightImage(centerColour, ambientColour, 64, 1.0)); texture-setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_BORDER); texture-setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_BORDER); texture-setWrap(osg::Texture::WRAP_R, osg::Texture::CLAMP_TO_BORDER); stateset-setTextureAttributeAndModes( (int)spotTUnit, texture, osg::StateAttribute::ON); // set up tex gens stateset-setTextureMode((int)spotTUnit, GL_TEXTURE_GEN_S, osg::StateAttribute::ON); stateset-setTextureMode((int)spotTUnit, GL_TEXTURE_GEN_T, osg::StateAttribute::ON); stateset-setTextureMode((int)spotTUnit, GL_TEXTURE_GEN_R, osg::StateAttribute::ON); stateset-setTextureMode((int)spotTUnit, GL_TEXTURE_GEN_Q, osg::StateAttribute::ON); /* 3. Handover the texture to the fragment shader via uniform */ osg::Uniform* texUniform = new osg::Uniform(osg::Uniform::SAMPLER_2D, projectionMap); texUniform-set( (int)spotTUnit ); stateset-addUniform(texUniform); /* 4. set Texture matrix*/ //If you want to create the texture matrix by yourself you can do this like this way: //osg::Vec3 projectorPos = osg::Vec3(0.0f, 0.0f, 324.0f); //osg::Vec3 projectorDirection = osg::Vec3(osg::inDegrees(dirX),osg::inDegrees(dirY), osg::inDegrees(dirZ)); //osg::Vec3 up(0.0f, 1.0f, 0.0f); //osg::Vec3 target = osg::Vec3(0.0f, 0.0f,0.0f); //float projectorAngle = 80.f; //FOV //mat = osg::Matrixd::lookAt(projectorPos, projectorPos*target ,up) * osg::Matrixd::perspective(projectorAngle, 1.0, 1.0, 10); osg::Matrix mat = viewA-getCamera()-getViewMatrix() * viewA-getCamera()-getProjectionMatrix(); texMat-setMatrix(mat); stateset-setTextureAttributeAndModes((int)spotTUnit, texMat, osg::StateAttribute::ON); stateset-addUniform( ViewMatInv ); } osg::StateSet* createProjectorState() { osg::StateSet* stateset = new osg::StateSet; osg::ref_ptrosg::Program prog = addShader(); addProjectionInfoToState(stateset, C:\\Users\\bcolbert\\Desktop\\Work\\OpenSceneGraph-Data-3.0.0\\Images\\clockface.JPG); stateset-setAttribute(prog.get());