Skip to content

armgit / 67.js

Public Imported from GitHub
0

3D engine that AI agents drive

Document environment map IBL and route it in the scene skill

Nguyen Xuan An9f3e1ace909e
diff --git a/docs/guide.md b/docs/guide.md
index 1a12525c..ebdeac7f 100644
--- a/docs/guide.md
+++ b/docs/guide.md
@@ -162,6 +162,10 @@ Collapsed output triangles cause errors. Projection does not guarantee clearance
The [surface patch contract](/surface.md) defines projector orientation, depth and local clearance.
Patches and shrinkwrap are static operations. They do not follow skin or morph deformation.
+## HDR environment lighting
+
+Pass `environment: { map }` to light and reflect from an equirectangular HDR image. `loadHdri(url)` from `67js/addons/hdri` parses a Poly Haven `.hdr` file, and `createEnvironmentMap` accepts your own float data. Without a map, rendering is unchanged. The [lighting contract](/lighting.md#environment-maps-ibl) covers rotation, background display, memory and limits.
+
## Baked liquid
`67js/addons/spume` is in the current source and not yet published. It plays back liquid baked offline by the Spume GPU solver.
diff --git a/docs/lighting.md b/docs/lighting.md
index 3ade73cd..a12c5ae8 100644
--- a/docs/lighting.md
+++ b/docs/lighting.md
@@ -31,7 +31,35 @@ renderer.render({ eye: [0, 2, 5], target: [0, 1, 0], fov: 40 });
`keyIntensity` scales the existing shadowed directional light. `keyColor` optionally replaces its linear RGB radiance color. `fillIntensity` scales the two existing fill/rim lights. `ambientIntensity` scales procedural reflection and hemisphere fill. Each intensity defaults to one, preserving previous lighting when no controls are supplied. Set all three to zero to isolate local lights on standard PBR surfaces.
-These controls do not disable the sky, emission, fog or special procedural floor/fire/smoke shading. They also scale foliage transmission, water reflection and the directional water glint. Environment reflections remain the existing procedural studio approximation, not a loaded HDR environment.
+These controls do not disable the sky, emission, fog or special procedural floor/fire/smoke shading. They also scale foliage transmission, water reflection and the directional water glint. Without an environment map, reflections remain the procedural studio approximation. See [Environment maps (IBL)](#environment-maps-ibl) to light from a loaded HDR.
+
+## Environment maps (IBL)
+
+An equirectangular HDR image can replace the procedural studio reflection and the fixed ambient term. Poly Haven CC0 HDRIs at 1k or 2k work well; larger files only cost load time.
+
+```js
+import { Renderer67 } from '67js';
+import { loadHdri } from '67js/addons/hdri';
+
+const map = await loadHdri('/studio_small_09_1k.hdr', { intensity: 1, rotation: 0.6 });
+const renderer = new Renderer67(canvas, parts, { hdr: true, environment: { map } });
+```
+
+`loadHdri(url, options)` fetches and parses a Radiance `.hdr` (RGBE, `-Y height +X width`, flat or run-length scanlines) and returns the descriptor. To build one from your own data, call `createEnvironmentMap({ width, height, data, intensity, rotation, showBackground, backgroundBlur })`, where `data` is a `Float32Array` of linear RGB or RGBA, top row first. The image centre looks toward -Z, `rotation` turns it about +Y in radians (0 to 1,000,000 as a finite number), `intensity` is 0 to 1000, `backgroundBlur` is 0 to 1.
+
+Set `environment.map` in the constructor or in `frame.environment`. Maps spread from one created map, such as `{ ...map, rotation: time }`, reuse its GPU textures, so rotation animates for free. Passing a different map prefilters it on first use, and `map: null` returns to studio lighting. With no map the output is pixel-identical to before.
+
+When a map is set:
+
+- Standard PBR surfaces take specular reflection by roughness from a GGX-prefiltered chain and diffuse ambient from L2 spherical harmonics, with a split-sum BRDF lookup. `ambientIntensity` and occlusion maps still scale it.
+- Liquid reflections sample the same chain.
+- `showBackground: true` draws the map behind the scene in studio and world mode, blurred by `backgroundBlur`. It is skipped on transparent canvases.
+- Key, fill and point lights still add direct light. Set `keyIntensity` and `fillIntensity` to zero to light a scene from the map alone.
+- The procedural floor, water tag, fire and smoke keep their own shading.
+
+Cost and memory: prefiltering runs once when a map is first used, not per frame (about 30 ms for a 512x256 map on an RTX 3060 after shader compilation, plus about 0.6 s of first-use shader compile). The renderer keeps a half-float chain of at most 1024 wide (about 8 MB for 1024x512, 1.4 MB for 512x256) and a 128x128 BRDF lookup, and counts both in the memory budget. The source upload is freed after prefiltering. A 2048x1024 source briefly needs about 11 MB of GPU memory and 32 MB of CPU memory while loading. Maps need `EXT_color_buffer_float`; without it the constructor throws.
+
+Limits: the diffuse term uses L2 spherical harmonics, so a very small intense sun gives soft, slightly ringing diffuse light and no shadow. Use the key light for sun shadows. Reflections have no parallax or occlusion, and the procedural water tag does not use the map.
## Point lights
diff --git a/skills/build-67js-scene/SKILL.md b/skills/build-67js-scene/SKILL.md
index 53f585d1..1f5a9151 100644
--- a/skills/build-67js-scene/SKILL.md
+++ b/skills/build-67js-scene/SKILL.md
@@ -18,6 +18,7 @@ Use `simplify-code` and `engineering-workflows` for implementation.
- A keyframe scene uses `src/animation.js`, `src/motion.js` and `src/motion-player.js`.
- An authored camera uses `src/camera-path.js` and the checkout's `docs/camera-path.md`.
- Local lights use the renderer environment and the checkout's `docs/lighting.md`.
+- Realistic reflections or HDRI lighting use `environment.map` from `createEnvironmentMap` or optional `src/hdri.js` (`loadHdri`) and the "Environment maps (IBL)" section of `docs/lighting.md`.
- Depth-clipped fog uses `{ hdr: true, depth: true }` and the checkout's `docs/volumetric.md`.
- A skeletal asset uses `src/skinning.js`, `src/gltf.js` and the checkout's `docs/skinning.md`.
- Relative facial or shape deformation uses `src/morph.js` and the checkout's `docs/morph-targets.md`. Check source versus published support first.