{
 "id": "normal-mapping-mikktspace",
 "title": "Normal mapping with MikkTSpace",
 "aliases": [],
 "domain": "materials",
 "subdomain": "bump and normal mapping",
 "stage": "material",
 "realtime": "realtime",
 "platforms": [
  "webgl2",
  "webgpu",
  "desktop-gpu",
  "mobile-gpu",
  "unity",
  "unreal",
  "godot",
  "blender"
 ],
 "year_introduced": 2008,
 "inputs": [
  "normals",
  "texture",
  "mesh",
  "uv-atlas"
 ],
 "outputs": [
  "normals"
 ],
 "style": "both",
 "dynamic": "both",
 "summary": "Normal mapping stores perturbed normals in a texture to fake fine detail; MikkTSpace is the standard tangent-basis definition that makes bakers and renderers agree. It is what glTF, Blender, Unity and Substance assume.",
 "how_it_works": "A tangent-space normal map encodes a unit normal per texel in a frame (tangent, bitangent, normal). At render time the shader fetches the texel, decodes it (n = 2c - 1), rebuilds the frame from interpolated vertex tangent and normal, and transforms to world space. Baking and rendering must use the same frame or the shading shows seams, which is why Mikkelsen defined MikkTSpace: a per-vertex tangent computed from the triangle's UV gradients, with a specific rule for splitting vertices at UV mirrors and for orthogonalisation. The tangent's w component stores handedness. In the fragment shader the bitangent is rebuilt as the cross product of normal and tangent scaled by that sign, and the frame is not re-orthogonalised per pixel; this is what makes baker and renderer match. Normal textures are stored linearly (not sRGB) and often as two-channel BC5.",
 "when_to_use": "Choose it as the default for authored detail on UV-mapped meshes. Prefer `surface-gradient-bump-mapping` for layered or non-UV sources, and `parallax-occlusion-mapping` or `relief-mapping` when parallax and self-occlusion matter at grazing angles. Pair with `toksvig-mipmapping` to stop minified normal maps shimmering.",
 "cost": {
  "class": "cheap",
  "notes": "One texture fetch and a 3x3 transform per pixel."
 },
 "failure_modes": [
  "Tangent mismatch between baker and renderer causes stretched or inverted lighting and visible seams along UV borders",
  "Mirrored UVs without correct handedness flip lighting",
  "Normal maps flatten under minification, making surfaces glossier unless filtered (toksvig-mipmapping)",
  "Flat silhouettes: normal mapping adds no geometry, so edges and shadows stay smooth"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "url:http://www.mikktspace.com/",
   "type": "web",
   "title": "MikkTSpace",
   "authors": [
    "Morten S. Mikkelsen"
   ],
   "year": null,
   "venue": "mikktspace.com",
   "url": "http://www.mikktspace.com/",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": {
     "url": "http://web.archive.org/web/20261026041729/http://www.mikktspace.com/",
     "timestamp": "20261026041729"
    },
    "page_title": "MikkTSpace.com",
    "host": "mikktspace.com",
    "title_confirmed_by_page": true,
    "title_unconfirmed": false
   },
   "provenance": {
    "title": {
     "authority": "http",
     "endpoint": "GET http://www.mikktspace.com/ → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "http",
     "endpoint": "GET http://www.mikktspace.com/ → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "http",
     "endpoint": "GET http://www.mikktspace.com/ → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 0.6666666666666666,
   "__bib": "mikkelsenmikktspace"
  },
  {
   "role": "implementation",
   "key": "gh:mmikk/mikktspace",
   "type": "code",
   "title": "mmikk/MikkTSpace",
   "description": "A common standard for tangent space used in baking tools to produce normal maps.",
   "authors": [
    "mmikk"
   ],
   "year": 2020,
   "venue": "GitHub",
   "url": "https://github.com/mmikk/MikkTSpace",
   "ids": {
    "repo": "mmikk/MikkTSpace"
   },
   "license": null,
   "extra": {
    "stars": 387,
    "stars_checked": "2026-11-29",
    "archived": false,
    "fork": false,
    "pushed_at": "2024-07-20T16:33:29Z",
    "language": "C",
    "homepage": null,
    "license_name": null
   },
   "provenance": {
    "title": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mmikk/MikkTSpace",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mmikk/MikkTSpace",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mmikk/MikkTSpace",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mmikk/MikkTSpace",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mmikk/MikkTSpace",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "license": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mmikk/MikkTSpace",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": null,
   "__bib": "mmikk2020mmikk"
  }
 ],
 "presets": [
  {
   "id": "normal-mapping-mikktspace-specimen",
   "title": "Tangent-space normal mapping on a sphere: geometric (left) vs mapped (right)",
   "runtime": "glsl-fragment",
   "params": {
    "STRENGTH": 2.2
   },
   "code": "// Tangent-space normal mapping with a per-pixel TBN frame built from the sphere's (longitude, latitude)\n// parametrisation. Left half: geometric normals. Right half: dimple normal map perturbs the shading normal.\nconst float STRENGTH = 2.2;\nconst vec2 CELLS = vec2(16.0, 8.0);\n\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord) {\n  vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;\n  vec3 ro = vec3(0.0, 0.0, 4.0), rd = normalize(vec3(uv, -2.6));\n  vec3 col = vec3(0.05) + 0.05 * uv.y;\n  float b = dot(ro, rd); float h = b * b - dot(ro, ro) + 0.81;\n  if (h > 0.0) {\n    vec3 p = ro + rd * (-b - sqrt(h)); vec3 n = normalize(p);\n    float lon = atan(n.x, n.z), lat = asin(clamp(n.y, -1.0, 1.0));\n    if (fragCoord.x > 0.5 * iResolution.x) {\n      vec2 g = vec2(lon / 6.2832, lat / 3.14159) * CELLS * 6.2832;\n      // height = cos(u) * cos(v); analytic derivatives w.r.t. u and v\n      vec2 dh = vec2(-sin(g.x) * cos(g.y), -cos(g.x) * sin(g.y));\n      vec3 nts = normalize(vec3(-dh * STRENGTH * 0.25, 1.0));\n      vec3 T = vec3(cos(lon), 0.0, -sin(lon));\n      vec3 B = cross(n, T);\n      n = normalize(T * nts.x + B * nts.y + n * nts.z);\n    }\n    vec3 l = normalize(vec3(0.6, 0.5, 0.7)), v = -rd, hv = normalize(l + v);\n    float nl = max(dot(n, l), 0.0);\n    col = vec3(0.55, 0.38, 0.3) * (nl + 0.08) + vec3(0.8) * pow(max(dot(n, hv), 0.0), 40.0) * nl;\n  }\n  if (abs(fragCoord.x - 0.5 * iResolution.x) < 1.0) col = vec3(1.0);\n  col = col / (1.0 + col * 0.6);\n  fragColor = vec4(pow(col, vec3(1.0 / 2.2)), 1.0);\n}\n",
   "basis": "original",
   "license_note": "written for this index",
   "execution_fidelity": "conceptual-diagram",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-29",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "normal-mapping-mikktspace",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-29T15:51:50.471Z",
     "renderer": "Chromium 145.0.7632.6 headless, WebGL2 via ANGLE/SwiftShader, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.4778,
      "std": 0.1415,
      "unique_colors": 74
     },
     "image": "/specimens/normal-mapping-mikktspace-specimen.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "surface-gradient-bump-mapping",
  "parallax-occlusion-mapping",
  "toksvig-mipmapping",
  "triplanar-mapping"
 ],
 "extends": [
  "normal-map-baking"
 ],
 "supersedes": [],
 "combines_with": [],
 "provenance": {
  "prose": "original text written for this index (research draft, editorially reviewed)",
  "sources_verified_at": "2026-11-29T15:51:27.588Z",
  "draft": "data/drafts/materials/normal-mapping-mikktspace.json"
 },
 "solves": [
  "baked normal map looks wrong in another engine",
  "lighting seams across uv islands",
  "tangent space mismatch between baker and renderer",
  "add surface detail to low poly without more triangles"
 ],
 "authority": "Mikkelsen",
 "url": "https://texelatlas.vercel.app/t/normal-mapping-mikktspace/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 2.18,
  "tier": "light",
  "p50_ms": 0.0716,
  "p95_ms": 0.0752,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 40,
  "preset_id": "normal-mapping-mikktspace-specimen",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 1.77,
   "tier": "feather",
   "p50_ms": 0.0281,
   "p95_ms": 0.0282,
   "speedup_x": 2.55,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 1.25,
   "tier": "feather",
   "p50_ms": 0.0359,
   "p95_ms": 0.036,
   "speedup_x": 1.99,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}