{
 "id": "portal-pvs-culling",
 "title": "Portal and PVS visibility culling",
 "aliases": [
  "portal culling",
  "potentially visible set",
  "PVS"
 ],
 "domain": "performance",
 "subdomain": "occlusion culling",
 "stage": "performance",
 "realtime": "realtime",
 "platforms": [
  "cpu",
  "desktop-gpu",
  "mobile-gpu",
  "unity",
  "unreal",
  "godot"
 ],
 "year_introduced": 1991,
 "inputs": [
  "mesh",
  "graph"
 ],
 "outputs": [
  "visibility-mask"
 ],
 "style": "both",
 "dynamic": "static",
 "summary": "Partition an indoor level into cells joined by portals and either clip the view frustum through portals at runtime or look up a precomputed set of cells visible from the current one.",
 "how_it_works": "The level is divided into convex cells (rooms) connected by portals, the openings between them. Two flavors exist.\n\nPortal rendering walks from the camera's cell: for each portal in view, the frustum is narrowed to the portal's screen-space polygon and recursion continues into the neighbor cell, drawing only what falls inside the narrowed frustum. Mirrors and distant windows can reuse the same traversal.\n\nA potentially visible set (PVS) moves that work offline: for each cell, a conservative computation (portal sight-line tests or sampling) produces a bitset of cells that could be seen from anywhere inside it. At runtime, find the camera's cell, read its bitset, draw those cells' contents, then apply normal frustum culling.\n\nDynamic objects are tagged by the cells they overlap and are drawn if any of those cells is visible.",
 "when_to_use": "Choose it for indoor, corridor or building-interior scenes with clear cell structure and static architecture: runtime cost is nearly zero with a PVS, and it never has GPU latency. Prefer `masked-software-occlusion-culling` or `hierarchical-z-occlusion-culling` for open or dynamic scenes where occluders cannot be authored as cells. Combine with `gpu-driven-rendering` to cull per-cell batches.",
 "cost": {
  "class": "cheap",
  "notes": "Runtime is a bitset lookup (PVS) or a small recursive clip (portals); the PVS bake can be long for complex levels."
 },
 "failure_modes": [
  "Conservative PVS over-includes cells, so large open rooms see little gain",
  "Misplaced or missing portals cause objects to vanish when they should be visible",
  "Doors and moving walls need runtime portal open/close handling or the PVS goes stale",
  "Bake time and memory for PVS bitsets grow quickly with cell count",
  "Poor fit to outdoor scenes where there are no natural cells"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1145/122718.122725",
   "type": "paper",
   "title": "Visibility preprocessing for interactive walkthroughs",
   "authors": [
    "Seth J. Teller",
    "Carlo H. Séquin"
   ],
   "year": 1991,
   "venue": "Proceedings of the 18th annual conference on Computer graphics and interactive techniques",
   "url": "https://doi.org/10.1145/122718.122725",
   "ids": {
    "doi": "10.1145/122718.122725"
   },
   "license": null,
   "extra": {
    "csl_type": "proceedings-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/122718.122725",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/122718.122725",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/122718.122725",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/122718.122725",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/122718.122725",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "teller1991visibility"
  },
  {
   "role": "secondary",
   "key": "doi:10.1145/199404.199422",
   "type": "paper",
   "title": "Portals and mirrors",
   "authors": [
    "David Luebke",
    "Chris Georges"
   ],
   "year": 1995,
   "venue": "Proceedings of the 1995 symposium on Interactive 3D graphics  - SI3D '95",
   "url": "https://doi.org/10.1145/199404.199422",
   "ids": {
    "doi": "10.1145/199404.199422"
   },
   "license": null,
   "extra": {
    "csl_type": "proceedings-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/199404.199422",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/199404.199422",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/199404.199422",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/199404.199422",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/199404.199422",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "luebke1995portals"
  }
 ],
 "presets": [
  {
   "id": "portal-pvs-culling-live",
   "title": "Portal & PVS visibility culling — recursive frustum clipping through architectural doorways",
   "runtime": "glsl-fragment",
   "params": {
    "P_FOV_ANGLE": 0.78,
    "P_PORTAL_WIDTH": 0.14,
    "P_CAM_SWEEP": 1,
    "P_SHOW_FRUSTUM": 1
   },
   "basis": "original",
   "license_note": "Original interactive WebGL2 fragment shader written for Texel Atlas (MIT).",
   "code": "const float P_FOV_ANGLE = 0.78; // P Camera FOV [0.35, 1.35, 0.03]\nconst float P_PORTAL_WIDTH = 0.14; // P Portal Width [0.06, 0.26, 0.01]\nconst float P_CAM_SWEEP = 1.0; // P Sweep Speed [0.0, 2.5, 0.05]\nconst float P_SHOW_FRUSTUM = 1.0; // P Frustum Beams [0.0, 1.5, 0.05]\n\nfloat sdSegment(vec2 p, vec2 a, vec2 b) {\n  vec2 pa = p - a, ba = b - a;\n  float h = clamp(dot(pa, ba) / max(dot(ba, ba), 1e-5), 0.0, 1.0);\n  return length(pa - ba * h);\n}\n\nfloat wrapPi(float a) {\n  return mod(a + 3.14159265, 6.2831853) - 3.14159265;\n}\n\n// Clip angular interval [aMin, aMax] to the sightline span of a portal segment (pA -> pB) seen from cam\nvec2 clipInterval(vec2 iv, vec2 cam, vec2 pA, vec2 pB, float refAng) {\n  float a1 = wrapPi(atan(pA.y - cam.y, pA.x - cam.x) - refAng);\n  float a2 = wrapPi(atan(pB.y - cam.y, pB.x - cam.x) - refAng);\n  float lo = min(a1, a2);\n  float hi = max(a1, a2);\n  return vec2(max(iv.x, lo), min(iv.y, hi));\n}\n\nbool inWedge(vec2 p, vec2 cam, vec2 iv, float refAng) {\n  if (iv.x >= iv.y) return false;\n  float a = wrapPi(atan(p.y - cam.y, p.x - cam.x) - refAng);\n  return a >= iv.x && a <= iv.y;\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 px = 1.0 / max(iResolution.y, 1.0);\n  float tAnim = iTime * max(P_CAM_SWEEP, 0.0);\n  float halfFov = clamp(P_FOV_ANGLE, 0.3, 1.45) * 0.5;\n  float pHalf = clamp(P_PORTAL_WIDTH, 0.04, 0.28) * 0.5;\n  float beamVis = clamp(P_SHOW_FRUSTUM, 0.0, 1.6);\n\n  // Architectural floorplan: 3 vertical zones (Left Room x<-0.22, Central Hall [-0.22,0.22], Right Rooms x>0.22)\n  // Right side split horizontally at y = 0.0 into Upper-Right Room and Lower-Right Room\n  vec2 cam = vec2(-0.56 + 0.08 * cos(tAnim * 0.7), 0.16 * sin(tAnim * 0.55));\n  float camAng = 0.42 * sin(tAnim * 0.62);\n\n  // Portal 1: doorway from Left Room into Central Hall at x = -0.22, y = 0.04\n  vec2 p1A = vec2(-0.22, 0.04 - pHalf);\n  vec2 p1B = vec2(-0.22, 0.04 + pHalf);\n\n  // Portal 2: doorway from Central Hall into Upper-Right Room at x = 0.22, y = 0.22\n  vec2 p2A = vec2(0.22, 0.22 - pHalf);\n  vec2 p2B = vec2(0.22, 0.22 + pHalf);\n\n  // Portal 3: doorway from Central Hall into Lower-Right Room at x = 0.22, y = -0.22\n  vec2 p3A = vec2(0.22, -0.22 - pHalf);\n  vec2 p3B = vec2(0.22, -0.22 + pHalf);\n\n  // Recursive portal frustum clipping!\n  vec2 ivRoot = vec2(-halfFov, halfFov);\n  vec2 ivHall = clipInterval(ivRoot, cam, p1A, p1B, camAng);\n  vec2 ivUpRight = clipInterval(ivHall, cam, p2A, p2B, camAng);\n  vec2 ivLoRight = clipInterval(ivHall, cam, p3A, p3B, camAng);\n\n  // Determine which room the pixel belongs to (bounds: x in [-0.80, 0.80], y in [-0.44, 0.44])\n  bool inBuilding = abs(uv.x) < 0.80 && abs(uv.y) < 0.44;\n  int roomId = -1;\n  if (inBuilding) {\n    if (uv.x < -0.22) roomId = 0; // Starting Room\n    else if (uv.x < 0.22) roomId = 1; // Central Hall\n    else if (uv.y >= 0.0) roomId = 2; // Upper-Right Chamber\n    else roomId = 3; // Lower-Right Chamber\n  }\n\n  // Visibility classification per pixel\n  bool inRawFov = inWedge(uv, cam, ivRoot, camAng);\n  bool visPixel = false;\n  bool roomActive = false;\n  if (roomId == 0) {\n    roomActive = true;\n    visPixel = inRawFov;\n  } else if (roomId == 1) {\n    roomActive = ivHall.x < ivHall.y;\n    visPixel = inWedge(uv, cam, ivHall, camAng);\n  } else if (roomId == 2) {\n    roomActive = ivUpRight.x < ivUpRight.y;\n    visPixel = inWedge(uv, cam, ivUpRight, camAng);\n  } else if (roomId == 3) {\n    roomActive = ivLoRight.x < ivLoRight.y;\n    visPixel = inWedge(uv, cam, ivLoRight, camAng);\n  }\n\n  // Blueprint background\n  vec3 col = vec3(0.028, 0.036, 0.055);\n  vec2 g = abs(fract(uv * 14.0 - 0.5) - 0.5);\n  col += vec3(0.018, 0.028, 0.042) * smoothstep(0.035, 0.005, min(g.x, g.y));\n\n  if (inBuilding) {\n    float hatch = smoothstep(0.45, 0.85, sin((uv.x - uv.y) * 95.0));\n    vec3 culledFloor = vec3(0.055, 0.062, 0.088) + vec3(0.05, 0.02, 0.04) * hatch;\n    vec3 activeFloor = vec3(0.09, 0.14, 0.19);\n    col = roomActive ? activeFloor : culledFloor;\n\n    // Highlight frustum-culled area that WAS inside the naive camera cone but eliminated by Portal clipping!\n    if (inRawFov && !visPixel) {\n      col = mix(col, vec3(0.32, 0.08, 0.16), 0.45 * min(beamVis, 1.2));\n    }\n    // Highlight true portal-clipped visible region\n    if (visPixel) {\n      float falloff = exp(-length(uv - cam) * 0.7);\n      col += vec3(0.14, 0.62, 0.46) * (0.28 + 0.42 * falloff) * min(beamVis, 1.3);\n    }\n\n    // Place room prop markers (colored pillars/crates) that light up ONLY when their room survives PVS culling\n    vec2 props[4];\n    props[0] = vec2(-0.42, -0.26);\n    props[1] = vec2(0.00, 0.24);\n    props[2] = vec2(0.54, 0.24);\n    props[3] = vec2(0.54, -0.24);\n    for (int k = 0; k < 4; k++) {\n      float dp = length(uv - props[k]) - 0.042;\n      bool pVis = (k == 0 && inRawFov) || (k == 1 && ivHall.x < ivHall.y) || (k == 2 && ivUpRight.x < ivUpRight.y) || (k == 3 && ivLoRight.x < ivLoRight.y);\n      vec3 pCol = pVis ? vec3(0.98, 0.82, 0.28) : vec3(0.42, 0.18, 0.26);\n      col = mix(col, pCol, smoothstep(px * 2.0, -px * 1.5, dp));\n    }\n  }\n\n  // Draw solid walls (excluding portal gaps)\n  float dWall = 1e5;\n  dWall = min(dWall, sdSegment(uv, vec2(-0.80, -0.44), vec2(0.80, -0.44)));\n  dWall = min(dWall, sdSegment(uv, vec2(-0.80, 0.44), vec2(0.80, 0.44)));\n  dWall = min(dWall, sdSegment(uv, vec2(-0.80, -0.44), vec2(-0.80, 0.44)));\n  dWall = min(dWall, sdSegment(uv, vec2(0.80, -0.44), vec2(0.80, 0.44)));\n  // Wall 1 (with Portal 1 gap)\n  dWall = min(dWall, sdSegment(uv, vec2(-0.22, -0.44), p1A));\n  dWall = min(dWall, sdSegment(uv, p1B, vec2(-0.22, 0.44)));\n  // Wall 2 (with Portal 2 & Portal 3 gaps)\n  dWall = min(dWall, sdSegment(uv, vec2(0.22, -0.44), p3A));\n  dWall = min(dWall, sdSegment(uv, p3B, p2A));\n  dWall = min(dWall, sdSegment(uv, p2B, vec2(0.22, 0.44)));\n  // Horizontal divider between right rooms\n  dWall = min(dWall, sdSegment(uv, vec2(0.22, 0.0), vec2(0.80, 0.0)));\n  col = mix(col, vec3(0.76, 0.84, 0.94), smoothstep(0.014, 0.004, dWall));\n\n  // Draw glowing doorway portals\n  float dP1 = sdSegment(uv, p1A, p1B);\n  float dP2 = sdSegment(uv, p2A, p2B);\n  float dP3 = sdSegment(uv, p3A, p3B);\n  col = mix(col, (ivHall.x < ivHall.y) ? vec3(0.18, 0.98, 0.72) : vec3(0.35, 0.42, 0.55), smoothstep(0.012, 0.003, dP1));\n  col = mix(col, (ivUpRight.x < ivUpRight.y) ? vec3(0.98, 0.78, 0.22) : vec3(0.35, 0.42, 0.55), smoothstep(0.012, 0.003, dP2));\n  col = mix(col, (ivLoRight.x < ivLoRight.y) ? vec3(0.98, 0.78, 0.22) : vec3(0.35, 0.42, 0.55), smoothstep(0.012, 0.003, dP3));\n\n  // Draw clipped frustum edge sightlines from camera\n  if (beamVis > 0.01) {\n    vec2 dirL = vec2(cos(camAng + ivRoot.x), sin(camAng + ivRoot.x));\n    vec2 dirR = vec2(cos(camAng + ivRoot.y), sin(camAng + ivRoot.y));\n    float dFr = min(sdSegment(uv, cam, cam + dirL * 1.5), sdSegment(uv, cam, cam + dirR * 1.5));\n    col += vec3(0.45, 0.72, 1.0) * smoothstep(px * 3.5, px * 0.8, dFr) * 0.55 * min(beamVis, 1.2);\n    if (ivHall.x < ivHall.y) {\n      vec2 hL = vec2(cos(camAng + ivHall.x), sin(camAng + ivHall.x));\n      vec2 hR = vec2(cos(camAng + ivHall.y), sin(camAng + ivHall.y));\n      float dH = min(sdSegment(uv, cam, cam + hL * 1.4), sdSegment(uv, cam, cam + hR * 1.4));\n      col += vec3(0.22, 0.96, 0.72) * smoothstep(px * 3.5, px * 0.8, dH) * 0.75 * min(beamVis, 1.2);\n    }\n  }\n\n  // Camera beacon\n  col = mix(col, vec3(1.0, 0.96, 0.82), smoothstep(0.026, 0.010, length(uv - cam)));\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": "portal-pvs-culling",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T19:04:36.000Z",
     "renderer": "Headless EGL Tesla T4/PCIe/SSE2, OpenGL 3.30 Core, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.4654,
      "std": 0.1753,
      "min": 0.1903,
      "max": 0.9524
     },
     "image": "/specimens/portal-pvs-culling-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "masked-software-occlusion-culling",
  "hierarchical-z-occlusion-culling",
  "hardware-occlusion-queries",
  "gpu-driven-rendering"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "lightmap-baking",
   "why": "The same cell partition used for the visibility bake can organize lightmap charts per room."
  }
 ],
 "provenance": {
  "prose": "original text written for this index (research draft, editorially reviewed)",
  "sources_verified_at": "2026-11-29T15:51:27.588Z",
  "draft": "data/drafts/performance/portal-pvs-culling.json"
 },
 "solves": [
  "indoor level renders rooms the player cannot see",
  "precomputed visibility for corridors and rooms",
  "walls hide most geometry but everything is drawn",
  "need zero runtime cost occlusion culling",
  "culling for building interiors with doors"
 ],
 "authority": "Teller & Séquin, 1991",
 "url": "https://texelatlas.vercel.app/t/portal-pvs-culling/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 10.59,
  "tier": "moderate",
  "p50_ms": 0.3326,
  "p95_ms": 0.3419,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 40,
  "preset_id": "portal-pvs-culling-live",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 9.8,
   "tier": "moderate",
   "p50_ms": 0.1548,
   "p95_ms": 0.1662,
   "speedup_x": 2.15,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 6.5,
   "tier": "moderate",
   "p50_ms": 0.1871,
   "p95_ms": 0.2066,
   "speedup_x": 1.78,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}