In this lesson, you will learn how to bypass standard static geometry by mathematically offsetting vertex positions within a shader to create fluid, organic animations.
Understanding Vertex Manipulation
Up until now, we have treated meshes as rigid shells that only change appearance through textures or lighting. However, the true power of shaders lies in the Vertex Stage. By accessing the position data of each individual vertex, we can shift, rotate, or oscillate points in 3D space before the GPU rasterizes them into pixels. This allows for effects like waving grass, rippling water, or pulsating alien surfaces without needing complex skeletal animations.
Applying Sine Waves for Movement
The most common way to achieve this is by using a mathematical function—usually a Sine wave—driven by the Time node. By adding the result of a Sine wave to the object's vertex position, you create a rhythmic, looping movement.
In Shader Graph, your workflow looks like this:
- Get Position: Start with a
Positionnode set to Object Space. - Isolate Axis: Use a
Splitnode to target the axis you want to deform (e.g., the Y-axis for vertical movement). - Apply Math: Feed a
Timenode into aSinenode. Multiply this by aFloatproperty (to control intensity) and add it to your original axis value. - Recombine: Use a
Combinenode to put the original X and Z coordinates back with your new, modified Y coordinate. - Output: Plug the result into the
Vertex Positionslot of the Master Node.
// Conceptual logic inside a custom HLSL block
float3 modifiedPos = input.positionOS;
modifiedPos.y += sin(input.positionOS.x + _Time.y * _Speed) * _Amplitude;
return modifiedPos;
Constraints and Performance
Because vertex manipulation happens on the GPU, it is highly performant. However, remember that you are only moving the visual mesh; the Collider of the object will remain in its original position. For physics-heavy gameplay, you would need to adjust the collider separately. Additionally, ensure you are using Object Space to keep the deformation relative to the object’s orientation, preventing the mesh from "tearing" or warping incorrectly when the object rotates.
Key Takeaway: By modifying vertex positions via mathematical functions like Sine waves, you can transform static meshes into dynamic, living assets directly within the GPU pipeline.