Class SoShaderProgram
- java.lang.Object
-
- com.openinventor.inventor.Inventor
-
- com.openinventor.inventor.misc.SoBase
-
- com.openinventor.inventor.fields.SoFieldContainer
-
- com.openinventor.inventor.nodes.SoNode
-
- com.openinventor.inventor.nodes.SoShaderProgram
-
- All Implemented Interfaces:
SafeDisposable
- Direct Known Subclasses:
SoVolumeShader
public class SoShaderProgram extends SoNode
Shader program property node. This property node defines the complete shader program for all subsequent shapes. A shader program may contain any graphics pipeline stage defined by the derivatives of aSoShaderObject
. 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, anSoShaderParameter1i
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, anSoVertexShaderParameter1f
holds a set of floating point values and anSoVertexShaderParameter3f
holds a set ofSbVec3f
values.SoShaderProgram
has specialized subclasses for volume visualization. If you are using the VolumeViz extension, seeSoVolumeShader
andSoVolumeRenderingQuality
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 EXAMPLE 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: SoGLShaderProgramElementShaderAPI,
SoFragmentShader
,SoGeometryShader
,SoShaderObject
,SoTessellationControlShader
,SoTessellationEvaluationShader
,SoUniformShaderParameter
,SoVertexShader
,SoVertexShaderParameter
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SoShaderProgram.GeometryInputTypes
Geometry input type.static class
SoShaderProgram.GeometryOutputTypes
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
Fields Modifier and Type Field Description SoMFNode
bufferObjects
Specifies a list ofSoShaderParameterBufferObject
to use with this shader.SoSFBool
generateTransparency
If set to true, then shapes affected by this shader will be considered transparent.SoSFEnum<SoShaderProgram.GeometryInputTypes>
geometryInputType
Specifies the input primitive type of the current geometry shader if any (not used otherwise).SoSFEnum<SoShaderProgram.GeometryOutputTypes>
geometryOutputType
Specifies the output primitive type of the current geometry shader if any (not used otherwise).SoMFNode
images
Specifies a list ofSoShaderParameterImage
nodes to use with this shader.SoSFInt32
maxGeometryOutputVertices
Set the maximum number of vertices the geometry shader will emit in one invocation.SoSFInt32
patchLength
Set the length of the fixed-size collection of vertices used by tessellation shaders.SoMFNode
shaderObject
Specifies the list of shader objects (i.e., vertex shaders, geometry and fragment shaders) which form the shader program.SoSFBool
shadowShader
Only used when anSoShadowGroup
is active.SoSFBool
vertexProgramTwoSide
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 Constructor Description SoShaderProgram()
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description SoShaderParameterImage
addShaderParameterImage(java.lang.String name, SoTexture tex)
Convenience method to create anSoShaderParameterImage
with the specified name and value and add it to this shader program.SoFragmentShader
getFragmentShader(int pos)
Returns the fragment shader at the specified position.SoGeometryShader
getGeometryShader(int pos)
Returns the geometry shader at the specified position.static int
getNumReservedTextures()
Returns the number of reserved texture units.SoTessellationControlShader
getTessellationControlShader(int pos)
Returns the tessellation control shader at the specified position.SoTessellationEvaluationShader
getTessellationEvaluationShader(int pos)
Returns the tessellation evaluation shader at the specified position.SoVertexShader
getVertexShader(int pos)
Returns the vertex shader at the specified position.SoComputeShader
setComputeShader(int pos, java.lang.String filenameOrSource)
Calls setComputeShader(pos, filenameOrSource, SoShaderObject.SourceTypes.valueOf( SoShaderObject.SourceTypes.FILENAME.getValue() )).SoComputeShader
setComputeShader(int pos, java.lang.String filenameOrSource, SoShaderObject.SourceTypes sourceType)
Convenience method to create a compute shader with the specified filename and add it at the specified position.SoFragmentShader
setFragmentShader(int pos, java.lang.String filenameOrSource)
Calls setFragmentShader(pos, filenameOrSource, SoShaderObject.SourceTypes.valueOf( SoShaderObject.SourceTypes.FILENAME.getValue() )).SoFragmentShader
setFragmentShader(int pos, java.lang.String filenameOrSource, SoShaderObject.SourceTypes sourceType)
Convenience method to create a fragment shader with the specified filename and add it at the specified position.SoGeometryShader
setGeometryShader(int pos, java.lang.String filenameOrSource)
Calls setGeometryShader(pos, filenameOrSource, SoShaderObject.SourceTypes.valueOf( SoShaderObject.SourceTypes.FILENAME.getValue() )).SoGeometryShader
setGeometryShader(int pos, java.lang.String filenameOrSource, SoShaderObject.SourceTypes sourceType)
Convenience method to create a geometry shader with the specified filename and add it at the specified position.SoTessellationControlShader
setTessellationControlShader(int pos, java.lang.String filenameOrSource)
Calls setTessellationControlShader(pos, filenameOrSource, SoShaderObject.SourceTypes.valueOf( SoShaderObject.SourceTypes.FILENAME.getValue() )).SoTessellationControlShader
setTessellationControlShader(int pos, java.lang.String filenameOrSource, SoShaderObject.SourceTypes sourceType)
Convenience method to create a tessellation control shader with the specified filename and add it at the specified position.SoTessellationEvaluationShader
setTessellationEvaluationShader(int pos, java.lang.String filenameOrSource)
Calls setTessellationEvaluationShader(pos, filenameOrSource, SoShaderObject.SourceTypes.valueOf( SoShaderObject.SourceTypes.FILENAME.getValue() )).SoTessellationEvaluationShader
setTessellationEvaluationShader(int pos, java.lang.String filenameOrSource, SoShaderObject.SourceTypes sourceType)
Convenience method to create a tessellation evaluation shader with the specified filename and add it at the specified position.SoVertexShader
setVertexShader(int pos, java.lang.String filenameOrSource)
Calls setVertexShader(pos, filenameOrSource, SoShaderObject.SourceTypes.valueOf( SoShaderObject.SourceTypes.FILENAME.getValue() )).SoVertexShader
setVertexShader(int pos, java.lang.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 Detail
-
shaderObject
public final SoMFNode 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
public final SoSFEnum<SoShaderProgram.GeometryInputTypes> 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
public final SoSFEnum<SoShaderProgram.GeometryOutputTypes> 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
public final SoSFBool vertexProgramTwoSide
If set to true, vertex shaders will operate in two-sided color mode. Default is false.- Since:
- Open Inventor 7.2
-
shadowShader
public final SoSFBool 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
public final SoSFInt32 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
public final SoSFBool 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
public final SoSFInt32 patchLength
Set the length of the fixed-size collection of vertices used by tessellation shaders. Default is 0.- Since:
- Open Inventor 9.3
-
bufferObjects
public final SoMFNode bufferObjects
Specifies a list ofSoShaderParameterBufferObject
to use with this shader. Default is empty.- Since:
- Open Inventor 9.8
-
images
public final SoMFNode images
Specifies a list ofSoShaderParameterImage
nodes to use with this shader. Default is empty.- Since:
- Open Inventor 10.10
-
-
Method Detail
-
setFragmentShader
public SoFragmentShader setFragmentShader(int pos, java.lang.String filenameOrSource)
Calls setFragmentShader(pos, filenameOrSource, SoShaderObject.SourceTypes.valueOf( SoShaderObject.SourceTypes.FILENAME.getValue() )).
-
setVertexShader
public SoVertexShader setVertexShader(int pos, java.lang.String filenameOrSource)
Calls setVertexShader(pos, filenameOrSource, SoShaderObject.SourceTypes.valueOf( SoShaderObject.SourceTypes.FILENAME.getValue() )).
-
setTessellationControlShader
public SoTessellationControlShader setTessellationControlShader(int pos, java.lang.String filenameOrSource)
Calls setTessellationControlShader(pos, filenameOrSource, SoShaderObject.SourceTypes.valueOf( SoShaderObject.SourceTypes.FILENAME.getValue() )).
-
setTessellationEvaluationShader
public SoTessellationEvaluationShader setTessellationEvaluationShader(int pos, java.lang.String filenameOrSource)
Calls setTessellationEvaluationShader(pos, filenameOrSource, SoShaderObject.SourceTypes.valueOf( SoShaderObject.SourceTypes.FILENAME.getValue() )).
-
setGeometryShader
public SoGeometryShader setGeometryShader(int pos, java.lang.String filenameOrSource)
Calls setGeometryShader(pos, filenameOrSource, SoShaderObject.SourceTypes.valueOf( SoShaderObject.SourceTypes.FILENAME.getValue() )).
-
setComputeShader
public SoComputeShader setComputeShader(int pos, java.lang.String filenameOrSource)
Calls setComputeShader(pos, filenameOrSource, SoShaderObject.SourceTypes.valueOf( SoShaderObject.SourceTypes.FILENAME.getValue() )).
-
getNumReservedTextures
public static int getNumReservedTextures()
Returns the number of reserved texture units.
-
getTessellationEvaluationShader
public SoTessellationEvaluationShader getTessellationEvaluationShader(int pos)
Returns the tessellation evaluation shader at the specified position.
-
getTessellationControlShader
public SoTessellationControlShader getTessellationControlShader(int pos)
Returns the tessellation control shader at the specified position.
-
setComputeShader
public SoComputeShader setComputeShader(int pos, java.lang.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
public SoShaderParameterImage addShaderParameterImage(java.lang.String name, SoTexture tex)
Convenience method to create anSoShaderParameterImage
with the specified name and value and add it to this shader program.
-
setTessellationControlShader
public SoTessellationControlShader setTessellationControlShader(int pos, java.lang.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, java.lang.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, java.lang.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
public SoVertexShader getVertexShader(int pos)
Returns the vertex shader at the specified position.
-
getFragmentShader
public SoFragmentShader getFragmentShader(int pos)
Returns the fragment shader at the specified position.
-
getGeometryShader
public SoGeometryShader getGeometryShader(int pos)
Returns the geometry shader at the specified position.
-
setVertexShader
public SoVertexShader setVertexShader(int pos, java.lang.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, java.lang.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.
-