Page MenuHome

Compositor: Add Distance Transform Node
Needs ReviewPublic

Authored by Shinsuke Irie (irie) on Feb 1 2017, 12:58 PM.



A compositor node for calculating distance from the nearest masked pixel.
This node is useful for complicated masking and the other various effects.

  • "Distance" output gives an Euclidean distance from the closest masked pixel
  • "Vector X"/"Vector Y" outputs allow us to obtain information at the starting point of the distance if combining with the Displace Node
  • "Invert" option specifies whether to invert the inner and outer areas
  • "Relative" option specifies whether to use relative distance
  • Included in "Convertor" category

Unfortunately, the DistanceTransformOperation is performed in a single thread, but much faster than the DilateDistanceOperation/ErodeDistanceOperation with large number of steps.

Note: The output sockets are two scalar outputs and have to be connected to the Displace Node's "X Scale"/"Y Scale" inputs, not to the "Vector" input, because the vector input changes the input values by bilinear filtering and produces unexpected results.


Distance (normalized)

Use "Invert" option


Fake glow

Material color of the nearest object

Voronoi diagram

Masking/coloring toon edges

Diff Detail

rB Blender
Build Status
Buildable 2518
Build 2518: arc lint + arc unit

Event Timeline

Shinsuke Irie (irie) retitled this revision from to Compositor: Add Distance Transform Node.
Shinsuke Irie (irie) updated this object.

Can this be used to refine every alpha channel edge, i.e. image with an alpha channel, or just objects with a material id?

How is the compositor node setup for "Material color of the nearest object" and for "Voronoi diagram"?

Any chance to get this into the 2.79 release?

Works fast. I hope someone review it someday. Its great for creating procedural textures ("Compositor nodetree" is better for this purpose than "texture nodetree" anyway).

Any progress here? I ask, because this is a useful feature. And there seems to be no activity here.
@Sean Kennedy (hype) Maybe interesting for you too. :-)

Hi @Brecht Van Lommel (brecht), I know you have a lot to do, but could this feature someday included in Blender? (Only asking)

This is interesting, for sure. I'm not sure that in a typical compositing workflow if it would be extremely useful, but from the examples posted, it certainly looks like you can do some very artsy, creative stuff with it.

Change the value of CMP_NODE_DISTANCE_TRANSFORM from 323 to 324. 323 was used for CMP_NODE_CRYPTOMATTE.

Wo!262 (wo262) added a subscriber: Wo!262 (wo262).
Wo!262 (wo262) removed a subscriber: Wo!262 (wo262).