Skip to content

Commit

Permalink
Documentation for shadow volumes, DLSS, FidelityFx upscaling
Browse files Browse the repository at this point in the history
  • Loading branch information
mlavik1 committed Apr 9, 2024
1 parent bdc1dd4 commit d711135
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 5 deletions.
1 change: 1 addition & 0 deletions Documentation/Documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- [Importing datasets](General/Importing/ImportingDatasets.md)
- [Using the imported datasets](General/VolumeRendering/GameObjectManipulation.md)
- [Changing the appearance](General/VolumeRendering/VolumeRenderingSettings.md)
- [Shadow volumes](General/VolumeRendering/ShadowVolumes.md)
- [Transfer Functions](General/TransferFunctions/TransferFunctions.md)
- [Cross section tools](General/CrossSectionTools/CrossSectionTools.md)
- [Slice renderer](General/SliceRenderer/SliceRenderer.md)
Expand Down
25 changes: 25 additions & 0 deletions Documentation/General/VolumeRendering/ShadowVolumes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Shadow volumes

To get more realistic rendering, you can optionally enable shadow volumes.

<img src="../../../Screenshots/shadow-volume.jpg" width="300px">

This can be enabled from the VolumeRenderedObject inspector in the editor, or by adding a `ShadowVolumeManager` component:

<img src="../../../Screenshots/volume-inspector-settings.jpg" width="300px">

## How it works

A shadow volume 3D texture is generated for the whole dataset.
A compute shader is repsonsible for updating the shadow volume, by casting rays from the light source through the dataset, and storing information about shadows.
Since this can take a long time, and async compute is not available on all platforms, the shadow volume manager divides the shadow volume into smaller chunks, and updates one chunk every frame.

## Performance

Because of the extra work of computing the shadow volume (compute shader) and the extra texture lookups during volume rendreing, this can have a bad impact on performance.

There are luckily some ways to work around this, at least on desktop applications (Windows, Linux, etc.).
- If you're using HDRP: [Enable DLSS](https://docs.unity3d.com/Packages/com.unity.render-pipelines.high-definition@12.0/manual/deep-learning-super-sampling-in-hdrp.html) and reduce the render scale.
- If you're using URP: [Enable FidelityFX Super Resolution](https://forum.unity.com/threads/amd-fidelityfx-super-resolution-fsr-preview-now-available.1141495/) and reduce the [render scale](https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@10.1/manual/universalrp-asset.html).

This works by rendering to a smaller render target (which is usually the bottleneck during volume rendering) and then doing "magic" upscaling on the rendered image.
14 changes: 10 additions & 4 deletions Documentation/General/VolumeRendering/VolumeRenderingSettings.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
**Table of contents:**
<!-- TOC -->

- [Cross section tools](#cross-section-tools)
- [Cross section plane](#cross-section-plane)
- [Box cutout](#box-cutout)
- [Sphere cutout](#sphere-cutout)
- [Render Mode](#render-mode)
- [Lighting](#lighting)
- [Shadow volumes](#shadow-volumes)
- [Cubic interpolation](#cubic-interpolation)
- [Early ray termination](#early-ray-termination)

<!-- /TOC -->

Expand All @@ -33,6 +34,11 @@ This comes at a cost, and performance may suffer (both memory and rendering spee

To apply lighting to the volume rendering, we calculate the gradient at each voxel and use this to calculate a normal, which we use to apply phong lighting.

## Shadow volumes

Improve the rendered image by using shadow volumes.
This is expensive, but there are ways to still get good performance with this enabled. See [shadow volume documentation](ShadowVolumes.md)

## Cubic interpolation

<img src="cubic-interpolation.png" width="300px">
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ There are 3 render modes:

There are also some other settings that you can adjust:
- "Enable lighting": Enable lighting calculations during volume rendering.
- "Enable shadow volume": Expensive, but may look much better!
- Enable early ray termination: Optimisation (you usually want this on). Requires the above setting to be disabled.
- Enable cubic interpolation: Use cubic interpolation of the 3D volume texture and gradient texture.

Expand Down Expand Up @@ -161,14 +162,18 @@ Yes, it's free even for commercial projects. The license ([MIT](https://chooseal

## How can I make it look better?
- Try [enabling cubic sampling](https://github.com/mlavik1/UnityVolumeRendering/pull/121#issuecomment-1281289885) in the inspector.
- Try [enabling shadow volumes](Documentation/General/VolumeRendering/ShadowVolumes.md) in the inspector.
- Try increasing the value of "MAX_NUM_STEPS" in the [DirectVolumeRenderingShader.shader](https://github.com/mlavik1/UnityVolumeRendering/blob/master/Assets/Shaders/DirectVolumeRenderingShader.shader)

## How can I get better rendering performance with lighting enabled?
If you're on a platform that supports it (Windows, etc.), try [enabling DLSS (HDRP)](https://docs.unity3d.com/Packages/com.unity.render-pipelines.high-definition@12.0/manual/deep-learning-super-sampling-in-hdrp.html) or [FidelityFX Super Resolution (URP)](https://forum.unity.com/threads/amd-fidelityfx-super-resolution-fsr-preview-now-available.1141495/) and reduce the render scale.

## How can I raycast the scene to find an intersection?
- See the [VolumeRaycasting documentation](Documentation/Scripting/VolumeRaycasting.md).

## I'm stuck! How can I get help?
[Create an issue](https://github.com/mlavik1/UnityVolumeRendering/issues).
You can also reach me on [Mastodon](https://floss.social/@sigsegv).
You can also reach me on [the fediverse](https://nattomaki.social/@matias).

# Contributing
See [CONTRIBUTING.md](CONTRIBUTING.md) for how to contribute.
Expand Down
Binary file added Screenshots/shadow-volume.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Screenshots/volume-inspector-settings.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d711135

Please sign in to comment.