Movatterモバイル変換


[0]ホーム

URL:


Mike Weiblen, profile picture
Uploaded byMike Weiblen
PDF, PPTX3,144 views

GLSL Shading with OpenSceneGraph

The document outlines the GLSL (OpenGL Shading Language) pipeline, its architecture, and its integration with OpenSceneGraph (OSG), focusing on the usage and syntax of GLSL as well as its support in OSG for creating shaders. It covers the compilation model, data types, uniforms, attributes, and best practices for using GLSL with OpenSceneGraph, including tips for debugging and performance optimization. Key aspects include a historical timeline of GLSL development, the mapping of GL API to OSG API, and a simple source code example demonstrating shader setup.

Embed presentation

Download as PDF, PPTX
GLSL Shading withOpenSceneGraph               Mike Weiblen               July 31, 2005               Los Angeles                       Rev B                               1
Summary of this talk   Overview of GLSL pipeline & syntax   OSG support for GLSL   Tips, Tricks, Gotchas, and Tools   Demos   What we’re not covering          Our focus will be the OSG API, not OpenGL API          Not lots of detail on the GLSL language itselfCopyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005         2
Our dependencies   OpenGL 2.0   OpenGL Shading Language 1.10 rev 59          Specs on opengl.org and CDROM   OpenSceneGraph 0.9.9          Note: GLSL support continues to evolve in CVSCopyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005        3
GLSL / OSG timeline   Fall 2001: 3Dlabs “GL2.0” whitepapers,   shading language is the centerpiece   July 2003: ARB approves GL1.5, GLSL as   ARB extension   Fall 2003: osgGL2 Nodekit   Sep 2004: ARB approves GL2.0, GLSL in   the core.   Spring 2005: 2nd generation GLSL support   integrated into OSG core          Supports both OpenGL 2.0 and 1.5 extensionsCopyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005      4
Overview of GLSL                   5
The OpenGL 2.0 PipelineCopyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005   6
GLSL pipeline architecture   GLSL exposes programmability at two   points in the OpenGL 2.0 pipeline          Vertex processor          Fragment processor   Compiled code to run on a particular   processor is a glShader   A linked executable unit to be activated on   the pipeline is a glProgramCopyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005   7
GLSL compilation model   Similar to familiar C build model   glShader = “object file”          Contains shader source code          Compiled to become an “.obj file”          Must be recompiled when source changes   glProgram = “executable file”          Contains a list of shaders          Linked to become an “.exe file”          Must be relinked when set of shaders changes   As with C, a glShader “.obj” can be   shared across multiple glPrograms “.exe”Copyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005       8
Vertex Processor Overview                                 Standard                                  OpenGL                 Generic                                 attributes             attributes                                        gl_color        0, 1, 2, …                                       gl_normal                                          etc.                                             Vertex                               User-defined uniforms:                                                                                epsilon, myLightPos, surfColor, etc.Texture Maps                           Processor                                      Built-in uniforms:                                                                                gl_FogColor, gl_ModelViewMatrix, etc.                  Standard                 Special User-defined                  Varying                 Variables  Varying                 gl_FrontColor             gl_Position              normal                 gl_BackColor             gl_ClipVertex            refraction                      etc.                gl_PointSize                etc.  Copyright © 2005, 3Dlabs, Inc. Ltd               July 31, 2005                                                       9
Fragment Processor Overview                 Standard                   Special User-defined                 Varying                   Variables  Varying                 gl_Color                 gl_FragCoord            normal            gl_SecondaryColor             gl_FrontFacing         refraction                    etc.                                            etc.                                           Fragment                             User-defined uniforms:                                                                              epsilon, myLightPos, surfColor, etc.Texture Maps                            Processor                                   Built-in uniforms:                                                                              gl_FogColor, gl_ModelViewMatrix, etc.                                          Special                                         Variables                                         gl_FragColor                                         gl_FragDepth                                        gl_FragData[n]   Copyright © 2005, 3Dlabs, Inc. Ltd            July 31, 2005                                                       10
GLSL language design   Based on syntax of ANSI C   Includes preprocessor   Additions for graphics functionality   Additions from C++   Some refactoring for cleaner design   Designed for parallelization on SIMD arrayCopyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005   11
Language enhanced for graphics   Added Vector and Matrix types   Added Sampler type for textures   Qualifiers: attribute, uniform, varying   Built-in variables to access GL state   Built-in functions   Vector component notation (swizzling)   discard keyword to cease fragment   processingCopyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005   12
Additions from C++   Function overloading   Variables declared when needed   struct definition performs typedef   bool datatypeCopyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005   13
Differences from C/C++   No automatic type conversion   Constructor notation rather than type cast          int x = int(5.0);   Function parameters passed by value-   return   No pointers or stringsCopyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005   14
GLSL compiler   The GLSL compiler is in the GL driver and   part of the core OpenGL API   No external compiler tools required.   So the compiler is always available at   runtime          Compile shaders whenever convenient   Tight integration allows every vendor to   exploit their architecture for best possible   performanceCopyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005   15
Comparing architectures                        Cg                             GLSL                      Cg Code                      Cg Code                          GLSL Code                                                       GLSL Code                    Cg Compiler                    Cg Compiler                 Intermediate Lang                  Intermediate Lang          Too                   (e.g. ARB vp/fp)                    (e.g. ARB vp/fp)         far                                            apart                      IL Translator                       IL Translator                                                       Compiler                                                       Compiler                        Driver                                       Tightly                        Driver                           Driver                                                         Driver      coupled                   Graphics HW                   Graphics HW                         Graphics HW                                                       Graphics HWCopyright © 2005, 3Dlabs, Inc. Ltd     July 31, 2005                           16
GLSL datatypes   Scalars: float, int, bool   Vectors: float, int, bool   Matrices: float   Samplers   Arrays   Structs   Note          int and bool types are semantic, not expected to          be supported natively          int at least as 16 bits plus sign bitCopyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005           17
GLSL datatype qualifiers   uniform          Relatively constant data from app or OpenGL          Input to both vertex and fragment shaders   attribute          Per-vertex data from app or OpenGL          Input to vertex shader only   varying          Perspective-correct interpolated value          Output from vertex, input to fragment   const   in, out, inout                             (for function parameters)Copyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005                        18
OpenGL state tracking   Common OpenGL state is available to   GLSL via built-in variables          Built-in variables do not need declaration          All begin with reserved prefix “gl_”          Includes uniforms, attributes, and varyings          Makes it easier to interface w/ legacy app code   However, recommend just defining your   own variables for semantic clarity; resist   temptation to overload built-ins          FYI OpenGL/ES will have no or few built-insCopyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005          19
uniform variables   Input to vertex and fragment shaders   Values from OpenGL or app          e.g.: gl_ModelViewProjectionMatrix   Changes relatively infrequently          Typically constant over several primitives   Queriable limit on number of floats   App sets values with glUniform*() APICopyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005     20
attribute variables   Input to vertex shader only   Values from OpenGL or app          e.g.: gl_Color, gl_Normal   Can change per-vertex          But doesn’t have to   Queriable limit on the # of vec4 slots          Scalars/vectors take a slot          Matrices take a slot per column   Apps sends with per-vertex API or vertex   arraysCopyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005   21
varying variables   Output from vertex, input to fragment   Name & type must match across shaders   Values from vertex stage are perspective-   corrected, interpolated, sent to fragment   stage   Queriable limit on number of floats   Usually defined by GLSL code          although GLSL defines some built-ins; e.g.:          gl_FrontColor (necessary when combining GLSL          with fixed-functionality)Copyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005       22
Defining variables in GLSL   Uniform, varying, attribute must be global   to a glShader   Over-declaring variables in GLSL code   doesn’t cost   Only those variables actually used in the   code (the “active” variables) consume   resources   After linking, the app queries uniforms   and attributes from glProgram   Runtime introspection; useful e.g. for   building a GUI on the flyCopyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005   23
Texture access   GLSL supports texture access in both   vertex and fragment stages   However, some hardware may not yet   support texture access in vertex          Vertex texturing is available when          GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS > 0   Mipmap LOD is handled differently   between Vertex and Fragment stagesCopyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005   24
Shader Configurations   May have more than 1 glShader per stage   attached to a glProgram   But there must be exactly one main() per   stage   Useful for a library of shared GLSL code   to be reused across several glProgramsCopyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005   25
Program Configurations   GLSL permits mixing a fixed-functionality   stage with a programmable stage          Prog Vertex + Prog Fragment          Prog Vertex + FF Fragment          FF Vertex + Prog Fragment   GLSL Built-in varyings are key when   mixing programmable stages w/ FFCopyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005   26
GLSL Versioning & Extensions   #version min_version_number          Default is “#version 110”          Good idea to always declare expected version   #extension name : behavior          Default is “#extension all : disable”   Extension names/capabilies defined in   usual GL extensions specifications   Special name “all” indicates all   extensions supported by a compiler   Details in GLSL 1.10 spec pp11-12Copyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005       27
Using GLSL extensions   Recommended approach      #ifdef ARB_texture_rectangle      #extension ARB_texture_rectangle : require      #endif      uniform sampler2DRect mysampler;Copyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005   28
GLSL Future   Expect GLSL to evolve   Possible new language features          More built-in functions, datatypes          Interfaces          Shader trees   Possible new programmable stages in   pipeline          Geometry          Blending   Use #version and #extensionCopyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005   29
OSG support for    GLSL                  30
OSG GLSL design goals   Continue OSG’s straightforward mapping   of classes to the underlying GL concepts   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.   Let OSG deal with the tedious GL stuff          Management of contexts, constructors, indices,          compile/link, etc.Copyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005         31
Mapping GL API to OSG API   glShader object -> osg::Shader   glProgram object -> osg::Program   glUniform*() -> osg::UniformCopyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005   32
OSG GLSL benefits over GL   Decouples shaders from GL contexts   Handles multiple instancing when multiple   GL contexts   osg::Uniform values correctly applied via   OSG’s state update mechanism at the   appropriate time   Compilation and linking automatically   handled when osg::Shader/osg::Program   are dirtied by modificationCopyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005   33
osg::Shader   Derived from osg::Object   Stores the shader’s source code text and   manages its compilation   Attach osg::Shader to osg::Program   osg::Shader be attached to more than one   osg::Program   More than one osg::Shader may be   attached to an osg::Program   Encapsulates per-context glShadersCopyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005   34
osg::Shader API subset   Shader Type          VERTEX or FRAGMENT   Sourcecode text management          setShaderSource() / getShaderSource()          loadShaderSourceFromFile()          readShaderFile()   Queries          getType()          getGlShaderInfoLog()Copyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005   35
osg::Program   Derived from osg::StateAttribute   Defines a set of osg::Shaders, manages   their linkage, and activates for rendering   osg::Programs may be attached anywhere   in the scenegraph   An “empty” osg::Program (i.e.: no   attached osg::Shaders) indicates fixed-   functionality   Automatically performs relink if attached   osg::Shaders are modified   Encapsulates per-context glProgramsCopyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005   36
osg::Program API subset   Shader management          addShader()          removeShader()          getNumShaders()          getShader()   Attribute binding management          addBindAttribLocation()          removeBindAttribLocation()          getAttribBindingList()   Queries          getActiveUniforms()          getActiveAttribs()          getGlProgramInfoLog()Copyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005   37
osg::Uniform   Derived from osg::Object   Attaches to osg::StateSet   May be attached anywhere in the   scenegraph, not just near osg::Program          e.g.: set default values at root of scenegraph   Their effect inherits/overrides through the   scenegraph, like osg::StateAttributes   OSG handles the uniform index   management automaticallyCopyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005         38
osg::Uniform API subset   Uniform Types          All defined GLSL types (float, vec, mat, etc)   Value management          Many convenient constructors          Many get()/set() methods   Callback support          setUpdateCallback() / getUpdateCallback()          setEventCallback() / getEventCallback()Copyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005        39
Simple source example     Putting it all together…osg::Program* pgm = new osg::Program;pgm->setName( "simple" );pgm->addShader(new osg::Shader( osg::Shader::VERTEX, vsrc ));pgm->addShader(new osg::Shader( osg::Shader::FRAGMENT, fsrc ));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 ));  Copyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005                     40
Attributes & osg::Program   GL supports both explicit and automatic   attribute binding          GLSL will dynamically assign attribute indices if          not otherwise specified   However, OSG currently supports only   explicit binding, so app must assign   indices          Automatic binding makes display lists dependent          on osg::Program, and has impact on DL sharing   GLSL specifies much freedom in selecting   attribute indices, but some current drivers   impose restrictionsCopyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005            41
Using textures   In the OSG app code          Construct an osg::Texture          Load image data, set filtering, wrap modes          Attach Texture to StateSet on any texunit          Create an int osg::Uniform with the texunit ID,          attach to StateSet   In GLSL code          Declare a uniform sampler*D foo;          Access the texture with texture*D( foo,          coord );Copyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005          42
OSG preset uniforms   “Always available” values, like OpenGL   built-in uniforms   In osgUtil::SceneView          int osg_FrameNumber;          float osg_FrameTime;          float osg_DeltaFrameTime;          mat4 osg_ViewMatrix;          mat4 osg_InverseViewMatrix;   Automatically updated once per frame by   SceneView   Bitmask to disable updating if desiredCopyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005   43
OSG file formats & GLSL   .osg & .ive formats have full read/write   support for GLSL objects   OSG formats can serve as a GLSL effect   file.   Today’s demos consist simply of a .osg   file          no runtime app other than osgviewer requiredCopyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005       44
Tips, Tricks,Gotchas, and ToolsGotchas,                     45
Tips for Shader Debugging   Name your osg::Shaders/osg::Programs   Review the infologs displayed at notify   osg::INFO level.   Assign internal vecs to color   Use discard like assert   Verify your code for conformance   Try glsl_dataflag.osg to see values inside   your scene   New in CVS: glValidateProgram() supportCopyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005   46
GLSL performance tips   Put algorithm in the right stage          Don’t compute in fragment if could be passed          from vertex stage or app   Don’t interpolate more than necessary          If your texture coord is a vec2, don’t pass as vec4   Try passing data as attributes rather than   uniforms          Changing uniforms sometimes have a setup cost   Use built-in functions and types   Review the infologs          Driver may give hints on non-optimal codeCopyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005              47
GLSL language gotchas   Comparing float values          Use an epsilon   Varyings are interpolated          Interpolating from A to A may not exactly == A   int is semantic (usually float internally)Copyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005         48
GLSL implementation gotchas   Drivers are new, there’s room for improvement   Don’t learn GLSL empirically on your driver   Example portability issues          “Any extended behavior must first be enabled.” (p11)          “There are no implicit conversions between types.” (p16)          Writes to read-only variables          Additional resource constraints (attribute slots, texture units)          Loops forced to constant number of iterations   Review your driver’s release notes, take heed   Note the driver’s GLSL version string   Depend on the GL and GLSL specs   Be vigilant now for compatibility laterCopyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005                           49
On the CDROM   Documentation          OpenGL 2.0, GLSL 1.10 specifications          GLSL Overview whitepaper & Quick Reference          OpenGL manpages (HTML & VS.net help)   Open-source tools from 3Dlabs website          GLSL Demo          GLSL Parser Test          GLSL Validate          ShaderGen          GLSL Compiler Front-endCopyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005     50
GLSL Validate   Open source, including commercial use   Uses the 3Dlabs GLSL compiler front-end   to check the validity of a shader   Contains both command line and GUI   interface   Does NOT require a GLSL-capable driverCopyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005   51
GLSL Parse Test   Open source, including commercial use   Suite of over 140 GLSL shader tests   Includes both known-good and known-   bad test cases   Compiles each shader, compares to   expected results   Results are summarized, written to HTML   Info logs can be examined   It tests a driver’s GLSL compiler, so a   GLSL-capable driver required (duh)Copyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005   52
GLSL Compiler Front-End              Front-End   Open source, including commercial use   Part of 3Dlabs’ production compiler   Compiles on Windows and Linux   Performs:          Preprocessing          Lexical analysis          Syntactic analysis          Semantic analysis          Constructs a high-level parse tree.Copyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005   53
osgToy::GlslLintosgToy::GlslLint   Proof-of-concept GLSLvalidate-like   functionality integrated with OSG   Uses the 3Dlabs GLSL compiler front-end   No GLSL driver or hardware necessary   Currently part of the osgToy collection          http://sourceforge.net/projects/osgtoy/   Accessible from C++ as a NodeVisitor:          osgToy::GlslLintVisitor   Or from cmdline as a pseudoloader:          osgviewer myScene.osg.glsllintCopyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005   54
Demos!         55
osgshaders example   The original OSG/GLSL example in C++   Demonstrates multiple osg::Programs,   time-varying uniforms, multi-textureCopyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005   56
glsl_simple.osgglsl_simple.osg   The first GLSL scene in a .osg file   Block colors are uniforms distributed   around the scenegraphCopyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005   57
glsl_confetti.osgglsl_confetti.osg   Demonstrates generic vertex attributes   and particle animation in a vertex shaderCopyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005   58
compactdisc.osgcompactdisc.osg   A vertex-only shader using generic vertex   attributesCopyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005   59
glsl_dataflag.osgglsl_dataflag.osg   Displays GLSL-internal values as ASCII   strings   Drawn in one pass; no render-to-textureCopyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005   60
3dataflags   Multiple dataflag instances can show   different dataCopyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005   61
For more info   http://openscenegraph.org/   http://developer.3Dlabs.com/   http://mew.cx/osg/   http://sourceforge.net/projects/osgtoy/Copyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005   62
Thank you!Copyright © 2005, 3Dlabs, Inc. Ltd   July 31, 2005   63

Recommended

PPTX
GS-4106 The AMD GCN Architecture - A Crash Course, by Layla Mah
PPTX
DRY or die
PDF
GPU Programming
PDF
How to migrate from Oracle Database with ease
PPTX
Jdk,jre,jvm
PPTX
Servlets
PPTX
AI3391 Artificial Intelligence Session 26 First order logic.pptx
PDF
Collada Reference Card 1.4
PPTX
Approaching zero driver overhead
PDF
Advanced Troublesshooting Nexus 7K.pdf
PPTX
1-introduction-to-dart-programming.pptx
PDF
All experiment of java
PDF
Introduction to CUDA
PPTX
PPTX
PostgreSQL- An Introduction
PPSX
Introduction to java
PPT
Java oops and fundamentals
PPT
Chapter8 pl sql
PDF
Programming with Python and PostgreSQL
PPT
PL/SQL Introduction and Concepts
PDF
CPU vs. GPU presentation
PPTX
05_DP_300T00A_Optimize.pptx
PPT
Finite automata examples
PDF
The Great Debate: PostgreSQL vs MySQL
byEDB
 
PPTX
INHERITANCE IN JAVA.pptx
PDF
ACRN vMeet-Up EU 2021 - Real Time Management and Performance Optimization
PDF
Project ACRN: SR-IOV implementation
PPT
Sql Server Performance Tuning
PDF
Woden 2: Developing a modern 3D graphics engine in Smalltalk
 
PPTX
What is 3 d modeling unit 66

More Related Content

PPTX
GS-4106 The AMD GCN Architecture - A Crash Course, by Layla Mah
PPTX
DRY or die
PDF
GPU Programming
PDF
How to migrate from Oracle Database with ease
PPTX
Jdk,jre,jvm
PPTX
Servlets
PPTX
AI3391 Artificial Intelligence Session 26 First order logic.pptx
PDF
Collada Reference Card 1.4
GS-4106 The AMD GCN Architecture - A Crash Course, by Layla Mah
DRY or die
GPU Programming
How to migrate from Oracle Database with ease
Jdk,jre,jvm
Servlets
AI3391 Artificial Intelligence Session 26 First order logic.pptx
Collada Reference Card 1.4

What's hot

PPTX
Approaching zero driver overhead
PDF
Advanced Troublesshooting Nexus 7K.pdf
PPTX
1-introduction-to-dart-programming.pptx
PDF
All experiment of java
PDF
Introduction to CUDA
PPTX
PPTX
PostgreSQL- An Introduction
PPSX
Introduction to java
PPT
Java oops and fundamentals
PPT
Chapter8 pl sql
PDF
Programming with Python and PostgreSQL
PPT
PL/SQL Introduction and Concepts
PDF
CPU vs. GPU presentation
PPTX
05_DP_300T00A_Optimize.pptx
PPT
Finite automata examples
PDF
The Great Debate: PostgreSQL vs MySQL
byEDB
 
PPTX
INHERITANCE IN JAVA.pptx
PDF
ACRN vMeet-Up EU 2021 - Real Time Management and Performance Optimization
PDF
Project ACRN: SR-IOV implementation
PPT
Sql Server Performance Tuning
Approaching zero driver overhead
Advanced Troublesshooting Nexus 7K.pdf
1-introduction-to-dart-programming.pptx
All experiment of java
Introduction to CUDA
PostgreSQL- An Introduction
Introduction to java
Java oops and fundamentals
Chapter8 pl sql
Programming with Python and PostgreSQL
PL/SQL Introduction and Concepts
CPU vs. GPU presentation
05_DP_300T00A_Optimize.pptx
Finite automata examples
The Great Debate: PostgreSQL vs MySQL
byEDB
 
INHERITANCE IN JAVA.pptx
ACRN vMeet-Up EU 2021 - Real Time Management and Performance Optimization
Project ACRN: SR-IOV implementation
Sql Server Performance Tuning

Viewers also liked

PDF
Woden 2: Developing a modern 3D graphics engine in Smalltalk
 
PPTX
What is 3 d modeling unit 66
PPTX
3D scanner using kinect
PPTX
3d password 23 mar 14
PDF
3D Laser Scanning
PPT
Radiosity algorithm
ODP
The Image-based data glove presentation
PPTX
Chapter 11 biotechnology by mohanbio
PPTX
3D internet
PDF
UP200 dental 3d scanner with dental CAD
PDF
Typography on the Web
PPT
Human Action Recognition Based on Spacio-temporal features
ODP
Building a DIY 3D Scanner
PPTX
Orthographic projection
PPTX
Quadtree In Game
KEY
Interactive Graphic Storytelling: “How the Internet Impacts the Graphic Novel”
PPTX
Steel monkeys: Unity3D глазами программиста графики
PPTX
Pelican Mapping - FOSS4G 2011
PPT
Shtanchaev_SPEKTR
PPTX
Shells
Woden 2: Developing a modern 3D graphics engine in Smalltalk
 
What is 3 d modeling unit 66
3D scanner using kinect
3d password 23 mar 14
3D Laser Scanning
Radiosity algorithm
The Image-based data glove presentation
Chapter 11 biotechnology by mohanbio
3D internet
UP200 dental 3d scanner with dental CAD
Typography on the Web
Human Action Recognition Based on Spacio-temporal features
Building a DIY 3D Scanner
Orthographic projection
Quadtree In Game
Interactive Graphic Storytelling: “How the Internet Impacts the Graphic Novel”
Steel monkeys: Unity3D глазами программиста графики
Pelican Mapping - FOSS4G 2011
Shtanchaev_SPEKTR
Shells

Similar to GLSL Shading with OpenSceneGraph

PPT
SIGGRAPH 2012: NVIDIA OpenGL for 2012
PPTX
OpenGL Introduction
PPTX
OpenGL Shading Language
PDF
Computer Graphics - Lecture 01 - 3D Programming I
PPT
CS 354 Texture Mapping
PPT
CS 354 GPU Architecture
PPT
PPT
CS 354 Programmable Shading
PPT
SIGGRAPH Asia 2012 Exhibitor Talk: OpenGL 4.3 and Beyond
PDF
Realizing OpenGL
PPT
Hardware Shaders
PDF
GL Shading Language Document by OpenGL.pdf
PPT
PPT
Advanced Graphics Workshop - GFX2011
PDF
Cg in Two Pages
PPTX
Opengl lec 3
PPTX
Getting started with open gl es 2
PDF
Open gl
PDF
The Ring programming language version 1.9 book - Part 199 of 210
PDF
The Ring programming language version 1.9 book - Part 157 of 210
SIGGRAPH 2012: NVIDIA OpenGL for 2012
OpenGL Introduction
OpenGL Shading Language
Computer Graphics - Lecture 01 - 3D Programming I
CS 354 Texture Mapping
CS 354 GPU Architecture
CS 354 Programmable Shading
SIGGRAPH Asia 2012 Exhibitor Talk: OpenGL 4.3 and Beyond
Realizing OpenGL
Hardware Shaders
GL Shading Language Document by OpenGL.pdf
Advanced Graphics Workshop - GFX2011
Cg in Two Pages
Opengl lec 3
Getting started with open gl es 2
Open gl
The Ring programming language version 1.9 book - Part 199 of 210
The Ring programming language version 1.9 book - Part 157 of 210

Recently uploaded

PDF
[BDD 2025 - Mobile Development] Exploring Apple’s On-Device FoundationModels
PDF
Lets Build a Serverless Function with Kiro
PDF
Running Non-Cloud-Native Databases in Cloud-Native Environments_ Challenges a...
PPTX
UFCD 0797 - SISTEMAS OPERATIVOS_Unidade Completa.pptx
PDF
Transforming Supply Chains with Amazon Bedrock AgentCore (AWS Swiss User Grou...
PDF
[BDD 2025 - Artificial Intelligence] Building AI Systems That Users (and Comp...
PDF
Transforming Content Operations in the Age of AI
PDF
So You Want to Work at Google | DevFest Seattle 2025
PDF
Dev Dives: Build smarter agents with UiPath Agent Builder
PPTX
"Feelings versus facts: why metrics are more important than intuition", Igor ...
 
PDF
Mastering Agentic Orchestration with UiPath Maestro | Hands on Workshop
PDF
MuleSoft Meetup: Dreamforce'25 Tour- Vibing With AI & Agents.pdf
PDF
Transcript: The partnership effect: Libraries and publishers on collaborating...
PDF
Top 10 AI Development Companies in UK 2025
PDF
Integrating AI with Meaningful Human Collaboration
PDF
The Evolving Role of the CEO in the Age of AI
PDF
[BDD 2025 - Artificial Intelligence] AI for the Underdogs: Innovation for Sma...
PPTX
Guardrails in Action - Ensuring Safe AI with Azure AI Content Safety.pptx
PDF
The partnership effect: Libraries and publishers on collaborating and thrivin...
PDF
Cybersecurity Prevention and Detection: Unit 2
[BDD 2025 - Mobile Development] Exploring Apple’s On-Device FoundationModels
Lets Build a Serverless Function with Kiro
Running Non-Cloud-Native Databases in Cloud-Native Environments_ Challenges a...
UFCD 0797 - SISTEMAS OPERATIVOS_Unidade Completa.pptx
Transforming Supply Chains with Amazon Bedrock AgentCore (AWS Swiss User Grou...
[BDD 2025 - Artificial Intelligence] Building AI Systems That Users (and Comp...
Transforming Content Operations in the Age of AI
So You Want to Work at Google | DevFest Seattle 2025
Dev Dives: Build smarter agents with UiPath Agent Builder
"Feelings versus facts: why metrics are more important than intuition", Igor ...
 
Mastering Agentic Orchestration with UiPath Maestro | Hands on Workshop
MuleSoft Meetup: Dreamforce'25 Tour- Vibing With AI & Agents.pdf
Transcript: The partnership effect: Libraries and publishers on collaborating...
Top 10 AI Development Companies in UK 2025
Integrating AI with Meaningful Human Collaboration
The Evolving Role of the CEO in the Age of AI
[BDD 2025 - Artificial Intelligence] AI for the Underdogs: Innovation for Sma...
Guardrails in Action - Ensuring Safe AI with Azure AI Content Safety.pptx
The partnership effect: Libraries and publishers on collaborating and thrivin...
Cybersecurity Prevention and Detection: Unit 2
In this document
Powered by AI

Overview of GLSL Shading Language, presentation summary, dependencies, and focus on OSG API.

Key historical milestones in GLSL and OSG's integration of GLSL support since its inception.

Detailed look at GLSL integration in the OpenGL pipeline, covering vertex and fragment processors.

GLSL language design, compilation model, architecture comparison with Cg, highlighting its integration with OpenGL.

Overview of GLSL's data types, qualifiers, and how OpenGL state is managed through built-in variables.

Usage of uniforms, attributes, and varying variables; handling textures in GLSL and within OSG. Demonstrating practical applications, using uniforms and attributes, integrating textures with OSG.

Tips, tricks, performance optimizations, and common gotchas when using GLSL.

Available GLSL resources, tools for shader validation, demonstrations of GLSL capabilities, and closing remarks.

GLSL Shading with OpenSceneGraph

  • 1.
    GLSL Shading withOpenSceneGraph Mike Weiblen July 31, 2005 Los Angeles Rev B 1
  • 2.
    Summary of thistalk Overview of GLSL pipeline & syntax OSG support for GLSL Tips, Tricks, Gotchas, and Tools Demos What we’re not covering Our focus will be the OSG API, not OpenGL API Not lots of detail on the GLSL language itselfCopyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 2
  • 3.
    Our dependencies OpenGL 2.0 OpenGL Shading Language 1.10 rev 59 Specs on opengl.org and CDROM OpenSceneGraph 0.9.9 Note: GLSL support continues to evolve in CVSCopyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 3
  • 4.
    GLSL / OSGtimeline Fall 2001: 3Dlabs “GL2.0” whitepapers, shading language is the centerpiece July 2003: ARB approves GL1.5, GLSL as ARB extension Fall 2003: osgGL2 Nodekit Sep 2004: ARB approves GL2.0, GLSL in the core. Spring 2005: 2nd generation GLSL support integrated into OSG core Supports both OpenGL 2.0 and 1.5 extensionsCopyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 4
  • 5.
  • 6.
    The OpenGL 2.0PipelineCopyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 6
  • 7.
    GLSL pipeline architecture GLSL exposes programmability at two points in the OpenGL 2.0 pipeline Vertex processor Fragment processor Compiled code to run on a particular processor is a glShader A linked executable unit to be activated on the pipeline is a glProgramCopyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 7
  • 8.
    GLSL compilation model Similar to familiar C build model glShader = “object file” Contains shader source code Compiled to become an “.obj file” Must be recompiled when source changes glProgram = “executable file” Contains a list of shaders Linked to become an “.exe file” Must be relinked when set of shaders changes As with C, a glShader “.obj” can be shared across multiple glPrograms “.exe”Copyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 8
  • 9.
    Vertex Processor Overview Standard OpenGL Generic attributes attributes gl_color 0, 1, 2, … gl_normal etc. Vertex User-defined uniforms: epsilon, myLightPos, surfColor, etc.Texture Maps Processor Built-in uniforms: gl_FogColor, gl_ModelViewMatrix, etc. Standard Special User-defined Varying Variables Varying gl_FrontColor gl_Position normal gl_BackColor gl_ClipVertex refraction etc. gl_PointSize etc. Copyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 9
  • 10.
    Fragment Processor Overview Standard Special User-defined Varying Variables Varying gl_Color gl_FragCoord normal gl_SecondaryColor gl_FrontFacing refraction etc. etc. Fragment User-defined uniforms: epsilon, myLightPos, surfColor, etc.Texture Maps Processor Built-in uniforms: gl_FogColor, gl_ModelViewMatrix, etc. Special Variables gl_FragColor gl_FragDepth gl_FragData[n] Copyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 10
  • 11.
    GLSL language design Based on syntax of ANSI C Includes preprocessor Additions for graphics functionality Additions from C++ Some refactoring for cleaner design Designed for parallelization on SIMD arrayCopyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 11
  • 12.
    Language enhanced forgraphics Added Vector and Matrix types Added Sampler type for textures Qualifiers: attribute, uniform, varying Built-in variables to access GL state Built-in functions Vector component notation (swizzling) discard keyword to cease fragment processingCopyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 12
  • 13.
    Additions from C++ Function overloading Variables declared when needed struct definition performs typedef bool datatypeCopyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 13
  • 14.
    Differences from C/C++ No automatic type conversion Constructor notation rather than type cast int x = int(5.0); Function parameters passed by value- return No pointers or stringsCopyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 14
  • 15.
    GLSL compiler The GLSL compiler is in the GL driver and part of the core OpenGL API No external compiler tools required. So the compiler is always available at runtime Compile shaders whenever convenient Tight integration allows every vendor to exploit their architecture for best possible performanceCopyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 15
  • 16.
    Comparing architectures Cg GLSL Cg Code Cg Code GLSL Code GLSL Code Cg Compiler Cg Compiler Intermediate Lang Intermediate Lang Too (e.g. ARB vp/fp) (e.g. ARB vp/fp) far apart IL Translator IL Translator Compiler Compiler Driver Tightly Driver Driver Driver coupled Graphics HW Graphics HW Graphics HW Graphics HWCopyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 16
  • 17.
    GLSL datatypes Scalars: float, int, bool Vectors: float, int, bool Matrices: float Samplers Arrays Structs Note int and bool types are semantic, not expected to be supported natively int at least as 16 bits plus sign bitCopyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 17
  • 18.
    GLSL datatype qualifiers uniform Relatively constant data from app or OpenGL Input to both vertex and fragment shaders attribute Per-vertex data from app or OpenGL Input to vertex shader only varying Perspective-correct interpolated value Output from vertex, input to fragment const in, out, inout (for function parameters)Copyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 18
  • 19.
    OpenGL state tracking Common OpenGL state is available to GLSL via built-in variables Built-in variables do not need declaration All begin with reserved prefix “gl_” Includes uniforms, attributes, and varyings Makes it easier to interface w/ legacy app code However, recommend just defining your own variables for semantic clarity; resist temptation to overload built-ins FYI OpenGL/ES will have no or few built-insCopyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 19
  • 20.
    uniform variables Input to vertex and fragment shaders Values from OpenGL or app e.g.: gl_ModelViewProjectionMatrix Changes relatively infrequently Typically constant over several primitives Queriable limit on number of floats App sets values with glUniform*() APICopyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 20
  • 21.
    attribute variables Input to vertex shader only Values from OpenGL or app e.g.: gl_Color, gl_Normal Can change per-vertex But doesn’t have to Queriable limit on the # of vec4 slots Scalars/vectors take a slot Matrices take a slot per column Apps sends with per-vertex API or vertex arraysCopyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 21
  • 22.
    varying variables Output from vertex, input to fragment Name & type must match across shaders Values from vertex stage are perspective- corrected, interpolated, sent to fragment stage Queriable limit on number of floats Usually defined by GLSL code although GLSL defines some built-ins; e.g.: gl_FrontColor (necessary when combining GLSL with fixed-functionality)Copyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 22
  • 23.
    Defining variables inGLSL Uniform, varying, attribute must be global to a glShader Over-declaring variables in GLSL code doesn’t cost Only those variables actually used in the code (the “active” variables) consume resources After linking, the app queries uniforms and attributes from glProgram Runtime introspection; useful e.g. for building a GUI on the flyCopyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 23
  • 24.
    Texture access GLSL supports texture access in both vertex and fragment stages However, some hardware may not yet support texture access in vertex Vertex texturing is available when GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS > 0 Mipmap LOD is handled differently between Vertex and Fragment stagesCopyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 24
  • 25.
    Shader Configurations May have more than 1 glShader per stage attached to a glProgram But there must be exactly one main() per stage Useful for a library of shared GLSL code to be reused across several glProgramsCopyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 25
  • 26.
    Program Configurations GLSL permits mixing a fixed-functionality stage with a programmable stage Prog Vertex + Prog Fragment Prog Vertex + FF Fragment FF Vertex + Prog Fragment GLSL Built-in varyings are key when mixing programmable stages w/ FFCopyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 26
  • 27.
    GLSL Versioning &Extensions #version min_version_number Default is “#version 110” Good idea to always declare expected version #extension name : behavior Default is “#extension all : disable” Extension names/capabilies defined in usual GL extensions specifications Special name “all” indicates all extensions supported by a compiler Details in GLSL 1.10 spec pp11-12Copyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 27
  • 28.
    Using GLSL extensions Recommended approach #ifdef ARB_texture_rectangle #extension ARB_texture_rectangle : require #endif uniform sampler2DRect mysampler;Copyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 28
  • 29.
    GLSL Future Expect GLSL to evolve Possible new language features More built-in functions, datatypes Interfaces Shader trees Possible new programmable stages in pipeline Geometry Blending Use #version and #extensionCopyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 29
  • 30.
  • 31.
    OSG GLSL designgoals Continue OSG’s straightforward mapping of classes to the underlying GL concepts 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. Let OSG deal with the tedious GL stuff Management of contexts, constructors, indices, compile/link, etc.Copyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 31
  • 32.
    Mapping GL APIto OSG API glShader object -> osg::Shader glProgram object -> osg::Program glUniform*() -> osg::UniformCopyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 32
  • 33.
    OSG GLSL benefitsover GL Decouples shaders from GL contexts Handles multiple instancing when multiple GL contexts osg::Uniform values correctly applied via OSG’s state update mechanism at the appropriate time Compilation and linking automatically handled when osg::Shader/osg::Program are dirtied by modificationCopyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 33
  • 34.
    osg::ShaderDerived from osg::Object Stores the shader’s source code text and manages its compilation Attach osg::Shader to osg::Program osg::Shader be attached to more than one osg::Program More than one osg::Shader may be attached to an osg::Program Encapsulates per-context glShadersCopyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 34
  • 35.
    osg::Shader API subset Shader Type VERTEX or FRAGMENT Sourcecode text management setShaderSource() / getShaderSource() loadShaderSourceFromFile() readShaderFile() Queries getType() getGlShaderInfoLog()Copyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 35
  • 36.
    osg::ProgramDerived from osg::StateAttribute Defines a set of osg::Shaders, manages their linkage, and activates for rendering osg::Programs may be attached anywhere in the scenegraph An “empty” osg::Program (i.e.: no attached osg::Shaders) indicates fixed- functionality Automatically performs relink if attached osg::Shaders are modified Encapsulates per-context glProgramsCopyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 36
  • 37.
    osg::Program API subset Shader management addShader() removeShader() getNumShaders() getShader() Attribute binding management addBindAttribLocation() removeBindAttribLocation() getAttribBindingList() Queries getActiveUniforms() getActiveAttribs() getGlProgramInfoLog()Copyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 37
  • 38.
    osg::UniformDerived from osg::Object Attaches to osg::StateSet May be attached anywhere in the scenegraph, not just near osg::Program e.g.: set default values at root of scenegraph Their effect inherits/overrides through the scenegraph, like osg::StateAttributes OSG handles the uniform index management automaticallyCopyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 38
  • 39.
    osg::Uniform API subset Uniform Types All defined GLSL types (float, vec, mat, etc) Value management Many convenient constructors Many get()/set() methods Callback support setUpdateCallback() / getUpdateCallback() setEventCallback() / getEventCallback()Copyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 39
  • 40.
    Simple source example Putting it all together…osg::Program* pgm = new osg::Program;pgm->setName( "simple" );pgm->addShader(new osg::Shader( osg::Shader::VERTEX, vsrc ));pgm->addShader(new osg::Shader( osg::Shader::FRAGMENT, fsrc ));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 )); Copyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 40
  • 41.
    Attributes & osg::Program GL supports both explicit and automatic attribute binding GLSL will dynamically assign attribute indices if not otherwise specified However, OSG currently supports only explicit binding, so app must assign indices Automatic binding makes display lists dependent on osg::Program, and has impact on DL sharing GLSL specifies much freedom in selecting attribute indices, but some current drivers impose restrictionsCopyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 41
  • 42.
    Using textures In the OSG app code Construct an osg::Texture Load image data, set filtering, wrap modes Attach Texture to StateSet on any texunit Create an int osg::Uniform with the texunit ID, attach to StateSet In GLSL code Declare a uniform sampler*D foo; Access the texture with texture*D( foo, coord );Copyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 42
  • 43.
    OSG preset uniforms “Always available” values, like OpenGL built-in uniforms In osgUtil::SceneView int osg_FrameNumber; float osg_FrameTime; float osg_DeltaFrameTime; mat4 osg_ViewMatrix; mat4 osg_InverseViewMatrix; Automatically updated once per frame by SceneView Bitmask to disable updating if desiredCopyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 43
  • 44.
    OSG file formats& GLSL .osg & .ive formats have full read/write support for GLSL objects OSG formats can serve as a GLSL effect file. Today’s demos consist simply of a .osg file no runtime app other than osgviewer requiredCopyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 44
  • 45.
  • 46.
    Tips for ShaderDebugging Name your osg::Shaders/osg::Programs Review the infologs displayed at notify osg::INFO level. Assign internal vecs to color Use discard like assert Verify your code for conformance Try glsl_dataflag.osg to see values inside your scene New in CVS: glValidateProgram() supportCopyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 46
  • 47.
    GLSL performance tips Put algorithm in the right stage Don’t compute in fragment if could be passed from vertex stage or app Don’t interpolate more than necessary If your texture coord is a vec2, don’t pass as vec4 Try passing data as attributes rather than uniforms Changing uniforms sometimes have a setup cost Use built-in functions and types Review the infologs Driver may give hints on non-optimal codeCopyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 47
  • 48.
    GLSL language gotchas Comparing float values Use an epsilon Varyings are interpolated Interpolating from A to A may not exactly == A int is semantic (usually float internally)Copyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 48
  • 49.
    GLSL implementation gotchas Drivers are new, there’s room for improvement Don’t learn GLSL empirically on your driver Example portability issues “Any extended behavior must first be enabled.” (p11) “There are no implicit conversions between types.” (p16) Writes to read-only variables Additional resource constraints (attribute slots, texture units) Loops forced to constant number of iterations Review your driver’s release notes, take heed Note the driver’s GLSL version string Depend on the GL and GLSL specs Be vigilant now for compatibility laterCopyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 49
  • 50.
    On the CDROM Documentation OpenGL 2.0, GLSL 1.10 specifications GLSL Overview whitepaper & Quick Reference OpenGL manpages (HTML & VS.net help) Open-source tools from 3Dlabs website GLSL Demo GLSL Parser Test GLSL Validate ShaderGen GLSL Compiler Front-endCopyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 50
  • 51.
    GLSL Validate Open source, including commercial use Uses the 3Dlabs GLSL compiler front-end to check the validity of a shader Contains both command line and GUI interface Does NOT require a GLSL-capable driverCopyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 51
  • 52.
    GLSL Parse Test Open source, including commercial use Suite of over 140 GLSL shader tests Includes both known-good and known- bad test cases Compiles each shader, compares to expected results Results are summarized, written to HTML Info logs can be examined It tests a driver’s GLSL compiler, so a GLSL-capable driver required (duh)Copyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 52
  • 53.
    GLSL Compiler Front-End Front-End Open source, including commercial use Part of 3Dlabs’ production compiler Compiles on Windows and Linux Performs: Preprocessing Lexical analysis Syntactic analysis Semantic analysis Constructs a high-level parse tree.Copyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 53
  • 54.
    osgToy::GlslLintosgToy::GlslLintProof-of-concept GLSLvalidate-like functionality integrated with OSG Uses the 3Dlabs GLSL compiler front-end No GLSL driver or hardware necessary Currently part of the osgToy collection http://sourceforge.net/projects/osgtoy/ Accessible from C++ as a NodeVisitor: osgToy::GlslLintVisitor Or from cmdline as a pseudoloader: osgviewer myScene.osg.glsllintCopyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 54
  • 55.
  • 56.
    osgshaders example The original OSG/GLSL example in C++ Demonstrates multiple osg::Programs, time-varying uniforms, multi-textureCopyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 56
  • 57.
    glsl_simple.osgglsl_simple.osgThe first GLSL scene in a .osg file Block colors are uniforms distributed around the scenegraphCopyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 57
  • 58.
    glsl_confetti.osgglsl_confetti.osgDemonstrates generic vertex attributes and particle animation in a vertex shaderCopyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 58
  • 59.
    compactdisc.osgcompactdisc.osgA vertex-only shader using generic vertex attributesCopyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 59
  • 60.
    glsl_dataflag.osgglsl_dataflag.osgDisplays GLSL-internal values as ASCII strings Drawn in one pass; no render-to-textureCopyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 60
  • 61.
    3dataflagsMultiple dataflag instances can show different dataCopyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 61
  • 62.
    For more info http://openscenegraph.org/ http://developer.3Dlabs.com/ http://mew.cx/osg/ http://sourceforge.net/projects/osgtoy/Copyright © 2005, 3Dlabs, Inc. Ltd July 31, 2005 62
  • 63.
    Thank you!Copyright ©2005, 3Dlabs, Inc. Ltd July 31, 2005 63

[8]ページ先頭

©2009-2025 Movatter.jp