Overview of a simple vertex animation shader for an oscillating fan asset I made for a Mobile VR Quest 2 project.
I like to avoid using bones and animations generally, if only for practice, it's nice to figure out and try new things. I know this would be very performant in some odd situation where you'd have many such fan assets in a scene, but for me this was a quick, flexible way to offload the animation of this asset to the GPU in the shader.
All of the fancy work happens in the Vertex Shader, where the mesh is rotated around an axis for the blades and head in two steps, first rotating the blades and masking them by the Green vertex colours and then oscillating the head and blades by the Red vertex colours. I could likely have made the fan one entire mesh and used a Blue vertex colour to apply the pitch rotation of the head and blades if I wanted to control that and reduce a draw call for the fan base, next time!
I know I can improve on this, but I feel it might be valuable for others who are learning Shader Graph and how they can use vertex colours with it, perhaps someone may learn from this as I did while making it.
Thanks for reading and looking.
Short capture of the shader working in Unity URP.
Capture of the fan in Marmoset to see that nicer PBR look.