SoVolumeShader Class Reference
[Nodes]

VolumeViz Shader node for volume rendering. More...

#include <VolumeViz/nodes/SoVolumeShader.h>

Inheritance diagram for SoVolumeShader:
SoShaderProgram SoNode SoFieldContainer SoBase SoRefCounter SoTypedObject SoVolumeIsosurface SoVolumeRenderingQuality

List of all members.

Public Types

enum  ShaderPosition {
  GEOMETRY_MAIN = 0,
  DATA_COMBINE_FUNCTION,
  GET_DATA_FUNCTION,
  FRAGMENT_COMPUTE_COLOR,
  VERTEX_MAIN,
  FRAGMENT_MAIN,
  VERTEX_POSTPROCESSING,
  CLIPPING_FUNCTION,
  CUSTOM_SHADER = 64
}

Public Member Functions

virtual SoType getTypeId () const
 SoVolumeShader ()
virtual SoFragmentShadersetFragmentShader (int pos, const SbString &filenameOrSource, SoShaderObject::SourceType sourceType=SoShaderObject::FILENAME)
virtual SoVertexShadersetVertexShader (int pos, const SbString &filenameOrSource, SoShaderObject::SourceType sourceType=SoShaderObject::FILENAME)

Static Public Member Functions

static SoType getClassTypeId ()
static SbBool isSupported (SoState *state=NULL)

Public Attributes

SoSFBool forVolumeOnly
SoSFBool interpolateOnMove

Deprecated



SoDEPRECATED SoSFBool raycasting
SoDEPRECATED void setForVolumeOnly (SbBool volOnly)

Detailed Description

VolumeViz Shader node for volume rendering.

This node manages the VolumeViz GLSL shader pipeline. It is derived from SoShaderProgram and behaves in 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 a minimum of new code. The VolumeViz GLSL shader pipeline API is described in the Shaders 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 still must 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+SoShaderProgramgetNumReservedTextures()-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.

Limitations:

Note: Since the GLSL specification doesn't currently allow the use of an 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 Shaders.

Available vertex program functions are described in Vertex shaders.

Available fragment program functions are described in Fragment shaders.

Available constants, macros and data structures are described in Data structures and constant.

EXAMPLE

FILE FORMAT/DEFAULT

SEE ALSO

SoShaderProgram, SoVolumeRenderingQuality, SoMultiDataSeparator, SoVolumeIsosurface, SoPreferences

See related examples:

InteractiveThresholding, MarkerPicking, OverlayDisplay, MedicalGPUDataCompose, MedicalIntensityAnisotropy, MedicalMultiChannel, MedicalVolumeTextureCompose, MedicalGammaCorrection, MedicalSimpleShader, HorizonIsolines, MultiChannel_ex1, MultiChannel_ex2, AmplitudeVelocity, GpuDataCompose, HorizonGpuCompose, VolumeTextureCompose, SimpleShader, VolumeProjection


Member Enumeration Documentation

Specifies the position of the shader pipeline stages in the field shaderObject.

In other words, use these enumeration values for the first parameter of the set1Value() method when setting a custom shader in the SoVolumeShader node.

Enumerator:
GEOMETRY_MAIN 

The main geometry program used for rendering.

Notes: Defining a custom GEOMETRY_MAIN slot is only supported for compatibility. It is not compatible with the raycasting volume rendering technique that is now the default for SoVolumeRender. If you must use this slot, set the raycasting field to FALSE.

DATA_COMBINE_FUNCTION 

This shader is used for GPU multi-data composition.

It must contain an application defined data combining function whose prototype is:

 VVIZ_DATATYPE VVizCombineData(in vec3 dataCoord);

The subtraction of two volumes can be written in GLSL like this:

   // !oiv_include <VolumeViz/vvizGetData_frag.h>
   // !oiv_include <VolumeViz/vvizCombineData_frag.h>

   uniform VVizDataSetId dataId1;
   uniform VVizDataSetId dataId2;

   VVIZ_DATATYPE VVizCombineData(vec3 tcoord)
   {
     VVIZ_DATATYPE d1 = VVizGetData(dataId1, tcoord);
     VVIZ_DATATYPE d2 = VVizGetData(dataId2, tcoord);
     return d1-d2;
   }
First volume Second volume Subtraction
iso_compose_vol1.jpg
iso_compose_vol2.jpg
iso_compose.jpg

NOTE: On the GPU, voxel values are always returned as a normalized value in the range 0..1. If the actual voxel value is needed, the shader function must compute that value using the current data range (see SoDataRange). The application must pass the data range to the shader function as a uniform parameter.

See Fragment shaders for more details.

GET_DATA_FUNCTION 

This shader is used to access datasets.

It must contain an application defined data accessor function whose prototype is:

 VVIZ_DATATYPE VVizGetData(in VVizDataSetId dataset, in vec3 dataCoord);

The default implementation is defined as follows:

 // !oiv_include <VolumeViz/vvizGetData_frag.h>

 // Default 3D DATA interpolation
 VVIZ_DATATYPE VVizGetData(VVizDataSetId tex, vec3 tcoord)
 {
   return VVizGetRawData(tex, tcoord);
 }

This function can be used to apply filters on each data volume. The following example shows how to make a smoothing filter which will remove some noise:

 // !oiv_include <VolumeViz/vvizGetData_frag.h>
 VVIZ_DATATYPE VVizGetData(in VVizDataSetId dataset, vec3 tcoord)
 {
   vec3 voxelDim = VVizGetVoxelDimensions(dataset);
   vec3 du = vec3(voxelDim[0], 0., 0.);
   vec3 dv = vec3(0., voxelDim[1], 0.);
   vec3 dw = vec3(0., 0., voxelDim[2]);

  return 1./6.*(VVizGetRawData(dataset, tcoord-du).w+VVizGetRawData(dataset, tcoord+du).w+
                VVizGetRawData(dataset, tcoord-dv).w+VVizGetRawData(dataset, tcoord+dv).w+
                VVizGetRawData(dataset, tcoord-dw).w+VVizGetRawData(dataset, tcoord+dw).w);

 }
Non filtered data Filtered data
iso_nofilter.jpg
iso_filter.jpg

NOTE: On the GPU, voxel values are always returned as a normalized value in the range 0..1. If the actual voxel value is needed, the shader function must compute that value using the current data range (see SoDataRange). The application must pass the data range to the shader function as a uniform parameter.

See Fragment shaders for more details.

FRAGMENT_COMPUTE_COLOR 

This shader is used to compute the current fragment color.

Note: VVizComputePreIntegrated should only be called when SoVolumeRendering::renderMode is set to VOLUME_RENDERING (the default). It is not appropriate for MIN, MAX, etc composition.

It must contain an application defined compute fragment color function whose prototype is:

 // For an SoVolumeRender node
 vec4 VVizComputeFragmentColor(in VVizDataSetId dataset, in vec3 rayDir, inout VVizVoxelInfo voxelInfoFront, in VVizVoxelInfo voxelInfoBack, in int mask);
 // For all other VolumeViz shape nodes (SoOrthoSlice, SoObliqueSlice, SoVolumeSkin ...)
 vec4 VVizComputeFragmentColor(in VVIZ_DATATYPE vox, in vec3 dataCoord);

This function can be used to do co-blending on multiple data volumes. The following example shows how to blend two volumes:

   // !oiv_include <VolumeViz/vvizGetData_frag.h>
   // !oiv_include <VolumeViz/vvizTransferFunction_frag.h>

   uniform VVizDataSetId data1;
   uniform VVizDataSetId data2;

   vec4 blend(in vec3 texCoord)
   {
     VVIZ_DATATYPE index1 = VVizGetData(data1, texCoord);
     vec4 data1Color = VVizTransferFunction(index1, 0);
   
     VVIZ_DATATYPE index2 = VVizGetData(data2, texCoord);
     vec4 data2Color = VVizTransferFunction(index2, 1);

     // Color modulated by intensity from volume2
     data2Color.rgb *= data1Color.r;
     data2Color.a   *= data1Color.a;
     return res;
   }

   // Implement VVizComputeFragmentColor for slice nodes
   vec4 VVizComputeFragmentColor(VVIZ_DATATYPE vox, vec3 texCoord)
   {
    return blend(texCoord);
   }

   // Implement VVizComputeFragmentColor for SoVolumeRender
   vec4 VVizComputeFragmentColor(VVizDataSetId data, vec3 rayDir, inout VVizVoxelInfo voxelInfoFront, in VVizVoxelInfo voxelInfoBack, int maskId)
   {
     return blend(voxelInfoFront.texCoord);
   }

See Fragment shaders for more details.

NOTE: enumeration value available since Open Inventor 9.0

VERTEX_MAIN 

Main vertex shader used for rendering.

This stage should not be redefined unless you know exactly what you are doing. If the goal of your application is to compute specific varying attributes to pass to the fragment shader you should use the shaderPosition slot named VERTEX_POSTPROCESSING.

Notes: Defining a custom VERTEX_MAIN slot is only supported for compatibility. It is not compatible with the raycasting volume rendering technique that is now the default for SoVolumeRender. If you must use this slot, set the raycasting field to FALSE.

See Vertex shaders for more details.

FRAGMENT_MAIN 

Main fragment shader used for rendering.

This stage should not be redefined unless you know exactly what you are doing. If the goal of your application is to blend colors or add effects to the existing pipeline you should use the shaderPosition slot named FRAGMENT_COMPUTE_COLOR.

Notes: Defining a custom FRAGMENT_MAIN slot is only supported for compatibility. It is not compatible with the raycasting volume rendering technique that is now the default for SoVolumeRender. If you must use this slot, set the raycasting field to FALSE.

See Fragment shaders for more details.

VERTEX_POSTPROCESSING 

Method called at the end of the VolumeViz vertex shader stage.


This shader allows the application to generate custom varying values at the vertex shader stage for use in the fragment shader stage.

See Vertex shaders for more details.

NOTE: enumeration value available since Open Inventor 9.0

CLIPPING_FUNCTION 

This method can be used to implement a custom clipping algorithm.

Note that when using this method, it may not always be possible for VolumeViz to correctly manage slicing artifacts. You have to use SoVolumeRender::samplingAlignement = BOUNDARY_ALIGNED to avoid slicing artifacts.

When applying a custom clipping function with SoVolumeRenderingQuality::voxelizedRendering = TRUE, the voxels will be hollow.

NOTE: enumeration value available since Open Inventor 9.7

CUSTOM_SHADER 

This position and all subsequent positions CUSTOM_SHADER+x are freely available for user-defined shaders.

NOTE: enumeration value available since Open Inventor 9.0


Constructor & Destructor Documentation

SoVolumeShader::SoVolumeShader (  ) 

Constructor.


Member Function Documentation

static SoType SoVolumeShader::getClassTypeId (  )  [static]

Returns the type identifier for this class.

Reimplemented from SoShaderProgram.

Reimplemented in SoVolumeIsosurface, and SoVolumeRenderingQuality.

virtual SoType SoVolumeShader::getTypeId (  )  const [virtual]

Returns the type identifier for this specific instance.

Reimplemented from SoShaderProgram.

Reimplemented in SoVolumeIsosurface, and SoVolumeRenderingQuality.

static SbBool SoVolumeShader::isSupported ( SoState state = NULL  )  [static]

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.

SoDEPRECATED void SoVolumeShader::setForVolumeOnly ( SbBool  volOnly  )  [inline]
virtual SoFragmentShader* SoVolumeShader::setFragmentShader ( int  pos,
const SbString filenameOrSource,
SoShaderObject::SourceType  sourceType = SoShaderObject::FILENAME 
) [virtual]

Create a fragment shader with the given filename and add it at the given pos.

Return value is the new fragment shader.

Reimplemented from SoShaderProgram.

virtual SoVertexShader* SoVolumeShader::setVertexShader ( int  pos,
const SbString filenameOrSource,
SoShaderObject::SourceType  sourceType = SoShaderObject::FILENAME 
) [virtual]

Create a vertex shader with the given filename and add it at the given pos.

Return value is the new vertex shader.

Reimplemented from SoShaderProgram.


Member Data Documentation

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 still must 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 the different cases.)

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

NOTE: field available since Open Inventor 9.0

Use raycasting for volume rendering (SoVolumeRender).

Note: Has no effect unless the forVolumeOnly field is TRUE. Default is TRUE. NOTE: field available since Open Inventor 9.0

Deprecated:

Deprecated since Open Inventor 9620
Only raycasting mode will be supported in OIV10

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/