/SDFGITest

Primary LanguageC#BSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

Signed Distance Field Generator

A Unity tool to generate signed distance field volumes (as Texture3D assets) from meshes.

demo

To Install

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.

To Use

  1. Select Signed Distance Field > Generator from the Unity menu bar, the tool window will pop up.
  2. Press Create and a save dialog will pop up.
  3. Choose a location and name to save your SDF as.

Options

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).

To Visualize

I also included a simple raymarching shader to visualize the resulting SDFs.

  1. Drag a cube primitive into the scene, and set its Transform position to (0, 0, 0).
  2. Change its material to SDF > Materials > SignedDistanceField_Visualizer.
  3. Drag one of your created SDF assets into the Volume slot of the material.
  4. 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.