---
id: "sharc"
title: "SHaRC: Spatially Hashed Radiance Cache"
aliases: [SHaRC, hash-grid radiance cache]
domain: "gi"
stage: "lighting"
realtime: "realtime"
platforms: [desktop-gpu]
year_introduced: 2023
inputs: [gbuffer, mesh]
outputs: [radiance]
style: "photoreal"
dynamic: "dynamic"
cost: "medium"
authority: "NVIDIA"
url: "https://texelatlas.vercel.app/t/sharc/"
sources_verified_at: "2026-11-29"
---
# SHaRC: Spatially Hashed Radiance Cache (NVIDIA)

> A world-space radiance cache stored in a GPU hash table keyed by quantized position and normal. Path-tracing paths end early by reading cached radiance, and a few extra paths update the cache.

## Reach for it when

- real-time gi on ray tracing with limited rays
- indirect lighting noise too high for the budget
- cache radiance in world space across frames
- path traced gi slows frame rate on mid range gpus

## How it works

The cache is a hash map from a voxel key (position quantized by a camera-dependent cell size, plus a coarse normal bucket) to an accumulated radiance and a sample count. There is no neural network.

A frame has three steps. **Update**: a sparse subset of screen pixels traces full paths of several bounces. At each vertex, the throughput-weighted contribution of the rest of the path is written to the hash entry for that vertex's cell with atomic adds, so each path trains many cells. **Resolve**: a pass converts raw accumulation to stable averages, blending with the previous frame using an exponential moving average and decaying old entries. **Query**: the normal render traces paths for each pixel but stops after one or two bounces, reading the cell's cached radiance in place of the remaining transport.

Cells are quantized with a level-of-detail that grows with distance from the camera, so the cache is compact and fine resolution is spent near the viewer. A compaction and stale-entry eviction scheme keep the table bounded.

## When to use it

Choose it as a simple, drop-in multi-bounce radiance cache for a path tracer, particularly when you want to avoid a neural network and need broad GPU support.

Prefer [neural-radiance-caching](neural-radiance-caching) when you want a smoother, learned cache and have the hardware for it. Prefer [surfel-gi](surfel-gi) when you want an explicit surface-based cache. Prefer [restir-gi](restir-gi) for high-frequency per-pixel indirect. Prefer [ddgi](ddgi) for regular-grid probes of diffuse irradiance.

## Cost

medium — Cost is one extra sparse path pass plus hash lookups at path ends; the number of update paths and cache capacity are the main tuning knobs.
Measured GPU Weight: 25.71× baseline (heavy) — 0.8459 ms median / 0.8751 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 23.81× baseline (heavy) — 0.3785 ms median (2.23× faster on L4).
Ampere A100 scaling: 15.57× baseline (moderate) — 0.4483 ms median (1.89× faster on A100).

## Failure modes

- Blocky or noisy indirect where the voxel size is coarse compared with lighting variation, with visible cell boundaries
- Light leaking across thin walls because cells key only on position and a coarse normal
- Hash collisions and eviction cause flicker if the table is undersized for the scene
- Cached radiance is diffuse-like: glossy and specular reflection hits get inaccurate values

## Dataflow

- Inputs: gbuffer, mesh
- Outputs: radiance
- Platforms: desktop-gpu

## Presets

### SHaRC (Spatial Hash Radiance Cache) — quantized world-space hash voxels (left) vs smooth multi-bounce GI (right) (glsl-fragment; rendered 2026-11-30)

```json
{
  "P_VOXEL_RES": 7,
  "P_BOUNCE_STR": 1.2,
  "P_SUN_SWEEP": 0.55,
  "P_SPLIT": 0.48
}
```

```glsl
const float P_VOXEL_RES = 7.0; // P Hash Grid Density [4.0, 14.0, 1.0]
const float P_BOUNCE_STR = 1.20; // P Radiance Gain [0.2, 2.0, 0.05]
const float P_SUN_SWEEP = 0.55; // P Sun Motion [0.0, 2.0, 0.05]
const float P_SPLIT = 0.48; // P Hash Voxels / GI [0.0, 1.0, 0.02]

vec2 mapCourtyard(vec3 p) {
  float dFloor = p.y + 0.72;
  float dBack = p.z + 1.45;
  vec2 res = vec2(dFloor, 1.0);
  if (dBack < res.x) res = vec2(dBack, 2.0); // terracotta sun-baked back wall

  // Two staggered modern architectural monoliths casting colored sky/sun bounce
  vec3 b1 = abs(p - vec3(-0.62, -0.08, -0.25)) - vec3(0.26, 0.64, 0.34);
  float d1 = length(max(b1, 0.0)) + min(max(b1.x, max(b1.y, b1.z)), 0.0);
  if (d1 < res.x) res = vec2(d1, 3.0);

  vec3 b2 = abs(p - vec3(0.56, -0.22, -0.45)) - vec3(0.30, 0.50, 0.28);
  float d2 = length(max(b2, 0.0)) + min(max(b2.x, max(b2.y, b2.z)), 0.0);
  if (d2 < res.x) res = vec2(d2, 4.0);

  float dSph = length(p - vec3(0.0, -0.40, 0.05)) - 0.32;
  if (dSph < res.x) res = vec2(dSph, 5.0);
  return res;
}

vec3 calcNormal(vec3 p) {
  vec2 e = vec2(0.0025, 0.0);
  return normalize(vec3(
    mapCourtyard(p + e.xyy).x - mapCourtyard(p - e.xyy).x,
    mapCourtyard(p + e.yxy).x - mapCourtyard(p - e.yxy).x,
    mapCourtyard(p + e.yyx).x - mapCourtyard(p - e.yyx).x
  ));
}

// Compute indirect radiance stored at a world position p & normal n (evaluated at voxel center on left, smooth on right!)
vec3 evalSharcRadiance(vec3 p, vec3 n, vec3 sunDir, float gain) {
  // Warm terracotta bounce from sun-lit back wall + cool zenith sky fill + emerald monolith bounce
  float backBounce = max(dot(n, vec3(0.0, 0.15, -1.0)), 0.0) / (0.65 + (p.z + 1.45) * (p.z + 1.45));
  float leftBounce = max(dot(n, normalize(vec3(-0.62, -0.1, -0.25) - p)), 0.0) / (0.55 + dot(p - vec3(-0.62, -0.1, -0.25), p - vec3(-0.62, -0.1, -0.25)));
  float skyFill = 0.5 + 0.5 * n.y;
  vec3 rad = vec3(0.95, 0.42, 0.22) * backBounce * 0.95
           + vec3(0.16, 0.72, 0.88) * leftBounce * 0.45
           + vec3(0.24, 0.44, 0.78) * skyFill * 0.42
           + vec3(0.98, 0.86, 0.62) * max(dot(n, sunDir), 0.0) * 0.22;
  return rad * gain;
}

vec3 aces(vec3 x) {
  x = max(x, 0.0);
  return (x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14);
}

void mainImage(out vec4 fragColor, in vec2 fragCoord) {
  vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
  float screenX = fragCoord.x / max(iResolution.x, 1.0);
  float split = clamp(P_SPLIT, 0.0, 1.0);
  bool isFinalGI = screenX >= split;
  float voxRes = clamp(floor(P_VOXEL_RES + 0.5), 3.0, 16.0);
  float gain = clamp(P_BOUNCE_STR, 0.15, 2.2);
  float sweep = iTime * max(P_SUN_SWEEP, 0.0);

  vec3 ro = vec3(0.0, 0.35, 2.22);
  vec3 rd = normalize(vec3(uv.x, uv.y - 0.12, -1.38));
  vec3 sky = mix(vec3(0.76, 0.82, 0.90), vec3(0.16, 0.38, 0.72), smoothstep(-0.08, 0.52, rd.y));
  vec3 col = sky;

  float t = 0.05;
  vec2 hit = vec2(10.0, 0.0);
  for (int i = 0; i < 64; i++) {
    vec2 h = mapCourtyard(ro + rd * t);
    if (h.x < 0.0025) { hit = vec2(t, h.y); break; }
    t += h.x;
    if (t > 8.0) break;
  }

  if (hit.y > 0.5) {
    vec3 p = ro + rd * hit.x;
    vec3 n = calcNormal(p);
    vec3 sunDir = normalize(vec3(0.62 * cos(sweep * 0.45), 0.72, 0.48));

    // Direct sun shadow ray
    float sh = 1.0;
    float ts = 0.03;
    for (int s = 0; s < 20; s++) {
      float ds = mapCourtyard(p + sunDir * ts).x;
      if (ds < 0.003) { sh = 0.0; break; }
      ts += max(ds, 0.03);
      if (ts > 3.5) break;
    }

    vec3 alb = vec3(0.70, 0.68, 0.64);
    if (hit.y > 1.5 && hit.y < 2.5) alb = vec3(0.86, 0.38, 0.22);
    else if (hit.y > 2.5 && hit.y < 3.5) alb = vec3(0.18, 0.64, 0.78);
    else if (hit.y > 3.5 && hit.y < 4.5) alb = vec3(0.84, 0.80, 0.74);
    else if (hit.y > 4.5) alb = vec3(0.90, 0.88, 0.84);

    // Distance-adaptive SHaRC cascade LOD level (coarser voxels further from camera!)
    float camDist = length(p - ro);
    float lodScale = (camDist > 2.6) ? (voxRes * 0.5) : voxRes;
    vec3 cellPos = (floor(p * lodScale) + 0.5) / lodScale;
    // Quantized surface normal direction into octants as in SHaRC hash key
    vec3 qNorm = normalize(floor(n * 2.5 + 0.5) + vec3(1e-4));

    vec3 direct = alb * vec3(1.0, 0.94, 0.84) * max(dot(n, sunDir), 0.0) * sh * 1.15;

    if (!isFinalGI) {
      // Left: Raw SHaRC spatial hash-grid cache cells visualized directly (discrete LOD voxel cells + cell borders!)
      vec3 cellRad = evalSharcRadiance(cellPos, qNorm, sunDir, gain);
      vec3 fracC = abs(fract(p * lodScale) - 0.5);
      float border = smoothstep(0.05, 0.012, min(min(0.5 - fracC.x, 0.5 - fracC.y), 0.5 - fracC.z));
      // Color-tint cascade boundary subtly to reveal camera-distance LOD transition
      vec3 lodEdgeCol = (camDist > 2.6) ? vec3(0.98, 0.76, 0.20) : vec3(0.20, 0.92, 0.98);
      col = cellRad * 1.25 + lodEdgeCol * border * 0.38;
    } else {
      // Right: Final path-traced render reading SHaRC cache at secondary bounce vertices -> clean, vivid multi-bounce GI!
      vec3 smoothGI = evalSharcRadiance(p, n, sunDir, gain);
      col = direct + alb * smoothGI;
    }
  }

  float sep = smoothstep(0.0035, 0.0008, abs(screenX - split));
  col = mix(col, vec3(0.95, 0.97, 1.0), sep);

  fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);
}
```

Attribution: MIT — written for this index.

## Combines with

- [Unidirectional Path Tracing](https://texelatlas.vercel.app/t/path-tracing.md): Paths terminate at the hash-grid cache instead of tracing every bounce.

## Sources

1. [primary] NVIDIA SHaRC Guide (RTXGI SDK documentation). github.com. https://github.com/NVIDIA-RTX/RTXGI/blob/main/Docs/SharcGuide.md (verified via http on 2026-11-29)
2. [implementation] NVIDIA-RTX (2024) NVIDIA-RTX/SHARC. https://github.com/NVIDIA-RTX/SHARC License: NOASSERTION. (verified via github on 2026-11-29)
3. [implementation] NVIDIA-RTX (2024) NVIDIA-RTX/RTXGI. https://github.com/NVIDIA-RTX/RTXGI License: NOASSERTION. (verified via github on 2026-11-29)

## Cite this entry

Texel. "SHaRC: Spatially Hashed Radiance Cache." https://texelatlas.vercel.app/t/sharc/ (accessed 2026-12-01).
