[osg-users] Multipass shading/rendering

hellhound at binary-revolution.org hellhound at binary-revolution.org
Wed Sep 12 06:07:18 PDT 2007


Hi,

I need to implement some post processing shader effect, based on multipass 
shading/rendering processes. In thiss multipass process each shader could have one or more RTT targets as input and output of the pass.

To realize this i've implemented a render to texture class based on the 
osgprerender and osgtexturerectangle examples. This class creates for each
instance a texture rectangle and a FBO POST-Process camera by this way:
 
void createCamera(osg::ref_ptr<osg::Node> subGraph, unsigned int passPos)
{ 
    m_camera = new osg::Camera;
    m_camera->setName("rttCamera");
    m_camera->setClearColor(m_clearColor);
    
    m_camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
    m_camera->setViewMatrix(osg::Matrix::identity());
    m_camera->setViewport(0,0,windowWidth,windowHeight);
    
    // define orthogonal projection
     m_camera->setProjectionMatrix(osg::Matrix::ortho2D(0,windowWidth,0,windowHeight));
    
    // bind camera as POST-Process Camera with the position value of the pass
    m_camera->setRenderOrder(osg::Camera::POST_RENDER, passPos);
    
    // add subcene to camera to render
    m_camera->addChild(subGraph.get());
} 

The initialized camera is a member of type osg::ref_ptr<osg::Camera> and the
passPos Parameter defines the pass of the shader. 

Each pass is handled as single osg::ref_ptr<osg::StateSet> in a specialised 
pass class. For each pass i define the referenced shader and textures which 
depends on. So that i have the following object tree structure:

osg::Geometry
      osg::Texture2D  "Decal"    
      osg::Texture2D  "Normal"

      RTT next (my RTTclass)
          RectangleTexture 
          Camera (PRE)

      RTT prev(my RTTclass)
          RectangleTexture 
          osg::CameraNode (PRE) 

      Pass1 "Dot3" (Main)
          StateSet
             Program
             ShaderV
                 Attributes
                 Uniform
                 Uniform
             ShaderF
                 Uniform
                 Uniform
             <-- Decal   (in)
             <-- Normal  (in)
             --> Next    (out)    

      Pass2 
          StateSet
             Program
             ShaderV
                 Attributes
                 Uniform
                 Uniform
             ShaderF
                 Uniform
                 Uniform
             <-- Next     (in)
             --> Prev     (out to screen (texturized quad))

This works fine, if i use only a single pass shader. In this case the RTT 
Texture is rendered to a texturized quad in front of the view. If i use this
RTT as input for the second path, and try to render the output of the second
rtt on the textured quad nothing is shown where the textured quad should be...

I have no idea what could be wrong or what i've overseen... Perhaps i made 
somthing conceptionally wrong. Has anyone implemented a multipass shadering
with osg and could me push to the correct sollution?

If you required more code, i will append if i am back from work...

Thanks in advance,
best regards
Chris







More information about the osg-users mailing list