Академический Документы
Профессиональный Документы
Культура Документы
OpenSceneGraph
Mike Weiblen
July 31, 2005
Los Angeles
Rev B
1
Summary of this talk
y Overview of GLSL pipeline & syntax
y OSG support for GLSL
y Tips, Tricks, Gotchas, and Tools
y Demos
5
The OpenGL 2.0 Pipeline
Special
Variables
gl_FragColor
gl_FragDepth
gl_FragData[n]
Cg GLSL
Cg
Cg Code
Code GLSL
GLSL Code
Code
Cg
Cg Compiler
Compiler
Intermediate
Intermediate Lang
Lang Too
(e.g.
(e.g. ARB
ARB vp/fp)
vp/fp) far
apart
IL
ILTranslator
Translator
Compiler
Compiler
Driver Tightly
Driver Driver
Driver coupled
Graphics
Graphics HW
HW Graphics
Graphics HW
HW
y Note
int and bool types are semantic, not expected to
be supported natively
int at least as 16 bits plus sign bit
Copyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 17
GLSL datatype qualifiers
y uniform
Relatively constant data from app or OpenGL
Input to both vertex and fragment shaders
y attribute
Per-vertex data from app or OpenGL
Input to vertex shader only
y varying
Perspective-correct interpolated value
Output from vertex, input to fragment
y const
y in, out, inout (for function parameters)
#ifdef ARB_texture_rectangle
#extension ARB_texture_rectangle : require
#endif
30
OSG GLSL design goals
y Continue OSG’s straightforward mapping
of classes to the underlying GL concepts
y Leverage OSG’s state stack to apply GLSL
state with proper scoping
App specifies where/what GLSL will do.
OSG determines when/how to apply, restoring to
previous state afterwards.
y Let OSG deal with the tedious GL stuff
Management of contexts, constructors, indices,
compile/link, etc.
osg::StateSet* ss = getOrCreateStateSet();
ss->setAttributeAndModes( pgm, osg::StateAttribute::ON );
ss->addUniform( new osg::Uniform( "color", osg::Vec3(1.0f, 0.0f, 0.0f) ));
ss->addUniform( new osg::Uniform( "val1", 0.0f ));
45
Tips for Shader Debugging
y Name your osg::Shaders/osg::Programs
y Review the infologs displayed at notify
osg::INFO level.
y Assign internal vecs to color
y Use discard like assert
y Verify your code for conformance
y Try glsl_dataflag.osg to see values inside
your scene
y New in CVS: glValidateProgram() support
55
osgshaders example
y The original OSG/GLSL example in C++
y Demonstrates multiple osg::Programs,
time-varying uniforms, multi-texture
y http://openscenegraph.org/
y http://developer.3Dlabs.com/
y http://mew.cx/osg/
y http://sourceforge.net/projects/osgtoy/