{
 "id": "photometric-stereo",
 "title": "Photometric Stereo",
 "aliases": [
  "shape from shading, multi-light"
 ],
 "domain": "capture",
 "subdomain": "shape from shading",
 "stage": "capture",
 "realtime": "offline",
 "platforms": [
  "cpu",
  "python"
 ],
 "year_introduced": 1980,
 "inputs": [
  "photos"
 ],
 "outputs": [
  "normals",
  "depth"
 ],
 "style": "photoreal",
 "dynamic": "static",
 "summary": "Estimates per-pixel surface normals from several photos of a fixed object and camera under different known lighting directions, assuming a simple reflectance model.",
 "how_it_works": "Place the camera and object still and capture images while varying the light direction. For a Lambertian surface each pixel's intensity is the dot product of the albedo-scaled normal with the light vector. With three or more known lights this becomes a linear system per pixel, solved by least squares for the scaled normal; its length is albedo and its direction the normal. Extra lights over-determine the system and let you reject shadows and specular highlights as outliers. The normal map is then integrated into a height field, which is a separate problem sensitive to noise and discontinuities. Modern variants relax the assumptions: calibrated non-Lambertian BRDFs, near lights, or learned networks for unknown lighting.",
 "when_to_use": "Choose it for fine surface detail (coins, reliefs, skin, fabric) where geometry from multi-view matching is too smooth. Prefer `universal-photometric-stereo` when lights are uncalibrated or the material is glossy. Prefer `multi-view-stereo-patchmatch` for large-scale shape, and combine the two: MVS for the base shape, photometric normals for detail.",
 "cost": {
  "class": "offline",
  "notes": "Per-pixel linear solve is cheap; the cost is capture and normal integration."
 },
 "failure_modes": [
  "Specular highlights and cast shadows break the Lambertian assumption and bias normals",
  "Inaccurate light directions cause a low-frequency bending of the integrated surface",
  "Inter-reflections in concavities flatten recovered depth",
  "Integrating normals to depth accumulates drift and smears depth discontinuities"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1117/12.7972479",
   "type": "paper",
   "title": "Photometric Method For Determining Surface Orientation From Multiple Images",
   "authors": [],
   "year": 1980,
   "venue": "Optical Engineering",
   "url": "https://doi.org/10.1117/12.7972479",
   "ids": {
    "doi": "10.1117/12.7972479"
   },
   "license": null,
   "extra": {
    "csl_type": "journal-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1117/12.7972479",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1117/12.7972479",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1117/12.7972479",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1117/12.7972479",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1117/12.7972479",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "anon1980photometric"
  }
 ],
 "presets": [
  {
   "id": "photometric-stereo-live",
   "title": "Photometric Stereo — rotating directional capture I_k (left) vs least-squares recovered normals (right)",
   "runtime": "glsl-fragment",
   "params": {
    "P_LIGHT_ELEV": 0.62,
    "P_RELIEF_AMP": 1,
    "P_NOISE_AMT": 0.03,
    "P_SPLIT": 0.48
   },
   "basis": "original",
   "license_note": "MIT — written for this index.",
   "code": "const float P_LIGHT_ELEV = 0.62; // P Light Elevation [0.25, 0.92, 0.02]\nconst float P_RELIEF_AMP = 1.0; // P Relief Depth [0.3, 1.8, 0.05]\nconst float P_NOISE_AMT = 0.03; // P Sensor Noise [0.0, 0.15, 0.005]\nconst float P_SPLIT = 0.48; // P Capture / Normals [0.0, 1.0, 0.02]\n\nfloat hash21(vec2 p) {\n  p = fract(p * vec2(127.1, 311.7));\n  p += dot(p, p + 34.5);\n  return fract(p.x * p.y);\n}\n\n// Sculpted classical coin / relief medallion heightfield h(u, v) + spatially varying albedo rho(u, v)\nvoid reliefSurface(vec2 p, float amp, out float h, out vec3 albedo, out float mask) {\n  float r = length(p);\n  mask = smoothstep(0.455, 0.442, r);\n\n  // Stepped coin rim + radial fluting + sculpted inner rosette/dome\n  float rim = exp(-pow((r - 0.41) / 0.025, 2.0)) * 0.075;\n  float dome = sqrt(max(0.14 - r * r, 0.0)) * 0.42 * smoothstep(0.38, 0.30, r);\n  float a = atan(p.y, p.x);\n  float petals = sin(a * 8.0) * exp(-pow((r - 0.22) / 0.085, 2.0)) * 0.038;\n  float innerRing = exp(-pow((r - 0.11) / 0.022, 2.0)) * 0.045;\n  float microGroove = sin(r * 75.0) * 0.0045 * smoothstep(0.40, 0.12, r);\n  h = (rim + dome + petals + innerRing + microGroove) * amp;\n\n  // Spatially varying patinated bronze / plaster albedo (photometric stereo separates albedo from normal!)\n  float patina = 0.5 + 0.5 * sin(p.x * 9.0 + sin(p.y * 7.0));\n  albedo = mix(vec3(0.66, 0.54, 0.42), vec3(0.84, 0.78, 0.68), patina * 0.65 + 0.25 * smoothstep(0.36, 0.10, r));\n}\n\nvec3 trueNormal(vec2 p, float amp) {\n  float e = 0.0025;\n  float h0, hX, hY, m;\n  vec3 a;\n  reliefSurface(p, amp, h0, a, m);\n  reliefSurface(p + vec2(e, 0.0), amp, hX, a, m);\n  reliefSurface(p + vec2(0.0, e), amp, hY, a, m);\n  return normalize(vec3(-(hX - h0) / e, -(hY - h0) / e, 1.0));\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 isRecovered = screenX >= split;\n  float elev = clamp(P_LIGHT_ELEV, 0.22, 0.94);\n  float amp = clamp(P_RELIEF_AMP, 0.25, 2.0);\n  float noiseAmt = clamp(P_NOISE_AMT, 0.0, 0.18);\n\n  vec3 col = mix(vec3(0.025, 0.034, 0.052), vec3(0.062, 0.080, 0.120), smoothstep(-0.5, 0.5, uv.y));\n  vec2 g = abs(fract(uv * 10.0 - 0.5) - 0.5);\n  col += vec3(0.015, 0.022, 0.036) * smoothstep(0.03, 0.006, min(g.x, g.y));\n\n  float h, mask;\n  vec3 albedo;\n  reliefSurface(uv, amp, h, albedo, mask);\n\n  // 3 known calibrated light directions L = [l0, l1, l2]^T separated by 120 deg in azimuth\n  float rHoriz = sqrt(max(1.0 - elev * elev, 0.01));\n  float baseAz = iTime * 0.75;\n  vec3 l0 = vec3(cos(baseAz) * rHoriz, sin(baseAz) * rHoriz, elev);\n  vec3 l1 = vec3(cos(baseAz + 2.0943951) * rHoriz, sin(baseAz + 2.0943951) * rHoriz, elev);\n  vec3 l2 = vec3(cos(baseAz + 4.1887902) * rHoriz, sin(baseAz + 4.1887902) * rHoriz, elev);\n\n  if (mask > 0.005) {\n    vec3 nTrue = trueNormal(uv, amp);\n    float rho = dot(albedo, vec3(0.299, 0.587, 0.114));\n\n    // Simulate 3 captured Lambertian photographs I_k = rho * max(n . l_k, 0) + sensor noise\n    float n0 = (hash21(fragCoord + 1.3) - 0.5) * noiseAmt;\n    float n1 = (hash21(fragCoord + 17.7) - 0.5) * noiseAmt;\n    float n2 = (hash21(fragCoord + 43.1) - 0.5) * noiseAmt;\n    vec3 measI = vec3(\n      max(rho * dot(nTrue, l0) + n0, 0.0),\n      max(rho * dot(nTrue, l1) + n1, 0.0),\n      max(rho * dot(nTrue, l2) + n2, 0.0)\n    );\n\n    if (!isRecovered) {\n      // Left: Live rotating capture photograph illuminated by active light direction l0\n      float liveLit = max(dot(nTrue, l0), 0.0);\n      vec3 captureImg = albedo * (0.04 + 1.25 * liveLit) + vec3(n0 * 0.6);\n      col = mix(col, captureImg, mask);\n    } else {\n      // Right: Direct linear Woodham photometric stereo solve: g = inverse(L) * I, n = normalize(g)!\n      // Matrix rows are l0, l1, l2 -> in GLSL mat3 columns are transposed, so transpose(mat3(l0, l1, l2))\n      mat3 Lmat = transpose(mat3(l0, l1, l2));\n      vec3 gVec = inverse(Lmat) * measI;\n      vec3 nEst = normalize(gVec + vec3(0.0, 0.0, 1e-4));\n      vec3 normMap = nEst * 0.5 + 0.5;\n      col = mix(col, normMap, mask);\n    }\n  }\n\n  // Draw the 3 calibrated light-source beacons orbiting around the medallion perimeter\n  for (int k = 0; k < 3; k++) {\n    vec3 lk = (k == 0) ? l0 : ((k == 1) ? l1 : l2);\n    vec2 beaconPos = lk.xy * (0.48 / max(rHoriz, 0.1)) * 0.94;\n    float dB = length(uv - beaconPos);\n    vec3 bCol = (k == 0) ? vec3(1.0, 0.88, 0.36) : vec3(0.32, 0.72, 0.98);\n    float bRad = (k == 0) ? 0.026 : 0.018;\n    col += bCol * smoothstep(bRad * 2.2, bRad * 0.4, dB) * (k == 0 ? 1.1 : 0.55);\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": "photometric-stereo",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T19:53:33.000Z",
     "renderer": "Headless EGL Tesla T4/PCIe/SSE2, OpenGL 3.30 Core, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.5316,
      "std": 0.2738,
      "min": 0.0935,
      "max": 0.9535
     },
     "image": "/specimens/photometric-stereo-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "universal-photometric-stereo",
  "bilateral-normal-integration",
  "light-stage-reflectance-capture"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "bilateral-normal-integration",
   "why": "Photometric stereo produces a normal map; normal integration turns it into a height field."
  }
 ],
 "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/photometric-stereo.json"
 },
 "solves": [
  "recover fine surface relief from photos with changing light",
  "coins and engravings lose detail in photogrammetry",
  "get per-pixel normals with fixed camera and varied lighting",
  "multi-view geometry is too smooth for small detail",
  "capture skin or fabric micro-geometry"
 ],
 "authority": "1980",
 "url": "https://texelatlas.vercel.app/t/photometric-stereo/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 5.22,
  "tier": "light",
  "p50_ms": 0.1617,
  "p95_ms": 0.1708,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 36,
  "preset_id": "photometric-stereo-live",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 4.45,
   "tier": "light",
   "p50_ms": 0.0708,
   "p95_ms": 0.072,
   "speedup_x": 2.28,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 3.53,
   "tier": "light",
   "p50_ms": 0.1016,
   "p95_ms": 0.1017,
   "speedup_x": 1.59,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}