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

2017-09-16 Thread antiro black
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.volcka...@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 pProgram = new osg::Program;
>
> pProgram->setName( "PostProcessProgram" );
>
>
>
> osg::ref_ptr 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 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.volcka...@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

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

2017-09-15 Thread Volckaert, Guy (CA - MTS)
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 pProgram = new osg::Program;
pProgram->setName( "PostProcessProgram" );

osg::ref_ptr 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 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.volcka...@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.

/* OpenSceneGraph example, osgprerender.
*
*  Permission is hereby granted, free of charge, to any person obtaining a copy
*  of this software and associated documentation files (the "Software"), to deal
*  in the Software without restriction, including without limitation the rights
*  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
*  copies of the Software, and to permit persons to whom the Software is
*  furnished to do so, subject to the following conditions:
*
*  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
*  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
*  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
*  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
*  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
*  OUT OF OR IN