UnityVolumeRendering Documentation

repository·master·Indexed 20 days ago

https://github.com/mlavik1/unityvolumerendering

A Unity3D plugin for high-quality volume rendering supporting Direct Volume Rendering (DVR), Maximum Intensity Projection (MIP), and Isosurface rendering. It supports Built-in, URP, and HDRP render pipelines and imports datasets in DICOM, NIFTI, NRRD, VASP, and raw formats. The package includes tools for 1D/2D transfer functions, cross-section clipping (planes, boxes, spheres), and programmatic dataset importing via ImporterFactory and VolumeObjectFactory. Requires Unity 6 (6000.0) or newer.

Tokens
7.2K
Snippets
8
Records
49
Agent score
68%

What's inside UnityVolumeRendering

  1. Coordinate systems and dataset scaling

    master

    The project handles coordinate systems for DICOM and NRRD formats, converting them to Unity's coordinate system using meter units.

    By default, imported datasets have their size normalized. If you need to maintain the original physical size (for example, to ensure multiple datasets align correctly in world space), select the outer GameObject (the one containing the VolumeRenderedObject component) and set its Scale to (1, 1, 1).

  2. Select a volume render mode

    master

    The Render mode setting determines the fundamental visualization technique used for the volume:

    • Direct Volume Rendering: Uses raymarching combined with transfer functions to visualize density.
    • Maximum Intensity Projection: Displays only the maximum density along each ray.
    • Isosurface Rendering: Uses raymarching but stops the ray once it hits a specific surface threshold.
  3. How shadow volumes are computed

    master

    Shadow volumes are implemented using a 3D texture generated for the entire dataset. A compute shader updates this volume by casting rays from the light source through the dataset to store shadow information.

    To maintain performance and handle platforms where async compute is unavailable, the ShadowVolumeManager divides the shadow volume into smaller chunks and updates exactly one chunk per frame.

  4. Configure Direct Volume Rendering transfer functions

    master

    Direct Volume Rendering maps density (and optionally gradient magnitude) to color and opacity. You can modify these via the menu bar: Volume Rendering > 1D Transfer Function or 2D Transfer Function.

    1D Transfer Function

    • X-axis: Density.
    • Y-axis: Alpha (opacity).
    • Interaction: Move grey alpha knots to create an opacity curve. Right-click to add new alpha knots. Use the bottom gradient panel to map color to density (right-click to add knots; click existing knots to modify color).

    2D Transfer Function

    • X-axis: Density.
    • Y-axis: Gradient magnitude.
    • Interaction: Click "add rectangle" to create a new shape. Use the four sliders (bottom left) to adjust size/position, and the two sliders on the right to adjust min/max alpha/opacity. Each rectangle can be assigned a specific color via a color picker.
  5. Optimize performance with Early ray termination

    master

    The raymarching shader can be configured to use Early ray termination. This optimization allows the shader to exit early once enough samples have been accumulated, avoiding the enumeration of invisible voxels.

    It is recommended to keep this setting enabled, as it provides significant performance improvements with typically no noticeable visual changes.

  6. Configure Isosurface Rendering threshold

    master
    Isosurface rendering draws the first point where the ray hits a density exceeding a specific threshold. To adjust this threshold, select the object and modify the Visible value range in the Inspector. These values can also be used in conjunction with Direct Volume Rendering mode.
  7. How to use the sample scene

    master

    To quickly preview the renderer with sample data:

    1. Install the package via UPM.
    2. In the Package Manager, find "Unity Volume Rendering", go to the Samples tab, and import both Basic Demo and Sample Data.
    3. Open the imported TestScene.unity.
    4. In the Unity menu bar, click Volume Rendering.
    5. Select Load Raw dataset.
    6. Choose the VisMale.raw file from the imported Sample Data.
    7. Click the import button.