[osg-users] [forum] passing material properties to shader uniforms

Gedalia Pasternak gpasternak at mak.com
Sat Jun 3 18:32:30 PDT 2017


For OpenGL 3.2, I've taken the approach of using an uniform block to
replace the materials, (if you think about this materials are currently
treated as something that is shared between all shaders, which is how they
are implemented in the fixed function pipeline) each material has a buffer
on the GPU, and I just switch the uniform block pointer as part of the
material apply. I found using callbacks really slowed down the scene graph
update as the scene got larger. And there were also a number of bugs I hit
by using material uniforms where scene graph optimizations seemed to lose
them.

-Gedalia

On Thu, Jun 1, 2017 at 10:12 AM, Robert Osfield <robert.osfield at gmail.com>
wrote:

> Hi Goran,
>
> In standard OSG (3.2.x, 3.4.0 or the 3.5.x dev series) there isn't any
> way to automatically remap osg::Material to uniforms so you'll have to
> run a traverser through the scene graph and replace the osg::Material
> to osg::Uniform's.
>
> If you are willing to experiment with bleeding edge experimental code
> then have a look at the shader_pipeline branch of the OSG, in this
> branch I'm working on a new scheme for automatically mapping old fixed
> function state like osg::Material to uniforms and #define settings
> that can then be used by #pragma(tic) shader composition to provide a
> fully integrated shader+fixed function state solution.
>
> Robert.
>
> On 15 May 2017 at 14:18, Goran Pantar <gpantar at logicbricks.com> wrote:
> > Hi,
> >
> > I'm using OpenGL ES 2.0 and having dificulties to pass the old style
> material properties (ambient, difusse, specular, shininess) to the uniforms
> used in my fragment shader.
> >
> > For the 3d model I use models in 3ds format with multiple materials and
> multiple drawables.
> >
> >
> > As a dirty hack I changed the Material.cpp Material::apply(State&)
> function. This worked properly and I was able to modify this several global
> uniforms used by my shader.
> >
> > Now I'm trying to do this the OSG way using updateCallbacks and visitors
> but the uniform are not updated during the rendering. Probably only the
> last drawable material properties are set to the uniform and than this is
> used when rendering.
> >
> >
> > I expect that there is some perfectly elegant way to do this, so please
> point me in the right direction.
> >
> > Thank you!
> >
> > Cheers,
> > Goran
> >
> > ------------------
> > Read this topic online here:
> > http://forum.openscenegraph.org/viewtopic.php?p=70931#70931
> >
> >
> >
> >
> >
> > _______________________________________________
> > osg-users mailing list
> > osg-users at lists.openscenegraph.org
> > http://lists.openscenegraph.org/listinfo.cgi/osg-users-
> openscenegraph.org
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>



-- 
DI-Guy Engineering Lead, VT MÄK
150 Cambridge Park Drive, 3rd Floor, Cambridge, MA 02140
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20170603/b4a7e213/attachment-0002.htm>


More information about the osg-users mailing list