Class SoVolumeShader

  • All Implemented Interfaces:
    SafeDisposable
    Direct Known Subclasses:
    SoVolumeIsosurface, SoVolumeRenderingQuality

    public class SoVolumeShader
    extends SoShaderProgram
    Shader node for volume rendering. This node manages the VolumeViz GLSL shader pipeline. It is derived from SoShaderProgram and behaves in a similar way. It allows you to supply custom shaders for all VolumeViz rendering shapes (SoVolumeRender, SoOrthoSlice, etc.).

    Note: GLSL is the only shading language supported by this node.

    SoVolumeShader fields provide different pre-implemented rendering effect options, but the application is free to redefine some stages of the VolumeViz shader pipeline by inserting GLSL shader functions in the shaderObject field (inherited from SoShaderProgram). The shaderObject multi-field contains only application redefined shaders. The position of a shader in the multi-field explicitly specifies the pipeline shader stage to redefine. Customizable stages are described below in the ShaderPosition enum. For example, a seismic application could implement co-blending of multiple volumes by supplying a replacement for the VVizComputeFragmentColor() function in the FRAGMENT_COMPUTE_COLOR position of the shaderObject field.

    Note: The advanced rendering options, e.g. lighting, are provided by the SoVolumeRenderingQuality node (a subclass of SoVolumeShader). Generally if an application wants to redefine a stage of the shader pipeline but still be able to use these advanced options, it should create an SoVolumeRenderingQuality node and set the replacement shader functions in the shaderObject field of that node.

    VolumeViz provides a shader pipeline API composed of GLSL functions that are automatically loaded. This allows the application to modify existing effects or add new effects with minimum new codes. The VolumeViz GLSL shader pipeline API is described in the VolumeVizShaders document.

    Use the forVolumeOnly field to specify if the shader is to be used for volume rendering or for non-volume rendering (slice, volume geometry, etc). In some cases it may be possible to use the same shader source for both volume and non-volume rendering. However the application must still create two shader nodes, one with the forVolumeOnly field set to true and one with it set to false, even if both nodes load the same shader source file. (This is necessary because the shader source must be compiled with different parameters for the different cases.)

    No more than one SoVolumeShader (or derived class) can be used with one volume visualization node, e.g. SoVolumeRender. Since SoVolumeIsosurface and SoVolumeRenderingQuality are derived from this class, only one (or none) of these three nodes can be used at the same time. Exception: Since Open Inventor 7.1 it is possible to use both SoVolumeRenderingQuality and SoVolumeIsosurface with SoVolumeRender.

    Remember that this is an SoShaderProgram node. The effect will usually be undesirable if it is applied to non-VolumeViz geometry (polygons, lines, etc). Therefore applications should generally keep the volume visualization nodes and standard geometry nodes separate in the scene graph (i.e. under different SoSeparator nodes).

    Reserved texture units:

    Because some rendering methods need to create and use special textures, some texture units must be reserved for internal use. The application can specify which texture units VolumeViz should use by setting environment variables (see SoPreferences). The texture units between OIV_FIRST_RESERVED_TEXTURE_UNIT and OIV_FIRST_RESERVED_TEXTURE_UNIT+SoShaderProgram.getNumReservedTextures()-1 inclusive are reserved for internal VolumeViz use. If OIV_FIRST_RESERVED_TEXTURE_UNIT is not set, its default value is SoFragmentShader.getMaxTextureImageUnit() - SoShaderProgram.getNumReservedTextures(). Note: The value returned by SoShaderProgram.getNumReservedTextures() may change between VolumeViz versions. The total number of available texture units depends on the graphics hardware.

    Composition with Multiple Data:
    When compositing multiple datasets that have different dimensions or extents using a custom shader, it is necessary to convert texture coordinates from one dataset to another in order to fetch the correct data values.
    For this purpose, texture coordinates conversion functions are provided in the VolumeViz/vvizStructure.h shader include.
    For instance,

     vec3 VVizTextureToTextureVec(in VVizDataSetId datasetSrc, in VVizDataSetId datasetDst, in vec3 texCoord);
    can be used to convert texture coordinates related to one dataset to texture coordinates related to another dataset.
    The conversion is based solely on the transformations applied to each dataset, which are defined by their model matrix and their extent.
    Please note that the model matrix of a dataset is defined by to the SoTransformation nodes that are placed before the SoDataSet node in the order of the traversal.

    Limitations:

    • Only graphics cards supporting the GLSL language can use this node.

    • Shader filenames beginning with "vviz" are reserved.
      Filenames set in a public slot with this prefix will be ignored.

    • Fragment shaders must not use the GLSL discard keyword when volume rendering is using the ray casting algorithm (the default since v9.0). If discard is used, the rendering will be incorrect. If a fragment should not affect the frame buffer, set it to completely transparent. If you are discarding fragments in the #VVizGetData() function (i.e. before assigning color), then you must reserve one entry in the color map to be completely transparent and return the appropriate data value. The easiest way to do this is to make the first color map entry transparent, either explicitly or by setting the SoTransferFunction node's minValue field to 1. Because the VVizGetData() works with normalized data values in the range 0..1, returning 0 will select the transparent entry regardless of the actual data range.

    Note: Since the GLSL specification doesn't currently allow the use of any include directive, Open Inventor provides this service through a comment directive. This provides greater flexibility in implementing complex GLSL shaders. Included files are loaded using SoInput and use the same search path order.

     //!oiv_include <VolumeViz/vvizCombine_frag.h>

    The VolumeViz shader API is described in VolumeVizShaders.

    Available vertex program functions are described in VolumeVizVertexShaders.

    Available fragment program functions are described in VolumeVizFragmentShaders.

    Available constants, macros and data structures are described in VolumeVizShadersData.

    EXAMPLE

    Load a fragment shader in the COMPUTE_COLOR slot.

    • Various important nodes are omitted here for clarity.
    • This example could be simplified slightly using the setFragmentShader() convenience method.

     // Create an SoVolumeData node
     SoVolumeData volData = new SoVolumeData();
       volData.dataSetId.setValue( 1 );
       volSep.addChild( volData );
     
     // Create an integer uniform parameter for the dataSetId
     SoShaderParameter1i paramTex1 = new SoShaderParameter1i();
       paramTex1.name.setValue( "dataId1" );
       paramTex1.value.setValue( volData.dataSetId.getValue() );
     
     // Create a fragment shader, load the source file and add the parameter
     SoFragmentShader fragmentShader = new SoFragmentShader();
       fragmentShader.sourceProgram.setValue( SHADER_FILENAME );
       fragmentShader.parameter.set1Value( 0, paramTex1 );
     
     // Create a shader program and add the fragment shader
     SoVolumeShader volShader = new SoVolumeShader();
       int shaderPosition = SoVolumeShader.ShaderPositions.FRAGMENT_COMPUTE_COLOR.getValue();
       volShader.shaderObject.set1Value( shaderPosition, fragmentShader );
       volSep.addChild( volShader );

    File format/default:

    SoShaderProgram {

      shaderObject [
      GEOMETRY_MAIN shader
      DATA_COMBINE_FUNCTION shader,
      GET_DAT_FUNCTION shader,
      FRAGMENT_COMPUTE_COLOR shader,
      VERTEX_MAIN shader,
      VERTEX_MAIN shader,
      FRAGMENT_MAIN shader,
      ... (reserved)
      CUSTOM_SHADER shader
      ... (free for apps)
      ]
      forVolumeOnly false
      raycasting true
      interpolateOnMove true
    }

    See Also:
    SoShaderProgram, SoVolumeRenderingQuality, SoMultiDataSeparator, SoVolumeIsosurface, SoPreferences
    • Field Detail

      • forVolumeOnly

        public final SoSFBool forVolumeOnly
        Set to true if the shader should be called for volume rendering (SoVolumeRender). Set to false if it should be called for other VolumeViz shapes (SoOrthoSlice, SoObliqueSlice, SoVolumeSkin, volume geometry, etc). Default is false.

        true means that if the shader uses texture coordinates, they will be 3D texture coordinates. false means they will be 2D texture coordinates.

        In some cases it may be possible to use the same shader source for both volume and non-volume rendering. However the application must still create two shader nodes, one with true and one with false, even if both nodes load the same shader source file. (This is necessary because the shader source must be compiled with different parameters for different cases.)

      • interpolateOnMove

        public final SoSFBool interpolateOnMove
        When set to false, interpolation between LDM tiles (across the tile boundary) is not done when rendering in interactive mode. This increases the interactive rendering frame rate at the cost of some rendering artifacts at the tile boundaries (seen as horizontal and vertical "lines" in the rendered image) and a small lag when switching between still and interactive. If your rendering shaders do not need to access voxel's neighbor (for lighting or gradient computation for instance), you should set this field to true as the cost of interpolation is not significant in this case.

        Default is true.

        Since:
        Open Inventor 9.0

    • Constructor Detail

      • SoVolumeShader

        public SoVolumeShader()
        Constructor.
    • Method Detail

      • isSupported

        public static boolean isSupported()
        Calls isSupported((com.openinventor.inventor.misc.SoState)null).
      • isSupported

        public static boolean isSupported​(SoState state)
        Returns true if SoVolumeShader is supported by the current graphics board. When using a debug build of Open Inventor, some "no context available" warning messages may be generated. You can ignore them or see SoGLExtension for an example of using SoGLContext to avoid them.