UnityRef is currently in early development. Some features may be incomplete and/or not functioning.

UNITYREF

Your Pit Stop For Solving ANYTHING in Unity

graphics

[URP] View Angle Face Fading in Shader Graph

Solution

shadersrenderingshader graphlighting

Unity 2021.x - Unity 6.3.x

Published 26 days ago

Issue

 Perpendicular faces to the camera can disrupt the visual integrity of translucent assets, leading to an unnatural appearance in foliage. Identifying the correct nodes and vector math within Shader Graph to control the Alpha channel effectively is necessary for smooth transitions.

Quick-Fix

Implement view-angle-based face fading by utilizing Normal Vector and View Direction nodes with a Dot Product operation to drive dynamic transparency.

Expand Analysis

Achieving view-angle-based fading involves calculating the relationship between your surface’s normal vector and the camera’s view direction. This indicates how directly a face is oriented towards the camera. Faces that are nearly perpendicular to the camera’s view will have a Dot Product closer to zero, while faces directly facing the camera will have a Dot Product closer to one.

To implement this in your shader graph:

  1. Create a Normal Vector node and set its Space property to World.
  2. Create a View Direction node and set its Space property to World.
  3. Feed both outputs into a Dot Product node.
  4. Connect the result to a Saturate node to clamp values between 0 and 1.
  5. Link the output to the Alpha input on the Fragment stack of your master node.

Additional Tips:

  • Apply a Power node to the Dot Product output to control the steepness of the fading effect.
  • Ensure the material’s Surface Type is set to Transparent or that Alpha Clipping is enabled in the Graph Settings for the effect to manifest.
  • Using the One Minus node can invert the Dot Product behavior to target faces pointing directly at the camera instead.
  • For foliage, multiply the Dot Product result by a Vertex Color or Texture2D alpha to maintain existing detail.

Related Posts Haven't quite found a solution to your problem? We think these posts might help you.

Content inspired by a Unity discussion post.