Ray

Cast rays and detect collisions with geometry.

What it does

Ray casts one or more rays from a point and finds where they first touch input geometry. Each ray reports a hit position, surface normal, distance, and a reflection direction, for driving particles, lasers, line-of-sight checks, or procedural bounce patterns. With Geometry unwired, rays collide with whatever else is visible in the scene.

Rays can fan out, as a flat 2D fan or a 3D cone or sphere of rays around one direction, and can ricochet off what they hit for a number of bounces, losing energy each time. Render Mode set to None returns the collision data with no visible ray.

When to use it

ParameterTypeDefault
geometryOneOf([Collection])
source_pointsOneOf([Collection, Vec3Array])
originVec3(0, 0, 0)
directionVec3(1, 0, 0)
max_lengthNumber1000
angle_offsetNumber0
offsetNumber0
max_bouncesNumber0
bounce_energy_lossNumber0
ray_countNumber1
spread_angleNumber360
ray_patternString"Fan"
max_stepsNumber1
hit_modeString"First Hit"
render_modeString"Tube"
stroke_widthNumber1
colorColorrgba(1.00, 1.00, 1.00, 1.00)
miss_colorColorrgba(0.50, 0.50, 0.50, 1.00)
analyticalBooleantrue
opacityNumber1

Gotchas

Max Steps, the distance-field ray-march step count, currently has no effect. Leave it at the default.

With Geometry left unwired, rays collide against last frame's scene. That keeps the graph free of same-frame cycles, and it means a shape added this frame is not hit until the next frame.

Wiring Source Points overrides the Origin parameter and casts one ray per point using the scalar Direction. Ray Count, the fan, and Spread Angle are all ignored in that mode.

Set Bounces to 0 for a first-hit ray. Raise Bounce Energy Loss toward 1 to make bounces die out quickly, or keep it near 0 for a near-perfect mirror ricochet.

Worked example

  1. Add a Ray. Set Origin and Direction, or wire Source Points to cast one ray per point instead.

  2. Wire a shape or mesh into Geometry, or leave it unwired to collide with the rest of the scene.

  3. Raise Ray Count and Spread Angle to fan the ray into a spray; switch Ray Pattern to Sphere for a 3D cone instead of a flat fan.

  4. Raise Bounces above 0 to have the ray ricochet off what it hits, and use Bounce Energy Loss to fade it out over successive bounces.

  5. Read Hit Points, Hit Normals, or Reflected downstream to drive particles, or set Render Mode to None if you only need the collision data.

See also

Stroke · Mutate · Skeleton · Geometry (meshes)