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 complete shader program may contain vertex shaders (SoVertexShader), geometry shaders (SoGeometryShader) and/or fragment shaders (SoFragmentShaders). SeeSoShaderObjectfor information common to all these classes.With some languages such as NVIDIA Cg or assembly language (ARB_vertex_program/ARB_fragment_program), only one vertex and one fragment program can be active at the same time. The field
shaderObjectcontains the vertex, geometry and fragment shader objects which form the shader program. Each shader object should be of typeSoShaderObject. Modifications that occur in shader objects are dynamically detected and the state is updated.Uniform parameters may be set for each shader object. Uniform means, in the case of a vertex or geometry program, a value which is the same for all vertices in a primitive, and, in the case of a fragment program, a value which is the same for all fragments created by a primitive. Each uniform parameter is represented by an instance of a specific subclass of
SoUniformShaderParameter. For example, anSoShaderParameter1iholds a single integer value.Vertex parameters may be set for a vertex shader object. Vertex parameters are per-vertex data passed from the application to the vertex shader. Vertex parameters are represented by an instance of a specific subclass of
SoVertexShaderParameter. For example, anSoVertexShaderParameter1fholds a set of floating point values and anSoVertexShaderParameter3fholds a set ofSbVec3fvalues.SoShaderProgramhas specialized subclasses for volume visualization. If you are using the VolumeViz extension, seeSoVolumeShaderandSoVolumeRenderingQualitynodes.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.
 - Since Open Inventor 10.0, 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/how-to-write-shaders-with-oiv-10/#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,SoGetPrimitiveCountActionandSoRayPickAction. 
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 
generateTransparencyfield 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 a comment directive. This provides greater flexibility in implementing complex GLSL shaders. Included files are loaded using 
SoInputand respect the same search path order. For example:
File format/default://!oiv_include <MyShaderDirectory/common.h>  
shaderObjectNULL geometryInputTypeTRIANGLES_INPUT geometryOutputTypeTRIANGLE_STRIP_OUTPUT vertexProgramTwoSidefalse shadowShaderfalse maxGeometryOutputVertices-1 generateTransparencyfalse patchLength0 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: SoGLShaderProgramElement 
- 
- 
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSoShaderProgram.GeometryInputTypesGeometry input type.static classSoShaderProgram.GeometryOutputTypesGeometry 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 SoMFNodebufferObjectsSpecifies a list ofSoShaderParameterBufferObjectto use with this shader.SoSFBoolgenerateTransparencyIf set to true, then shapes affected by this shader will be considered transparent.SoSFEnum<SoShaderProgram.GeometryInputTypes>geometryInputTypeSpecifies the input primitive type of the current geometry shader if any (not used otherwise).SoSFEnum<SoShaderProgram.GeometryOutputTypes>geometryOutputTypeSpecifies the output primitive type of the current geometry shader if any (not used otherwise).SoMFNodeimagesSpecifies a list ofSoShaderParameterImagenodes to use with this shader.SoSFInt32maxGeometryOutputVerticesSet the maximum number of vertices the geometry shader will emit in one invocation.SoSFInt32patchLengthSet the length of the fixed-size collection of vertices used by tessellation shaders.SoMFNodeshaderObjectSpecifies the list of shader objects (i.e., vertex shaders, geometry and fragment shaders) which form the shader program.SoSFBoolshadowShaderOnly used when anSoShadowGroupis active.SoSFBoolvertexProgramTwoSideIf 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 SoShaderParameterImageaddShaderParameterImage(java.lang.String name, SoTexture tex)Convenience method to create anSoShaderParameterImagewith the specified name and value and add it to this shader program.SoFragmentShadergetFragmentShader(int pos)Returns the fragment shader at the specified position.SoGeometryShadergetGeometryShader(int pos)Returns the geometry shader at the specified position.static intgetNumReservedTextures()Returns the number of reserved texture units.SoTessellationControlShadergetTessellationControlShader(int pos)Returns the tessellation control shader at the specified position.SoTessellationEvaluationShadergetTessellationEvaluationShader(int pos)Returns the tessellation evaluation shader at the specified position.SoVertexShadergetVertexShader(int pos)Returns the vertex shader at the specified position.SoComputeShadersetComputeShader(int pos, java.lang.String filenameOrSource)Calls setComputeShader(pos, filenameOrSource, SoShaderObject.SourceTypes.valueOf( SoShaderObject.SourceTypes.FILENAME.getValue() )).SoComputeShadersetComputeShader(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.SoFragmentShadersetFragmentShader(int pos, java.lang.String filenameOrSource)Calls setFragmentShader(pos, filenameOrSource, SoShaderObject.SourceTypes.valueOf( SoShaderObject.SourceTypes.FILENAME.getValue() )).SoFragmentShadersetFragmentShader(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.SoGeometryShadersetGeometryShader(int pos, java.lang.String filenameOrSource)Calls setGeometryShader(pos, filenameOrSource, SoShaderObject.SourceTypes.valueOf( SoShaderObject.SourceTypes.FILENAME.getValue() )).SoGeometryShadersetGeometryShader(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.SoTessellationControlShadersetTessellationControlShader(int pos, java.lang.String filenameOrSource)Calls setTessellationControlShader(pos, filenameOrSource, SoShaderObject.SourceTypes.valueOf( SoShaderObject.SourceTypes.FILENAME.getValue() )).SoTessellationControlShadersetTessellationControlShader(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.SoTessellationEvaluationShadersetTessellationEvaluationShader(int pos, java.lang.String filenameOrSource)Calls setTessellationEvaluationShader(pos, filenameOrSource, SoShaderObject.SourceTypes.valueOf( SoShaderObject.SourceTypes.FILENAME.getValue() )).SoTessellationEvaluationShadersetTessellationEvaluationShader(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.SoVertexShadersetVertexShader(int pos, java.lang.String filenameOrSource)Calls setVertexShader(pos, filenameOrSource, SoShaderObject.SourceTypes.valueOf( SoShaderObject.SourceTypes.FILENAME.getValue() )).SoVertexShadersetVertexShader(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 anSoShadowGroupis 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 ofSoShaderParameterBufferObjectto use with this shader. Default is empty.- Since:
 - Open Inventor 9.8
 
 
- 
images
public final SoMFNode images
Specifies a list ofSoShaderParameterImagenodes 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 anSoShaderParameterImagewith 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. 
 -