{
 "id": "bilateral-normal-integration",
 "title": "Bilateral Normal Integration",
 "aliases": [
  "BNI"
 ],
 "domain": "capture",
 "subdomain": "normal integration",
 "stage": "capture",
 "realtime": "offline",
 "platforms": [
  "python",
  "cpu"
 ],
 "year_introduced": 2022,
 "inputs": [
  "normals"
 ],
 "outputs": [
  "depth",
  "mesh"
 ],
 "style": "photoreal",
 "dynamic": "static",
 "summary": "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.",
 "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": "Choose it to turn normal maps from photometric stereo, monocular normal estimators or `moge` 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` when you can supply many views instead of a single normal map.",
 "cost": {
  "class": "offline",
  "notes": "Sparse solves per iteration; seconds for megapixel normal maps on CPU in the reference implementation."
 },
 "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"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1007/978-3-031-19769-7_32",
   "type": "chapter",
   "title": "Bilateral Normal Integration",
   "authors": [
    "Xu Cao",
    "Hiroaki Santo",
    "Boxin Shi",
    "Fumio Okura",
    "Yasuyuki Matsushita"
   ],
   "year": 2022,
   "venue": "Lecture Notes in Computer Science",
   "url": "https://doi.org/10.1007/978-3-031-19769-7_32",
   "ids": {
    "doi": "10.1007/978-3-031-19769-7_32"
   },
   "license": null,
   "extra": {
    "csl_type": "book-chapter"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1007/978-3-031-19769-7_32",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1007/978-3-031-19769-7_32",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1007/978-3-031-19769-7_32",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1007/978-3-031-19769-7_32",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1007/978-3-031-19769-7_32",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "cao2022bilateral"
  },
  {
   "role": "implementation",
   "key": "gh:xucao-42/bilateral_normal_integration",
   "type": "code",
   "title": "xucao-42/bilateral_normal_integration",
   "description": "Official implementation of \"Bilateral Normal Integration\" (BiNI), ECCV 2022.",
   "authors": [
    "xucao-42"
   ],
   "year": 2022,
   "venue": "GitHub",
   "url": "https://github.com/xucao-42/bilateral_normal_integration",
   "ids": {
    "repo": "xucao-42/bilateral_normal_integration"
   },
   "license": "GPL-3.0",
   "extra": {
    "stars": 250,
    "stars_checked": "2026-11-29",
    "archived": false,
    "fork": false,
    "pushed_at": "2026-04-20T09:04:53Z",
    "language": "Python",
    "homepage": null,
    "license_name": "GNU General Public License v3.0"
   },
   "provenance": {
    "title": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/xucao-42/bilateral_normal_integration",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/xucao-42/bilateral_normal_integration",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/xucao-42/bilateral_normal_integration",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/xucao-42/bilateral_normal_integration",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/xucao-42/bilateral_normal_integration",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "license": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/xucao-42/bilateral_normal_integration",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": null,
   "__bib": "xucao2022xucao"
  }
 ],
 "presets": [
  {
   "id": "bilateral-normal-integration-live",
   "title": "Bilateral Normal Integration — blurred Poisson integration (left) vs discontinuity-preserving bilateral relief (right)",
   "runtime": "glsl-fragment",
   "params": {
    "P_DISCONT_K": 0.88,
    "P_RELIEF_H": 0.72,
    "P_LIGHT_SPIN": 0.65,
    "P_SPLIT": 0.48
   },
   "basis": "original",
   "license_note": "MIT — written for this index.",
   "code": "const float P_DISCONT_K = 0.88; // P Bilateral Sharpness [0.1, 1.0, 0.02]\nconst float P_RELIEF_H = 0.72; // P Relief Height [0.2, 1.2, 0.04]\nconst float P_LIGHT_SPIN = 0.65; // P Light Sweep [0.0, 2.2, 0.05]\nconst float P_SPLIT = 0.48; // P Poisson / Bilateral [0.0, 1.0, 0.02]\n\n// Ground-truth stepped architectural bas-relief heightfield with sharp depth discontinuities!\nfloat exactRelief(vec2 p) {\n  // Concentric stepped Aztec/classical relief terraces + domed medallions\n  float dBox = max(abs(p.x), abs(p.y));\n  float h = 0.0;\n  h += 0.22 * step(dBox, 0.42);\n  h += 0.18 * step(length(p), 0.30);\n  // 4 carved corner medallions with sharp cliffs\n  vec2 q = abs(p) - vec2(0.28, 0.28);\n  h += 0.20 * step(length(q), 0.105);\n  // Central spherical relief dome\n  float rC = length(p);\n  if (rC < 0.20) h += 0.22 * sqrt(max(1.0 - (rC / 0.20) * (rC / 0.20), 0.0));\n  return h;\n}\n\n// Smooth (Poisson-integrated) version: continuous integrability smears across jump discontinuities!\nfloat poissonRelief(vec2 p) {\n  float h = 0.0;\n  float wSum = 0.0;\n  for (int dy = -2; dy <= 2; dy++) {\n    for (int dx = -2; dx <= 2; dx++) {\n      vec2 off = vec2(float(dx), float(dy)) * 0.022;\n      float w = exp(-dot(off, off) * 750.0);\n      h += exactRelief(p + off) * w;\n      wSum += w;\n    }\n  }\n  return h / max(wSum, 1e-5);\n}\n\n// Bilateral-integrated version: sigmoid discontinuity weight k keeps step cliffs razor sharp\nfloat bilateralRelief(vec2 p, float kSharp) {\n  return mix(poissonRelief(p), exactRelief(p), smoothstep(0.05, 0.95, kSharp));\n}\n\nvec3 aces(vec3 x) {\n  x = max(x, 0.0);\n  return (x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14);\n}\n\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord) {\n  vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;\n  float screenX = fragCoord.x / max(iResolution.x, 1.0);\n  float split = clamp(P_SPLIT, 0.0, 1.0);\n  bool isBilateral = screenX >= split;\n  float kSharp = clamp(P_DISCONT_K, 0.05, 1.0);\n  float relH = clamp(P_RELIEF_H, 0.15, 1.4);\n  float spin = iTime * max(P_LIGHT_SPIN, 0.0);\n\n  // Oblique 3D camera inspecting the reconstructed heightfield surface\n  vec3 ro = vec3(0.0, 0.92, 1.25);\n  vec3 rd = normalize(vec3(uv.x, uv.y - 0.48, -1.25));\n  vec3 col = mix(vec3(0.025, 0.032, 0.052), vec3(0.065, 0.082, 0.128), smoothstep(-0.5, 0.5, uv.y));\n\n  // Raymarch the integrated heightfield y = h(x, z)\n  float t = 0.4;\n  bool hit = false;\n  for (int i = 0; i < 60; i++) {\n    vec3 p = ro + rd * t;\n    float h = isBilateral ? bilateralRelief(p.xz, kSharp) : poissonRelief(p.xz);\n    float d = p.y - h * relH;\n    if (d < 0.004) { hit = true; break; }\n    t += max(d * 0.48, 0.012);\n    if (t > 4.5) break;\n  }\n\n  if (hit) {\n    vec3 p = ro + rd * t;\n    float e = 0.006;\n    float hC = isBilateral ? bilateralRelief(p.xz, kSharp) : poissonRelief(p.xz);\n    float hX = isBilateral ? bilateralRelief(p.xz + vec2(e, 0.0), kSharp) : poissonRelief(p.xz + vec2(e, 0.0));\n    float hZ = isBilateral ? bilateralRelief(p.xz + vec2(0.0, e), kSharp) : poissonRelief(p.xz + vec2(0.0, e));\n    vec3 n = normalize(vec3((hC - hX) * relH / e, 1.0, (hC - hZ) * relH / e));\n\n    vec3 lDir = normalize(vec3(cos(spin * 0.7) * 0.72, 0.78, sin(spin * 0.7) * 0.72));\n    float diff = max(dot(n, lDir), 0.0);\n    float spec = pow(max(dot(n, normalize(lDir - rd)), 0.0), 36.0);\n\n    // Subtle elevation contour lines & discontinuity edge glow\n    float discEdge = clamp(length(vec2(hC - hX, hC - hZ)) * 18.0, 0.0, 1.0);\n    vec3 marble = mix(vec3(0.22, 0.30, 0.42), vec3(0.92, 0.88, 0.82), smoothstep(0.02, 0.58, hC));\n    float contour = smoothstep(0.06, 0.01, abs(fract(hC * 12.0) - 0.5));\n    marble = mix(marble, vec3(0.16, 0.80, 0.94), contour * 0.24);\n\n    col = marble * (0.28 + 0.84 * diff) + vec3(1.0, 0.96, 0.90) * spec * 0.38;\n    if (isBilateral) {\n      // Highlight crisp detected bilateral discontinuity creases in gold\n      col += vec3(0.98, 0.68, 0.22) * discEdge * 0.45;\n    } else {\n      // Highlight Poisson ramp-blurring error in magenta\n      col += vec3(0.94, 0.24, 0.52) * discEdge * 0.45;\n    }\n  }\n\n  float sep = smoothstep(0.0035, 0.0008, abs(screenX - split));\n  col = mix(col, vec3(0.95, 0.97, 1.0), sep);\n\n  fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);\n}",
   "execution_fidelity": "conceptual-diagram",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-30",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "bilateral-normal-integration",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T20:35:45.000Z",
     "renderer": "Headless EGL Tesla T4/PCIe/SSE2, OpenGL 3.30 Core, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.6392,
      "std": 0.2161,
      "min": 0.3077,
      "max": 0.9336
     },
     "image": "/specimens/bilateral-normal-integration-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "photometric-stereo",
  "universal-photometric-stereo",
  "moge"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "universal-photometric-stereo",
   "why": "UniPS outputs normals; BNI integrates them into depth with preserved discontinuities."
  }
 ],
 "provenance": {
  "prose": "original text written for this index (research draft, editorially reviewed)",
  "sources_verified_at": "2026-11-29T15:51:27.588Z",
  "draft": "data/drafts/capture/bilateral-normal-integration.json"
 },
 "solves": [
  "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"
 ],
 "authority": "Cao et al., 2022",
 "url": "https://texelatlas.vercel.app/t/bilateral-normal-integration/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 274.63,
  "tier": "extreme",
  "p50_ms": 9.0353,
  "p95_ms": 9.1495,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 32,
  "preset_id": "bilateral-normal-integration-live",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 235.94,
   "tier": "extreme",
   "p50_ms": 3.7514,
   "p95_ms": 3.8251,
   "speedup_x": 2.41,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 206.33,
   "tier": "extreme",
   "p50_ms": 5.9423,
   "p95_ms": 5.9786,
   "speedup_x": 1.52,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}