[osg-users] using modern shaders with osg - setting vertex attribute layout
Sebastian Messerschmidt
sebastian.messerschmidt at gmx.de
Sat Sep 2 11:11:25 PDT 2017
Hi Chris,
> I'm also transitioning a legacy GL OSG project with a mix of custom shaders to modern GL bit by bit. And I've also had lots of trouble and headache with the built-in modern GL vertex attrib aliasing setting.
>
> It seems crazy that the official advice is to write shaders and use OSG just like legacy GL, and OSG will then change your shader code and reinterpret deprecated calls to make it work via "modern" GL: Obviously in years to come when GL newcomers want to use OSG the official line can't be "learn how GL was 20 years ago, write your OSG code like that, and the system will make it work".
>
> So I'm afraid this isn't as simple as it could be, but of course it's still easier than converting raw GL calls..
Who told you something like this? OSG is totally capable of using modern
GLSL. For some legacy support you might need to write appropriate
visitors, but there is nothing stopping you using modern approaches.
>
>
> Here is my only advice since I'm not yet finished myself:
> My recommendation is just leave that attrib aliasing setting alone; you can use modern GL anyway. Just make sure that you use the setVertexAttribute() calls instead of setTextureCoords() / setNormals() / etc, and use the same attrib location numbering convention as OSG (I believe NVidia's drivers enforce those conventions, so you can get the vertex positions at loc=0).
Basically you're duplicating the vertexAttributeAliasing mechanism.
There might be problems with non-conforming drivers, but in general the
mapping is fixed on all conforming OpenGL drivers I've used (And the
mechanism works on a lot of heterogeneous machines)
>
> Then you'll want to get a copy of the ShaderGen class so you can customize because you'll likely want to modify it yourself. You can use this code to hook into osgDB::readNode()'s behavior to setup your shaders/attribs/etc the way you want.
I don't see how this is related to ShaderGen (I suppose you're talking
about the old class). I strongly suggest to write your own shaders and
use the setDefine (#pragmatic shader composition) mechanism to create
shader variations.
Cheers
Sebastian
> You then need to set useModelViewUniforms, which seems to be less harmful than useVertexAttribAliasing and will make sure osg_ModelViewMatrix is set.
>
>
> Interested to compare notes on how you go anyway
>
> ------------------------
> http://www.hrwallingford.com/facilities/ship-simulation-centre (http://www.hrwallingford.com/facilities/ship-simulation-centre)
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=71598#71598
>
>
>
>
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
More information about the osg-users
mailing list