Hi. 
I need some help on getting projective texturing working properly. Fixed
Functionality is no problem however in GLSL am having a number of
problems. I can get the texture onto my quad however I can't position it
correctly. The texture appears basically in the Middle of my plane  -
however I require it to be scaled and positioned anywhere  - in this
case it will be the wake of a ship.

I've included the basic setup of my code - with relevant sections.

Hopefully someone may see something I'm missing.

Kind Regards
Paul 





                        SETTING UP
///////////////////////////////////////////////////////////////////


     _group = new osg::Group;

        osg::Vec3 position(1500.0f,1500.0f,0.0f);
        osg::Vec3 direction( 0.0f,0.0f,-1.0f);
        osg::Vec3 up(0.0f,1.0f,0.0f);


        //create the _camera
        _camera = new osg::Camera;

        _camera->setClearMask(GL_DEPTH_BUFFER_BIT);
        _camera->setClearColor(osg::Vec4(1.0f,1.0f,1.0f,1.0f));

_camera->setComputeNearFarMode(osg::Camera::DO_NOT_COMPUTE_NEAR_FAR);
        
        // set viewport
        _camera->setViewport(0,0,256,256);
       
        // set the _camera to render before the main _camera.
        _camera->setRenderOrder(osg::Camera::PRE_RENDER);

        // tell the _camera to use OpenGL frame buffer object where
supported.

_camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);

        // attach the texture and use it as the color buffer.
        _camera->attach(osg::Camera::DEPTH_BUFFER, _projectionTexture);

        // add subgraph to render
        //_camera->addChild(_nodeprojectedonto.get());

        
        

     _group->addChild(_camera);

    osg::StateSet* stateset = _group->getOrCreateStateSet();

    osg::Vec4 centerColour(0.5f,0.5f,0.5f,1.0f);
    osg::Vec4 borderColour(1.0f,1.0f,1.0f,1.0f);

    // set up forest _projectionTexture
    _projectionTexture = new osg::Texture2D();
    _projectionTexture->setImage(createForestImage(centerColour, 64));
    _projectionTexture->setBorderColor(osg::Vec4(borderColour));

_projectionTexture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_BORDER);

_projectionTexture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_BORDER);

_projectionTexture->setWrap(osg::Texture::WRAP_R,osg::Texture::CLAMP_TO_BORDER);

    stateset->setTextureAttributeAndModes(textureUnit,
_projectionTexture, osg::StateAttribute::ON); //TEXUNIT2

    // set up tex gens
    stateset->setTextureMode(textureUnit, GL_TEXTURE_GEN_S,
osg::StateAttribute::ON);
    stateset->setTextureMode(textureUnit, GL_TEXTURE_GEN_T,
osg::StateAttribute::ON);
    stateset->setTextureMode(textureUnit, GL_TEXTURE_GEN_R,
osg::StateAttribute::ON);
    stateset->setTextureMode(textureUnit, GL_TEXTURE_GEN_Q,
osg::StateAttribute::ON);
        
   




    osg::TexGenNode* _texgenNode = new osg::TexGenNode;
    _texgenNode->setTextureUnit(textureUnit);   //TEXUNIT2
    osg::TexGen* texgen = _texgenNode->getTexGen();
    texgen->setMode(osg::TexGen::EYE_LINEAR );/

                                
        
    _group->addChild(_texgenNode);





    
    texGenMatUniform->setUpdateCallback(new
TexGenUpdateCallback(_viewer,projection->getTexGenNode()));             
    stateset->addUniform( texGenMatUniform);    
        
        
        
    //set a wake texture
    stateset->setTextureAttributeAndModes(TEXUNIT2,
projection->getTexture(),osg::StateAttribute::ON);
    stateset->addUniform( new osg::Uniform("PROJECTION",TEXUNIT2) );




                                CALLBACK
///////////////////////////////////////////////////////////////////


class TexGenUpdateCallback: public osg::Uniform::Callback
{
    public:
    
        
    
        TexGenUpdateCallback(osg::ref_ptr<osgViewer::Viewer>
_viewer,osg::TexGenNode* texgenNode) : viewer(_viewer),
_texgenNode(texgenNode){}

        virtual void operator() ( osg::Uniform* uniform,
osg::NodeVisitor* nv )
        {


        
            if( _enabled )
            {
                //Camera position
                //osg::Matrix  MVPT = 
(viewer->getCamera()->getProjectionMatrix() *
viewer->getCamera()->getViewMatrix()  );        
                //_texgenNode->getTexGen()->setMode(osg::TexGen::EYE_LINEAR);
                //_texgenNode->getTexGen()->setPlanesFromMatrix(MVPT);
                
                
                // compute the matrix which takes a vertex from local coords 
into
tex coords
                // will use this later to specify osg::TexGen..
                osg::Matrix MVP = viewer->getCamera()->getViewMatrix()
* 

viewer->getCamera()->getProjectionMatrix();

                osg::Matrix MVPT = MVP *
osg::Matrix::translate(1.0,1.0,1.0) *  osg::Matrix::scale(1.0,1.0,1.0);


_texgenNode->getTexGen()->setMode(osg::TexGen::EYE_LINEAR);
                _texgenNode->getTexGen()->setPlanesFromMatrix(MVPT);



                uniform->set(MVPT);
                //std::cerr<<" TexGenUpdateCallback "<<std::endl;  
            }
        }

    private:
        bool _enabled;
        float angle;
        osg::ref_ptr<osgViewer::Viewer> viewer;
        osg::TexGenNode*                 _texgenNode;
};



                        VERTEX SHADER
//////////////////////////////////////////////////////////////////////

        vec4 ecPosition = gl_Vertex * gl_ModelViewMatrix;
   
        gl_TexCoord[0].s = dot(ecPosition, gl_EyePlaneS[0])  ;
        gl_TexCoord[0].t = dot(ecPosition, gl_EyePlaneT[0]) ;
        gl_TexCoord[0].p = dot(ecPosition, gl_EyePlaneR[0]);
        gl_TexCoord[0].q = 1.0;


                        FRAGMENT SHADER
//////////////////////////////////////////////////////////////////////

 vec4 ProjMapColor = texture2DProj(PROJECTION, gl_TexCoord[0]);










IMPORTANT: This email remains the property of the Australian Defence 
Organisation and is subject to the jurisdiction of section 70 of the CRIMES ACT 
1914.  If you have received this email in error, you are requested to contact 
the sender and delete the email.


_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to