Website powered by

Unity Shadergraph Oscillating Fan

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.

Overiew of the Vertex Shader where all of the fancy stuff happens, it's very simple, which is nice.

Overiew of the Vertex Shader where all of the fancy stuff happens, it's very simple, which is nice.

Simple Fragment shader using 3 texture samples, this could have been simplified, the Roughness should have been set as Smoothness from Painters export also.

Simple Fragment shader using 3 texture samples, this could have been simplified, the Roughness should have been set as Smoothness from Painters export also.

Material overview with the two animation properties exposed for the user to easily change the blade rotation speed and the head oscilation speed.

Material overview with the two animation properties exposed for the user to easily change the blade rotation speed and the head oscilation speed.

Texture sets and UV layout, it could be better, some islands want rotating/straightening, I didn't want to overlay the blades but scaled down to save on texture space you'd not see much due to the animation.

Texture sets and UV layout, it could be better, some islands want rotating/straightening, I didn't want to overlay the blades but scaled down to save on texture space you'd not see much due to the animation.

Capture of the fan in Marmoset to see that nicer PBR look.

Wireframe overlay view in Marmoset, the mesh could be much more optimised, reducing the edge bevels etc but I was aiming for a close up view for this asset and focused more on the shader animation aspect.

Wireframe overlay view in Marmoset, the mesh could be much more optimised, reducing the edge bevels etc but I was aiming for a close up view for this asset and focused more on the shader animation aspect.

Vertex Colour Red and Green was used on the mesh to mask out the fan blades and head so that those elements can be separated in the shader, the base is separate with no vertex colours to remain unaffected, the head is separate for rotation angle.

Vertex Colour Red and Green was used on the mesh to mask out the fan blades and head so that those elements can be separated in the shader, the base is separate with no vertex colours to remain unaffected, the head is separate for rotation angle.