Struct ScyllaRay3
Blittable 3D ray representation with precomputed inverse direction for efficient ray-AABB intersection tests.
Inherited Members
Namespace: Scylla.Core.Structures
Assembly: ScyllaCore.dll
Syntax
[BurstCompile]
public struct ScyllaRay3
Remarks
This struct is specifically designed for Burst-compiled and DOTS-compatible ray queries. The precomputed InvDir field enables the efficient "slab method" for ray-AABB intersection testing, which computes intersection distances along each axis using reciprocals of the ray direction. By caching the inverse direction, we avoid repeated division operations during traversal. Special handling for zero or near-zero direction components:
- Components with absolute value ≤ 1e-12 are treated as zero
- Their inverse is set to +infinity to correctly handle rays parallel to axis planes This struct is fully blittable (contains only primitive types) and can be safely used in Burst-compiled jobs and DOTS contexts without managed object overhead.
Constructors
ScyllaRay3(float3, float3)
Creates a new ray and precomputes the inverse direction for efficient AABB intersection tests.
Declaration
public ScyllaRay3(float3 origin, float3 dir)
Parameters
| Type | Name | Description |
|---|---|---|
| float3 | origin | Ray starting point in 3D space |
| float3 | dir | Ray direction vector (does not need to be normalized) |
Remarks
The inverse direction is computed using the following safe reciprocal strategy:
- Computes 1/dir for each component using math.rcp()
- Checks if any component's absolute value is ≤ 1e-12 (effectively zero)
- For zero components, sets the inverse to +infinity This special handling ensures rays parallel to axis planes work correctly:
- A ray traveling along the XY plane (dir.z ≈ 0) will have InvDir.z = +infinity
- This causes the slab method to correctly handle infinite intersection distances The direction vector does NOT need to be normalized (any non-zero vector works).
Fields
Dir
Ray direction.
Declaration
public float3 Dir
Field Value
| Type | Description |
|---|---|
| float3 |
InvDir
Component-wise reciprocal of Dir. Zero (or near-zero) components produce +infinity.
Declaration
public float3 InvDir
Field Value
| Type | Description |
|---|---|
| float3 |
Origin
Ray origin.
Declaration
public float3 Origin
Field Value
| Type | Description |
|---|---|
| float3 |