---
id: "bilateral-normal-integration"
title: "Bilateral Normal Integration"
aliases: [BNI]
domain: "capture"
stage: "capture"
realtime: "offline"
platforms: [python, cpu]
year_introduced: 2022
inputs: [normals]
outputs: [depth, mesh]
style: "photoreal"
dynamic: "static"
cost: "offline"
authority: "Cao et al., 2022"
url: "https://texelatlas.vercel.app/t/bilateral-normal-integration/"
sources_verified_at: "2026-11-29"
---
# Bilateral Normal Integration (Cao et al., 2022)

> Integrates a normal map into a depth surface while preserving depth discontinuities, using a bilateral weighting that is optimised iteratively in a sparse linear least-squares loop.

## Reach for it when

- turn a normal map into a depth surface
- integrating normals smears over sharp depth steps
- photometric stereo normals need to become a mesh
- recover height from estimated normals keeping discontinuities

## How it works

Classic normal integration assumes the surface is smooth, so it smears across steps and occlusion boundaries. This method writes the integration as a sparse system relating neighbouring pixels' log-depth through the normals, but weights each pixel pair with a bilateral term that tells it whether the pair lies across a discontinuity. The weights are unknown, so they are estimated from the current solution and the system is re-solved in an alternating scheme, which is a form of iteratively reweighted least squares with a robust cost. Orthographic and perspective camera models are both supported. The result is a depth map that keeps sharp silhouettes and creases. Pixels outside a mask are ignored.

## When to use it

Choose it to turn normal maps from photometric stereo, monocular normal estimators or [MoGe (Monocular Geometry Estimation)](https://texelatlas.vercel.app/t/moge.md) into usable depth or meshes with sharp steps. Prefer a simple Poisson or Frankot-Chellappa integrator when the surface is genuinely smooth and speed matters. Prefer multi-view [NeuS](https://texelatlas.vercel.app/t/neus.md) when you can supply many views instead of a single normal map.

## Cost

offline — Sparse solves per iteration; seconds for megapixel normal maps on CPU in the reference implementation.
Measured GPU Weight: 274.63× baseline (extreme) — 9.0353 ms median / 9.1495 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 235.94× baseline (extreme) — 3.7514 ms median (2.41× faster on L4).
Ampere A100 scaling: 206.33× baseline (extreme) — 5.9423 ms median (1.52× faster on A100).

## Failure modes

- Normals with low-frequency bias integrate into a globally warped surface regardless of weighting
- Wrong discontinuity decisions split or merge surface patches, producing cliffs at the wrong places
- Depth scale is only defined up to the camera model assumptions, so absolute size needs another cue
- Mask errors bleed background depth into the object boundary

## Dataflow

- Inputs: normals
- Outputs: depth, mesh
- Platforms: python, cpu

## Presets

### Bilateral Normal Integration — blurred Poisson integration (left) vs discontinuity-preserving bilateral relief (right) (glsl-fragment; rendered 2026-11-30)

```json
{
  "P_DISCONT_K": 0.88,
  "P_RELIEF_H": 0.72,
  "P_LIGHT_SPIN": 0.65,
  "P_SPLIT": 0.48
}
```

```glsl
const float P_DISCONT_K = 0.88; // P Bilateral Sharpness [0.1, 1.0, 0.02]
const float P_RELIEF_H = 0.72; // P Relief Height [0.2, 1.2, 0.04]
const float P_LIGHT_SPIN = 0.65; // P Light Sweep [0.0, 2.2, 0.05]
const float P_SPLIT = 0.48; // P Poisson / Bilateral [0.0, 1.0, 0.02]

// Ground-truth stepped architectural bas-relief heightfield with sharp depth discontinuities!
float exactRelief(vec2 p) {
  // Concentric stepped Aztec/classical relief terraces + domed medallions
  float dBox = max(abs(p.x), abs(p.y));
  float h = 0.0;
  h += 0.22 * step(dBox, 0.42);
  h += 0.18 * step(length(p), 0.30);
  // 4 carved corner medallions with sharp cliffs
  vec2 q = abs(p) - vec2(0.28, 0.28);
  h += 0.20 * step(length(q), 0.105);
  // Central spherical relief dome
  float rC = length(p);
  if (rC < 0.20) h += 0.22 * sqrt(max(1.0 - (rC / 0.20) * (rC / 0.20), 0.0));
  return h;
}

// Smooth (Poisson-integrated) version: continuous integrability smears across jump discontinuities!
float poissonRelief(vec2 p) {
  float h = 0.0;
  float wSum = 0.0;
  for (int dy = -2; dy <= 2; dy++) {
    for (int dx = -2; dx <= 2; dx++) {
      vec2 off = vec2(float(dx), float(dy)) * 0.022;
      float w = exp(-dot(off, off) * 750.0);
      h += exactRelief(p + off) * w;
      wSum += w;
    }
  }
  return h / max(wSum, 1e-5);
}

// Bilateral-integrated version: sigmoid discontinuity weight k keeps step cliffs razor sharp
float bilateralRelief(vec2 p, float kSharp) {
  return mix(poissonRelief(p), exactRelief(p), smoothstep(0.05, 0.95, kSharp));
}

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 isBilateral = screenX >= split;
  float kSharp = clamp(P_DISCONT_K, 0.05, 1.0);
  float relH = clamp(P_RELIEF_H, 0.15, 1.4);
  float spin = iTime * max(P_LIGHT_SPIN, 0.0);

  // Oblique 3D camera inspecting the reconstructed heightfield surface
  vec3 ro = vec3(0.0, 0.92, 1.25);
  vec3 rd = normalize(vec3(uv.x, uv.y - 0.48, -1.25));
  vec3 col = mix(vec3(0.025, 0.032, 0.052), vec3(0.065, 0.082, 0.128), smoothstep(-0.5, 0.5, uv.y));

  // Raymarch the integrated heightfield y = h(x, z)
  float t = 0.4;
  bool hit = false;
  for (int i = 0; i < 60; i++) {
    vec3 p = ro + rd * t;
    float h = isBilateral ? bilateralRelief(p.xz, kSharp) : poissonRelief(p.xz);
    float d = p.y - h * relH;
    if (d < 0.004) { hit = true; break; }
    t += max(d * 0.48, 0.012);
    if (t > 4.5) break;
  }

  if (hit) {
    vec3 p = ro + rd * t;
    float e = 0.006;
    float hC = isBilateral ? bilateralRelief(p.xz, kSharp) : poissonRelief(p.xz);
    float hX = isBilateral ? bilateralRelief(p.xz + vec2(e, 0.0), kSharp) : poissonRelief(p.xz + vec2(e, 0.0));
    float hZ = isBilateral ? bilateralRelief(p.xz + vec2(0.0, e), kSharp) : poissonRelief(p.xz + vec2(0.0, e));
    vec3 n = normalize(vec3((hC - hX) * relH / e, 1.0, (hC - hZ) * relH / e));

    vec3 lDir = normalize(vec3(cos(spin * 0.7) * 0.72, 0.78, sin(spin * 0.7) * 0.72));
    float diff = max(dot(n, lDir), 0.0);
    float spec = pow(max(dot(n, normalize(lDir - rd)), 0.0), 36.0);

    // Subtle elevation contour lines & discontinuity edge glow
    float discEdge = clamp(length(vec2(hC - hX, hC - hZ)) * 18.0, 0.0, 1.0);
    vec3 marble = mix(vec3(0.22, 0.30, 0.42), vec3(0.92, 0.88, 0.82), smoothstep(0.02, 0.58, hC));
    float contour = smoothstep(0.06, 0.01, abs(fract(hC * 12.0) - 0.5));
    marble = mix(marble, vec3(0.16, 0.80, 0.94), contour * 0.24);

    col = marble * (0.28 + 0.84 * diff) + vec3(1.0, 0.96, 0.90) * spec * 0.38;
    if (isBilateral) {
      // Highlight crisp detected bilateral discontinuity creases in gold
      col += vec3(0.98, 0.68, 0.22) * discEdge * 0.45;
    } else {
      // Highlight Poisson ramp-blurring error in magenta
      col += vec3(0.94, 0.24, 0.52) * discEdge * 0.45;
    }
  }

  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

- [Universal Photometric Stereo (SDM-UniPS)](https://texelatlas.vercel.app/t/universal-photometric-stereo.md): UniPS outputs normals; BNI integrates them into depth with preserved discontinuities.

## Combination ideas

- [Drawings to relief via generated relighting](https://texelatlas.vercel.app/ideas/relit-drawings-to-relief/)

## Sources

1. [primary] Xu Cao, Hiroaki Santo, Boxin Shi, Fumio Okura, Yasuyuki Matsushita (2022) Bilateral Normal Integration. Lecture Notes in Computer Science. https://doi.org/10.1007/978-3-031-19769-7_32 (verified via crossref on 2026-11-29)
2. [implementation] xucao-42 (2022) xucao-42/bilateral_normal_integration. https://github.com/xucao-42/bilateral_normal_integration License: GPL-3.0. (verified via github on 2026-11-29)

## Cite this entry

Texel. "Bilateral Normal Integration." https://texelatlas.vercel.app/t/bilateral-normal-integration/ (accessed 2026-12-01).
