graphics
[VFX Graph] Randomly Select Sprite Sheet Frames in Shader Graph
Solution
Unity 2021.x - Unity 6.3.x
Published 28 days ago
Developers often encounter limitations when synchronizing per-particle data from VFX Graph to a custom Shader Graph for texture atlas indexing. Without manual UV manipulation, particles cannot independently select unique frames from your sprite sheet.
To achieve random texture selection, UV coordinates must be mapped to a specific grid index.
- Create a new
Shader Graphand add aFlipbooknode. - Define the
WidthandHeightparameters to match the grid of your sprite sheet. - Create a new
Floatproperty named FrameIndex and ensure it is exposed in theBlackboard. - Connect the FrameIndex property to the
Tileinput of theFlipbooknode. - Within the
VFX Graph, locate the exposed FrameIndex on theOutput Particleblock. - Assign a
Random Numbernode or use thetexIndexattribute to drive the FrameIndex value.
Additional Tips
- Set the texture
Wrap ModetoClampto avoid sampling pixels from adjacent tiles. - Use a
Floornode before theTileinput if the incoming value is a continuous float to ensure discrete frame selection. - For high-performance requirements, consider using
Texture2DArrayto simplify the sampling logic and avoid UV math.
TL;DR
Utilize the Flipbook node and drive the Tile input with an exposed FrameIndex property linked to per-particle attributes.
Related Posts Haven't quite found a solution to your problem? We think these posts might help you.
[Vector Graphics] Referencing SVG Assets via C# Scripts[VFX Graph] Fix Performance Drops from Transparent Fog Overdraw[HDRP Water] Eliminate Visual Glitches: Subsurface Control with UnderwaterMask
Content inspired by a Unity discussion post.