SoShaderObject Class |
Abstract node class which defines a shader object.
Namespace: OIV.Inventor.Nodes
The SoShaderObject type exposes the following members.
Name | Description | |
---|---|---|
AddShaderParameter(String, SbVec2f) | ||
AddShaderParameter(String, SbVec2i32) | ||
AddShaderParameter(String, SbVec3f) | ||
AddShaderParameter(String, SbVec3i32) | ||
AddShaderParameter(String, SbVec4f) | ||
AddShaderParameter(String, SbVec4i32) | ||
AddShaderParameter(String, Int32) | ||
AddShaderParameter(String, Single) | ||
AffectsState | Returns true if a node has an effect on the state during traversal. | |
Callback | (Inherited from SoNode.) | |
Copy | Calls Copy(false). (Inherited from SoNode.) | |
Copy(Boolean) | Creates and returns an exact copy of the node. | |
CopyFieldValues(SoFieldContainer) | Calls CopyFieldValues(fc, false). (Inherited from SoFieldContainer.) | |
CopyFieldValues(SoFieldContainer, Boolean) | Copies the contents of fc's fields into this object's fields. | |
Dispose |
Releases all resources used by SoDisposable.
(Inherited from SoDisposable.) | |
Distribute | (Inherited from SoNode.) | |
DoAction | (Inherited from SoNode.) | |
EnableNotify | Notification at this Field Container is enabled (if flag == true) or disabled (if flag == false). | |
Equals | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) | |
FieldsAreEqual | Returns true if this object's fields are exactly equal to fc's fields. | |
Get | Returns the values of the fields of this object in the Open Inventor ASCII file format in the given string. | |
GetAllFields | Returns a list of fields, including the eventIn's and eventOut's. | |
GetAlternateRep | This method is called by actions to allow the node to provide an "alternate representation" when appropriate (typically depending on the action type). | |
GetBoundingBox | (Inherited from SoNode.) | |
GetEventIn | Returns a the eventIn with the given name. | |
GetEventOut | Returns the eventOut with the given name. | |
GetField | Returns a the field of this object whose name is fieldName. | |
GetFieldName | Returns the name of the given field in the fieldName argument. | |
GetFields | Appends references to all of this object's fields to resultList, and returns the number of fields appended. | |
GetHashCode |
Overrides GetHashCode().
(Inherited from SoNetBase.) | |
GetMatrix | (Inherited from SoNode.) | |
GetName | Returns the name of an instance. | |
GetPrimitiveCount | (Inherited from SoNode.) | |
GetRenderEngineMode | Returns the supported Render engine mode. | |
GetRenderUnitID | (Inherited from SoNode.) | |
GetShaderType | Must be redefined by derived class. | |
GetStringName | (Inherited from SoBase.) | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
GLRender | (Inherited from SoNode.) | |
GLRenderBelowPath | (Inherited from SoNode.) | |
GLRenderInPath | (Inherited from SoNode.) | |
GLRenderOffPath | (Inherited from SoNode.) | |
GrabEventsCleanup | (Inherited from SoNode.) | |
GrabEventsSetup | (Inherited from SoNode.) | |
HandleEvent | (Inherited from SoNode.) | |
HasDefaultValues | Returns true if all of the object's fields have their default values. | |
IsBoundingBoxIgnoring | This method is used by getBoundingBox action traversal to know if the current node must be traversed or not, ie the bounding should be ignored. | |
IsNotifyEnabled | Notification is the process of telling interested objects that this object has changed. | |
IsOverride | Returns the state of the override flag. | |
IsSynchronizable | Gets the ScaleViz synchronizable state of this object. | |
Pick | (Inherited from SoNode.) | |
RayPick | (Inherited from SoNode.) | |
Search | (Inherited from SoNode.) | |
Set | Sets one or more fields in this object to the values specified in the given string, which should be a string in the Open Inventor file format. | |
SetName | (Inherited from SoBase.) | |
SetOverride | Turns the override flag on or off. | |
SetShaderParameter(String, SbVec2f) | ||
SetShaderParameter(String, SbVec2i32) | ||
SetShaderParameter(String, SbVec3f) | ||
SetShaderParameter(String, SbVec3i32) | ||
SetShaderParameter(String, SbVec4f) | ||
SetShaderParameter(String, SbVec4i32) | ||
SetShaderParameter(String, Int32) | ||
SetShaderParameter(String, Single) | ||
SetSynchronizable | Sets this to be a ScaleViz synchronizable object. | |
SetToDefaults | Sets all fields in this object to their default values. | |
ToString |
Converts this SoBase structure to a human readable string.
(Inherited from SoBase.) | |
Touch | Marks an instance as modified, simulating a change to it. | |
Write | (Inherited from SoNode.) |
Name | Description | |
---|---|---|
isActive | Specifies if the shader object is active or not. | |
IsDisposable | ISafeDisposable interface implementation.
(Inherited from SoDisposable.) | |
parameter | Contains the shader's uniform parameters. | |
sourceProgram | Contains the shader object's source program, specified by a filename (OIV.Inventor.Nodes.SoShaderObject.sourceType set to OIV.Inventor.Nodes.SoShaderObject.SourceTypes.FILENAME) or by the string containing the program (OIV.Inventor.Nodes.SoShaderObject.sourceType set to OIV.Inventor.Nodes.SoShaderObject.SourceTypes.ARB_PROGRAM, OIV.Inventor.Nodes.SoShaderObject.SourceTypes.CG_PROGRAM, or OIV.Inventor.Nodes.SoShaderObject.SourceTypes.GLSL_PROGRAM). | |
sourceType | Specifies the shader object's source type. | |
UserData |
Gets or sets the user data to be contained by the field container.
(Inherited from SoFieldContainer.) |
This abstract class is the parent of classes that define a vertex shader (OIV.Inventor.Nodes.SoVertexShader), a geometry shader (OIV.Inventor.Nodes.SoGeometryShader), a fragment shader (OIV.Inventor.Nodes.SoFragmentShader), a tessellation control shader (OIV.Inventor.Nodes.SoTessellationControlShader) or a tessellation evaluation shader (OIV.Inventor.Nodes.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.
Vertex shader The vertex shader is executed once for each vertex (usually in parallel). The purpose is to transform each vertex's 3D position in virtual space to the 2D coordinate at which it appears on the screen (as well as a depth value for the Z-buffer). 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 defining a patch from the vertex shader and controls the amount of tessellation applied to the patch. Following execution of this shader, a fixed tesselator 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.
Shader object nodes cannot be inserted directly in a scene graph. They must be added to the shaderObject field of an OIV.Inventor.Nodes.SoShaderProgram node.
A shader object is defined by the following properties:
Source program, which is the shader's source code (see OIV.Inventor.Nodes.SoShaderObject.sourceProgram field),
Uniform parameters set by the application (see OIV.Inventor.Nodes.SoShaderObject.parameter field),
State (active or not) (see OIV.Inventor.Nodes.SoShaderObject.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 OIV.Inventor.Nodes.SoShaderObject.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 OIV.Inventor.Nodes.SoShaderObject.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 OIV.Inventor.Nodes.SoUniformShaderParameter. For example, an OIV.Inventor.Nodes.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 OIV.Inventor.Nodes.SoVertexShaderParameter. For example, an OIV.Inventor.Nodes.SoVertexShaderParameter1f holds a set of floating point values and an OIV.Inventor.Nodes.SoVertexShaderParameter3f holds a set of OIV.Inventor.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:
When using GLSL shaders, 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.
NOTE 1: In case of Cg, the default profile used for the vertex shader is arbvp1, and arbfp1 for a fragment shader. However, we advise users to use the default profile because it enables you to retrieve the OpenGL state directly in your vertex/fragment program instead of passing the OpenGL state as uniform parameters, which could be inefficient in terms of performance.
NOTE 2: With NVIDIA Cg and ARB_vertex_program/ARB_fragment_program, a texture sampler can be retrieved in your fragment program without specifying any OIV.Inventor.Nodes.SoShaderParameter parameter.
With ARB_vertex_program/ARB_fragment_program, texture[i] corresponds to the texture sampler of unit i.
With NVIDIA Cg, the first texture sampler parameter in your fragment program corresponds to the texture sampler of the texture unit 0, the second texture sampler parameter to the texture sampler of the texture unit 1, and so on. Example:
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 ...
With GLSL, an OIV.Inventor.Nodes.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.
Vertex programs replace the following parts of the OpenGL graphics pipeline:
Vertex transformation,
Normal transformation normalization and rescaling,
Lighting,
Color material application,
Clamping of colors,
Texture coordinate generation,
Texture coordinate transformation.
But do not replace:
Perspective divide and viewport mapping,
Frustum and user clipping,
Backface culling,
Primitive assembly,
Two sided lighting selection,
Polygon offset,
Polygon mode.
Fragment programs replace the following parts of the OpenGL graphics pipeline:
Operations on interpolated values,
Pixel zoom,
Texture access,
Scale and bias,
Texture application,
Color table lookup,
Fog convolution,
Color sum,
Color matrix.
But do not replace:
Shading model,
Histogram,
Coverage,
Minmax,
Pixel ownership test,
Pixel packing and unpacking,
Scissor,
Stipple,
Alpha test,
Depth test,
Stencil test,
Alpha blending,
Logical ops,
Dithering,
Plane masking.
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:
SoFragmentShader fragmentShader = new SoFragmentShader(); fragmentShader.sourceProgram.Value = "filename.glsl"; SoShaderParameter1i parameter = new SoShaderParameter1i(); parameter.name.Value = "data1"; parameter.value.Value = 1; fragmentShader.parameter[0] = parameter; SoShaderProgram shaderProgram = new SoShaderProgram(); shaderProgram.shaderObject[0] = fragmentShader; root.AddChild(shaderProgram);