Class SoShaderProgram

  • All Implemented Interfaces:
    SafeDisposable
    Direct Known Subclasses:
    SoVolumeShader

    public class SoShaderProgram
    extends SoNode
    Shader program property node. This property node defines the complete shader program for all subsequent shapes. A shader program may contain any graphics pipeline stage defined by the derivatives of a SoShaderObject. These stage programs are stored in the field shaderObject. Any Modifications that occur in the shader objects are dynamically detected and the state is updated.

    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 shader parameters can be set per shader object and are available for all pipeline stages of the shader program. Uniform means a constant value during the shader execution. A uniform parameter is represented by an instance of a specific subclass of SoUniformShaderParameter. For example, an SoShaderParameter1i holds a single integer value.

    Vertex parameters can be accessible from a vertex shader object. Vertex parameters are per-vertex data passed from the application to the vertex shader. A vertex parameter is 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.

    SoShaderProgram has specialized subclasses for volume visualization. If you are using the VolumeViz extension, see SoVolumeShader and SoVolumeRenderingQuality nodes.

    Notes:

    Tips:

    • To see the output from the GLSL compiler/linker, set the environment variable OIV_GLSL_DEBUG.
    • 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 the shader source code without needing to restart your application after each shader modification.
    • If your shader makes geometry transparent (sets alpha values < 1), you should set the generateTransparency field to true. This ensures that Open Inventor knows to apply the correct handling for the current transparency mode.
    • Since the GLSL specification doesn't currently provide a "#include" directive, Open Inventor provides this service through the comment directive "//!oiv_include". This provides greater flexibility in implementing complex GLSL shaders. Included files are loaded using SoInput and respect the same search path order. For example:

       //!oiv_include <MyShaderDirectory/common.h>

      File format/default:

    SoShaderProgram {

    }

    EXAMPLE

    Shader program with one 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);

    Action behavior:

    SoGLRenderAction
    Sets the Open Inventor state with the active shader program. Sets: SoGLShaderProgramElement

    ShaderAPI, SoFragmentShader, SoGeometryShader, SoShaderObject, SoTessellationControlShader, SoTessellationEvaluationShader, SoUniformShaderParameter, SoVertexShader, SoVertexShaderParameter

    • Field Detail

      • shaderObject

        public final SoMFNode shaderObject
        Specifies the list of shader objects (i.e., vertex shaders, geometry and fragment shaders) which form the shader program. Be careful, with some languages (CG_PROGRAM or ARB_PROGRAM), only one vertex program and one fragment program can be active at the same time. In this case, only the first vertex shader and the first fragment shader are used.
      • vertexProgramTwoSide

        public final SoSFBool vertexProgramTwoSide
        If set to true, vertex shaders will operate in two-sided color mode. Default is false.

        Since:
        Open Inventor 7.2

      • shadowShader

        public final SoSFBool shadowShader
        Only used when an SoShadowGroup is active. Default is false. If set to false, a default shader will be used during the shadowmap generation pass. If true, the shader will be used as is and must handle the shadowmap pass correctly:
        • If the uniform OivShadowPass is true, call OivGenerateShadowMap() and output nothing into gl_FragColor, but discard fragments if needed.
        • If the uniform OivShadowPass is false, follow the normal render path If the shader doesn't modify the depth (with a discard or an alpha test), Open Inventor will handle the shadowmap generation pass automatically. Default is false
          See also: SoShadowGroup

        Since:
        Open Inventor 8.1

    • maxGeometryOutputVertices

      public final SoSFInt32 maxGeometryOutputVertices
      Set the maximum number of vertices the geometry shader will emit in one invocation. Default is -1 which means it is set to the hardware limit.

      Since:
      Open Inventor 8.1

    • generateTransparency

      public final SoSFBool generateTransparency
      If set to true, then shapes affected by this shader will be considered transparent. Otherwise, the shape transparency is deducted from the state.

      This allows Open Inventor to apply the correct handling for the current transparency mode.

      Default is false.

      Since:
      Open Inventor 9.0

    • patchLength

      public final SoSFInt32 patchLength
      Set the length of the fixed-size collection of vertices used by tessellation shaders. Default is 0.

      Since:
      Open Inventor 9.3

    • images

      public final SoMFNode images
      Specifies a list of SoShaderParameterImage nodes to use with this shader. Default is empty.

      Since:
      Open Inventor 10.10

  • Constructor Detail

    • SoShaderProgram

      public SoShaderProgram()
      Constructor.
  • Method Detail

    • setFragmentShader

      public SoFragmentShader setFragmentShader​(int pos,
                                                java.lang.String filenameOrSource)
      Calls setFragmentShader(pos, filenameOrSource, SoShaderObject.SourceTypes.valueOf( SoShaderObject.SourceTypes.FILENAME.getValue() )).
    • setVertexShader

      public SoVertexShader setVertexShader​(int pos,
                                            java.lang.String filenameOrSource)
      Calls setVertexShader(pos, filenameOrSource, SoShaderObject.SourceTypes.valueOf( SoShaderObject.SourceTypes.FILENAME.getValue() )).
    • setTessellationControlShader

      public SoTessellationControlShader setTessellationControlShader​(int pos,
                                                                      java.lang.String filenameOrSource)
      Calls setTessellationControlShader(pos, filenameOrSource, SoShaderObject.SourceTypes.valueOf( SoShaderObject.SourceTypes.FILENAME.getValue() )).
    • setTessellationEvaluationShader

      public SoTessellationEvaluationShader setTessellationEvaluationShader​(int pos,
                                                                            java.lang.String filenameOrSource)
      Calls setTessellationEvaluationShader(pos, filenameOrSource, SoShaderObject.SourceTypes.valueOf( SoShaderObject.SourceTypes.FILENAME.getValue() )).
    • setGeometryShader

      public SoGeometryShader setGeometryShader​(int pos,
                                                java.lang.String filenameOrSource)
      Calls setGeometryShader(pos, filenameOrSource, SoShaderObject.SourceTypes.valueOf( SoShaderObject.SourceTypes.FILENAME.getValue() )).
    • setComputeShader

      public SoComputeShader setComputeShader​(int pos,
                                              java.lang.String filenameOrSource)
      Calls setComputeShader(pos, filenameOrSource, SoShaderObject.SourceTypes.valueOf( SoShaderObject.SourceTypes.FILENAME.getValue() )).
    • getNumReservedTextures

      public static int getNumReservedTextures()
      Returns the number of reserved texture units.
    • getTessellationEvaluationShader

      public SoTessellationEvaluationShader getTessellationEvaluationShader​(int pos)
      Returns the tessellation evaluation shader at the specified position.
    • getTessellationControlShader

      public SoTessellationControlShader getTessellationControlShader​(int pos)
      Returns the tessellation control shader at the specified position.
    • setComputeShader

      public SoComputeShader setComputeShader​(int pos,
                                              java.lang.String filenameOrSource,
                                              SoShaderObject.SourceTypes sourceType)
      Convenience method to create a compute shader with the specified filename and add it at the specified position. Return value is the new compute shader.
    • setTessellationControlShader

      public SoTessellationControlShader setTessellationControlShader​(int pos,
                                                                      java.lang.String filenameOrSource,
                                                                      SoShaderObject.SourceTypes sourceType)
      Convenience method to create a tessellation control shader with the specified filename and add it at the specified position. Return value is the new tessellation control shader.
    • setTessellationEvaluationShader

      public SoTessellationEvaluationShader setTessellationEvaluationShader​(int pos,
                                                                            java.lang.String filenameOrSource,
                                                                            SoShaderObject.SourceTypes sourceType)
      Convenience method to create a tessellation evaluation shader with the specified filename and add it at the specified position. Return value is the new tessellation evaluation shader.
    • setGeometryShader

      public SoGeometryShader setGeometryShader​(int pos,
                                                java.lang.String filenameOrSource,
                                                SoShaderObject.SourceTypes sourceType)
      Convenience method to create a geometry shader with the specified filename and add it at the specified position. Return value is the new geometry shader.
    • getVertexShader

      public SoVertexShader getVertexShader​(int pos)
      Returns the vertex shader at the specified position.
    • getFragmentShader

      public SoFragmentShader getFragmentShader​(int pos)
      Returns the fragment shader at the specified position.
    • getGeometryShader

      public SoGeometryShader getGeometryShader​(int pos)
      Returns the geometry shader at the specified position.
    • setVertexShader

      public SoVertexShader setVertexShader​(int pos,
                                            java.lang.String filenameOrSource,
                                            SoShaderObject.SourceTypes sourceType)
      Convenience method to create a vertex shader with the specified filename and add it at the specified position. Return value is the new vertex shader.
    • setFragmentShader

      public SoFragmentShader setFragmentShader​(int pos,
                                                java.lang.String filenameOrSource,
                                                SoShaderObject.SourceTypes sourceType)
      Convenience method to create a fragment shader with the specified filename and add it at the specified position. Return value is the new fragment shader.