Share

Query raycast intersections

Use the get_raycast_locations node to return the locations of the first intersections of rays with a mesh. You can then use the locations with the sample_property node to sample the values of properties such as position, color, surface normal, and so on.

Getting the colors at raycast locations

In the example above, rays are cast from the ball's point positions along their normals. If the rays hit the plane, the interpolated vertex colors are sampled.

To find the locations of raycast intersections and sample values from them:

  1. Add a get_raycast_locations node to the graph.

  2. Connect the target object toward which you are casting rays into the geometry input.

  3. Connect the source positions from which the rays originate into the positions input.

  4. Connect the matching directions along which to cast each ray into the directions input.

  5. Specify the proximity_method:

    • semi-line shoots an infinite ray along the direction vector.
    • line shoots infinite rays along both the positive and negative direction vectors.
    • segment shoots a ray along the direction vector but only as far as the vector's length. This allows for different distances for each ray, unlike cutoff_distance.
  6. Set use_cutoff_distance and cutoff_distance as desired. When used, only intersections that within the cutoff distance are returned. If you use a cutoff distance in addition to the segment method, the shorter distance is used for each ray individually.

  7. Set min_distance to a non-zero value if desired. This prevents returning locations that are too close to each position. It can be useful to avoid always returning the input position when casting rays from an object onto itself.

  8. Use the outputs of the get_closest_locations node to sample the values of properties on the geometry:

    • You can connect the locations output into one or more sample_property nodes to sample properties immediately (see Sample geo properties at locations). In these cases, you typically sample on the same geometry that is connected to the get_closest_locations node.
    • You can use the found output with if nodes to control what happens next in the graph on a per-ray basis, including whether or not to sample properties.
    • If the input positions correspond to the points of another geometric object, you can store the outputs as geo properties on that object to use them elsewhere (see Getting and setting properties of geometric objects). You can also cache them and use them for future frames in a simulation (see Create custom simulations).

Sampling colors and positions at the intersections of rays with a mesh

Was this information helpful?