Rendering

Screen Space Tracing

ScreenSpace::Trace provides functionality for tracing rays in screen space to compute effects like Dynamic Reflections or any kind of ray in world space. It leverages hierarchical ray marching for efficient performance.

API Reference

static TraceResult ScreenSpace::Trace(
    const float3 Position,  // The world-space origin point of the trace.
    const float3 Direction, // The world-space direction vector of the ray.
    uint nMaxSteps = 64     // Maximum steps for ray marching.
);

The TraceResult structure represents the outcome of a trace operation:

MemberTypeDescription
HitClipSpacefloat3The hit position in clip space. XY is the UV, Z is the depth.
ConfidencefloatThe confidence level of the hit detection.
ValidHitboolIndicates whether a valid hit was found.

Usage Example

Texture2D FrameBufferCopy = /* .. */
Material m = /* .. */

float3 origin = /* world-space origin */;
float3 direction = /* world-space direction */;

TraceResult result = ScreenSpace::Trace( origin, direction );

if ( result.ValidHit )
{
    float3 vReflectionColor = FrameBufferCopy[ result.HitClipSpace.xy ].rgb;
    m.Emission = lerp( m.Emission, vReflectionColor, result.Confidence );
}

Source: Facepunch/sbox-docs (CC-BY-4.0) · updated 2026-08-03. Read it rendered on the official docs.

More in Rendering

Community wiki — not affiliated with Facepunch Studios. For the latest and most authoritative information, see the official developer wiki.