Vixen
02b45cc4
csharp
public sealed class ScreenSpaceTrace

A ray against the frame's own depth buffer — doc 19 § L3's trace order, first stage.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

What a screen trace is for. The depth buffer holds geometry the distance field may not — skinned meshes, alpha-tested foliage, anything too small or too mobile for a signed distance representation — so the trace order asks the screen first and marches the field only where the screen has no answer. A hit gives back nothing, exactly as a field hit does: a surface's own radiance is the § L4 surface cache, and until it exists a screen hit is an occlusion, honest rather than convenient.

The naive march is the baseline, and the HZB traversal landed against it. A fixed count of equal steps along the ray, each projected and compared — deterministic, so the device kernel is held to it texel by texel. Setting Pyramid switches the march to the hierarchical DDA over ScreenDepthPyramid — the nearest reduction, where HiZReduce keeps the farthest — with the agreement and the fetch counts both asserted rather than claimed.

The perspective form is the same DDA, and it is exact. Screen position and device depth are both linear in the screen-space parameter of the projected segment — the rasteriser's own interpolation argument — so projecting the two endpoints is the whole perspective form of the traversal. What perspective changes is the shell: 1/w is the third quantity linear in that parameter, and interpolating it is what lets LinearThickness measure the shell in view units, where a constant device-depth shell is paper-thin near and metres deep far. Only a ray with an endpoint behind the camera's plane — a projected segment that is not a segment — declines to the fixed-step walk, which guards per sample.

A sample is occluded when it stands behind a surface, within its thickness. Depth is reversed, so behind is a smaller device depth; the shell is Thickness deep in device-depth units, or LinearThickness deep in view units where a perspective ray can pay for the conversion. A sky texel occludes nothing, and a ray that leaves the viewport stops being the screen's to answer — the caller's field march continues regardless, because a screen miss never proves the world empty.

Fields and properties (6)

  • public Matrix4x4 ViewProjection

    The view-projection of the camera that drew the depth being marched.

  • public int Steps

    How many equal steps a ray takes over its distance.

  • public float Thickness

    How deep behind a surface a sample still counts as inside it, in device depth.

  • public float LinearThickness

    How deep the shell is in view units, where a perspective ray can say. Zero keeps the device-depth shell everywhere.

  • public ScreenDepthPyramid? Pyramid

    The nearest-per-cell pyramid the march skips empty screen with, or null for the fixed-step walk.

  • public int Samples

    How many pyramid or depth fetches the last march made.

Methods (3)

  • public ScreenSpaceTrace(ReconstructedScreenSurface surface)

    Builds a trace over one frame's buffers.

  • public bool Hit(Vector3 origin, Vector3 direction, float maxDistance)

    Whether a ray from a point is stopped by something the screen can see.

  • public bool TryHit(Vector3 origin, Vector3 direction, float maxDistance, out Int2 pixel)

    The same march, keeping which pixel stopped the ray.

Used by (7)

  • ReflectionRendererDeviceTestsVixen.Graphics.Golden.Tests
  • ReflectionTraceDeviceTestsVixen.Graphics.Golden.Tests
  • ScreenDepthPyramidTestsVixen.Rendering.ScreenProbes.Tests
  • ScreenProbeTraceDeviceTestsVixen.Graphics.Golden.Tests
  • ScreenSpaceTraceTestsVixen.Rendering.ScreenProbes.Tests
  • TracedReflectionsVixen.Rendering.Reflections
  • TracedScreenProbeGatherVixen.Rendering.ScreenProbes