Home

Awesome

Capsule Occlusion

Top to bottom:Shaded view, ambient only, capsule/cluster debug view

What is this?

A Unity package implementing capsule/character occlusion as seen in The Last Of Us1, Shadow Warrior 22 and others. It is mainly intended to be used in forward rendering pipelines with MSAA (where SSAO is not viable).

Unlike other implementations I've seen, this one supports fairly robust self-occlusion based on the normal direction, which means you can evaluate it for the caster mesh as well.

To speed up rendering, capsules are gathered in clusters (implemented as a linked list on the GPU) which are used to limit per-pixel occlusion evaluation.

Clustering can be performed using either a naive compute shader or a single rasterization pass (the latter being the faster and preferred method).

How do I use it?

  1. Add the package to your project either using the Package Manager (Add package from GIT url...) or by manually placing it in your project's Packages folder (embedded package).
  2. In your scene or prefab, add one or more OcclusionCapsule components.
  3. Add a CapsuleOcclusionCamera component to your camera.
  4. In your shader, add #include "Packages/se.fewes.capsuleocclusion/Shaders/CapsuleOcclusion.hlsl"
  5. In your shader, evaluate occlusion using the function GetCapsuleOcclusion(worldPos, worldNormal, screenUV, linear01Depth);

Requirements

Areas of improvement

Acknowledgements

Capsule intersection and occlusion approximation functions by Inigo Quilez:

Capsule-capsule collision function (used for compute clustering) by Noah Zuo:

Low Poly Soldiers Demo used for screenshot by Polygon Blacksmith:

Footnotes

  1. Lighting Technology of "The Last Of Us" - http://miciwan.com/SIGGRAPH2013/Lighting%20Technology%20of%20The%20Last%20Of%20Us.pdf

  2. Rendering of Shadow Warrior 2 - https://knarkowicz.files.wordpress.com/2017/05/knarkowicz_rendering_sw2_dd_20171.pdf