A Unity tool to generate signed distance field volumes (as Texture3D
assets) from meshes.
Download the .unitypackage, or clone this repository.
Tested on Unity 2018.4, should work on earlier and later versions as well. Requires a GPU that supports Compute shaders.
- Select
Signed Distance Field > Generator
from the Unity menu bar, the tool window will pop up. - Press
Create
and a save dialog will pop up. - Choose a location and name to save your SDF as.
Mesh: the mesh you want to make an SDF from.
Resolution: the resulting Texture3D
resolution (I recommend you keep this below 64).
Submesh Index: for multi-part meshes, the index of the submesh you want to use.
Padding: the padding to surround your mesh within the SDF (only set this to be non-zero if you see artifacts).
Method: the method used to determine the sign of each voxel (only use DotProduct
if IntersectionCounter
yields artifacts).
I also included a simple raymarching shader to visualize the resulting SDFs.
- Drag a cube primitive into the scene, and set its
Transform
position to (0, 0, 0). - Change its material to
SDF > Materials > SignedDistanceField_Visualizer
. - Drag one of your created SDF assets into the
Volume
slot of the material. - Adjust the other material parameters as necessary.
Render As Solid: renders the SDF as a solid object with a simple Lambertian shading model.
Density: adjusts the density of the solid when Render As Solid
is turned off.
Maximum Steps: sets the number of steps taken when raytracing through the volume. Setting this requires some trial and error. Too small and detail is lost as sample positions are missed when tracing. Too big and performance suffers.