Class SoVolumeShader
- java.lang.Object
-
- com.openinventor.inventor.Inventor
-
- com.openinventor.inventor.misc.SoBase
-
- com.openinventor.inventor.fields.SoFieldContainer
-
- com.openinventor.inventor.nodes.SoNode
-
- com.openinventor.inventor.nodes.SoShaderProgram
-
- com.openinventor.volumeviz.nodes.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 fromSoShaderProgram
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 theshaderObject
field (inherited fromSoShaderProgram
). 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 theShaderPosition
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 ofSoVolumeShader
). 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 anSoVolumeRenderingQuality
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 theforVolumeOnly
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
. SinceSoVolumeIsosurface
andSoVolumeRenderingQuality
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 bothSoVolumeRenderingQuality
andSoVolumeIsosurface
withSoVolumeRender
.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 differentSoSeparator
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 (seeSoPreferences
). 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 isSoFragmentShader.getMaxTextureImageUnit()
-SoShaderProgram.getNumReservedTextures()
. Note: The value returned bySoShaderProgram.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);
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 theSoTransformation
nodes that are placed before theSoDataSet
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:
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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SoVolumeShader.ShaderPositions
Specifies the position of the shader pipeline stages in the fieldshaderObject
.-
Nested classes/interfaces inherited from class com.openinventor.inventor.nodes.SoShaderProgram
SoShaderProgram.GeometryInputTypes, SoShaderProgram.GeometryOutputTypes
-
Nested classes/interfaces inherited from class com.openinventor.inventor.nodes.SoNode
SoNode.RenderModes
-
Nested classes/interfaces inherited from class com.openinventor.inventor.Inventor
Inventor.ConstructorCommand
-
-
Field Summary
Fields Modifier and Type Field Description SoSFBool
forVolumeOnly
Set to true if the shader should be called for volume rendering (SoVolumeRender
).SoSFBool
interpolateOnMove
When set to false, interpolation between LDM tiles (across the tile boundary) is not done when rendering in interactive mode.-
Fields inherited from class com.openinventor.inventor.nodes.SoShaderProgram
bufferObjects, generateTransparency, geometryInputType, geometryOutputType, images, maxGeometryOutputVertices, patchLength, shaderObject, shadowShader, vertexProgramTwoSide
-
Fields inherited from class com.openinventor.inventor.Inventor
VERBOSE_LEVEL, ZeroHandle
-
-
Constructor Summary
Constructors Constructor Description SoVolumeShader()
Constructor.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
isSupported()
Calls isSupported((com.openinventor.inventor.misc.SoState)null).static boolean
isSupported(SoState state)
Returns true ifSoVolumeShader
is supported by the current graphics board.-
Methods inherited from class com.openinventor.inventor.nodes.SoShaderProgram
addShaderParameterImage, getFragmentShader, getGeometryShader, getNumReservedTextures, getTessellationControlShader, getTessellationEvaluationShader, getVertexShader, setComputeShader, setComputeShader, setFragmentShader, setFragmentShader, setGeometryShader, setGeometryShader, setTessellationControlShader, setTessellationControlShader, setTessellationEvaluationShader, setTessellationEvaluationShader, setVertexShader, setVertexShader
-
Methods inherited from class com.openinventor.inventor.nodes.SoNode
affectsState, callback, copy, copy, distribute, doAction, getAlternateRep, getBoundingBox, getByName, getMatrix, getPrimitiveCount, getRenderEngineMode, getRenderUnitID, GLRender, GLRenderBelowPath, GLRenderInPath, GLRenderOffPath, grabEventsCleanup, grabEventsSetup, handleEvent, isBoundingBoxIgnoring, isOverride, pick, rayPick, search, setOverride, touch, write
-
Methods inherited from class com.openinventor.inventor.fields.SoFieldContainer
copyFieldValues, copyFieldValues, enableNotify, fieldsAreEqual, get, getAllFields, getEventIn, getEventOut, getField, getFieldName, hasDefaultValues, isNotifyEnabled, set, setToDefaults
-
Methods inherited from class com.openinventor.inventor.misc.SoBase
dispose, getName, isDisposable, isSynchronizable, setName, setSynchronizable
-
Methods inherited from class com.openinventor.inventor.Inventor
getNativeResourceHandle
-
-
-
-
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
-
-
Method Detail
-
isSupported
public static boolean isSupported()
Calls isSupported((com.openinventor.inventor.misc.SoState)null).
-
isSupported
public static boolean isSupported(SoState state)
Returns true ifSoVolumeShader
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 seeSoGLExtension
for an example of usingSoGLContext
to avoid them.
-
-