GLSL Shader Pipeline¶
Introduction¶
The SoShaderPipeline modules offer an extensible GLSL shader pipeline based on the SuperShader concept. The fragment and vertex shaders are divided into a dynamic shader pipeline, which allows for the interactive addition of custom shader code. A pipeline step is modeled as a subset of several shader pipeline functions that contain the GLSL shader code.
The main advantage over bare-metal GLSL shaders is that different aspects of the shader can be extended or exchanged without requiring adaptations to other parts of the shader. For example, you can add a new light model without having to handle the different number of fixed-function lights in the scene. The basic shader pipeline incorporates the following Open Inventor or OpenGL fixed function state:
- lighting (supporting all Open Inventor lights)
- fixed function texturing
- fog
Both the surface shading and the lighting model can be exchanged and/or extended separately.
Usage¶
The shader of a shader pipeline is generated and activated by placing a SoShaderPipeline
module into the scene graph. If no other extensions are in the Open Inventor state, the generated shader will contain only the GLSL code that implements the fixed-function state of OpenGL at that position in the scene graph.
Any number of extensions can be placed in front of a SoShaderPipeline
module and will be incorporated into the generated GLSL code. Extensions placed after a SoShaderPipeline
module do NOT affect the created shader at all.
Since the shader pipeline is based on the GLSL shader framework
, extensions can utilize the SoShaderParameter*, SoSampler*, SoImageFileSampler
, and SoVertexAttribute* modules, taking advantage of the resulting uniforms and vertex attributes in the extensions.
Typical use cases for pipeline extensions are:
- Modifying the geometry
- Exchanging the light model for a custom model
- Implementing a custom surface shader
- Adding new light types (e.g., shadow-casting lights)
- Modifying the result color or transparency
- Extending the writing of the result color/normal
- Extending any step of the pipeline
Debugging/Development¶
The SoShaderPipelineDiagnosis
module can be placed in front of a
SoShaderPipeline
module and will show the resulting shaders, errors/warnings, and
all pipeline steps and includes.