Jiaquarium / unity-URP-2.5D-lit-shader

2D Lit Sprite shader for 2.5D art style using an orthographic camera 🖤

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Universal RP 2.5D Lit Sprite Shader 🖤 · Hits

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.

Shader Demo Pic

  • 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

Before and After Comparison of Using Sprites Near 3D Meshes

Comparison

"Feels good to not have my head inside these cabinets all day."

Requirements

  • URP 10.2.1+
  • Unity 2020.2.1

For older versions see branches (e.g. 2019.3)

Things to Keep in Mind

  • 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 and Receive Shadows = True (which are available in Debug mode only)
  • in LitForwardPass.hlsl, in the vertex shader, the clip space depth is overwritten

References

About

2D Lit Sprite shader for 2.5D art style using an orthographic camera 🖤


Languages

Language:HLSL 61.7%Language:ShaderLab 38.3%