In this lesson, you will learn how to procedurally recalculate surface normals when applying vertex displacement to ensure your lighting reacts correctly to dynamic geometry.
When you use the Position node in Shader Graph to push vertices outward—perhaps to create a pulsating organic growth or ocean waves—you are changing the physical orientation of the mesh. However, the light-reflecting "Normal" vectors often remain fixed in their original orientation. This causes the lighting to look "flat" or disconnected from the new, displaced shape, resulting in artifacts where shadows and highlights don't align with the altered geometry.
To solve this, you must derive new surface normals based on the displacement. The most efficient way to do this in Shader Graph is by using the Normal Reconstruct node or by calculating the cross-product of two displaced neighboring points.
Implementation Logic
- Sample Displacement: Determine the offset for your current vertex and two slightly offset neighboring points (e.g.,
UV + (0.01, 0)andUV + (0, 0.01)). - Apply Math: Use the
Positionnode to apply your displacement logic to all three points. - Calculate Tangents: Find the vectors between these displaced positions.
- Cross Product: Use a
Cross Productnode on these vectors to find the new surface normal vector. - Normalize: Always plug the result into a
Normalizenode to ensure the vector has a length of 1, preventing lighting intensity bugs.
By outputting this calculated vector into the Normal slot of your Master Stack, the GPU performs a lighting calculation based on the current orientation of the displaced vertex rather than the static mesh data. This ensures that as your object deforms, the light "wraps" around the new curves and ridges naturally, maintaining visual continuity during complex geometry animations.
Key Takeaway: Dynamic vertex displacement requires procedural normal recalculation to ensure that your lighting model correctly interprets the new orientation of your geometry.