Using uniforms

There are three types of inputs and outputs in a typical shader: uniforms, vertex attributes, and varyings. Uniforms and vertex attributes are read-only during the shader's execution, but can be set by host OpenGL or OSG applications. They are actually global GLSL variables used for interactions between shaders and user applications.

Varyings are used for passing data from one shader to the next one. They are invisible to external programs.

OSG uses the osg::Uniform class to define a GLSL uniform variable. Its constructor has a name and an initial value parameter, which should match the definition in the shader source code, for instance:

float length = 1.0f; osg::ref_ptr<osg::Uniform> uniform = new osg::Uniform( "length", length ); ...

Get OpenSceneGraph 3.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.