Skip to content

Distance Fields

Luis Sanchez edited this page Mar 18, 2019 · 2 revisions

Distance fields are not used in this project

Distance fields notes

What are distance fields

A gridded structure, where each cell represents the shortest distance to a cell with some other property. Example (Designing with Distance Fields - S. Frisken): distFieldsR The distance field can be signed, to distinguish between the inside and outside of an object.

What are they good for in Pepr3d

Using distance fields allows us to represent binary texture information with better accuracy, while using less dense grid for the texture. Essentially, we trade color information for positional accuracy. Example (Improved Alpha-Tested Magnification for Vector Textures and Special Effects - Chris Green, Valve)

distFieldsValve

How are they gonna be used

Representation

All painting operations in Pepr3d are limited to N=4 user-defined colors. Compared to traditional approach, using distance fields requires lower texture resolution, saves memory and improves accuracy and speed of operations.

To store information for each of the N colors, we will require log₂(N) distance field textures total. (Colors are mutually exclusive, textures represent a binary value)

Usage

While painging the model we can either use either 2D or 3D texture to store the distance field. Both have their advantages and disadvantages:

2D
  • Lower memory consumption, faster operations
  • Allows painting on the surface directly, with no depth limitation

  • Requires unwrapping the mesh, while preserving correct triangle sizes
  • 2D distance field texture would not be continuous - this could cause issues with texture filtering
  • Texture lookup from a DF could cause "leaks" at triangle edges, even inside connected surfaces (unless we overdraw every time).
3D
  • More physically plausible painting. Ultra thin surfaces will be overdrawn through, but this behavior is to be expected while printing anyway.
  • Does not require mesh unwrapping
  • Easier to set resolution to correctly represent printing accuracy

  • Higher memory consumption, operations slower by a constant factor

Speedup

For our purposes, we only require the distance field data for the painted shape and a narrow shell around it, big enough to allow texture interpolation to work. Therefore we can avoid calculating the distance field outside this region.

** TODO ** Adaptively sampled distance fields

Exporting the color information

At export time, all triangles will need to be sampled for color at multiple points. Triangles can be divided into smaller ones as required, until we can export color accurately.