Dynamic Signed Distance Fields in Unity

Signed Distance Fields, or SDF are increasingly common in game development, from the SDFGI global illumination solution in the Godot Engine, to the in development modeler MagicaCSG and now dynamic support in the Unity game engine. Unity already had support for SDF in the VFX graph, however you had to prebake them either in a DCC tool like Houdini or using the SDF bake tool. Now there is a new project, Mesh to SDF that enables you to create SDFs at runtime.

Details of Mesh to SDF:

A real-time Signed Distance Field generator. Use a Mesh or a dynamically deforming SkinnedMesh as input to generate a 3D SDF texture every frame.

The SDF can be used by the VFX Graph, the Hair system, and other effects relying on SDFs.

The generator is real-time – to achieve better performance, it sacrifices robustness and the ability to handle large meshes. Typical resolutions would be a 5-8k triangle mesh in a 16^3-64^3 voxel volume. If your mesh is much larger or messy (holes, spiky shapes, etc.), it’s best to use a cleaner low-res proxy mesh instead. Note that the SDF generator shipping with the VFX Graph has a more robust handling of larger or messy meshes, but it’s slower.

The generator works by first splatting distances into voxels in a small area around each triangle, then using either a linear flood or jump flood to fill the rest of the volume.

You can add SDF Mesh support to Unity using the Package Manager’s GitHub support. Additionally there are a trio of examples available for showing how to interact with the new SDF functionality in a VFX graph.

Key Links

Mesh To SDF GitHub Repository

Mesh To SDF Examples

You can learn more about adding dynamic signed distance fields to the Unity game engine in the video below.

Scroll to Top