Click or drag to resize
SoShaderObject Class

Abstract node class which defines a shader object.

Inheritance Hierarchy

Namespace: OIV.Inventor.Nodes
Assembly: OIV.Inventor (in OIV.Inventor.dll) Version: 2023.1.3.0 (2023.1.3)
Syntax
public abstract class SoShaderObject : SoNode

The SoShaderObject type exposes the following members.

Methods
  NameDescription
Public methodAddShaderParameter(String, SbVec2f)
Public methodAddShaderParameter(String, SbVec2i32)
Public methodAddShaderParameter(String, SbVec3f)
Public methodAddShaderParameter(String, SbVec3i32)
Public methodAddShaderParameter(String, SbVec4f)
Public methodAddShaderParameter(String, SbVec4i32)
Public methodAddShaderParameter(String, Int32)
Public methodAddShaderParameter(String, Single)
Public methodAffectsState

Returns true if a node has an effect on the state during traversal.

(Inherited from SoNode.)
Public methodCallback
(Inherited from SoNode.)
Public methodCopy
Calls Copy(false).
(Inherited from SoNode.)
Public methodCopy(Boolean)

Creates and returns an exact copy of the node.

(Inherited from SoNode.)
Public methodCopyFieldValues(SoFieldContainer)
Calls CopyFieldValues(fc, false).
(Inherited from SoFieldContainer.)
Public methodCopyFieldValues(SoFieldContainer, Boolean)

Copies the contents of fc's fields into this object's fields.

(Inherited from SoFieldContainer.)
Public methodDispose
Releases all resources used by SoDisposable.
(Inherited from SoDisposable.)
Public methodDistribute
(Inherited from SoNode.)
Public methodDoAction
(Inherited from SoNode.)
Public methodEnableNotify

Notification at this Field Container is enabled (if flag == true) or disabled (if flag == false).

(Inherited from SoFieldContainer.)
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Public methodFieldsAreEqual

Returns true if this object's fields are exactly equal to fc's fields.

(Inherited from SoFieldContainer.)
Public methodGet

Returns the values of the fields of this object in the Open Inventor ASCII file format in the given string.

(Inherited from SoFieldContainer.)
Public methodGetAllFields

Returns a list of fields, including the eventIn's and eventOut's.

(Inherited from SoFieldContainer.)
Public methodGetAlternateRep

This method is called by actions to allow the node to provide an "alternate representation" when appropriate (typically depending on the action type).

(Inherited from SoNode.)
Public methodGetBoundingBox
(Inherited from SoNode.)
Public methodGetEventIn

Returns a the eventIn with the given name.

(Inherited from SoFieldContainer.)
Public methodGetEventOut

Returns the eventOut with the given name.

(Inherited from SoFieldContainer.)
Public methodGetField

Returns a the field of this object whose name is fieldName.

(Inherited from SoFieldContainer.)
Public methodGetFieldName

Returns the name of the given field in the fieldName argument.

(Inherited from SoFieldContainer.)
Public methodGetFields

Appends references to all of this object's fields to resultList, and returns the number of fields appended.

(Inherited from SoFieldContainer.)
Public methodGetHashCode
Overrides GetHashCode().
(Inherited from SoNetBase.)
Public methodGetMatrix
(Inherited from SoNode.)
Public methodGetName

Returns the name of an instance.

(Inherited from SoBase.)
Public methodGetPrimitiveCount
(Inherited from SoNode.)
Public methodGetRenderEngineMode

Returns the supported Render engine mode.

(Inherited from SoNode.)
Public methodGetRenderUnitID
(Inherited from SoNode.)
Public methodGetShaderType

Must be redefined by derived class.

Public methodGetStringName (Inherited from SoBase.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodGLRender
(Inherited from SoNode.)
Public methodGLRenderBelowPath
(Inherited from SoNode.)
Public methodGLRenderInPath
(Inherited from SoNode.)
Public methodGLRenderOffPath
(Inherited from SoNode.)
Public methodGrabEventsCleanup
(Inherited from SoNode.)
Public methodGrabEventsSetup
(Inherited from SoNode.)
Public methodHandleEvent
(Inherited from SoNode.)
Public methodHasDefaultValues

Returns true if all of the object's fields have their default values.

(Inherited from SoFieldContainer.)
Public methodIsBoundingBoxIgnoring

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.

(Inherited from SoNode.)
Public methodIsNotifyEnabled

Notification is the process of telling interested objects that this object has changed.

(Inherited from SoFieldContainer.)
Public methodIsOverride

Returns the state of the override flag.

(Inherited from SoNode.)
Public methodIsSynchronizable

Gets the ScaleViz synchronizable state of this object.

(Inherited from SoBase.)
Public methodPick
(Inherited from SoNode.)
Public methodRayPick
(Inherited from SoNode.)
Public methodSearch
(Inherited from SoNode.)
Public methodSet

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.

(Inherited from SoFieldContainer.)
Public methodSetName (Inherited from SoBase.)
Public methodSetOverride

Turns the override flag on or off.

(Inherited from SoNode.)
Public methodSetShaderParameter(String, SbVec2f)
Public methodSetShaderParameter(String, SbVec2i32)
Public methodSetShaderParameter(String, SbVec3f)
Public methodSetShaderParameter(String, SbVec3i32)
Public methodSetShaderParameter(String, SbVec4f)
Public methodSetShaderParameter(String, SbVec4i32)
Public methodSetShaderParameter(String, Int32)
Public methodSetShaderParameter(String, Single)
Public methodSetSynchronizable

Sets this to be a ScaleViz synchronizable object.

(Inherited from SoBase.)
Public methodSetToDefaults

Sets all fields in this object to their default values.

(Inherited from SoFieldContainer.)
Public methodToString
Converts this SoBase structure to a human readable string.
(Inherited from SoBase.)
Public methodTouch

Marks an instance as modified, simulating a change to it.

(Inherited from SoNode.)
Public methodWrite
(Inherited from SoNode.)
Top
Properties
  NameDescription
Public propertyisActive

Specifies if the shader object is active or not.

Public propertyIsDisposable
ISafeDisposable interface implementation.
(Inherited from SoDisposable.)
Public propertyparameter

Contains the shader's uniform parameters.

Public propertysourceProgram
Public propertysourceType

Specifies the shader object's source type.

Public propertyUserData
Gets or sets the user data to be contained by the field container.
(Inherited from SoFieldContainer.)
Top
Remarks

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:

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.

FILE FORMAT/DEFAULT

This is an abstract class. See the reference page of a derived class for the format and default values.

EXAMPLE

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);

See Also
Inheritance Hierarchy
SystemObject
  OIV.InventorSoNetBase
    OIV.InventorSoDisposable
      OIV.Inventor.MiscSoBase
        OIV.Inventor.FieldsSoFieldContainer
          OIV.Inventor.NodesSoNode
            OIV.Inventor.NodesSoShaderObject
              OIV.Inventor.NodesSoComputeShader
              OIV.Inventor.NodesSoFragmentShader
              OIV.Inventor.NodesSoGeometryShader
              OIV.Inventor.NodesSoTessellationControlShader
              OIV.Inventor.NodesSoTessellationEvaluationShader
              OIV.Inventor.NodesSoVertexShader