SoView2DShaderFunction

InventorModule
genre View2DExtended
author MeVis Medical Solutions AG
package MeVisLab/Standard
dll SoView2D
definition SoView2DShader.def
keywords GLSL

Purpose

The SoView2DShaderFunction module can be used to add/remove steps to the SoView2DShaderOverlay.

Details

Positions

The shader function has access to the following per-fragment positions via the state:

// the device position (x,y coordinate in screen pixels)
state vec2 devicePos;

// the normalized position on the visible area viewer
state vec2 normalizedPos;

// the world position
state vec3 worldPos;

Overlays

A SoView2DOverlay or SoView2DOverlayMPR can be used together with the SoView2DShaderOverlay by giving them a SoView2DOverlay.overlayName.

If an overlayName is given, the overlay is not rendered by the overlay module. Instead it is collected in the state and is added to the shader of the SoView2DShaderOverlay module. This shader typically contains the following steps (depending on the settings of the overlay) for each overlay:

  • Setup Overlay
  • Check Inside Overlay
  • Fetch Overlay
  • Classify Overlay
  • Composite Overlay

Each of these steps can be modified by a SoView2DShaderFunction module.

The information about each overlay and its LUT are stored inside of a uniform struct that is named like the overlayName. Each overlay step will add variables to the state, which all start with the name of the overlay:

// the sample position into the overlay texture (in normalized texture coordinates)
state vec2  overlaySamplePos;

// contains 1. if the overlaySamplePos is inside the overlay texture, 0. otherwise
state float overlayInside;

// the value of the overlay, sampled at overlaySamplePos
state vec4  overlayValue;

// the value of the overlay, scaled and shifted to be in the original data range
// (this allows to do thresholding etc. with the real data values)
state vec4  overlayOriginalValue;

// the overlay color after classification (if no LUT is used, this is the same as the overlayValue)
state vec4  overlayColor;

To understand what possibilities this offers, it is the easiest to have a look at the SoView2DShaderDiagnosis, which allows to look into the running pipeline, or to have a look at the example networks of SoView2DShaderFunction.

Note that a different interpolation mode for an overlay will generate a different shader and that the overlayValue and overlayOriginalValue are only available if the filterMode is not FILTER_LINEAR. This is the case because FILTER_LINEAR filters on four pre-classified samples and this happens in the “Classify Overlay” step.

The shader is typically applied on the complete visible area (visible device rect) of the SoView2D. This means that it will also sample outside of overlays. To avoid using the samples outside of an overlay texture, the overlayInside state is used to decide if the overlay is composited or not.

Each overlay is available as a uniform struct, containing information about the overlay:

 struct OverlayInfo {
   // 1. means that there is valid content
   // 0. means that the overlay has no valid data in the current slice/view
   float validContent;

   // the overlay data
   sampler2D texture;

   // the texture size of the overlay texture
   vec2 texSize;
   // the inverse texture size of the overlay texture
   // (this is useful to sample neighboring texels)
   vec2 texSizeInv;

   // the lut for the overlay (if applyLut is enabled)
   sampler2D lutTexture;

   // internal LUT parameters
   float lutHeightScaleFactor;
   vec2 lutSize;
   vec2 lutSizeInv;

   // the color of the overlay
   vec4 color;
   // the transformation matrix which transforms a device coordinate to an overlay sample position
   mat3 transform;
}

Parameter Fields

Field Index

Enabled: Bool Substep: String
Fragment Step: Enum  
Function Body: String  
Function Display: String  
Function Name: String  
Modification Type: Enum  
Needs Active Step: Bool  
Parameter Declaration: String  

Visible Fields

Enabled

name: enabled, type: Bool, default: TRUE

Enables the function.

Function Name

name: functionName, type: String

Defines the (optional) function name.

Function Body

name: functionBody, type: String

The implementation of the function body. The state variable contains the current pipeline state.

Parameter Declaration

name: parameterDeclaration, type: String

Allows to declare parameters which are used in the custom function body. Possible parameters:

  • uniform: for a GLSL uniform parameter
  • varying: for a GLSL varying parameter
  • state: for a input/output pipeline struct parameter
  • include: for a custom shader header or pipeline library function

Using uniform, varying and state will add the declared variable declaration to the header string. Using include will add the declaration of the specified include to the header.

Syntax:

uniform TYPE identifier;
uniform TYPE identifier [size];
varying TYPE identifier;
attribute TYPE identifier;
state TYPE identifier;
state TYPE identifier = DEFAULTVALUE;
include name;

Entries in the parameter declaration field are separated by newline. The ; and = characters can be ommitted. TYPE can be any GLSL type, identifier can be any GLSL identifier (e.g. variable name). DEFAULTVALUE can be a GLSL statement to initialize a variable which matches the respective type and can be called in a struct constructor. For includes, name is a user defined identifier for the include. In every line, character after the expected number of words are ignored, which can e.g. be used for comments.

For includes, you can either use the SoView2DShaderOverlay builtin includes, or define your own includes with the SoView2DShaderInclude module.

Substep

name: substep, type: String

Defines the substep, which is typically the name of an overlay.

Function Display

name: functionDisplay, type: String, persistent: no

Shows the complete function.

Modification Type

name: modificationType, type: Enum, default: ADD_AFTER

Defines which operation is applied.

Values:

Title Name
Add After ADD_AFTER
Add Before ADD_BEFORE
Replace REPLACE
Remove REMOVE
Add Before Inorder ADD_BEFORE_INORDER

Fragment Step

name: fragmentStep, type: Enum, default: START

Selects the fragment step.

Values:

Title Name
Start START
Setup Overlay SETUP_OVERLAY
Check Inside Overlay CHECK_INSIDE_OVERLAY
Fetch Overlay FETCH_OVERLAY
Classify Overlay CLASSIFY_OVERLAY
Composite Overlay COMPOSITE_OVERLAY
End END

Needs Active Step

name: needsActiveStep, type: Bool, default: FALSE

If enabled, the function is only added if the given step is active.