[osg-users] how to set the model view projection matrix for my own vertex shader

432 views
Skip to first unread message

Gianluca Natale

unread,
Sep 2, 2014, 5:59:54 AM9/2/14
to OpenSceneGraph Users

Hi all.

First of all, sorry if mine is a silly question, I’m quite new to using shaders in OSG.

 

My scenario is this:

I have a vertex shader that gets as uniform in-variable the model view projection matrix, “MVP_matrix” is the name of that variable in my shader.

The shader is written in GL4.3, so I cannot rely upon the deprecated built-in variable gl_ModelViewProjection matrix.

Now, I have to attach such shader in a program that is set in a state set used to render my geometry (that state set is attached to the geode that contains my drawable, where the geometry is defined).

So, I would like that OSG automatically passes the model view projection matrix to my shader during rendering traversal.

I’ve seen in some OSG code that there is a predefined in-variable called “osg_ModelViewProjectionMatrix” that I think is filled by OSG during rendering traversal with the current model view projection matrix. Is that correct?

So, should I rely upon it in my shader, basically replacing my “MVP_matrix” with “osg_ModelViewProjectionMatrix”?

 

Further question: unfortunately the shader I have to use is shared among other applications in my company, and not all of them use OSG for rendering (some use pure OpenGL) L

So it’s likely that I cannot modify it (otherwise I should ask all developers to change the name of the in-variable they pass directly to the shader to “osg_ModelViewProjectionMatrix”).

Hence the question: if I’m forced to use “MVP_matrix”, is there a way I can tell OSG to set automatically the value of “osg_ModelViewProjectionMatrix” to “MVP_matrix” at run-time, i.e. during rendering traversal?

 

Thanks,

Gianluca

 

Robert Osfield

unread,
Sep 2, 2014, 7:56:19 AM9/2/14
to OpenSceneGraph Users
Hi Gianluca,

osg_ModelViewProjectionMatrix is the OSG's equivilant to gl_ModelViewProjectMatrix, and there is a mechanism in osg::State that can replace gl_ModelViewMatrixProjectMatrix usage in shaders with the osg_ equivalent at runtime.  There isn't however a general customizable support for setting and substituting your own uniforms in this role.

In your own application I'd suggest when you set up your osg::Shader with the shader source you replace the MVP_matrix usage with gl_ or osg_ equivalent.

Robert.


_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Gianluca Natale

unread,
Sep 2, 2014, 9:31:35 AM9/2/14
to OpenSceneGraph Users

Oh yes, Robert,

that’s the most obvious and quickest solution, sorry for the silly question!

Once loaded my shader source code from the file, I’ll replace all the occurrences of “MVP_matrix” with “osg_ModelViewProjectionMatrix”, and OSG will update it for me during rendering traversal.

 

Thanks a lot! J

Gianluca

 

Da: osg-users [mailto:osg-user...@lists.openscenegraph.org] Per conto di Robert Osfield
Inviato: martedì 2 settembre 2014 13:56
A: OpenSceneGraph Users
Oggetto: Re: [osg-users] how to set the model view projection matrix for my own vertex shader

Reply all
Reply to author
Forward
0 new messages