Volume rendering, implemented in Unity3D. Want to support my project? Donate some money to Red Cross and send me a screenshot/message/issue, and I'll be greatly motivated! :) Any amount is welcome!
Перейти к файлу
Steve Borkman fc1574855d
Merge pull request #1 from Unity-Technologies/setup
Post Hackweek
2022-11-01 17:26:30 -04:00
.github/workflows GitHub workflows for packaging 2022-10-25 21:49:57 +02:00
Assets some cool stuff 2022-10-27 18:11:56 -04:00
DataFiles Added license file for PARCHG dataset. Some cleanup. 2021-12-30 19:31:12 +01:00
Documentation SimpleITK upgrade + Linux/MacOS support (#117) 2022-09-25 20:13:04 +02:00
Packages camera working 2022-10-26 16:28:42 -04:00
ProjectSettings camera working 2022-10-26 16:28:42 -04:00
Screenshots better screenshot 2021-12-20 17:30:45 -06:00
scripts GitHub workflows for packaging 2022-10-25 21:49:57 +02:00
.gitignore Initial commit 2019-02-11 17:16:36 +01:00
ACKNOWLEDGEMENTS.txt Nifti importer (Nifti.NET) (#126) 2022-10-24 20:37:36 +02:00
CONTRIBUTING.md Dataset's data values are now always stored as float. This removes the need for different implementations for PARCHG. 2021-10-18 20:26:35 +02:00
CREDITS.md Update CREDITS.md 2022-04-06 00:20:51 +10:00
FUNDING.yml Added FUNDLING.yml (link to Red Cross) 2022-02-26 20:23:32 +01:00
LICENSE Initial commit 2019-02-11 17:16:36 +01:00
README.md test 2022-10-25 16:18:38 -04:00
TestChecklist.md Create TestChecklist.md 2022-03-24 21:44:57 +01:00
gitattributes SimpleITK: DICOM JPEG, NRRD, NIFTI (Windows only) (#95) 2022-04-07 18:32:50 +02:00

README.md

UnityVolumeRendering

A volume renderer, made in Unity3D. I have written a tutorial explaining the basic implementation. Have any questions? Create an issue or contact me on Mastodon.

I also have a tutorial video that shows how to use the project

alt tag

Requirements:

  • Unity 2018 1.5 or newer (should also work with some older versions, but I haven't tested)

Update

How to use sample scene

  • Open "TestScene.unity"
  • Click "Volume Rendering" in the menu bar
  • Select "Load Asset"
  • Pick a file in the "DataFiles" folder (I recommend vismale.dat)
  • Click the "import"-button

Step-by-step instructions

1. Import model

Raw datasets:

In the menu bar, click "Volume Rendering" and "Load raw dataset"

Then select the dataset you wish to import. Currently only raw datasets are supported (you can add your own importer for other datasets).

In the next menu you can optionally set the import setting for the raw dataset. For the sample files you don't need to change anything.

DICOM:

To import a DICOM dataset, click "Volume Rendering" and "Load DICOM" and select the folder containing your DICOM files. The dataset must be of 3D nature, and contain several files - each being a slice along the Z axis.

2. Moving the model

You can move the model like any other GameObject. Simply select it in the scene view or scene hierarchy, and move/rotate it like normal.

3. Changing the visualisation

Select the model and find the "Volume Render Object" in the inspector.

Here you can change the "Render mode":

Example:

There are 3 render modes:

  • Direct Volume Rendering (using transfer functions)
  • Maximum Intensity Projection (shows the maximum density)
  • Isosurface Rendering

Direct Volume Rendering

Direct volume rendering is the most standard rendering mode. It sends rays through the dataset, and uses "transfer functions" (1D or 2D) to determine the colour and opacity. Transfer functions map density (2D: also gradient magnitude) to a colour and opacity.

  • Modifying transfer functions: Click "Volume Rendering" in the menu bar and select "1D Transfer Function" or "2D Transfer Function"
    • 1D Transfer Function: X-axis represents density and Y-axis represents alpha (opaccity). Move the grey alpha knots to create a curve for opacity by density. Right-click to add new alpha knots. The bottom gradient-coloured panel maps colour to density. Right-click to add new knots and click on an existing colour knot to modify its colour.
    • 2D Transfer Function: X-axis represents density and Y-axis represents gradient magnitude. Click "add rectangle" to add a new rectangle-shape. Move the four sliders (bottom left) to modify size/position. Modify the two sliders to the right to change min/max alpha/opacity. Each rectangle can have one colour (see colour picker).

Isosurface Rendering

Isosurface rendering draws the first thing the ray hits, with a density higher than some threshold. You can set this threshold yourself, by selecting the object and changing the "Visible value range" in the inspector. These can also be used with direct volume rendering mode.

(VR) performance

Since VR requires two cameras to render each frame, you can expect worse performance. However, you can improve the FPS in two ways:

  • Open DirectVolumeRenderingShader.shader and reduce the value of NUM_STEPS inthe frag_dvr function. This will sacrifice quality for performance.
  • Disable the DEPTHWRITE_ON shader variant. You can do this from code, or just remove the line "#pragma multi_compile DEPTHWRITE_ON DEPTHWRITE_OFF" in DirectVolumeRenderingShader.shader. Note: this will remove depth writing, so you won't be able to intersect multiple datasets.

How to use in your own project

  • Create an instance of an importer (Directly, or indirectly using the ImporterFactory):
    IImageFileImporter importer = ImporterFactory.CreateImageFileImporter(ImageFileFormat.NRRD); (alternatively, use the DICOMImporter)
  • Call the Import()-function, which returns a Dataset:
    VolumeDataset dataset = importer.Import(file);
  • Use VolumeObjectFactory to create an object from the dataset:
    VolumeRenderedObject obj = VolumeObjectFactory.CreateObject(dataset);

See the importer documentation for more detailed information.

alt tag alt tag alt tag alt tag alt tag alt tag alt tag

Contributing

See CONTRIBUTING.md for how to contribute.

Thanks to everyone who have contributed so far.

See ACKNOWLEDGEMENTS.txt for libraries used by this project.