[osg-users] Post Processing Effect - Vertex Shader not working
antiro black
antiro42 at gmail.com
Sat Sep 16 04:23:45 PDT 2017
Hi Guy,
Have you enabled the tracking of model,view and projection matrices as well
as the vertex attribute aliasing?
I use this in my own code:
// switch on the uniforms that track the modelview and projection matrices
mViewer->getCamera()->getGraphicsContext()->getState()->setUseModelViewAndProjectionUniforms(true);
//proper initialization of vertex attribute
mViewer->getCamera()->getGraphicsContext()->getState()->setUseVertexAttributeAliasing(true);
As vertex shader I use (untested after removing irrelevant parts, but
should work):
#version 330 core
layout(location = 0) in vec4 position;
layout(location = 1) in vec3 normal;
layout(location = 2) in vec4 color;
layout(location = 3) in vec4 texCoords;
out vec2 TexCoords;
uniform mat4 osg_ModelViewProjectionMatrix;
void main()
{
gl_Position = osg_ModelViewProjectionMatrix * position;
TexCoords = texCoords.st;
}
you can then pick up the texture coordinates again in the fragment shader
using:
in vec2 TexCoords;
Goodluck!
Antiro
On Sat, Sep 16, 2017 at 12:35 AM, Volckaert, Guy (CA - MTS) <
Guy.Volckaert at meggitt.com> wrote:
> 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 <(514)%20339-9938>
> Fax: 1 (514) 339 2641 <(514)%20339-2641>
> Cell: 1 (514) 928-5641 <(514)%20928-5641>
> email: guy.volckaert at meggitt.com <brian.bakker at meggitt.com>
> url; 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.
>
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20170916/45f8ebfe/attachment.htm>
More information about the osg-users
mailing list