Share

Distance - Arnold User Guide

The Distance shader uses sample rays to estimate the distance from the shading point to the nearest surface. This distance is mapped to a color linear gradient from Near Color to Far Color. You can use trace sets to include or exclude objects from the distance measurement.

A video that demonstrates uses for the Distance shader can be found here.

Note:

The Distance shader does not currently work with displacement. Trace sets are not currently available on GPU.

Samples

The Distance measured by this shader is a sampled estimate and not exact, so as the number of Samples increases the measure becomes more accurate. However, increasing the Samples also makes the shader more expensive to evaluate, so a tradeoff must be made that will depend on how important relatively small and faraway surfaces which are unlikely to be sampled are to the final result.

Note:

Increasing this value will increase render times.

Below we see the difference increasing the number of Distance Samples has when some small spheres are positioned on a plane that has the Distance shader assigned to it (via a Ramp RGB).

Distance

This parameter controls the maximum Distance beyond which the shader will not take surfaces into consideration.

Note:

Larger Distance values may require more Distance Samples.

Near Color

This parameter controls the color of the shading resulting from the nearest sampled surface being in contact with the shading point.

Far Color

This parameter controls the color of the shading resulting from the nearest sampled surface being at a distance or greater distance from the shading point.

Near Color: black, Far Color: white (default).

Trace Set

Note:

Trace sets are not currently available on GPU.

It is possible to tag objects to be part of one or many trace sets. You can use trace sets to control which objects are traced.

If you want only certain objects to use distance:

  1. Create a trace set by entering a name in the shader Trace Set text box (for example, "objects_to_use_distance").
  2. Put the objects in that trace set (by entering the same trace set name for those shapes). Only objects in the trace set will be clipped.

If you want to avoid some objects using distance:

  1. Create a trace set by entering a name in the shader Trace Set text box (for example, "objects_not_to_use_distance").
  2. Disable the Inclusive checkbox.
  3. Put the objects in that trace set (by entering the same trace set name for those shapes).
  4. All objects not in the trace set will be clipped.

Inclusive

If on, the tracing works in inclusive mode, else in exclusive, as described above.

In the example below, the sphere has the same Trace Set name as the Distance shader. The plane and cube do not have trace sets.

In the example below, the wall object has a Distance shader assigned to it.

Alternative Outputs

Out Distance

Returns the distance to the nearest surface.

Out Direction

Returns the direction to the nearest surface.

Note:

Depending on the plugin that you are using, you may need to connect the Distance Out Direction via a Float to RGB to the color rgb of a surface shader.

.ass files that demonstrate Distance Out Direction can be found here.

In the above example we are seeing color on one side and negative color on the other. This can cause issues. To view color on both sides you will need to clamp negative values to 0. For example, if you want red on both sides then use an Abs shader as per the images below.

If you want positive and negative values, then you need to remap the -1, to 1 range to 0 to 1. You can for instance do that with a shader network that does (input+1) * 0.5. So an Add shader piped to a Multiply shader (or ramp shader). Alternatively, in the images below a Pow shader raised to the 4 (Exponent) has been used.

In the example below, a Distance shader has been connected to a Standard Surface shader (Out Direction xyz -> Base Color rgb). Metalness is at 1 and Specular Anisotropy has been set to 0.9. A clipping object has been placed in the center of the disc geometry to achieve the distance shading effect.

In the example below, the building facade geometry has been instanced. A Distance shader (out_color.xyz -> rgb color) has been layered over the building texture map to create the appearance of fire damage (Out Direction: x) or a worn and darkening effect under the ledges of the windows (Out Direction: y).

In the example below, the head and eyeball geometry are separate objects. The skin texture is being multiplied with a Ramp RGB which is being driven by the Distance Out Direction Y and Z.

In a similar example below, the clown mask and eyeball geometry are separate objects. The texture areas around the eyes are being multiplied by the color of a Ramp RGB which has a Distance shader (Out Direction Y) connected to it.

Was this information helpful?