Log inGet started
Package

ray_shapes.computeShader

Newest version

This package holds more than this page lists. See all of its files in its world.

README.md

ray_shapes

Casts rays and segments against a table of analytic shapes (plane, sphere, box, capsule) and answers the closest hit of each. A ray is 8 words of rays: origin xyz, tmin, direction xyz, tmax; the direction need not be unit length, so a segment from a to b is origin a, direction b - a, tmin 0, tmax 1. A ray whose tmax is below its tmin meets nothing and tests no shape. The RAYS=segments variant takes the segments as columns instead: ray i runs from ray_from[i] to ray_to[i] (both Vec3), and is cast when ray_cast[i] is above 0; a segment not cast meets nothing and tests no shape. The table is one columns binding named shapes, a row a shape, columns in this order: shapeKind (Int: 0 plane, 1 sphere, 2 box, 3 capsule), center (Vec3), extent (Vec3: a plane's unit normal, a sphere's radius in x, a box's half size, a capsule's radius in x and half length in y), rotation (Vec4 quaternion x y z w; a capsule lies along its own y), bounce, friction (Float, carried for the caller) and index (Int, the caller's id for the shape).

Outputs, a value per ray: hit (t, then three zeros), hit_prim (the row of the hit shape, 0xffffffff for a miss), hit_normal (the unit surface normal, turned to face the ray's origin side, zero for a miss) and hit_end (the hit point pushed out along the normal by the skin param; for a miss the ray's end, origin + direction * tmax). A shape is hit from outside at its entry and from inside at its exit; of two hits at equal t the lower row wins. Exact.

The RAYS=live variant casts the segments of the first domain_count elements of ray_from and ray_to: n is the capacity a live count bounds, and a ray at or past the count leaves its outputs as they stand.

sim.particles runs the RAYS=live variant in its collision stage, a segment for each slot up to the extent of the slots its particles hold, from where the particle stands to where the step moves it, against the shape table of its colliders.