@null3d/engine 0.0.0 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +109 -0
- package/THIRD-PARTY-NOTICES.txt +0 -1
- package/dist/wasm/single/null3d.js +19 -6
- package/dist/wasm/single/null3d_bg.wasm +0 -0
- package/dist/wasm/threaded/null3d.js +19 -6
- package/dist/wasm/threaded/null3d_bg.wasm +0 -0
- package/docs/api/animation.md +23 -67
- package/docs/api/assets.md +42 -26
- package/docs/api/cameras.md +8 -6
- package/docs/api/controls.md +46 -44
- package/docs/api/debug.md +13 -8
- package/docs/api/engine.md +17 -11
- package/docs/api/feature-draws.md +3 -3
- package/docs/api/feature-effects.md +3 -3
- package/docs/api/feature-instances.md +2 -2
- package/docs/api/features.md +14 -15
- package/docs/api/geometry.md +56 -75
- package/docs/api/grass.md +1 -1
- package/docs/api/impostors.md +120 -9
- package/docs/api/input.md +4 -11
- package/docs/api/lights.md +14 -38
- package/docs/api/lines.md +8 -25
- package/docs/api/materials.md +69 -70
- package/docs/api/math.md +6 -7
- package/docs/api/objects.md +13 -13
- package/docs/api/particles.md +2 -14
- package/docs/api/points.md +3 -25
- package/docs/api/post.md +22 -23
- package/docs/api/quality.md +11 -6
- package/docs/api/raycast.md +13 -32
- package/docs/api/reference/animation.md +9 -9
- package/docs/api/reference/assets.md +18 -18
- package/docs/api/reference/cameras.md +5 -2
- package/docs/api/reference/controls.md +75 -23
- package/docs/api/reference/debug.md +23 -8
- package/docs/api/reference/engine.md +22 -10
- package/docs/api/reference/geometry.md +161 -82
- package/docs/api/reference/grass.md +1 -1
- package/docs/api/reference/impostors.md +92 -1
- package/docs/api/reference/input.md +3 -3
- package/docs/api/reference/lights.md +9 -9
- package/docs/api/reference/lines.md +7 -7
- package/docs/api/reference/materials.md +48 -48
- package/docs/api/reference/math.md +22 -22
- package/docs/api/reference/objects.md +9 -9
- package/docs/api/reference/points.md +4 -4
- package/docs/api/reference/post.md +18 -18
- package/docs/api/reference/quality.md +7 -3
- package/docs/api/reference/raycast.md +6 -6
- package/docs/api/reference/render.md +2 -2
- package/docs/api/reference/scene.md +29 -26
- package/docs/api/reference/sketch.md +4 -0
- package/docs/api/reference/sound.md +203 -0
- package/docs/api/reference/sprites.md +5 -5
- package/docs/api/reference/terrain.md +2 -1
- package/docs/api/reference/textures.md +4 -4
- package/docs/api/reference/ui.md +3 -3
- package/docs/api/reference/vertex-draws.md +3 -3
- package/docs/api/reference/water.md +77 -6
- package/docs/api/reference/wind.md +2 -2
- package/docs/api/render.md +12 -10
- package/docs/api/scene.md +40 -29
- package/docs/api/sketch.md +64 -3
- package/docs/api/sound.md +169 -0
- package/docs/api/splats.md +7 -0
- package/docs/api/sprites.md +4 -20
- package/docs/api/tasks.md +2 -2
- package/docs/api/terrain.md +2 -14
- package/docs/api/textures.md +9 -9
- package/docs/api/ui.md +3 -15
- package/docs/api/water.md +198 -15
- package/docs/api/wind.md +5 -5
- package/docs/cli/null3d.md +93 -18
- package/docs/concepts/architecture.md +10 -10
- package/docs/concepts/assets.md +2 -19
- package/docs/concepts/backends.md +7 -5
- package/docs/concepts/color-management.md +15 -26
- package/docs/concepts/culling.md +1 -1
- package/docs/concepts/instances.md +5 -5
- package/docs/concepts/large-worlds.md +1 -1
- package/docs/concepts/lighting.md +50 -55
- package/docs/concepts/lod.md +2 -15
- package/docs/concepts/materials.md +16 -16
- package/docs/concepts/post-processing.md +7 -29
- package/docs/concepts/quality-preset-tables.md +53 -50
- package/docs/concepts/quality-presets.md +56 -27
- package/docs/concepts/render-graph.md +19 -14
- package/docs/concepts/render-layers.md +3 -17
- package/docs/concepts/shadows.md +10 -28
- package/docs/concepts/static-dynamic.md +2 -2
- package/docs/cookbook/index.md +1 -1
- package/docs/data/threejs-mapping.json +136 -102
- package/docs/errors/E1214.md +3 -3
- package/docs/errors/E1307.md +23 -0
- package/docs/errors/E1420.md +3 -3
- package/docs/errors/index.md +3 -2
- package/docs/getting-started/cdn.md +17 -1
- package/docs/getting-started/first-scene.md +1 -1
- package/docs/getting-started/hosting.md +50 -9
- package/docs/getting-started/install.md +8 -7
- package/docs/getting-started/network-use.md +10 -2
- package/docs/getting-started/project-structure.md +15 -6
- package/docs/getting-started/third-party-notices.md +8 -6
- package/docs/guides/accessibility.md +1 -1
- package/docs/guides/add-ons.md +3 -2
- package/docs/guides/agents.md +16 -5
- package/docs/guides/assets-pipeline.md +13 -12
- package/docs/guides/audio.md +109 -124
- package/docs/guides/car-paint.md +1 -1
- package/docs/guides/content-pages.md +10 -6
- package/docs/guides/custom-passes.md +9 -8
- package/docs/guides/custom-shaders.md +6 -3
- package/docs/guides/debugging.md +78 -4
- package/docs/guides/deploying.md +105 -5
- package/docs/guides/deterministic-simulation.md +1 -1
- package/docs/guides/first-use-shaders.md +4 -4
- package/docs/guides/loading-screens.md +78 -33
- package/docs/guides/multiple-views.md +41 -2
- package/docs/guides/performance.md +6 -3
- package/docs/guides/phones.md +12 -1
- package/docs/guides/physics.md +1 -1
- package/docs/guides/screens.md +7 -5
- package/docs/guides/start-time.md +328 -0
- package/docs/guides/testing.md +23 -5
- package/docs/guides/ui-overlays.md +3 -3
- package/docs/index.md +12 -8
- package/docs/pages.md +26 -23
- package/docs/porting/react-three-fiber.md +228 -5
- package/docs/porting/threejs-loop-and-threads.md +220 -6
- package/docs/porting/threejs-mapping.md +86 -84
- package/docs/porting/threejs-materials.md +212 -5
- package/docs/porting/threejs-overview.md +218 -5
- package/docs/porting/threejs-postprocessing.md +2 -2
- package/docs/porting/threejs-shaders.md +298 -5
- package/docs/porting/threejs-unsupported.md +82 -6
- package/docs/porting/verification.md +181 -5
- package/docs/shaders/builtins.md +1 -1
- package/docs/shaders/library.md +63 -39
- package/docs/shaders/surface-functions.md +11 -10
- package/docs/shaders/wgsl-rules.md +1 -1
- package/lib/debug/channel.d.ts +103 -0
- package/lib/debug/channel.js +269 -0
- package/lib/debug/debug.d.ts +9 -7
- package/lib/debug/draw.d.ts +9 -0
- package/lib/debug/draw.js +49 -2
- package/lib/debug/inspector.d.ts +60 -0
- package/lib/debug/inspector.js +475 -0
- package/lib/debug/stats-panel.d.ts +1 -1
- package/lib/debug/stats.d.ts +2 -3
- package/lib/errors/codes.js +8 -2
- package/lib/errors/engine-error.js +25 -10
- package/lib/errors/fixes.d.ts +1 -0
- package/lib/errors/fixes.js +3 -2
- package/lib/generated/core.d.ts +1 -1
- package/lib/generated/core.js +1 -1
- package/lib/gpu/early-builds.d.ts +68 -0
- package/lib/gpu/early-builds.js +158 -0
- package/lib/gpu/pipeline-name.d.ts +6 -0
- package/lib/gpu/pipeline-name.js +23 -0
- package/lib/gpu/webgl2/backend.d.ts +63 -2
- package/lib/gpu/webgl2/backend.js +226 -8
- package/lib/gpu/webgl2/programs.d.ts +18 -0
- package/lib/gpu/webgl2/programs.js +4 -1
- package/lib/gpu/webgpu/backend.d.ts +89 -2
- package/lib/gpu/webgpu/backend.js +255 -8
- package/lib/gpu/webgpu/pipelines.d.ts +13 -0
- package/lib/gpu/webgpu/pipelines.js +15 -1
- package/lib/index.d.ts +6 -4
- package/lib/index.js +3 -2
- package/lib/math/color.d.ts +5 -5
- package/lib/math/color.js +5 -5
- package/lib/math/mat4.d.ts +6 -12
- package/lib/math/mat4.js +6 -12
- package/lib/math/namespaces/quat.d.ts +3 -3
- package/lib/math/namespaces/quat.js +3 -3
- package/lib/math/quat.d.ts +8 -12
- package/lib/math/quat.js +8 -12
- package/lib/math/random.d.ts +2 -3
- package/lib/math/random.js +2 -3
- package/lib/math/types.d.ts +4 -4
- package/lib/math/vec3.d.ts +3 -6
- package/lib/math/vec3.js +3 -6
- package/lib/page/capabilities.d.ts +7 -7
- package/lib/page/capabilities.js +39 -25
- package/lib/page/check-store.d.ts +14 -2
- package/lib/page/check-store.js +34 -11
- package/lib/page/engine.d.ts +103 -26
- package/lib/page/engine.js +420 -97
- package/lib/page/first-frame.d.ts +16 -0
- package/lib/page/first-frame.js +35 -0
- package/lib/page/frame-stats.d.ts +34 -1
- package/lib/page/frame-stats.js +15 -0
- package/lib/page/label-loop.d.ts +7 -3
- package/lib/page/label-loop.js +17 -10
- package/lib/page/labels.d.ts +3 -3
- package/lib/page/pipeline-store.d.ts +25 -0
- package/lib/page/pipeline-store.js +84 -0
- package/lib/page/start-marker.d.ts +4 -1
- package/lib/page/start-marker.js +5 -2
- package/lib/page/switches.d.ts +32 -2
- package/lib/page/switches.js +9 -1
- package/lib/quality/check.d.ts +24 -3
- package/lib/quality/check.js +21 -7
- package/lib/quality/chooser.d.ts +6 -0
- package/lib/quality/chooser.js +8 -0
- package/lib/quality/governor.d.ts +98 -6
- package/lib/quality/governor.js +250 -20
- package/lib/quality/preset-docs.d.ts +16 -1
- package/lib/quality/preset-docs.js +3 -0
- package/lib/quality/presets.d.ts +84 -7
- package/lib/quality/presets.js +94 -2
- package/lib/render/draw.d.ts +3 -2
- package/lib/render/draw.js +15 -5
- package/lib/render/load-draw.d.ts +7 -5
- package/lib/render/load-draw.js +7 -5
- package/lib/render/loss.d.ts +28 -10
- package/lib/render/loss.js +50 -22
- package/lib/render/recovery.d.ts +20 -0
- package/lib/render/recovery.js +44 -4
- package/lib/render/renderer.d.ts +85 -9
- package/lib/render/renderer.js +181 -42
- package/lib/render/scene-renderer.d.ts +19 -1
- package/lib/render/scene-renderer.js +25 -1
- package/lib/render/webgl2-renderers.js +8 -5
- package/lib/render/webgpu-renderers.js +5 -4
- package/lib/scene/animation.d.ts +28 -32
- package/lib/scene/animation.js +12 -15
- package/lib/scene/assets.d.ts +61 -86
- package/lib/scene/assets.js +103 -236
- package/lib/scene/background.d.ts +14 -18
- package/lib/scene/background.js +5 -2
- package/lib/scene/color.d.ts +3 -3
- package/lib/scene/downloads.d.ts +2 -0
- package/lib/scene/downloads.js +371 -0
- package/lib/scene/environment.d.ts +7 -7
- package/lib/scene/environment.js +1 -1
- package/lib/scene/fake-call-values.js +1 -1
- package/lib/scene/fog.d.ts +11 -4
- package/lib/scene/fog.js +8 -2
- package/lib/scene/frame-cameras.d.ts +19 -0
- package/lib/scene/frame-cameras.js +58 -0
- package/lib/scene/gltf.d.ts +32 -2
- package/lib/scene/gltf.js +78 -49
- package/lib/scene/grading.d.ts +2 -2
- package/lib/scene/grading.js +3 -3
- package/lib/scene/ktx2.d.ts +9 -1
- package/lib/scene/ktx2.js +3 -2
- package/lib/scene/level-rule.d.ts +120 -0
- package/lib/scene/level-rule.js +130 -0
- package/lib/scene/lines.d.ts +13 -17
- package/lib/scene/lines.js +3 -3
- package/lib/scene/lut.d.ts +1 -2
- package/lib/scene/lut.js +1 -2
- package/lib/scene/picks.d.ts +2 -2
- package/lib/scene/pointer-events.d.ts +4 -7
- package/lib/scene/post.d.ts +38 -43
- package/lib/scene/post.js +4 -1
- package/lib/scene/prefab.d.ts +7 -8
- package/lib/scene/prefab.js +7 -8
- package/lib/scene/property-animation.d.ts +1 -1
- package/lib/scene/property-animation.js +1 -1
- package/lib/scene/queries.d.ts +7 -13
- package/lib/scene/resources.d.ts +225 -254
- package/lib/scene/resources.js +179 -81
- package/lib/scene/scene.d.ts +149 -118
- package/lib/scene/scene.js +196 -98
- package/lib/scene/serial-loads.d.ts +29 -0
- package/lib/scene/serial-loads.js +68 -0
- package/lib/scene/shader-preloads.d.ts +34 -0
- package/lib/scene/shader-preloads.js +38 -0
- package/lib/scene/sprites.d.ts +14 -17
- package/lib/scene/sprites.js +5 -6
- package/lib/scene/textures.d.ts +11 -12
- package/lib/scene/textures.js +9 -10
- package/lib/scene/time-of-day.d.ts +3 -4
- package/lib/scene/time-of-day.js +2 -3
- package/lib/scene/vertex-draws.d.ts +5 -4
- package/lib/scene/vertex-draws.js +7 -5
- package/lib/shader-artifact.json +1 -0
- package/lib/shared/core.d.ts +5 -0
- package/lib/shared/core.js +1 -0
- package/lib/shared/import-once.d.ts +6 -0
- package/lib/shared/import-once.js +19 -0
- package/lib/shared/metrics.d.ts +38 -0
- package/lib/shared/metrics.js +62 -1
- package/lib/shared/run-task.js +7 -1
- package/lib/shared/task-pending.d.ts +12 -0
- package/lib/shared/task-pending.js +61 -1
- package/lib/shared/tasks.js +79 -32
- package/lib/shared/version.d.ts +17 -1
- package/lib/shared/version.js +19 -1
- package/lib/shared/wasm.d.ts +12 -4
- package/lib/shared/wasm.js +50 -27
- package/lib/shared/worker-start.d.ts +7 -0
- package/lib/shared/worker-start.js +27 -0
- package/lib/sketch/define-sketch.d.ts +35 -0
- package/lib/sketch/input.d.ts +2 -2
- package/lib/sketch/preset-check.d.ts +20 -6
- package/lib/sketch/preset-check.js +42 -17
- package/lib/sketch/quality.d.ts +69 -11
- package/lib/sketch/quality.js +54 -13
- package/lib/sketch/runner.d.ts +76 -9
- package/lib/sketch/runner.js +385 -52
- package/lib/sketch/ui.d.ts +5 -8
- package/lib/workers/probe-worker.d.ts +5 -0
- package/lib/workers/probe-worker.js +13 -4
- package/lib/workers/protocol.d.ts +61 -13
- package/lib/workers/protocol.js +4 -0
- package/lib/workers/render-worker.js +25 -4
- package/lib/workers/sketch-worker.js +104 -15
- package/package.json +2 -2
|
@@ -8,7 +8,7 @@ summary: "Light types, units and exposure; clustered lighting; fog; environment
|
|
|
8
8
|
|
|
9
9
|
# Lighting and environment
|
|
10
10
|
|
|
11
|
-
> Roadmap step 0.1, first released in null3D 0.1.0.
|
|
11
|
+
> Roadmap step 0.1, first released in null3D 0.1.0. The API is experimental, so it can still change between versions. Surfaces show up to four directional lights. The quality presets cap area lights, and they do not cap point and spot lights.
|
|
12
12
|
|
|
13
13
|
```mermaid
|
|
14
14
|
flowchart LR
|
|
@@ -38,7 +38,7 @@ A scene pass ([Custom passes](../guides/custom-passes.md)) does steps 3 and 4 ag
|
|
|
38
38
|
|
|
39
39
|
## Kinds of light and their units
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
Each kind of light takes its intensity in a physical unit:
|
|
42
42
|
|
|
43
43
|
| Light | What it models | Intensity | `intensityUnit` |
|
|
44
44
|
| --- | --- | --- | --- |
|
|
@@ -50,17 +50,17 @@ Units follow three.js since r155, which dropped its legacy light mode. A scene t
|
|
|
50
50
|
| Rectangle | A window, a screen or a soft box: light from a glowing rectangle | Nits: the brightness of its surface | None |
|
|
51
51
|
| Tube | A neon or fluorescent tube: light from a glowing tube | Nits: the brightness of its surface | None |
|
|
52
52
|
|
|
53
|
-
A standard material reflects light with the
|
|
53
|
+
A standard material reflects light with the physically based model of glTF's metallic-roughness materials: a Lambert diffuse term and a GGX highlight. A rough surface that is not a metal reflects close to its color divided by π, times the light that reaches it. A white directional light with an intensity of π therefore shows a white, rough surface that faces it as nearly white.
|
|
54
54
|
|
|
55
55
|
Three defaults keep shiny surfaces clean. They are always on, and they have no settings:
|
|
56
56
|
|
|
57
|
-
- The smoothest surface has a roughness of 0.045, as in
|
|
58
|
-
- Highlights flicker less on curved shapes. A highlight narrower than a pixel comes and goes as the camera moves. So where a mesh's normal turns fast between pixels, the highlight widens by the spread of the normals within the pixel. This is Filament's specular anti-aliasing. The widening has a limit, so edges stay glossy, and flat surfaces get none.
|
|
59
|
-
- Reflections never come from inside an object. A normal map can tilt a surface so far that its reflection points below the mesh's own surface. There the environment's reflection fades out, as in Unity and Godot.
|
|
57
|
+
- The smoothest surface has a roughness of 0.045, as in Filament. A roughness of 0 still shows a small highlight, and reads the sharpest level of an environment.
|
|
58
|
+
- Highlights flicker less on curved shapes. A highlight narrower than a pixel comes and goes as the camera moves. So where a mesh's normal turns fast between pixels, the highlight widens by the spread of the normals within the pixel. This is Filament's specular anti-aliasing. The widening has a limit, so edges stay glossy, and flat surfaces get none.
|
|
59
|
+
- Reflections never come from inside an object. A normal map can tilt a surface so far that its reflection points below the mesh's own surface. There the environment's reflection fades out, as in Unity and Godot.
|
|
60
60
|
|
|
61
|
-
A rectangle or tube light's light follows from its size and brightness
|
|
61
|
+
A rectangle or tube light's light follows from its size and brightness. The engine integrates it over the light's area with linearly transformed cosines, the method of Heitz, Dupuy, Hill and Neubelt. A larger light of the same intensity therefore gives more light, and a shiny surface shows its shape. [Area lights](../api/lights.md#area-lights) gives the details.
|
|
62
62
|
|
|
63
|
-
Point and spot lights fade with distance by their `decay`. A decay of 2, the default, fades light with the square of the distance, as real light fades. Each also ends at its `range`, because the engine finds the lights near each surface by their ranges.
|
|
63
|
+
Point and spot lights fade with distance by their `decay`. A decay of 2, the default, fades light with the square of the distance, as real light fades. Each also ends at its `range`, because the engine finds the lights near each surface by their ranges. So every point and spot light needs a range above 0.
|
|
64
64
|
|
|
65
65
|
```ts
|
|
66
66
|
import { defineSketch } from '@null3d/engine';
|
|
@@ -79,7 +79,7 @@ Up to four directional lights light a frame. The first one created that remains
|
|
|
79
79
|
|
|
80
80
|
```mermaid
|
|
81
81
|
flowchart LR
|
|
82
|
-
units["Intensity in lumens,<br/>candela or lux"] --> light["Light in
|
|
82
|
+
units["Intensity in lumens,<br/>candela or lux"] --> light["Light in candela or lux"]
|
|
83
83
|
camera["exposure, and ev100:<br/>1 / (1.2 × 2^ev100)"] --> factor["The frame's exposure"]
|
|
84
84
|
light --> times["Light times the exposure,<br/>on the CPU"]
|
|
85
85
|
factor --> times
|
|
@@ -89,7 +89,7 @@ flowchart LR
|
|
|
89
89
|
scene --> tone["Tone mapping"]
|
|
90
90
|
```
|
|
91
91
|
|
|
92
|
-
|
|
92
|
+
Most scenes give small intensities, such as 3 for a bright sun, with an exposure of 1. A scene can also give its lights real values. A real sun gives about 100,000 lux, an 800-lumen bulb lights a room, and a camera's exposure brings that light to the screen. In null3D, `intensityUnit` gives a light its real unit, and `post.set({ ev100 })` sets the camera's exposure value at ISO 100, as in Filament and Bevy. The exposure is 1 / (1.2 × 2^ev100): about 1 / 39,000 at 15, a sunny day.
|
|
93
93
|
|
|
94
94
|
The engine multiplies the exposure into each light at its source, as Filament does, not into the finished picture. On the CPU it scales each light, the background color and the fog color. In the shaders it scales emissive light, light maps, unlit colors and background textures. Everything before the tone mapping is linear, so the picture is the same as with the exposure at the end. But the scene's colors stay near 1, so a 16-bit float holds them. With the exposure at the end, a sun of 100,000 lux gives a smooth metal a highlight above 65,504. That is the largest 16-bit float, so the highlight loses its color.
|
|
95
95
|
|
|
@@ -105,7 +105,7 @@ export default defineSketch(({ scene, post }) => {
|
|
|
105
105
|
});
|
|
106
106
|
```
|
|
107
107
|
|
|
108
|
-
Colors that you set in the scene's units take the exposure too: a background color, an unlit material's color and an emissive color. At EV100 15 a background color of white draws black
|
|
108
|
+
Colors that you set in the scene's units take the exposure too: a background color, an unlit material's color and an emissive color. At EV100 15 a background color of white draws black. Give emissive light in nits instead, through `emissiveIntensity`, such as 40,000 for about white at EV100 15. [Post-processing API](../api/post.md#lights-in-real-units) gives the settings.
|
|
109
109
|
|
|
110
110
|
## Clustered forward shading
|
|
111
111
|
|
|
@@ -139,7 +139,7 @@ The engine shades each surface in the pass that draws it. A deferred renderer wo
|
|
|
139
139
|
- Forward shading works with MSAA directly, where deferred shading needs extra passes.
|
|
140
140
|
- Transparent surfaces use the same lighting code as opaque ones.
|
|
141
141
|
|
|
142
|
-
Both GPU paths light a scene the same way. WebGPU reads the lists from storage buffers, and WebGL2 from small data textures.
|
|
142
|
+
Both GPU paths light a scene the same way. WebGPU reads the lists from storage buffers, and WebGL2 from small data textures. The camera lists up to 1,024 lights in a frame, the ones nearest to it. Each cluster lists up to 128. Of those, the quality preset's `areaLights` caps the rectangle and tube lights, which cost more per pixel. [Performance guide](../guides/performance.md#point-and-spot-lights) gives the cost of lights.
|
|
143
143
|
|
|
144
144
|
## Lights as objects
|
|
145
145
|
|
|
@@ -151,9 +151,17 @@ A glTF file's lights (`KHR_lights_punctual`) become directional, point and spot
|
|
|
151
151
|
|
|
152
152
|
## Ambient and hemisphere lights
|
|
153
153
|
|
|
154
|
-
An ambient light gives every surface the same light. A hemisphere light blends from its ground color to its sky color as a surface's normal turns toward its +Y axis
|
|
154
|
+
An ambient light gives every surface the same light. A hemisphere light blends from its ground color to its sky color as a surface's normal turns toward its +Y axis. That blend is half the sum of the two colors, plus a term that grows with the cosine between the normal and the sky's direction. Each frame, the engine sums every ambient and hemisphere light on the CPU. The sum is one color from every direction and one color along each world axis. Each pixel of a standard material adds them up with three multiply-adds, whatever the number of lights.
|
|
155
155
|
|
|
156
|
-
Both lights are diffuse only
|
|
156
|
+
Both lights are diffuse only: they light a surface's color and give no highlights. An environment's light adds to theirs. The environment's `intensity` and a material's `envIntensity` scale only the environment's own light. The occlusion map and ambient occlusion darken the light of all of them.
|
|
157
|
+
|
|
158
|
+
### A scene that shows a time of day
|
|
159
|
+
|
|
160
|
+
A light that stands for the sky must follow the hour. An ambient or hemisphere light with a fixed color and intensity is a day light. Under a night sky it lights sand, wall and road as brightly as at noon. The scene then reads as a dark sky over a lit town.
|
|
161
|
+
|
|
162
|
+
Scale the light with the hour, shifting its colors cool at night. The island showcase holds its hemisphere light at 0.8 with warm sky and ground colors by day. By night it takes it to a cool 0.06, driven by the share of a town's lamps that are lit. The moon's directional light and the lamps then carry the night, and a faint ambient keeps the dark from going black.
|
|
163
|
+
|
|
164
|
+
Exposure is one value for the whole scene. An exposure high enough for a bright day lifts a moonlit scene by the same factor, so choose it at the hour the scene shows longest. A demo stage offers the share of a town's lamps as `stage.lamps`, from 0 by day to 1 at night, which drives such a light.
|
|
157
165
|
|
|
158
166
|
## Lights far from the origin
|
|
159
167
|
|
|
@@ -161,13 +169,13 @@ The engine keeps each object's position relative to a grid cell, a cube of space
|
|
|
161
169
|
|
|
162
170
|
## Fog
|
|
163
171
|
|
|
164
|
-
Fog fades objects toward one color with their distance from the camera, as air does over a landscape. A sketch sets it with `scene.setFog`, and [Scene](../api/scene.md#fog) lists the options. The distance is the straight line from the camera to each point. A point therefore keeps its fog as the camera turns, and fog at the screen's edges does not shift.
|
|
172
|
+
Fog fades objects toward one color with their distance from the camera, as air does over a landscape. A sketch sets it with `scene.setFog`, and [Scene](../api/scene.md#fog) lists the options. The distance is the straight line from the camera to each point. A point therefore keeps its fog as the camera turns, and fog at the screen's edges does not shift.
|
|
165
173
|
|
|
166
|
-
A curve sets how the fog thickens. The default, exponential fog, follows light through an even haze: each unit of distance hides the same share of what is left. Exponential squared fog
|
|
174
|
+
A curve sets how the fog thickens. The default, exponential fog, follows light through an even haze: each unit of distance hides the same share of what is left. Exponential squared fog thickens with the square of the distance. Linear fog is clear up to `near` and hides objects from `far`, with a smooth change between them.
|
|
167
175
|
|
|
168
176
|
Real mist lies low and thins with height. With a `heightFalloff`, the fog's density falls by a factor of e every 1 / `heightFalloff` units up. The engine sums that density along each line of sight with an exact formula, as Filament does. A view down into the mist then sees thick fog, and a view across its top sees thin fog. With a `sunGlow`, the fog toward the main directional light takes some of that light's color, as haze around a low sun does. The glow follows the light and its intensity. Shadows do not block it.
|
|
169
177
|
|
|
170
|
-
The engine mixes the fog into each pixel's color as it shades the pixel, after lighting and before the tone mapping. Fog therefore needs no pass and no texture. It costs about 15 arithmetic operations and one or two exponentials per pixel, and nothing in a scene without fog. The mix happens in linear color
|
|
178
|
+
The engine mixes the fog into each pixel's color as it shades the pixel, after lighting and before the tone mapping. Fog therefore needs no pass and no texture. It costs about 15 arithmetic operations and one or two exponentials per pixel, and nothing in a scene without fog. The mix happens in linear color. The sky and the background can take the same fog as a surface at the camera's far plane. They do so at the share that the fog's `background` option sets, above 0; the default is 0. The haze over the land can then continue over the sky it meets. A material created with `fog: false` keeps its color at every distance.
|
|
171
179
|
|
|
172
180
|
### Volumetric fog
|
|
173
181
|
|
|
@@ -204,7 +212,7 @@ An environment map holds the light that reaches a point from every direction, su
|
|
|
204
212
|
import { defineSketch } from '@null3d/engine';
|
|
205
213
|
|
|
206
214
|
export default defineSketch(async ({ scene, assets, materials, geometry }) => {
|
|
207
|
-
// The room
|
|
215
|
+
// The built-in room: soft, neutral light, with no file of your own.
|
|
208
216
|
scene.setEnvironment(await assets.builtinEnvironment('room'));
|
|
209
217
|
// Or a file that `bunx @null3d/cli assets env` made from an HDR image, turned and dimmed:
|
|
210
218
|
// scene.setEnvironment(await assets.loadEnvironment('/env/sunset.ktx2'), { intensity: 0.8, rotation: [0, Math.PI / 2, 0] });
|
|
@@ -221,34 +229,34 @@ export default defineSketch(async ({ scene, assets, materials, geometry }) => {
|
|
|
221
229
|
The fast path is one KTX2 file, which `bunx @null3d/cli assets env` makes from an HDR image before you publish:
|
|
222
230
|
|
|
223
231
|
- A cube map with one level for each step of roughness. Level 0 holds the light itself, for mirrors. Each smaller level holds the light blurred as a rougher surface reflects it, with the GGX distribution of the standard material.
|
|
224
|
-
- Nine spherical harmonics coefficients, the diffuse light from each direction in a few numbers
|
|
232
|
+
- Nine spherical harmonics coefficients, the diffuse light from each direction in a few numbers.
|
|
225
233
|
|
|
226
|
-
|
|
234
|
+
The tool filters the map before you publish, so a page does no prefiltering before it draws. [The asset pipeline](../guides/assets-pipeline.md#environment-maps) gives the command's options and the file's sizes.
|
|
227
235
|
|
|
228
|
-
The engine also reads the HDR image itself, a Radiance (`.hdr`) or OpenEXR (`.exr`) file
|
|
236
|
+
The engine also reads the HDR image itself, a Radiance (`.hdr`) or OpenEXR (`.exr`) file. A worker reads the file, and the GPU filters it at load with the asset tool's steps. On every GPU path, the map lies on average within a tenth of a step of 255 of the tool's map of the same file. As in the tool's map, light past the 16-bit float limit, such as an unclipped sun, keeps its share of the rough levels.
|
|
229
237
|
|
|
230
|
-
The built-in room needs no file. The GPU draws
|
|
238
|
+
The built-in room needs no file. The GPU draws the room into a cube map and filters it for each roughness when a sketch first asks for it. It follows the asset tool's steps, so it gives the same map as `bunx @null3d/cli assets env --builtin room`.
|
|
231
239
|
|
|
232
|
-
The sky's environment needs no file either. The GPU draws the sky that `scene.setBackground({ sky })` shows into a cube map, and filters it for each roughness.
|
|
240
|
+
The sky's environment needs no file either. The GPU draws the sky that `scene.setBackground({ sky })` shows into a cube map, and filters it for each roughness. The map follows the sky by itself: when the sun moves, the map refreshes over the next frames. [Sky and backgrounds](#sky-and-backgrounds) says how.
|
|
233
241
|
|
|
234
242
|
### How an environment lights a surface
|
|
235
243
|
|
|
236
|
-
The standard material takes the environment's light
|
|
244
|
+
The standard material takes the environment's light in these ways:
|
|
237
245
|
|
|
238
246
|
- Specular light comes from the cube map, along the view's reflection about the surface's normal. A rough surface reads a smaller, blurrier level.
|
|
239
247
|
- Diffuse light comes from the nine coefficients, along the surface's normal.
|
|
240
|
-
-
|
|
241
|
-
- The occlusion map darkens the diffuse light
|
|
248
|
+
- A table of split-sum terms weighs the two by the view's angle, the roughness and the metalness. Fdez-Agüera's multiple-scattering model adds back the light that a rough surface reflects more than once.
|
|
249
|
+
- The occlusion map darkens the diffuse light. It darkens the specular light too, by the specular occlusion of Lagarde and de Rousiers, which depends on the view's angle and the roughness.
|
|
242
250
|
- The specular light fades where a normal map tilts the reflection below the mesh's own surface.
|
|
243
251
|
|
|
244
|
-
|
|
252
|
+
A small table picks the level that each roughness reads.
|
|
245
253
|
|
|
246
|
-
`scene.setEnvironment(environment, { intensity, rotation })` sets the scene's environment, and `scene.setEnvironment(null)` removes it. `intensity` scales the light
|
|
254
|
+
`scene.setEnvironment(environment, { intensity, rotation })` sets the scene's environment, and `scene.setEnvironment(null)` removes it. `intensity` scales the light. `rotation` turns the environment by Euler angles in radians, in the order X, Y, Z. The call allocates nothing, so a sketch can turn the environment in every frame. A material's `envIntensity` scales the environment's light on that material alone, and multiplies the scene's `intensity`. A scene has one environment. For the light of one place in the scene, use a [reflection probe](#reflection-probes).
|
|
247
255
|
|
|
248
256
|
| Call | Gives |
|
|
249
257
|
| --- | --- |
|
|
250
258
|
| `assets.loadEnvironment(url)` | An environment from a file of `bunx @null3d/cli assets env`, or from a Radiance or OpenEXR file that the GPU filters at load |
|
|
251
|
-
| `assets.builtinEnvironment('room')` |
|
|
259
|
+
| `assets.builtinEnvironment('room')` | A white room with six boxes and glowing panels, blurred by 0.04 radians. The GPU makes it, so no file downloads |
|
|
252
260
|
| `assets.skyEnvironment()` | The light of the scene's sky, which follows the sky background. The GPU makes it, so no file downloads |
|
|
253
261
|
| `scene.setEnvironment(environment, options)` | Nothing: it lights the scene with the environment from the next frame |
|
|
254
262
|
| `environment.destroy()` | Nothing: it frees the cube map's GPU memory |
|
|
@@ -275,11 +283,6 @@ The tests of the room's generator measured these times in Chrome. The phones ran
|
|
|
275
283
|
| Galaxy S25, Pixel 9, Pixel 10 and Pixel 11, WebGPU | 93 to 129 ms | 48 to 100 ms |
|
|
276
284
|
| The same phones, WebGL2 | 100 to 226 ms | 58 to 107 ms |
|
|
277
285
|
|
|
278
|
-
### Differences from three.js
|
|
279
|
-
|
|
280
|
-
- three.js takes `scene.environmentIntensity` in place of a material's `envMapIntensity` when the material has no map of its own. The engine multiplies the two, so `envIntensity` keeps its meaning with a scene environment.
|
|
281
|
-
- Each material can have its own `envMap` in three.js. The engine has one environment per scene. For the light of one place in the scene, use a [reflection probe](#reflection-probes).
|
|
282
|
-
|
|
283
286
|
## Reflection probes
|
|
284
287
|
|
|
285
288
|
An environment map holds light from infinitely far away. In a room, a polished floor then reflects the sky, not the walls. A reflection probe holds the light around one point of the scene, and lights the surfaces inside its box in place of the environment:
|
|
@@ -307,7 +310,7 @@ The engine captures the scene from the probe's point on the GPU, through six squ
|
|
|
307
310
|
|
|
308
311
|
- **Box projection.** A reflection ray meets the box's sides, and the probe reads its light in the direction from its point to that place. So a wall reflects in the floor at its own distance, and a reflection moves right as the camera moves. `boxProjection: false` reads the probe as light from far away, for open ground.
|
|
309
312
|
- **Blending.** A probe lights its whole box, a floor on its bottom side included, and fades out over `blend` meters beyond its sides. So make each box the shape of its room or street. Where boxes overlap, the probe with the higher `priority` lights the surface, or the smaller box at the same priority, and the next probe takes the rest. A surface takes light from at most two probes. The environment lights what the probes leave.
|
|
310
|
-
- **Diffuse light.** A probe also gives the diffuse light of its surfaces, from its roughest level
|
|
313
|
+
- **Diffuse light.** A probe also gives the diffuse light of its surfaces, from its roughest level.
|
|
311
314
|
- **Refresh.** `refresh: 'once'` captures when the probe is made or moved, and when `probe.capture()` asks. `refresh: 'always'` captures again and again, so moving objects show. One probe captures per frame, in turns. A capture whose pipelines are still building keeps its request, so that probe takes the next frame's turn too.
|
|
312
315
|
- **What a capture sees.** Objects on the probe's `layers`, the sun and its shadows, the ambient, hemisphere and environment light, fog and the background. A probe sees the environment, not other probes.
|
|
313
316
|
|
|
@@ -357,13 +360,13 @@ Such a mesh keeps the environment's diffuse light, and takes no light from the g
|
|
|
357
360
|
|
|
358
361
|
## Sky and backgrounds
|
|
359
362
|
|
|
360
|
-
The background is what the camera shows behind every object. `scene.setBackground` takes a color, a texture, an environment, a cube map,
|
|
363
|
+
The background is what the camera shows behind every object. `scene.setBackground` takes a color, a texture, an environment, a cube map, the analytic sky, or the physical sky. [Scene](../api/scene.md#environments-cube-maps-and-the-sky) gives the options.
|
|
361
364
|
|
|
362
365
|
```ts
|
|
363
366
|
import { defineSketch } from '@null3d/engine';
|
|
364
367
|
|
|
365
368
|
export default defineSketch(async ({ scene, assets }) => {
|
|
366
|
-
// A low sun over a hazy sky
|
|
369
|
+
// A low sun over a hazy sky.
|
|
367
370
|
scene.setBackground({ sky: { sunPosition: [0, 0.07, -1], turbidity: 10, rayleigh: 3 } });
|
|
368
371
|
// Light from an environment, which the sky does not give.
|
|
369
372
|
scene.setEnvironment(await assets.builtinEnvironment('room'));
|
|
@@ -371,13 +374,13 @@ export default defineSketch(async ({ scene, assets }) => {
|
|
|
371
374
|
});
|
|
372
375
|
```
|
|
373
376
|
|
|
374
|
-
The engine draws a background after the opaque objects, at the far plane, with the depth test. So it shades only the pixels that no object covers, and transparent objects draw over it. While an opaque material has `depthWrite: false` or `depthTest: false`, the background draws before the objects instead, without the depth test
|
|
377
|
+
The engine draws a background after the opaque objects, at the far plane, with the depth test. So it shades only the pixels that no object covers, and transparent objects draw over it. While an opaque material has `depthWrite: false` or `depthTest: false`, the background draws before the objects instead, without the depth test. That material then still shows over the background. A texture fills the view as one triangle. An environment, a cube map and the sky draw as a box around the camera. So each pixel takes its color from its own direction. Their light goes into the scene's color like an object's, so exposure and tone mapping change them too.
|
|
375
378
|
|
|
376
|
-
- An environment's background reads the environment's cube map at the level of the blur's roughness
|
|
377
|
-
- A cube map
|
|
378
|
-
- The sky is
|
|
379
|
+
- An environment's background reads the environment's cube map at the level of the blur's roughness. The levels hold the blur already, so a blurred background costs no more than a sharp one. Only environments blur: for a background that blurs, load an environment with `assets.loadEnvironment`.
|
|
380
|
+
- A cube map shows its six images as seen from inside the cube, mirrored across x.
|
|
381
|
+
- The analytic sky is the Preetham daylight model, with a sun disc and clouds. It is the scene's background, so it draws behind every object, whatever the camera's far plane. It moves its clouds by its `time` setting, so a still frame always shows the same clouds.
|
|
379
382
|
|
|
380
|
-
The sky lights nothing by itself
|
|
383
|
+
The sky lights nothing by itself. For light that matches it, add a directional light along the sun, and light the scene with the sky's environment:
|
|
381
384
|
|
|
382
385
|
```ts
|
|
383
386
|
import { defineSketch } from '@null3d/engine';
|
|
@@ -407,11 +410,11 @@ export default defineSketch(async ({ scene, assets, time }) => {
|
|
|
407
410
|
- So the light follows a sun that turned half a degree 19 frames later, about 320 ms at 60 frames per second. A smaller turn waits, and the map captures the sun exactly once it stops. A change during a refresh waits until it ends: then it takes up to 39 frames.
|
|
408
411
|
- The steps are short so that a phone keeps its frame rate. On a software GPU, the longest step takes under 6 ms.
|
|
409
412
|
- The engine works out the diffuse light on the CPU, from the same sky model, in about 0.1 ms on a MacBook Pro.
|
|
410
|
-
-
|
|
413
|
+
- The analytic sky is about 5 at the horizon by day, while a sun light of about 3 is bright. Lit by the sky at full intensity, a scene looks too bright. Lower the environment's `intensity`, or the exposure. [Time of day](#time-of-day) gives values that match each other.
|
|
411
414
|
|
|
412
415
|
### Where the land ends
|
|
413
416
|
|
|
414
|
-
|
|
417
|
+
With the fog's `background` share at its default of 0, the background takes no fog. Where an outdoor scene's land ends, the camera then sees the plain background below the horizon, with no haze to blend it in. Fog cannot hide that edge. Set `background: 1` to give the sky and the background the fog of a surface at the camera's far plane. The fog then blends the edge. Where that is not wanted, hide the edge with geometry, and keep the camera where the geometry hides it:
|
|
415
418
|
|
|
416
419
|
- Put a ring of hills or mountains around the land. Make its lowest crest stand above the highest point that the camera can reach. Then every line of sight below the horizon meets ground.
|
|
417
420
|
- Limit the camera. With [orbit controls](../api/controls.md), set `maxDistance` and `maxPolarAngle`, and keep `controls.target` inside the land.
|
|
@@ -510,14 +513,6 @@ The sky's environment shows the physical sky too. When a refresh starts, the eng
|
|
|
510
513
|
- The settings are a small block of values that the GPU reads, and the engine writes them again only when they change. Setting or moving a background builds no pipeline. The first background of each kind builds one.
|
|
511
514
|
- A cube map's six images upload in the frames after the load, within the frame's upload budget. Its faces have one level, so large faces seen small can shimmer.
|
|
512
515
|
|
|
513
|
-
### Backgrounds beside three.js
|
|
514
|
-
|
|
515
|
-
- three.js's `Sky` and `SkyMesh` are meshes in the scene. The engine's sky is the scene's background, so it draws behind every object, whatever the camera's far plane.
|
|
516
|
-
- three.js's `SkyMesh` moves its clouds by the renderer's clock. The engine's sky moves them by its `time` setting, as three.js's `Sky` does, so a still frame shows the same clouds.
|
|
517
|
-
- Only environments blur. three.js blurs a cube texture by turning it into a PMREM texture first. For a background that blurs, load an environment with `assets.loadEnvironment`.
|
|
518
|
-
- `WebGLRenderer` draws an sRGB cube texture without exposure and tone mapping. The engine changes every background with them, as three.js's `WebGPURenderer` does.
|
|
519
|
-
- three.js has no physical sky of its own. Ports of its `Sky` keep `{ sky }`, which matches three.js. `{ atmosphere }` is the engine's best sky, which a port can move to.
|
|
520
|
-
|
|
521
516
|
## Time of day
|
|
522
517
|
|
|
523
518
|
`timeOfDay` works out the settings that change together through a day, from one value: an hour from 0 to 24, or a preset. They are the sky's sun and air, the main light, the fog's color and glow, an ambient light, the sky's intensity and the exposure. Each comes from the same sky model as the sky background. The fog takes the sky's mean light at every hour, the same light that the exposure follows, so it stays as dim as the sky around it. A fog of the sky's horizon instead carries the sky's brightest band over the whole scene and washes out its shaded surfaces, and a low sun makes that band its own glow.
|
|
@@ -568,15 +563,15 @@ With `{ model: 'physical' }`, the values match the physical sky instead, from a
|
|
|
568
563
|
|
|
569
564
|
The helper gives values and leaves them to the sketch. A scene keeps its own light, fog curve and density, and post settings, which a call that applied them would overwrite.
|
|
570
565
|
|
|
571
|
-
-
|
|
572
|
-
-
|
|
566
|
+
- The analytic sky is far brighter than the lights' usual range. By day `skyIntensity` is 0.15, so the sun outshines the sky's diffuse light about two to one, and the fog's color can match the horizon.
|
|
567
|
+
- The analytic sky gives no light once its sun is about 2.3 degrees under the horizon. The tone curve maps what is left to black. So after sunset the helper keeps the sky's own sun just under the horizon, and `skyIntensity` dims the sky to a deep blue.
|
|
573
568
|
- At night the sky's own sun stands at the moon's place, and `skyIntensity` dims it: the "day for night" sky of film. The sky is a navy blue with a lighter horizon and a faint glow around the moon. Its sun's disc draws a small moon, and the sky's environment lights the scene a dim blue. `showSunDisc: false` hides the moon's disc.
|
|
574
569
|
- As the sun sinks from 6 to 12 degrees under the horizon, the sunset's sky fades straight into the moon's sky. No frame goes dark between them. The sky draws both at once: `sky.secondSunPosition` is the moon's place, and `sky.secondSkyWeight` is the moon sky's share. At other times the weight is 0, so pass the whole `sky` each time.
|
|
575
570
|
- Each call returns a new object, unless you pass one for it to fill. `timeOfDay(hour, {}, day)` writes into `day`, so a day cycle that moves the time in every frame makes no settings object of its own. `setColor` converts a color. A day that changes a few times a second is enough for a still scene: the sky's environment takes about 20 frames to follow anyway.
|
|
576
571
|
|
|
577
572
|
## Lights in scene passes
|
|
578
573
|
|
|
579
|
-
A [scene pass](../api/render.md) draws the scene from another camera into a texture.
|
|
574
|
+
A [scene pass](../api/render.md) draws the scene from another camera into a texture. It lights its objects with the sun, the ambient and hemisphere lights, the environment and the fog. It draws the sun's shadows where the camera's cascades reach, and the point, spot and area lights that its camera sees. It draws the scene's background behind them, the sky included, unless the pass has a `clearColor`, which its texture then clears to.
|
|
580
575
|
|
|
581
576
|
## Related pages
|
|
582
577
|
|
package/docs/concepts/lod.md
CHANGED
|
@@ -56,7 +56,7 @@ tree.setLevels([
|
|
|
56
56
|
scene.createInstances(tree, 20_000, { material: bark });
|
|
57
57
|
```
|
|
58
58
|
|
|
59
|
-
The switch distances grow from level to level, whatever their measures. Levels set by hand win over planned ones: `setLevels` ends a plan that runs, and the planned levels go. The asset tool works out each level's error for you, as the next section shows.
|
|
59
|
+
The switch distances grow from level to level, whatever their measures. The `fov` option of `setLevels` checks that order when the mesh takes the levels. Each frame compares a level's error or coverage with the field of view of the view that draws it, so `fov` moves no switch. Levels set by hand win over planned ones: `setLevels` ends a plan that runs, and the planned levels go. The asset tool works out each level's error for you, as the next section shows.
|
|
60
60
|
|
|
61
61
|
## A material per level
|
|
62
62
|
|
|
@@ -230,25 +230,12 @@ Distance bands, and levels given by a distance or by screen coverage, keep the c
|
|
|
230
230
|
|
|
231
231
|
## Cards beyond the levels
|
|
232
232
|
|
|
233
|
-
A level of detail keeps one draw and one mesh per object. Far past the last level, an object can draw as a card instead: a quad that stands upright, turns to the eye, and shows a picture of the object. The `@null3d/impostors` add-on draws those cards, and a distance band on the meshes hands the object over to them.
|
|
233
|
+
A level of detail keeps one draw and one mesh per object. Far past the last level, an object can draw as a card instead: a quad that stands upright, turns to the eye, and shows a picture of the object. The picture should come from a bake of several views with the engine's baker, so the card holds the object from every side; a hand-painted side view belongs only on a card that never covers more than a few pixels. The `@null3d/impostors` add-on draws those cards, and a distance band on the meshes hands the object over to them. [Impostors](../api/impostors.md#bake-several-views-not-one-side) shows the bake.
|
|
234
234
|
|
|
235
235
|
A bake stores the object from many directions, folded onto an octahedral grid, in a color atlas and a surface atlas of normals and depths. Each card blends the three stored views nearest the direction from the card toward the eye, so the picture changes smoothly as the camera moves rather than jumping between views. The card's light comes from the scene, through the stored normal, so a sun that moves relights the cards exactly as it relights the meshes. A copy's turn about the world's up turns its views and its light too, so a turned tree hands over to a card whose crown matches it. A camera that moves around the tree does not turn its light: the card turns to the eye, and the stored normal turns only with the tree. A card casts the crown's shape, and takes the shadows that fall on the surface it shows, when the sketch asks for it.
|
|
236
236
|
|
|
237
237
|
`setDrawRange` fades a band's edges with the dither, so the hand-over from a mesh to its cards need not pop. The impostors add-on's `handOverToCards` sets the two bands for a batch of meshes and its cards. It starts the cards early enough that their own dithered edge finishes first. The mesh and the card are different sources, so their dither phases differ. The card must already cover every pixel that the mesh will drop. [Impostors](../api/impostors.md#hand-the-near-meshes-over-to-the-cards) gives the calls, and the demo `examples/impostors` draws a forest three ways by distance.
|
|
238
238
|
|
|
239
|
-
## From three.js
|
|
240
|
-
|
|
241
|
-
| three.js | null3D |
|
|
242
|
-
| --- | --- |
|
|
243
|
-
| `const lod = new LOD(); lod.addLevel(high, 0); lod.addLevel(low, 50)` | `highMesh.setLevels([{ mesh: lowMesh, distance: 50 }])`, then draw `highMesh` |
|
|
244
|
-
| a `LOD` object whose `far` the sketch checks | `mesh.setDrawRange(start, end)` |
|
|
245
|
-
| `lod.addLevel(object, distance, hysteresis)` | `{ mesh, distance }`. The bands replace hysteresis |
|
|
246
|
-
| `lod.autoUpdate`, `lod.update(camera)` | None: the engine picks levels in every frame |
|
|
247
|
-
| `lod.getCurrentLevel()` | None |
|
|
248
|
-
| `SimplifyModifier` from three/addons, to make the far copies | None: a mesh of 4,096 triangles or more plans its levels on the job workers when it first draws, and `mesh.buildLevels()` plans a smaller one |
|
|
249
|
-
|
|
250
|
-
A three.js `LOD` holds whole objects. In null3D the levels belong to the mesh, and every object and instance batch that draws it picks its own level. A level given by its distance switches in at that distance for an object of scale 1, on every screen. The distance measures to the nearest point of the object's bounds. three.js measures to the object's position instead, so a large object switches later in null3D. A level given by its error or its coverage is compared with the field of view of the view that draws it. The `fov` option of `setLevels` only checks the order of the levels when the mesh takes them, and moves no switch.
|
|
251
|
-
|
|
252
239
|
## API reference
|
|
253
240
|
|
|
254
241
|
`mesh.setLevels`, `mesh.buildLevels` and the options they take are on the [geometry page's reference](../api/reference/geometry.md). The quality settings are on [the quality page](../api/quality.md).
|
|
@@ -8,7 +8,7 @@ summary: "Built-in materials; permutations; pipeline warm-up; why changing shade
|
|
|
8
8
|
|
|
9
9
|
# Materials and pipelines
|
|
10
10
|
|
|
11
|
-
> Roadmap step 0.1, first released in null3D 0.1.0. The API is experimental, so it can still change between versions. Custom materials take a surface function, a vertex offset, their uniforms and up to 6 textures of their own, or a full shader. They take none of the standard texture maps.
|
|
11
|
+
> Roadmap step 0.1, first released in null3D 0.1.0. The API is experimental, so it can still change between versions. Custom materials take a surface function, a vertex offset, their uniforms and up to 6 textures of their own, or a full shader. They take none of the standard texture maps.
|
|
12
12
|
|
|
13
13
|
```mermaid
|
|
14
14
|
flowchart LR
|
|
@@ -24,15 +24,15 @@ A material has two parts. Its values, such as its color and roughness, sit in on
|
|
|
24
24
|
|
|
25
25
|
## The built-in materials
|
|
26
26
|
|
|
27
|
-
| Material | Model |
|
|
28
|
-
| --- | --- |
|
|
29
|
-
| `materials.standard` | glTF's metallic-roughness model, lit by the scene's lights |
|
|
30
|
-
| `materials.unlit` | Its color alone, without lights |
|
|
31
|
-
| `materials.shader` | The standard model, with a WGSL surface function that changes the look |
|
|
32
|
-
| `materials.shadowCatcher` | Only the shadows that fall on it, and nothing where the light reaches it |
|
|
33
|
-
| `materials.decal` | The standard model, projected by a box onto the surfaces inside it |
|
|
27
|
+
| Material | Model |
|
|
28
|
+
| --- | --- |
|
|
29
|
+
| `materials.standard` | glTF's metallic-roughness model, lit by the scene's lights |
|
|
30
|
+
| `materials.unlit` | Its color alone, without lights |
|
|
31
|
+
| `materials.shader` | The standard model, with a WGSL surface function that changes the look |
|
|
32
|
+
| `materials.shadowCatcher` | Only the shadows that fall on it, and nothing where the light reaches it |
|
|
33
|
+
| `materials.decal` | The standard model, projected by a box onto the surfaces inside it |
|
|
34
34
|
|
|
35
|
-
The standard material
|
|
35
|
+
The standard material lights a surface with Lambert diffuse light and a GGX highlight. The cube map and the spherical harmonics of the environment give its light, and a table of split-sum terms weighs it. A term for light that bounces more than once keeps a rough surface's energy. [Materials](../api/materials.md) lists every option.
|
|
36
36
|
|
|
37
37
|
## Values cost almost nothing
|
|
38
38
|
|
|
@@ -66,7 +66,7 @@ A feature that changes what a shader costs is a variant of the shader, which the
|
|
|
66
66
|
| `colorWrite: false` | The pipeline's color state, and the place in the opaque pass: its objects draw first, so their depth holds back the surfaces behind them |
|
|
67
67
|
| `flatShading` | The material's row: every standard shader can light with face normals |
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
To change one of these options, create one material for each combination in the setup, and give an object another one with `setMaterial`.
|
|
70
70
|
|
|
71
71
|
```ts
|
|
72
72
|
// sketch.ts: two variants, made once in the setup.
|
|
@@ -76,15 +76,15 @@ const cloth = materials.standard({ color: '#8098d0', doubleSided: true });
|
|
|
76
76
|
|
|
77
77
|
## Alpha modes
|
|
78
78
|
|
|
79
|
-
A material's `alphaMode` says what its alpha does. The default, `opaque`, ignores it. The `mask` mode draws nothing where the alpha is below the material's `alphaCutoff
|
|
79
|
+
A material's `alphaMode` says what its alpha does. The default, `opaque`, ignores it. The `mask` mode draws nothing where the alpha is below the material's `alphaCutoff`. A masked surface is opaque where it draws, so it hides what lies behind it, and its objects draw in any order.
|
|
80
80
|
|
|
81
|
-
The `hash` mode draws each point opaque or not at all
|
|
81
|
+
The `hash` mode draws each point opaque or not at all. A hash of the point's place on the mesh sets a threshold, and the point draws where its alpha reaches it. The alpha then sets the share of the surface that draws, and hashed objects need no sort.
|
|
82
82
|
|
|
83
83
|
The shader that drops fragments costs more than one that never does: a GPU cannot always test depth before it runs such a shader. Tile GPUs, as in phones and Apple's chips, also lose part of their hidden-surface removal. So only masked and hashed materials draw with that variant. The cutoff is a value, and `set({ alphaCutoff })` changes it at no cost.
|
|
84
84
|
|
|
85
85
|
`alphaToCoverage`, on by default, smooths a mask's cut edges with MSAA. The masked alpha fades over about one pixel above the cutoff, and MSAA covers that share of each edge pixel's samples. Where the target's format has an alpha channel, the GPU turns the alpha into coverage. WebGPU's HDR scene color has none, so there the shader writes the covered samples itself. Those shader builds load the first time a material needs them. Without MSAA, alpha to coverage is a plain mask.
|
|
86
86
|
|
|
87
|
-
The `blend` mode blends the surface over what lies behind it
|
|
87
|
+
The `blend` mode blends the surface over what lies behind it. Its `blending` chooses how: `normal`, `additive`, `multiply` or `weighted` ([Weighted blending](../api/materials.md#weighted-blending)). [Materials](../api/materials.md#alpha-modes) shows each mode.
|
|
88
88
|
|
|
89
89
|
## The transparent pass
|
|
90
90
|
|
|
@@ -94,15 +94,15 @@ flowchart LR
|
|
|
94
94
|
sort --> transparent["Transparent pass:<br/>each blends over the ones before"]
|
|
95
95
|
```
|
|
96
96
|
|
|
97
|
-
The result of blending depends on the order in which surfaces draw. A surface must blend over everything behind it. So the engine draws blended objects in a pass of their own, after the opaque ones, farthest first. In each frame, for each view, the job workers cull the blended objects and sort them. An object's depth is the depth of its bounding sphere's center
|
|
97
|
+
The result of blending depends on the order in which surfaces draw. A surface must blend over everything behind it. So the engine draws blended objects in a pass of their own, after the opaque ones, farthest first. In each frame, for each view, the job workers cull the blended objects and sort them. An object's depth is the depth of its bounding sphere's center. `mesh.setRenderOrder(order)` comes first: a lower order draws first, at any depth.
|
|
98
98
|
|
|
99
|
-
The rows of an instance batch sort one by one, so a batch of blended particles draws in the right order.
|
|
99
|
+
The rows of an instance batch sort one by one, so a batch of blended particles draws in the right order. Neighbors in the sorted order that share a mesh and a material draw together. A batch that no other blended object crosses therefore draws in few draw calls.
|
|
100
100
|
|
|
101
101
|
Sorting by object has these limits:
|
|
102
102
|
|
|
103
103
|
- Surfaces that cross each other have no right order. One object draws before the other, so where the second lies behind the first, it shows wrong. Split such meshes, or give them `depthWrite: false` so they never hide each other.
|
|
104
104
|
- A large object, such as a long glass wall, has one center. A small object can have a center that is farther away than the wall's while it stands in front of the wall. Split large blended meshes, or set their order with `setRenderOrder`.
|
|
105
|
-
- The triangles of one mesh draw in the mesh's own order. A closed blended mesh, such as a sphere, draws only its front faces unless it is double-sided. A double-sided one draws its back faces first, then its front faces
|
|
105
|
+
- The triangles of one mesh draw in the mesh's own order. A closed blended mesh, such as a sphere, draws only its front faces unless it is double-sided. A double-sided one draws its back faces first, then its front faces. So its near side covers its far side. Each run of neighbors that share its mesh and material takes a second draw. On flat surfaces, whose faces never overlap, `forceSinglePass: true` saves it.
|
|
106
106
|
|
|
107
107
|
Surfaces of the `weighted` blending need no sort. In the camera's view they leave the transparent pass and draw after it, in any order, into two targets of their own. A last step blends their weighted average over the scene, as far as they cover it together ([Weighted blending](../api/materials.md#weighted-blending)). Use it where the limits above make smoke, particles or crossing panes pop.
|
|
108
108
|
|
|
@@ -88,7 +88,7 @@ Bloom spreads light from the bright parts of the scene into their surroundings,
|
|
|
88
88
|
| `blend` | `'mix'`, `'add'` or `'screen'`. | `'mix'` |
|
|
89
89
|
| `weights` | Up to 10 numbers of 0 or more: each level's share of the glow, from the narrowest level to the widest. Not all 0. | Shares for 8 levels |
|
|
90
90
|
|
|
91
|
-
- The `'mix'` blend moves each pixel's color toward the glow by the intensity, so the image keeps its total light. A lit wall keeps its brightness and turns softer. `'add'` adds the glow,
|
|
91
|
+
- The `'mix'` blend moves each pixel's color toward the glow by the intensity, so the image keeps its total light. A lit wall keeps its brightness and turns softer. The `'add'` blend adds the glow, so the image gains light. The `'screen'` blend screens it, so the glow adds less where the scene is already bright.
|
|
92
92
|
- At a threshold of 0, all light glows a little, as in a real lens. At 1, only light brighter than white glows, such as an emissive material with an `emissiveIntensity` above 1.
|
|
93
93
|
- The levels have the canvas's shape and a fixed number of texels on its shorter side. So the glow keeps its size as a share of the screen at any pixel ratio, render scale and screen orientation.
|
|
94
94
|
- Each level spreads light twice as far as the one before. The eighth spreads it over about a quarter of the canvas's shorter side, and the tenth over all of it. The engine divides the weights by their sum. The default gives eight levels a share, most to the narrow ones, for a soft glow that keeps the shape of the light.
|
|
@@ -220,7 +220,7 @@ A custom tone curve replaces the built-in curves. Its WGSL declares `fn toneCurv
|
|
|
220
220
|
|
|
221
221
|
## Ambient occlusion
|
|
222
222
|
|
|
223
|
-
Ambient occlusion darkens the light that comes from all around where nearby surfaces hide a surface from it. That happens in corners, in creases and under objects that rest on the ground. It
|
|
223
|
+
Ambient occlusion darkens the light that comes from all around where nearby surfaces hide a surface from it. That happens in corners, in creases and under objects that rest on the ground. It uses ground-truth ambient occlusion (GTAO), at half the render size:
|
|
224
224
|
|
|
225
225
|
1. The depth prepass draws the opaque objects' depth. Ambient occlusion turns the prepass on while it draws.
|
|
226
226
|
2. A first step copies the depth of one pixel under each texel.
|
|
@@ -242,8 +242,7 @@ post.set({ ao: { radius: 0.5, intensity: 1 } });
|
|
|
242
242
|
| `samples` | The depth samples of each pixel's search, a whole number from 1 to 64: 3 directions below 30, and 5 from 30. | 16 |
|
|
243
243
|
| `intensity` | From 0 to 1: how much of the occlusion reaches the ambient light. | 1 |
|
|
244
244
|
|
|
245
|
-
-
|
|
246
|
-
- `GTAOPass` darkens the whole image, direct light and highlights included. null3D darkens only the ambient light, and the light that light maps add. A surface in the sun keeps its sunlight in a corner, as it would in the real world. In a scene that only ambient light lights, the two give the same image.
|
|
245
|
+
- It darkens only the ambient light, and the light that light maps add. Direct light and highlights keep their strength, so a surface in the sun keeps its sunlight in a corner, as in the real world.
|
|
247
246
|
- Blended objects draw over the surfaces that ambient occlusion saw, so they take none.
|
|
248
247
|
- The depth prepass leaves out masked surfaces and levels of detail while they fade, so ambient occlusion may see only what lies behind them. Such a surface takes the occlusion only where ambient occlusion saw a surface at its own depth, such as a leaf on the ground. A petal in front of grass takes none of the grass's occlusion.
|
|
249
248
|
- `post.set({ ao: false })` turns ambient occlusion off. The settings keep their values, so `post.set({ ao: {} })` turns it on again with them.
|
|
@@ -261,7 +260,7 @@ Ambient occlusion needs no HDR color, so it draws on the 8-bit path too. Its tar
|
|
|
261
260
|
|
|
262
261
|
### Cost
|
|
263
262
|
|
|
264
|
-
Ambient occlusion adds the depth prepass and three small passes at half the render size. It also adds four texture reads to each pixel that the opaque pass shades. The engine's ambient occlusion scene ran on a MacBook Pro in Chrome, at 3,024 x 1,518 pixels. There it added 2.42 ms of GPU time per frame. three.js's `GTAOPass` added about 5.3 ms to the same scene and canvas
|
|
263
|
+
Ambient occlusion adds the depth prepass and three small passes at half the render size. It also adds four texture reads to each pixel that the opaque pass shades. The engine's ambient occlusion scene ran on a MacBook Pro in Chrome, at 3,024 x 1,518 pixels. There it added 2.42 ms of GPU time per frame, and 1.18 ms at a render scale of 0.5. three.js's `GTAOPass` added about 5.3 ms to the same scene and canvas, more than twice as much.
|
|
265
264
|
|
|
266
265
|
- Its targets follow the render scale, so a lower scale costs less, and a new scale makes no new target. They take 20 bytes per texel at half size, 5 bytes per pixel of the canvas. They exist only while ambient occlusion draws.
|
|
267
266
|
- The depth prepass costs a second pass over the opaque objects' vertices. In a scene with many vertices it adds time of its own. [Quality presets](quality-presets.md#the-depth-prepass) says when the prepass pays.
|
|
@@ -350,7 +349,7 @@ Outlines draw a crisp line around the meshes that `setOutlined(true)` marks:
|
|
|
350
349
|
|
|
351
350
|
- The line has no blur, so it ends as sharply as the meshes' own edges. Its width counts pixels of the canvas, so it stays sharp at every pixel ratio and render scale.
|
|
352
351
|
- The mask pass culls the outlined meshes with the camera's view on its own, so outlined meshes out of view cost nothing.
|
|
353
|
-
-
|
|
352
|
+
- The mask pass finds the hidden parts from the depth that the scene passes drew, so it draws no other object again.
|
|
354
353
|
- The 8-bit path draws the same line as the HDR path.
|
|
355
354
|
- While nothing is outlined, the mask pass and the mask are off, so turning outlines on costs nothing until a mesh is outlined.
|
|
356
355
|
|
|
@@ -360,15 +359,14 @@ Outlines draw the outlined meshes twice into the mask, which takes 4 bytes per p
|
|
|
360
359
|
|
|
361
360
|
## Color grading and the vignette
|
|
362
361
|
|
|
363
|
-
A color grading table, from a `.cube` or a `.3dl` file through `assets.loadLut` or from numbers through `assets.lutFromData`, maps each display color to a graded color
|
|
362
|
+
A color grading table, from a `.cube` or a `.3dl` file through `assets.loadLut` or from numbers through `assets.lutFromData`, maps each display color to a graded color. The vignette darkens the picture toward its edges. [The post-processing API](../api/post.md#color-grading) lists their settings.
|
|
364
363
|
|
|
365
|
-
- The vignette multiplies HDR color before the tone mapping, as Filament, Unity's URP, Bevy and Babylon.js do. Bright corners then darken as dark corners do
|
|
364
|
+
- The vignette multiplies HDR color before the tone mapping, as Filament, Unity's URP, Bevy and Babylon.js do. Bright corners then darken as dark corners do, and never turn gray.
|
|
366
365
|
- The grading controls work on display color, after the tone mapping, as most grading tools do. A `.cube` or `.3dl` table works there too: grading tools make tables for display color, so they look as their authors made them.
|
|
367
366
|
- Both draw on every GPU path, with HDR color or without it, as [Post-processing API](../api/post.md#vignette) says.
|
|
368
367
|
- They are settings of the final pass, not passes of their own. Turning one on builds no pipeline, so the picture changes in the next frame with no pause.
|
|
369
368
|
- Each table is a 3D texture, read with one filtered texture read per pixel. The vignette costs a few operations per pixel.
|
|
370
369
|
- The grading controls' table holds 32 texels a side, and the final pass takes the square root of a color before it reads the table, which places the texels closer together toward black where a grade's curve is steepest. A job worker computes the table's texels, so a value that changes stalls no frame. The frame that lands a bake uploads the table, 256 KB. The table keeps the worker's whole range, past white, and the canvas clips it, so a color that crosses white inside a texel's cell still matches the grade.
|
|
371
|
-
- The engine's parity test compares a `.cube` table alone with three.js's composer. It matches in all but under 0.1% of the pixels on every GPU path. With the vignette too, mapped from `VignetteShader`'s settings for AgX, it matches as closely.
|
|
372
370
|
|
|
373
371
|
## Sharpening
|
|
374
372
|
|
|
@@ -410,26 +408,6 @@ Bloom, depth of field, automatic exposure, custom effects and custom tone curves
|
|
|
410
408
|
|
|
411
409
|
The devices that the engine was tested on all draw HDR color with WebGL2, and with core WebGPU.
|
|
412
410
|
|
|
413
|
-
## Porting from three.js
|
|
414
|
-
|
|
415
|
-
- Delete `EffectComposer`, `RenderPass` and `OutputPass`. The scene pass and the final pass are built in.
|
|
416
|
-
- `new UnrealBloomPass(resolution, strength, radius, threshold)` becomes `post.set({ bloom })` with `blend: 'add'`, the same `threshold` and a `knee` of 0.01. The intensity is about 8.8 times `strength`, and `radius` becomes the `weights`. The `null3d-port-threejs` skill holds a table of weights by radius, and a script that maps the settings for a canvas size. The resolution is the canvas's, so it needs no setting.
|
|
417
|
-
- three.js's glow spans a number of pixels, and null3D's a share of the screen. So a mapping matches at one canvas size, 1080 pixels on the shorter side by default. On a larger screen null3D's glow looks wider than three.js's.
|
|
418
|
-
- A strong bloom spreads a little wider at the edges of the frame than three.js's. three.js's faint haze fades toward the corners, and null3D's keeps its light there. To soften it, lower `strength` or `radius` before you map the settings, or lower `intensity`.
|
|
419
|
-
- pmndrs's `BloomEffect` maps the same way, with `blend: 'screen'`: its `intensity` stays, `luminanceThreshold` becomes `threshold`, and `luminanceSmoothing` becomes `knee`. three.js's `bloom()` node maps as `UnrealBloomPass` does, at a third of the intensity.
|
|
420
|
-
- `new BokehPass(scene, camera, { focus, aperture, maxblur })` becomes `post.set({ dof: { focusDistance: focus, maxBlur } })`, with the lens's `aperture` as an f-number. `BokehPass`'s aperture scales its blur with the distance from the focus. null3D's lens blurs as a camera does, so set `camera.setFocalLength` and pick an f-number by eye, such as 2.8.
|
|
421
|
-
- The `maxblur` of `BokehPass` is a share of the canvas's width, and `maxBlur` is a share of its height. Multiply it by the aspect ratio. In one pass, `BokehPass` blurs each pixel by its own depth, so a sharp object spreads a halo into a blurred background. null3D's near and far fields spread no halo.
|
|
422
|
-
- `new GTAOPass(scene, camera, width, height)` becomes `post.set({ ao: {} })`. Its `updateGtaoMaterial({ radius, thickness, distanceExponent, distanceFallOff, scale, samples })` settings keep their names, with `distanceFalloff` spelled so, and `blendIntensity` becomes `intensity`. Set `quality.set({ aoScale: 0.5 })` too where phones and tablets should draw it.
|
|
423
|
-
- `SSAOPass`, `SAOPass` and the N8AO library also become `post.set({ ao })`. Their settings have other meanings, so start from the defaults and tune `radius` and `scale` by eye.
|
|
424
|
-
- `new OutlinePass(resolution, scene, camera, selectedObjects)` becomes `post.set({ outline: { color, hiddenColor, width } })`, from `visibleEdgeColor` and `hiddenEdgeColor`. `OutlinePass` draws its edge at half size, so a `width` of twice its `edgeThickness` gives about the same line. three.js draws a dark brown line around hidden parts by default, and null3D draws none until `hiddenColor` is set. Each selected mesh calls `setOutlined(true)`. A selected model's copy from `scene.instantiate` calls it once for all of its meshes.
|
|
425
|
-
- A port that needs `OutlinePass`'s soft edge, its glow or its pulse installs `@null3d/three-compat` and calls `createOutlinePass(ctx, { color, hiddenColor, strength, thickness, glow, pulsePeriod })`. Its settings keep `edgeStrength`, `edgeThickness`, `edgeGlow` and `pulsePeriod`, and `visibleEdgeColor` and `hiddenEdgeColor` become `color` and `hiddenColor`. The add-on turns the core's crisp line off, and it costs five full-screen passes and one effect ([three.js compatibility](../api/three-compat.md)).
|
|
426
|
-
- three.js has no automatic exposure. pmndrs's `ToneMappingEffect` with `mode: ToneMappingMode.REINHARD2_ADAPTIVE` adapts, and becomes `post.set({ autoExposure: { metering: 'mean' } })`. Its `adaptationRate` becomes about `speedUp` and `speedDown`, and its `middleGrey` the `compensation`: `log2(middleGrey / 0.18)` stops. Its Reinhard curve becomes a custom tone curve. pmndrs meters a mip chain of the whole frame. null3D meters on the GPU with center weighting, so the result differs a little.
|
|
427
|
-
- `renderer.toneMapping` and `toneMappingExposure` become `post.set({ toneMapping, exposure })`. three.js applies no tone mapping by default, and null3D applies punchy AgX. A port that set `AgXToneMapping` sets `'agx'`, and one that set `ACESFilmicToneMapping` sets `'aces'`. `ReinhardToneMapping` and `CineonToneMapping` become the `reinhard` and `cineon` curves of `@null3d/three-compat`. The exposure gives the same picture: null3D applies it to each light rather than at the end, and bloom's threshold keeps its meaning.
|
|
428
|
-
- `new LUTPass({ lut: result.texture3D, intensity })` after a `LUTCubeLoader` or `LUT3dlLoader` becomes `post.set({ lut: await assets.loadLut(url), lutIntensity: intensity })`. A `Data3DTexture` that code fills becomes `await assets.lutFromData({ size, data })`.
|
|
429
|
-
- A `ShaderPass(VignetteShader)` with its `offset` and `darkness` uniforms becomes `post.set({ vignette: { size: offset, intensity: darkness } })`. Under ACES the default falloff gives a close match. Under AgX, keep `intensity` at 1 or less and set `falloff` to 3. With a `darkness` below 1, three.js also lifts dark corners toward a gray, and null3D does not.
|
|
430
|
-
- `new SharpenNode(target, sharpness, denoise)` becomes `post.set({ sharpen })`. Both sharpen display color with FSR 1's RCAS over the same five texels. null3D draws it in the final pass, so the port needs no render target and no pass of its own. The two settings count the other way round. three.js scales the sharpening by `2^-sharpness`, where 0 sharpens the most and 2 does nothing. So `sharpen` takes that factor: three.js's default of 0.2 is `sharpen: 0.87`, and `sharpen: 0.5` is stronger than three.js's default. null3D always damps the sharpening where the ring around a pixel is noise, which three.js does only with `denoise: true`.
|
|
431
|
-
- Any other `ShaderPass` becomes `post.addEffect` with the shader rewritten in WGSL. A pass after `OutputPass` saw display color, and an effect sees linear HDR color. Numbers that assume colors from 0 to 1 may need changes. `CustomToneMapping` becomes a custom tone curve, and `ReinhardToneMapping` and `CineonToneMapping` take the curves of `@null3d/three-compat`. [Porting post-processing](../porting/threejs-postprocessing.md) shows both.
|
|
432
|
-
|
|
433
411
|
## Related pages
|
|
434
412
|
|
|
435
413
|
- [Post-processing API](../api/post.md): `post.set` and its settings, and `post.addEffect`.
|