[osg-users] Post Processing Effect - Vertex Shader not working

Volckaert, Guy (CA - MTS) Guy.Volckaert at meggitt.com
Fri Sep 15 15:35:51 PDT 2017


Hi,

Sorry to bother you guys... but I was wondering if you can help identify why my pass through vertex shader isn't working. In essence, if I enable the vertex shader, then the scene disappears (I only see that blue background color). If I disable it then the scene appears correctly. No errors are generated by OSG after linking the vertex shader. I know that my fragment shader is working because if I set the gl_FragColor to red then the scene is completely red.

Here are my pass-thru shaders:

[code]
VERTEX SHADER
=============
attribute vec4 osg_Vertex;
void main( void )
{
     gl_Position = osg_Vertex;
}

FRAGMENT SHADER
===============
uniform sampler2D tRttTexture;

void main( void )
{
     vec3 vColor = texture2D( tRttTexture, gl_TexCoord[0].st ).rgb;
     // Output color.
     gl_FragColor = vec4( vColor, 1.0 );
}
[/code]


The shader is applied on a fullscreen quad using typical Ortho2D projection. Here is the code that loads the shader which is applied to the post process geode containing a single geometry quad:

[code]
void loadShaders( )
{
    osg::StateSet* pStateSet = g_pPolyGeode->getOrCreateStateSet( );

    osg::ref_ptr<osg::Program> pProgram = new osg::Program;
    pProgram->setName( "PostProcessProgram" );

    osg::ref_ptr<osg::Shader> pVertShader = osg::Shader::readShaderFile( osg::Shader::VERTEX, osgDB::findDataFile( "shaders/osgprerender.vert" ) );
    if( pVertShader )
    {
        pVertShader->setName( "osgprerender.vert" );
        pProgram->addShader( pVertShader );
        pProgram->addBindAttribLocation( "osg_Vertex", 0 );
    }

    osg::ref_ptr<osg::Shader> pFragShader = osg::Shader::readShaderFile( osg::Shader::FRAGMENT, osgDB::findDataFile( "shaders/osgprerender.frag" ) );
    if( pFragShader )
    {
        pFragShader->setName( "osgprerender.frag" );
        pProgram->addShader( pFragShader );
    }

    // RTT texture.
    pStateSet->addUniform( new osg::Uniform( "tRttTexture", 0 ) );
    pStateSet->setAttributeAndModes( pProgram, osg::StateAttribute::ON );
}
[/code]


What am I doing wrong? I tried different variation of the shader but nothing works. Here are the variations that I tried:

[code]
VARIATION #1
===========
void main( void )
{
     gl_Position = gl_Vertex;
}

VARIATION #2
===========
void main( void )
{
     gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}

VARIATION #3
===========
attribute vec4 osg_Vertex;
void main( void )
{
     gl_Position = gl_ModelViewProjectionMatrix * osg_Vertex;
}

VARIATION #4
===========
void main( void )
{
     gl_Position = ftransform();
}
[/code]

Any help would be really appreciated... The full source code is attached.

Thank you!

Cheers,
Guy

Guy Volckaert, ing.
Snr Software Engineer

Meggitt Training Systems (Quebec) Inc.
Systèmes d'entraînement Meggitt (Québec) Inc.
6140 Henri Bourassa West
Montreal, Quebec, H4R 3A6
Canada

Tel: 1 (514) 339 9938 Ext 617
Fax: 1 (514) 339 2641
Cell: 1 (514) 928-5641
email: guy.volckaert at meggitt.com<mailto:brian.bakker at meggitt.com>
url; www.meggitt.com<http://www.meggitt.com>
skype: guy.volckaert

Svp. Considérez l'environnement avant d'imprimer
Please consider the environment before printing this e-mail.


________________________________


This e-mail may contain proprietary information and/or copyright material. This e-mail is intended for the use of the addressee only. Any unauthorized use may be unlawful. If you receive this e-mail by mistake, please advise the sender immediately by using the reply facility in your e-mail software.

Information contained in and/or attached to this document may be subject to export control regulations of the European Community, USA, or other countries. Each recipient of this document is responsible to ensure that usage and/or transfer of any information contained in this document complies with all relevant export control regulations. If you are in any doubt about the export control restrictions that apply to this information, please contact the sender immediately.

Be aware that Meggitt may monitor incoming and outgoing e-mails to ensure compliance with the Meggitt IT Use policy.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20170915/28bfd552/attachment.htm>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: osgprerender2.cpp
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20170915/28bfd552/attachment.asc>


More information about the osg-users mailing list