Class SoShaderProgram
- All Implemented Interfaces:
SafeDisposable
- Direct Known Subclasses:
SoVolumeShader
SoShaderObject
. These stage programs are stored in the field shaderObject. Any Modifications that occur in the shader objects are dynamically detected and the state is updated.
The supported shading language of the program source is OpenGL Shader Language (GLSL) . Furthermore, the Open Inventor shader API or VolumeViz shader API must be used to write any GLSL shader program. See ShaderAPI for detail.
Uniform shader parameters can be set per shader object and are available for all pipeline stages of the shader program. Uniform means a constant value during the shader execution. A uniform parameter is represented by an instance of a specific subclass of SoUniformShaderParameter
. For example, an SoShaderParameter1i
holds a single integer value.
Vertex parameters can be accessible from a vertex shader object. Vertex parameters are per-vertex data passed from the application to the vertex shader. A vertex parameter is represented by an instance of a specific subclass of SoVertexShaderParameter
. For example, an SoVertexShaderParameter1f
holds a set of floating point values and an SoVertexShaderParameter3f
holds a set of SbVec3f
values.
SoShaderProgram
has specialized subclasses for volume visualization. If you are using the VolumeViz extension, see SoVolumeShader
and SoVolumeRenderingQuality
nodes.
Notes:
- For geometry shaders: the EXT_geometry_shader4 OpenGL extension must be supported by your graphics board.
- For tesselation shaders: the GL_ARB_tessellation_shader OpenGL extensions must be supported by your graphics board.
- When writing geometry shaders, the input and output primitive types must be specified in the shader code. See https://developer.openinventor.com/index.php/general-documentation/upgrade-oiv9-shader-code/#geomshader for more information.
- Transparency and fast editing are compatible with shader modified geometry, but most actions use the vertices of the basic shape (the vertices stored in the scene graph). This includes, for example,
SoGetBoundingBoxAction
,SoGetPrimitiveCountAction
andSoRayPickAction
.
Tips:
- To see the output from the GLSL compiler/linker, set the environment variable OIV_GLSL_DEBUG.
- If you set the environment variable OIV_SHADER_CHECK_INTERVAL, the shader source file is checked for a change every n seconds, where n is the value specified by the variable. This allows you to edit the shader source code without needing to restart your application after each shader modification.
- If your shader makes geometry transparent (sets alpha values < 1), you should set the
generateTransparency
field to true. This ensures that Open Inventor knows to apply the correct handling for the current transparency mode. - Since the GLSL specification doesn't currently provide a "#include" directive, Open Inventor provides this service through the comment directive "//!oiv_include". This provides greater flexibility in implementing complex GLSL shaders. Included files are loaded using
SoInput
and respect the same search path order. For example://!oiv_include <MyShaderDirectory/common.h>
shaderObject | NULL |
geometryInputType | TRIANGLES_INPUT |
geometryOutputType | TRIANGLE_STRIP_OUTPUT |
vertexProgramTwoSide | false |
shadowShader | false |
maxGeometryOutputVertices | -1 |
generateTransparency | false |
patchLength | 0 |
Shader program with one fragment shader with one uniform parameter.
// Simple fragment shader with one uniform parameter // First load the fragment shader code SoFragmentShader fragmentShader = new SoFragmentShader(); fragmentShader.sourceProgram.setValue( "filename.glsl" ); // Set the shader parameter SoShaderParameter1i parameter = new SoShaderParameter1i(); parameter.name.setValue( "data1" ); parameter.value.setValue( 1 ); fragmentShader.parameter.set1Value( 0, parameter ); // Associate fragment shader with a shader program node SoShaderProgram shaderProgram = new SoShaderProgram(); shaderProgram.shaderObject.set1Value( 0, fragmentShader ); root.addChild(shaderProgram);
Action behavior:
SoGLRenderAction
Sets the Open Inventor state with the active shader program. Sets: SoGLShaderProgramElement
ShaderAPI, SoFragmentShader
, SoGeometryShader
, SoShaderObject
, SoTessellationControlShader
, SoTessellationEvaluationShader
, SoUniformShaderParameter
, SoVertexShader
, SoVertexShaderParameter
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Geometry input type.static enum
Geometry ouput type.Nested classes/interfaces inherited from class com.openinventor.inventor.nodes.SoNode
SoNode.RenderModes
Nested classes/interfaces inherited from class com.openinventor.inventor.Inventor
Inventor.ConstructorCommand
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal SoMFNode
Specifies a list ofSoShaderParameterBufferObject
to use with this shader.final SoSFBool
If set to true, then shapes affected by this shader will be considered transparent.Specifies the input primitive type of the current geometry shader if any (not used otherwise).Specifies the output primitive type of the current geometry shader if any (not used otherwise).final SoMFNode
Specifies a list ofSoShaderParameterImage
nodes to use with this shader.final SoSFInt32
Set the maximum number of vertices the geometry shader will emit in one invocation.final SoSFInt32
Set the length of the fixed-size collection of vertices used by tessellation shaders.final SoMFNode
Specifies the list of shader objects (i.e., vertex shaders, geometry and fragment shaders) which form the shader program.final SoSFBool
Only used when anSoShadowGroup
is active.final SoSFBool
If set to true, vertex shaders will operate in two-sided color mode.Fields inherited from class com.openinventor.inventor.Inventor
VERBOSE_LEVEL, ZeroHandle
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddShaderParameterImage
(String name, SoTexture tex) Convenience method to create anSoShaderParameterImage
with the specified name and value and add it to this shader program.getFragmentShader
(int pos) Returns the fragment shader at the specified position.getGeometryShader
(int pos) Returns the geometry shader at the specified position.static int
Returns the number of reserved texture units.getTessellationControlShader
(int pos) Returns the tessellation control shader at the specified position.getTessellationEvaluationShader
(int pos) Returns the tessellation evaluation shader at the specified position.getVertexShader
(int pos) Returns the vertex shader at the specified position.setComputeShader
(int pos, String filenameOrSource) Calls setComputeShader(pos, filenameOrSource, SoShaderObject.SourceTypes.valueOf( SoShaderObject.SourceTypes.FILENAME.getValue() )).setComputeShader
(int pos, String filenameOrSource, SoShaderObject.SourceTypes sourceType) Convenience method to create a compute shader with the specified filename and add it at the specified position.setFragmentShader
(int pos, String filenameOrSource) Calls setFragmentShader(pos, filenameOrSource, SoShaderObject.SourceTypes.valueOf( SoShaderObject.SourceTypes.FILENAME.getValue() )).setFragmentShader
(int pos, String filenameOrSource, SoShaderObject.SourceTypes sourceType) Convenience method to create a fragment shader with the specified filename and add it at the specified position.setGeometryShader
(int pos, String filenameOrSource) Calls setGeometryShader(pos, filenameOrSource, SoShaderObject.SourceTypes.valueOf( SoShaderObject.SourceTypes.FILENAME.getValue() )).setGeometryShader
(int pos, String filenameOrSource, SoShaderObject.SourceTypes sourceType) Convenience method to create a geometry shader with the specified filename and add it at the specified position.setTessellationControlShader
(int pos, String filenameOrSource) Calls setTessellationControlShader(pos, filenameOrSource, SoShaderObject.SourceTypes.valueOf( SoShaderObject.SourceTypes.FILENAME.getValue() )).setTessellationControlShader
(int pos, String filenameOrSource, SoShaderObject.SourceTypes sourceType) Convenience method to create a tessellation control shader with the specified filename and add it at the specified position.setTessellationEvaluationShader
(int pos, String filenameOrSource) Calls setTessellationEvaluationShader(pos, filenameOrSource, SoShaderObject.SourceTypes.valueOf( SoShaderObject.SourceTypes.FILENAME.getValue() )).setTessellationEvaluationShader
(int pos, String filenameOrSource, SoShaderObject.SourceTypes sourceType) Convenience method to create a tessellation evaluation shader with the specified filename and add it at the specified position.setVertexShader
(int pos, String filenameOrSource) Calls setVertexShader(pos, filenameOrSource, SoShaderObject.SourceTypes.valueOf( SoShaderObject.SourceTypes.FILENAME.getValue() )).setVertexShader
(int pos, String filenameOrSource, SoShaderObject.SourceTypes sourceType) Convenience method to create a vertex shader with the specified filename and add it at the specified position.Methods inherited from class com.openinventor.inventor.nodes.SoNode
affectsState, callback, copy, copy, distribute, doAction, getAlternateRep, getBoundingBox, getByName, getMatrix, getPrimitiveCount, getRenderEngineMode, getRenderUnitID, GLRender, GLRenderBelowPath, GLRenderInPath, GLRenderOffPath, grabEventsCleanup, grabEventsSetup, handleEvent, isBoundingBoxIgnoring, isOverride, pick, rayPick, search, setOverride, touch, write
Methods inherited from class com.openinventor.inventor.fields.SoFieldContainer
copyFieldValues, copyFieldValues, enableNotify, fieldsAreEqual, get, getAllFields, getEventIn, getEventOut, getField, getFieldName, hasDefaultValues, isNotifyEnabled, set, setToDefaults
Methods inherited from class com.openinventor.inventor.misc.SoBase
dispose, getName, isDisposable, isSynchronizable, setName, setSynchronizable
Methods inherited from class com.openinventor.inventor.Inventor
getNativeResourceHandle
-
Field Details
-
shaderObject
Specifies the list of shader objects (i.e., vertex shaders, geometry and fragment shaders) which form the shader program. Be careful, with some languages (CG_PROGRAM or ARB_PROGRAM), only one vertex program and one fragment program can be active at the same time. In this case, only the first vertex shader and the first fragment shader are used. -
geometryInputType
Specifies the input primitive type of the current geometry shader if any (not used otherwise). Use enumGeometryInputType
. Default is TRIANGLES_INPUT.- Since:
- Open Inventor 7.0
-
geometryOutputType
Specifies the output primitive type of the current geometry shader if any (not used otherwise). Use enumGeometryOutputType
. Default is TRIANGLE_STRIP_OUTPUT.- Since:
- Open Inventor 7.0
-
vertexProgramTwoSide
If set to true, vertex shaders will operate in two-sided color mode. Default is false.- Since:
- Open Inventor 7.2
-
shadowShader
Only used when anSoShadowGroup
is active. Default is false. If set to false, a default shader will be used during the shadowmap generation pass. If true, the shader will be used as is and must handle the shadowmap pass correctly:- If the uniform OivShadowPass is true, call OivGenerateShadowMap() and output nothing into gl_FragColor, but discard fragments if needed.
- If the uniform OivShadowPass is false, follow the normal render path If the shader doesn't modify the depth (with a discard or an alpha test), Open Inventor will handle the shadowmap generation pass automatically. Default is false
See also:SoShadowGroup
- Since:
- Open Inventor 8.1
-
-
maxGeometryOutputVertices
Set the maximum number of vertices the geometry shader will emit in one invocation. Default is -1 which means it is set to the hardware limit.- Since:
- Open Inventor 8.1
-
generateTransparency
If set to true, then shapes affected by this shader will be considered transparent. Otherwise, the shape transparency is deducted from the state.This allows Open Inventor to apply the correct handling for the current transparency mode.
Default is false.
- Since:
- Open Inventor 9.0
-
patchLength
Set the length of the fixed-size collection of vertices used by tessellation shaders. Default is 0.- Since:
- Open Inventor 9.3
-
bufferObjects
Specifies a list ofSoShaderParameterBufferObject
to use with this shader. Default is empty.- Since:
- Open Inventor 9.8
-
images
Specifies a list ofSoShaderParameterImage
nodes to use with this shader. Default is empty.- Since:
- Open Inventor 10.10
Constructor Details
-
SoShaderProgram
public SoShaderProgram()Constructor.
Method Details
-
setFragmentShader
Calls setFragmentShader(pos, filenameOrSource, SoShaderObject.SourceTypes.valueOf( SoShaderObject.SourceTypes.FILENAME.getValue() )). -
setVertexShader
Calls setVertexShader(pos, filenameOrSource, SoShaderObject.SourceTypes.valueOf( SoShaderObject.SourceTypes.FILENAME.getValue() )). -
setTessellationControlShader
Calls setTessellationControlShader(pos, filenameOrSource, SoShaderObject.SourceTypes.valueOf( SoShaderObject.SourceTypes.FILENAME.getValue() )). -
setTessellationEvaluationShader
public SoTessellationEvaluationShader setTessellationEvaluationShader(int pos, String filenameOrSource) Calls setTessellationEvaluationShader(pos, filenameOrSource, SoShaderObject.SourceTypes.valueOf( SoShaderObject.SourceTypes.FILENAME.getValue() )). -
setGeometryShader
Calls setGeometryShader(pos, filenameOrSource, SoShaderObject.SourceTypes.valueOf( SoShaderObject.SourceTypes.FILENAME.getValue() )). -
setComputeShader
Calls setComputeShader(pos, filenameOrSource, SoShaderObject.SourceTypes.valueOf( SoShaderObject.SourceTypes.FILENAME.getValue() )). -
getNumReservedTextures
public static int getNumReservedTextures()Returns the number of reserved texture units. -
getTessellationEvaluationShader
Returns the tessellation evaluation shader at the specified position. -
getTessellationControlShader
Returns the tessellation control shader at the specified position. -
setComputeShader
public SoComputeShader setComputeShader(int pos, String filenameOrSource, SoShaderObject.SourceTypes sourceType) Convenience method to create a compute shader with the specified filename and add it at the specified position. Return value is the new compute shader. -
addShaderParameterImage
Convenience method to create anSoShaderParameterImage
with the specified name and value and add it to this shader program. -
setTessellationControlShader
public SoTessellationControlShader setTessellationControlShader(int pos, String filenameOrSource, SoShaderObject.SourceTypes sourceType) Convenience method to create a tessellation control shader with the specified filename and add it at the specified position. Return value is the new tessellation control shader. -
setTessellationEvaluationShader
public SoTessellationEvaluationShader setTessellationEvaluationShader(int pos, String filenameOrSource, SoShaderObject.SourceTypes sourceType) Convenience method to create a tessellation evaluation shader with the specified filename and add it at the specified position. Return value is the new tessellation evaluation shader. -
setGeometryShader
public SoGeometryShader setGeometryShader(int pos, String filenameOrSource, SoShaderObject.SourceTypes sourceType) Convenience method to create a geometry shader with the specified filename and add it at the specified position. Return value is the new geometry shader. -
getVertexShader
Returns the vertex shader at the specified position. -
getFragmentShader
Returns the fragment shader at the specified position. -
getGeometryShader
Returns the geometry shader at the specified position. -
setVertexShader
public SoVertexShader setVertexShader(int pos, String filenameOrSource, SoShaderObject.SourceTypes sourceType) Convenience method to create a vertex shader with the specified filename and add it at the specified position. Return value is the new vertex shader. -
setFragmentShader
public SoFragmentShader setFragmentShader(int pos, String filenameOrSource, SoShaderObject.SourceTypes sourceType) Convenience method to create a fragment shader with the specified filename and add it at the specified position. Return value is the new fragment shader.