Order-independent Transparency in Unity
Description
This is an implementation of order-independent transparency in Unity's render pipelines. Order-independent transparency allows blending transparent objects correctly according to their actual depth in the scene. This is a huge improvement compared to traditional blending of transparent objects in the realtime graphics pipeline. The implementation uses Per-Pixel Linked Lists, implemented with RWStructuredBuffers. These are features requiring Shader Model 5.0 with ComputeBuffers, see the Unity Manual for supported platforms. Further technical information and resources are listed in the references section.
Installation
You can easily install this package with the Unity Package Manager using the project's git url. You can look at Unity's guide for detailed instructions.
Usage
For every implementation a sample scene is included and available for import with the Unity Package Manager. If in doubt try to import the sample you want to use and start from there.
-
Setup the rendering implementation for your chosen pipeline:
- High-Definition Render Pipeline: Create a Custom Pass volume and add
OitRenderPass
to it. - Universal Render Pipeline: Add the renderer feature
Order Independent Transparency Renderer
to your Universal Renderer Asset. Note: URP documentation only describes a fullscreen Blit which only works in Game view. If you know whether a fullscreen Blit in URP in Scene view as well as in Game view is possible, help would be very much appreciated. - Post-Processing Stack v2: Add the post-processing override
Order Independent Transparency
to a post-processing volume in your scene. - ImageEffect Component: Add the component
OitImageEffectComponent
to your scene e.g. to your main camera.
- High-Definition Render Pipeline: Create a Custom Pass volume and add
-
Change the material of every object that shall be rendered with order-independent transparency. They have to be rendered with a shader writing to the buffer used by the order-independent transparency implementation. Two sample shaders that you can use are included in this project:
OrderIndependentTransparency/Unlit
for all pipelines and additionallyOrderIndependentTransparency/Standard
for the built-in pipeline. -
Run your scene.
Platforms tested (Unity 2021.3.9f1)
Platform | Graphics Backend | Render output |
---|---|---|
Windows | DirectX 12 | โ |
DirectX 11 | โ | |
Vulkan | โ | |
OpenGLCore | ๐ (poor performance) | |
OpenGLES3 | โ (editor crashes) | |
Linux | Vulkan | โ |
OpenGLCore | ๐ (poor performance) | |
Mac | Metal | โ |
OpenGLCore | โ | |
iOS | Metal | โ |
Android | Vulkan | โ |
OpenGLES3 | ๐ (render artifacts) | |
WebGPU | - | ๐ฎ |
WebGL | - | โ |
Feedback and Contribution
- I consider this an open project. If you are interested in this topic or want to improve something please discuss, contribute and feel at home! ๐
- Feel free to open a discussion or an issue if you have ideas and improvements in mind.
- Pull requests are very welcome, see the issues section for open tasks that would improve this project.
References
- https://github.com/GameTechDev/AOIT-Update
- Holger Gruen and Nicolas Thibieroz, "OIT and Indirect Illumination using DX11 Linked Lists" https://de.slideshare.net/hgruen/oit-and-indirect-illumination-using-dx11-linked-lists
- Salvi, Marco, and Karthik Vaidyanathan, "Multi-layer Alpha Blending", in Proceedings of the 18th ACM SIGGRAPH Symposium on Interactive 3D Graphics and Games, ACM, pp. 151-158, 2014. https://www.intel.com/content/www/us/en/developer/articles/technical/multi-layer-alpha-blending.html
- Real-Time Rendering, Fourth Edition, by Tomas Akenine-Mรถller, Eric Haines, Naty Hoffman, Angelo Pesce, Michaล Iwanicki, and Sรฉbastien Hillaire, 1198 pages, from A K Peters/CRC Press, ISBN-13: 978-1138627000, ISBN-10: 1138627003 http://www.realtimerendering.com/