SoShaderObject Class Reference
[Shaders]

VSG extension Abstract node class which defines a shader object. More...

#include <Inventor/nodes/SoShaderObject.h>

Inheritance diagram for SoShaderObject:
SoNode SoFieldContainer SoBase SoRefCounter SoTypedObject SoFragmentShader SoGeometryShader SoTessellationControlShader SoTessellationEvaluationShader SoVertexShader

List of all members.

Public Types

enum  SourceType {
  ARB_PROGRAM,
  CG_PROGRAM,
  GLSL_PROGRAM,
  FILENAME
}
enum  ShaderType {
  VERTEX_SHADER,
  GEOMETRY_SHADER,
  FRAGMENT_SHADER,
  TESSELLATION_CONTROL_SHADER,
  TESSELLATION_EVALUATION_SHADER
}

Public Member Functions

virtual SoType getTypeId () const
template<typename UniformParamType , typename ParamValueType >
UniformParamType * addShaderParameter (const SbString &name, ParamValueType val)
virtual ShaderType getShaderType () const =0
template<typename UniformParamType , typename ParamValueType >
void setShaderParameter (const SbString &name, ParamValueType val)

Static Public Member Functions

static SoType getClassTypeId ()

Public Attributes

SoSFBool isActive
SoSFEnum sourceType
SoSFFilePathString sourceProgram
SoMFUniformShaderParameter parameter

Friends

class SoShaderProgram

Detailed Description

VSG extension Abstract node class which defines a shader object.

This abstract class is the parent of classes that define a vertex shader (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:

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:

NOTE 1: In case of Cg, the default profile used for the vertex shader is arbvp1, and arbfp1 for a fragment shader. The environment variables OIV_CG_VTX_PROFILE and OIV_CG_FRAG_PROFILE enable you to change the vertex and fragment profiles respectively. 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 SoShaderParameter parameter.

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

EXAMPLE

SEE ALSO

SoVertexShader, SoGeometryShader, SoFragmentShader, SoShaderProgram, SoShaderParameter, SoUniformShaderParameter, SoVertexShaderParameter, SoTessellationControlShader, SoTessellationEvaluationShader

See related examples:

ShadersBrowser, AnimatedFlag, GeometryShader, PixelLighting, shadowShader, TessellationShader, ToonShading


Member Enumeration Documentation

Type of the shader.

Enumerator:
VERTEX_SHADER 

The shader is a vertex shader.

GEOMETRY_SHADER 

The shader is a geometry shader.

FRAGMENT_SHADER 

The shader is a fragment shader.

TESSELLATION_CONTROL_SHADER 

The shader is a tessellation control shader.

TESSELLATION_EVALUATION_SHADER 

The shader is a tessellation evaluation shader.

Shader Object source type possible values.

Enumerator:
ARB_PROGRAM 

The source is an ARB vertex or fragment program.

CG_PROGRAM 

The source is a CG program.

GLSL_PROGRAM 

The source is an OpenGL Shading Language program.

FILENAME 

Only the name of the file containing the source is given (default).


Member Function Documentation

template<typename UniformParamType , typename ParamValueType >
UniformParamType * SoShaderObject::addShaderParameter ( const SbString name,
ParamValueType  val 
) [inline]

Convenience method to create an SoShaderUniformParameter with the specified name and value and add it to the given shader object.

UniformParamType is the type of parameter to add. This function also generates the following helper methods not visible in the documentation:

  • UniformParamType* addShaderParameter{1,2,3,4}i(const SbString&, ParamValueType)
  • UniformParamType* addShaderParameter{1,2,3,4}f(const SbString&, ParamValueType)
  • UniformParamType* addShaderParameterArray{1,2,3,4}i(const SbString&, ParamValueType)
  • UniformParamType* addShaderParameterArray{1,2,3,4}f(const SbString&, ParamValueType)
  • UniformParamType* addShaderParameterMatrix

These are template methods, so ParamValueType must have an operator= compatible with the field value of the corresponding SoShaderParameter (for example, addShaderParameter2f can take an SbVec2f as ParamValueType)

static SoType SoShaderObject::getClassTypeId (  )  [static]

Returns the type identifier for this class.

Reimplemented from SoNode.

Reimplemented in SoFragmentShader, SoGeometryShader, SoTessellationControlShader, SoTessellationEvaluationShader, and SoVertexShader.

virtual ShaderType SoShaderObject::getShaderType (  )  const [pure virtual]
virtual SoType SoShaderObject::getTypeId (  )  const [virtual]

Returns the type identifier for this specific instance.

Reimplemented from SoNode.

Reimplemented in SoFragmentShader, SoGeometryShader, SoTessellationControlShader, SoTessellationEvaluationShader, and SoVertexShader.

template<typename UniformParamType , typename ParamValueType >
void SoShaderObject::setShaderParameter ( const SbString name,
ParamValueType  val 
) [inline]

UniformParamType is the type of parameter to set.

This function also generates the following helper methods not visible in the documentation:

  • void setShaderParameter{1,2,3,4}i(const SbString&, ParamValueType)
  • void setShaderParameter{1,2,3,4}f(const SbString&, ParamValueType)
  • void setShaderParameterArray{1,2,3,4}i(const SbString&, ParamValueType)
  • void setShaderParameterArray{1,2,3,4}f(const SbString&, ParamValueType)
  • void setShaderParameterParameterMatrix

These are template methods, so ParamValueType must have an operator= compatible with the field value of the corresponding SoShaderParameter (for example, setShaderParameter2f can take an SbVec2f as ParamValueType).


Friends And Related Function Documentation

friend class SoShaderProgram [friend]

Member Data Documentation

Specifies if the shader object is active or not.

Contains the shader's uniform parameters.

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

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.

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 (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.


The documentation for this class was generated from the following file:

Open Inventor Toolkit reference manual, generated on 12 Feb 2024
Copyright © Thermo Fisher Scientific All rights reserved.
http://www.openinventor.com/