public abstract class SoShaderObject extends SoNode
SoVertexShader
), a geometry shader (SoGeometryShader
), a fragment shader (SoFragmentShader
), a tessellation control shader (SoTessellationControlShader
) or a tessellation evaluation shader (SoTessellationEvaluationShader
) program. (Tessellation shaders are supported since Open Inventor 9.3)
There are five types of shaders that may be executed (in this order) in the rendering pipeline. Any one or all of these stages may be replaced by an application defined shader program.
Shader object nodes cannot be inserted directly in a scene graph. They must be added to the
shaderObject field of an SoShaderProgram
node.
A shader object is defined by the following properties:
sourceProgram
field),
parameter
field),
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 shading languages accepted for the source program are OpenGL Shader Language (GLSL) , Cg from NVIDIA (see NOTE 1) and assembly language ( ARB_vertex_program, ARB_fragment_program). Generally GLSL is recommended because it works on any OpenGL hardware and is much higher level than the ARB commands.
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 CG/GLSL (ARB) source program. See NOTE 2 for info on retrieving a texture sampler uniform parameter within a GLSL program, an NVIDIA Cg fragment program, or an ARB_vertex_program/ARB_fragment_program program.
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:
SoShaderParameter
parameter.
void main(// Inputs Input IN, uniform sampler2D rampDiffuse, // Texture sampler 2D of the texture unit 0 uniform sampler2D rampSpecular, // Texture sampler 2D of the texture unit 1 uniform sampler2D rampEdge, // Texture sampler 2D of the texture unit 2 ...
SoShaderParameter1i
must used for each texture sampler in order to specify the texture unit and texture sampler uniform parameter name pair.
NOTE 3: With Cg and ARB languages, at least the ARB_vertex_program and ARB_fragment_program, and with GLSL, at least GL_ARB_vertex_shader, GL_ARB_fragment_shader, and GL_ARB_shader_objects OpenGL extensions must be supported by your graphics board in order to be able to define a vertex shader and a fragment shader respectively. Otherwise no shader program will be executed.
NOTE 4: You should keep in mind that vertex and fragment programs modify the standard OpenGL pipeline.
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);
See also:
SoVertexShader
, SoGeometryShader
, SoFragmentShader
, SoShaderProgram
, SoShaderParameter
, SoUniformShaderParameter
, SoVertexShaderParameter
, SoTessellationControlShader
, SoTessellationEvaluationShader
Modifier and Type | Class and Description |
---|---|
static class |
SoShaderObject.ShaderTypes
Type of the shader.
|
static class |
SoShaderObject.SourceTypes
Shader Object source type possible values.
|
Inventor.ConstructorCommand
Modifier and Type | Field and Description |
---|---|
static int |
ARB_PROGRAM
Deprecated.
Use
SoShaderObject.SourceTypes.ARB_PROGRAM instead. |
static int |
CG_PROGRAM
Deprecated.
Use
SoShaderObject.SourceTypes.CG_PROGRAM instead. |
static int |
FILENAME
Deprecated.
Use
SoShaderObject.SourceTypes.FILENAME instead. |
static int |
FRAGMENT_SHADER
Deprecated.
Use
SoShaderObject.ShaderTypes.FRAGMENT_SHADER instead. |
static int |
GEOMETRY_SHADER
Deprecated.
Use
SoShaderObject.ShaderTypes.GEOMETRY_SHADER instead. |
static int |
GLSL_PROGRAM
Deprecated.
Use
SoShaderObject.SourceTypes.GLSL_PROGRAM instead. |
SoSFBool |
isActive
Specifies if the shader object is active or not.
|
SoMFUniformShaderParameter |
parameter
Contains the shader's uniform parameters.
|
SoSFFilePathString |
sourceProgram
Contains the shader object's source program, specified by a filename (
sourceType set to FILENAME ) or by the string containing the program (sourceType set to ARB_PROGRAM , CG_PROGRAM , or GLSL_PROGRAM ). |
SoSFEnum<SoShaderObject.SourceTypes> |
sourceType
Specifies the shader object's source type.
|
static int |
TESSELLATION_CONTROL_SHADER
Deprecated.
|
static int |
TESSELLATION_EVALUATION_SHADER
Deprecated.
|
static int |
VERTEX_SHADER
Deprecated.
Use
SoShaderObject.ShaderTypes.VERTEX_SHADER instead. |
VERBOSE_LEVEL, ZeroHandle
Modifier and Type | Method and Description |
---|---|
SoShaderObject.ShaderTypes |
getShaderType()
Must be redefined by derived class.
|
affectsState, callback, copy, copy, distribute, doAction, getAlternateRep, getBoundingBox, getByName, getMatrix, getPrimitiveCount, getRenderUnitID, GLRender, GLRenderBelowPath, GLRenderInPath, GLRenderOffPath, grabEventsCleanup, grabEventsSetup, handleEvent, isBoundingBoxIgnoring, isOverride, pick, rayPick, search, setOverride, touch, write
copyFieldValues, copyFieldValues, enableNotify, fieldsAreEqual, get, getAllFields, getEventIn, getEventOut, getField, getFieldName, hasDefaultValues, isNotifyEnabled, set, setToDefaults
dispose, getEXTERNPROTO, getName, getPROTO, isDisposable, isSynchronizable, setName, setSynchronizable
getAddress, getNativeResourceHandle, startInternalThreads, stopInternalThreads
@Deprecated public static final int ARB_PROGRAM
SoShaderObject.SourceTypes.ARB_PROGRAM
instead.@Deprecated public static final int CG_PROGRAM
SoShaderObject.SourceTypes.CG_PROGRAM
instead.@Deprecated public static final int GLSL_PROGRAM
SoShaderObject.SourceTypes.GLSL_PROGRAM
instead.@Deprecated public static final int FILENAME
SoShaderObject.SourceTypes.FILENAME
instead.@Deprecated public static final int VERTEX_SHADER
SoShaderObject.ShaderTypes.VERTEX_SHADER
instead.@Deprecated public static final int GEOMETRY_SHADER
SoShaderObject.ShaderTypes.GEOMETRY_SHADER
instead.@Deprecated public static final int FRAGMENT_SHADER
SoShaderObject.ShaderTypes.FRAGMENT_SHADER
instead.@Deprecated public static final int TESSELLATION_CONTROL_SHADER
SoShaderObject.ShaderTypes.TESSELLATION_CONTROL_SHADER
instead.@Deprecated public static final int TESSELLATION_EVALUATION_SHADER
SoShaderObject.ShaderTypes.TESSELLATION_EVALUATION_SHADER
instead.public final SoSFBool isActive
public final SoSFEnum<SoShaderObject.SourceTypes> sourceType
FILENAME
), or a string containing the source program (ARB_PROGRAM
, CG_PROGRAM
, or GLSL_PROGRAM
). Use enum SourceType
. Defaule is FILENAME.
NOTE: The source type must be specified before the source program (sourceProgram
) is specified.
public final SoSFFilePathString sourceProgram
sourceType
set to FILENAME
) or by the string containing the program (sourceType
set to ARB_PROGRAM
, CG_PROGRAM
, or GLSL_PROGRAM
).
If the filename is not an absolute path name, the list of directories maintained by SoInput
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 the SoShaderObject
node was read.
NOTE: The source type (sourceType
) must be specified before the source program is specified.
public final SoMFUniformShaderParameter parameter
public SoShaderObject.ShaderTypes getShaderType()
Generated on January 23, 2025, Copyright © Thermo Fisher Scientific. All rights reserved. http://www.openinventor.com