An implementation of this shader is used in Night Loops (Wishlist if you'd like to support, thank you!)
The shader prevents 2D Sprites from clipping horribly into the 3D environment when using a skewed orthographic camera. This is useful for setups where 2D sprites must be rotated towards the camera in a 3D environment to achieve a 2.5D look and feel. Also gives 2D Sprites a Lit Behavior when using Unity's Universal RP 3D settings.
- helps prevent rotated Sprites from clipping nearby 3D meshes by rewriting the clip space depth as if the Sprite were vertically aligned in the world like the meshes are
- allows Sprites to react to lighting and receive / cast realtime shadows from Directional Lights
"Feels good to not have my head inside these cabinets all day."
- URP 10.2.1+
- Unity 2020.2.1
For older versions see branches (e.g. 2019.3)
- nondirectional shadows and directional shadows on mobile use world position passed to the fragment shader pass, so you may see sprites receiving shadows as if they were still being clipped with these use cases
- this renders the Sprite as an opaque object, so sorting order will be ignored
- in Unity, you may need to also set the Sprite Renderer component's properties
Cast Shadows = On
andReceive Shadows = True
(which are available in Debug mode only) - in LitForwardPass.hlsl, in the vertex shader, the clip space depth is overwritten
- bgolus' shader-only solution for 2D sprites clipping into 3D meshes here
- Unity's Graphics repo
- original discussion can be found here