Class SoShaderObject
- All Implemented Interfaces:
SafeDisposable
- Direct Known Subclasses:
SoComputeShader
,SoFragmentShader
,SoGeometryShader
,SoTessellationControlShader
,SoTessellationEvaluationShader
,SoVertexShader
There are five types of shader objects that can be added to a shader program. Any of these stages can be user defined.
- Vertex shader
The vertex shader is executed once for each vertex (usually in parallel). The main purpose is to transform each vertex's 3D position from model space to projection space. Vertex shaders can manipulate properties such as position, color and texture coordinate, but cannot create new vertices. - Tessellation control shader
This shader accepts a list of vertices defined as a patch to control the amount of tessellation applied to the patch. Following the execution of this shader, a tessellator computes a set of triangles in a parametric space. - Tessellation evaluation shader
This shader is executed at least once for each vertex that was created by the tesselator in the parametric space. The TES takes the parametric coordinate and the patch data output by the TCS to generate a final position for the surface. - Geometry shader
The geometry shader acts on a complete primitive (triangle or line): it can modify existing primitives, it can insert (create) new primitives, it can remove (destroy) existing primitives. - Fragment shader
Fragment shaders compute color and other attributes of each fragment.
Note: Compute shaders are not part of the rendering pipeline. They represent a shader stage used entirely for computing arbitrary information.
Shader object nodes cannot be inserted directly in a scene graph. They must be added to the field shaderObject
of an SoShaderProgram
node.
A shader object is defined by the following properties:
- Source program, which is the shader's source code (see
sourceProgram
field), - Uniform parameters set by the application (see
parameter
field), - State (active or not) (see
isActive
field).
The source program can be specified either by a string containing the program source code, or by a filename which contains the program source code. How the sourceProgram field is interpreted depends on the field sourceType
.
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 parameters can be set through the parameter
field. 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, an SoShaderParameter1i
holds a single integer value. A uniform parameter has no effect if it is not valid, that is, if there is no corresponding name (identifier) in the GLSL source program. An SoShaderParameter1i
must be used for each texture sampler in order to specify the texture unit and texture sampler uniform parameter name pair.
A vertex shader can also use
vertex parameters, which 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, an SoVertexShaderParameter1f
holds a set of floating point values and an SoVertexShaderParameter3f
holds a set of SbVec3f
values. Vertex parameter nodes are property nodes (similar to materials or normals) and should be added directly in the scene graph, not in the shader object.
Tips:
- Set the environment variable OIV_GLSL_DEBUG to get the GLSL compile/link output in the console.
- 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 a shader source file without needing to restart your application after each shader modification.
File format/default:
This is an abstract class. See the reference page of a derived class for the format and default values.
Simple 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);
ShaderAPI, SoVertexShader
, SoGeometryShader
, SoFragmentShader
, SoShaderProgram
, SoShaderParameter
, SoUniformShaderParameter
, SoVertexShaderParameter
, SoTessellationControlShader
, SoTessellationEvaluationShader
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Type of the shader.static enum
Shader Object source type possible values.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 SoSFBool
Specifies if the shader object is active or not.Contains the shader's uniform parameters.final SoSFFilePathString
Contains the shader object's source program, specified by a filename (sourceType
set toFILENAME
) or by the string containing the program (sourceType
set toGLSL_PROGRAM
).Specifies the shader object's source type.Fields inherited from class com.openinventor.inventor.Inventor
VERBOSE_LEVEL, ZeroHandle
-
Method Summary
Modifier and TypeMethodDescriptionMust be redefined by derived class.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
-
isActive
Specifies if the shader object is active or not. -
sourceType
Specifies the shader object's source type. The type of source can be either a filename containing the program (FILENAME
), or a string containing the source program (GLSL_PROGRAM
). Use enumSourceType
. Default is FILENAME.NOTE: The source type must be specified before the source program (
sourceProgram
) is specified. -
sourceProgram
Contains the shader object's source program, specified by a filename (sourceType
set toFILENAME
) or by the string containing the program (sourceType
set toGLSL_PROGRAM
). If the filename is not an absolute path name, the list of directories maintained bySoInput
is searched. If the source program is not found in any of those directories, then the file is searched for relative to the directory from which theSoShaderObject
node was read.NOTE: The source type (
sourceType
) must be specified before the source program is specified. -
parameter
Contains the shader's uniform parameters.
-
-
Method Details
-
getShaderType
Must be redefined by derived class.
-