How does OSG pass in the correct incoming ModelViewProjectionMatrix using SHAder version 330?

29 views
Skip to first unread message

Mirro Xu

unread,
Jun 21, 2020, 10:42:27 PM6/21/20
to osg-...@googlegroups.com
The following code is invalid

osg::Uniform* modelViewProjectionMatrix = new osg::Uniform(osg::Uniform::FLOAT_MAT4, "MVP");
osg
::Matrixd  model = osg::Matrixd::identity();
osg::Matrix mat = model  * viewCamera->getViewMatrix() * viewCamera->getProjectionMatrix() ;
modelViewProjectionMatrix->set(mat);


OpenSceneGraph Users

unread,
Jun 22, 2020, 8:32:09 AM6/22/20
to OpenSceneGraph Users
There is no need to provide the modelview and projection matrices yourself, and I'd recommend against doing so as you'd loose much of the OSG functionality relating to Camera's and accumulating modelview and projection matrices/

When using shaders the OSG can provide the projection and modelview matrices via osg_* built in uniforms that stand in place of the older OpenGL gl_* matrices (these are deprecated in OpenGL and don't exist for GLES2 and GL3 core profile).  You need to enable this mapping. by setting the osg::State's    UseModelViewAndProjectionUniforms to true. The osgsimplegl3 example illustrates how this is done.
Reply all
Reply to author
Forward
0 new messages