@null3d/engine 0.0.0 → 0.1.1
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 +25 -10
- package/dist/wasm/single/null3d_bg.wasm +0 -0
- package/dist/wasm/threaded/null3d.js +25 -10
- package/dist/wasm/threaded/null3d_bg.wasm +0 -0
- package/docs/api/animation.md +114 -86
- package/docs/api/assets.md +135 -49
- package/docs/api/cameras.md +45 -12
- package/docs/api/controls.md +88 -62
- package/docs/api/debug.md +116 -41
- package/docs/api/engine.md +117 -35
- package/docs/api/feature-draws.md +23 -17
- package/docs/api/feature-effects.md +11 -11
- package/docs/api/feature-instances.md +70 -19
- package/docs/api/features.md +77 -47
- package/docs/api/geometry.md +132 -82
- package/docs/api/grass.md +55 -13
- package/docs/api/impostors.md +175 -22
- package/docs/api/input.md +24 -18
- package/docs/api/lights.md +78 -51
- package/docs/api/lines.md +41 -33
- package/docs/api/materials.md +248 -121
- package/docs/api/math.md +12 -13
- package/docs/api/objects.md +47 -22
- package/docs/api/page.md +58 -7
- package/docs/api/particles.md +33 -20
- package/docs/api/points.md +19 -31
- package/docs/api/post.md +75 -42
- package/docs/api/quality.md +42 -17
- package/docs/api/raycast.md +65 -51
- package/docs/api/reference/animation.md +10 -11
- package/docs/api/reference/assets.md +25 -22
- package/docs/api/reference/cameras.md +8 -4
- package/docs/api/reference/controls.md +134 -25
- package/docs/api/reference/debug.md +81 -14
- package/docs/api/reference/engine.md +58 -17
- package/docs/api/reference/feature-draws.md +3 -4
- package/docs/api/reference/feature-effects.md +2 -3
- package/docs/api/reference/feature-instances.md +5 -4
- package/docs/api/reference/features.md +7 -4
- package/docs/api/reference/geometry.md +287 -97
- package/docs/api/reference/grass.md +63 -3
- package/docs/api/reference/impostors.md +208 -13
- package/docs/api/reference/input.md +4 -5
- package/docs/api/reference/lights.md +13 -12
- package/docs/api/reference/lines.md +10 -11
- package/docs/api/reference/materials.md +54 -53
- package/docs/api/reference/math.md +35 -24
- package/docs/api/reference/objects.md +11 -12
- package/docs/api/reference/particles.md +31 -6
- package/docs/api/reference/points.md +6 -7
- package/docs/api/reference/post.md +21 -20
- package/docs/api/reference/quality.md +8 -5
- package/docs/api/reference/raycast.md +7 -8
- package/docs/api/reference/render.md +5 -4
- package/docs/api/reference/scene.md +52 -30
- package/docs/api/reference/sketch.md +15 -11
- package/docs/api/reference/sound.md +234 -0
- package/docs/api/reference/splats.md +42 -3
- package/docs/api/reference/sprites.md +7 -8
- package/docs/api/reference/tasks.md +16 -3
- package/docs/api/reference/terrain.md +27 -5
- package/docs/api/reference/textures.md +5 -6
- package/docs/api/reference/three-compat.md +18 -7
- package/docs/api/reference/time.md +1 -2
- package/docs/api/reference/ui.md +12 -9
- package/docs/api/reference/vertex-draws.md +5 -6
- package/docs/api/reference/water.md +153 -9
- package/docs/api/reference/wind.md +17 -4
- package/docs/api/render.md +73 -29
- package/docs/api/scene.md +164 -60
- package/docs/api/sketch.md +102 -15
- package/docs/api/sound.md +205 -0
- package/docs/api/splats.md +46 -12
- package/docs/api/sprites.md +10 -24
- package/docs/api/tasks.md +33 -24
- package/docs/api/terrain.md +42 -22
- package/docs/api/textures.md +68 -19
- package/docs/api/three-compat.md +15 -7
- package/docs/api/time.md +3 -5
- package/docs/api/ui.md +19 -23
- package/docs/api/vertex-draws.md +13 -12
- package/docs/api/water.md +262 -35
- package/docs/api/wind.md +63 -17
- package/docs/cli/null3d.md +177 -27
- package/docs/concepts/architecture.md +73 -27
- package/docs/concepts/assets.md +57 -33
- package/docs/concepts/backends.md +69 -27
- package/docs/concepts/color-management.md +54 -36
- package/docs/concepts/culling.md +68 -47
- package/docs/concepts/handles.md +14 -5
- package/docs/concepts/instances.md +74 -25
- package/docs/concepts/large-worlds.md +18 -8
- package/docs/concepts/lighting.md +155 -87
- package/docs/concepts/lod.md +126 -44
- package/docs/concepts/materials.md +58 -27
- package/docs/concepts/particle-buffer.md +48 -35
- package/docs/concepts/post-processing.md +84 -43
- package/docs/concepts/quality-preset-tables.md +56 -52
- package/docs/concepts/quality-presets.md +164 -52
- package/docs/concepts/render-graph.md +69 -29
- package/docs/concepts/render-layers.md +11 -21
- package/docs/concepts/shadows.md +105 -52
- package/docs/concepts/static-dynamic.md +22 -7
- package/docs/cookbook/index.md +164 -120
- package/docs/data/threejs-mapping.json +362 -367
- package/docs/errors/E1101.md +23 -5
- package/docs/errors/E1102.md +11 -3
- package/docs/errors/E1103.md +11 -3
- package/docs/errors/E1104.md +11 -3
- package/docs/errors/E1105.md +13 -5
- package/docs/errors/E1106.md +11 -3
- package/docs/errors/E1107.md +15 -5
- package/docs/errors/E1108.md +11 -3
- package/docs/errors/E1109.md +32 -6
- package/docs/errors/E1110.md +23 -5
- package/docs/errors/E1111.md +11 -3
- package/docs/errors/E1112.md +11 -3
- package/docs/errors/E1203.md +12 -4
- package/docs/errors/E1204.md +11 -3
- package/docs/errors/E1205.md +11 -3
- package/docs/errors/E1206.md +28 -6
- package/docs/errors/E1207.md +11 -3
- package/docs/errors/E1208.md +12 -3
- package/docs/errors/E1209.md +11 -3
- package/docs/errors/E1213.md +27 -5
- package/docs/errors/E1214.md +14 -6
- package/docs/errors/E1215.md +31 -6
- package/docs/errors/E1216.md +31 -6
- package/docs/errors/E1217.md +29 -6
- package/docs/errors/E1218.md +22 -6
- package/docs/errors/E1219.md +11 -3
- package/docs/errors/E1220.md +24 -5
- package/docs/errors/E1221.md +24 -5
- package/docs/errors/E1222.md +11 -3
- package/docs/errors/E1223.md +39 -6
- package/docs/errors/E1224.md +11 -3
- package/docs/errors/E1225.md +11 -3
- package/docs/errors/E1301.md +11 -3
- package/docs/errors/E1302.md +11 -3
- package/docs/errors/E1303.md +11 -3
- package/docs/errors/E1304.md +11 -3
- package/docs/errors/E1305.md +13 -3
- package/docs/errors/E1306.md +11 -3
- package/docs/errors/E1307.md +40 -0
- package/docs/errors/E1401.md +11 -3
- package/docs/errors/E1402.md +13 -5
- package/docs/errors/E1403.md +11 -3
- package/docs/errors/E1404.md +13 -3
- package/docs/errors/E1405.md +15 -4
- package/docs/errors/E1406.md +31 -5
- package/docs/errors/E1407.md +11 -3
- package/docs/errors/E1408.md +11 -3
- package/docs/errors/E1409.md +11 -3
- package/docs/errors/E1410.md +13 -5
- package/docs/errors/E1411.md +11 -3
- package/docs/errors/E1412.md +29 -6
- package/docs/errors/E1413.md +11 -3
- package/docs/errors/E1414.md +11 -3
- package/docs/errors/E1415.md +11 -3
- package/docs/errors/E1416.md +27 -6
- package/docs/errors/E1417.md +11 -3
- package/docs/errors/E1418.md +12 -3
- package/docs/errors/E1419.md +13 -5
- package/docs/errors/E1420.md +14 -6
- package/docs/errors/E1421.md +11 -3
- package/docs/errors/E1422.md +12 -3
- package/docs/errors/E1423.md +12 -3
- package/docs/errors/E1424.md +24 -5
- package/docs/errors/E1425.md +11 -3
- package/docs/errors/E1426.md +11 -3
- package/docs/errors/E1430.md +11 -3
- package/docs/errors/E1431.md +11 -3
- package/docs/errors/E1432.md +11 -3
- package/docs/errors/E1433.md +11 -3
- package/docs/errors/E1434.md +15 -6
- package/docs/errors/E1435.md +11 -3
- package/docs/errors/E1436.md +11 -3
- package/docs/errors/E1437.md +14 -6
- package/docs/errors/E1501.md +41 -6
- package/docs/errors/E1502.md +13 -3
- package/docs/errors/E1503.md +11 -3
- package/docs/errors/E1504.md +11 -3
- package/docs/errors/E1505.md +23 -5
- package/docs/errors/E1506.md +11 -3
- package/docs/errors/index.md +54 -30
- package/docs/getting-started/cdn.md +32 -10
- package/docs/getting-started/first-scene.md +21 -13
- package/docs/getting-started/hosting.md +152 -63
- package/docs/getting-started/install.md +44 -28
- package/docs/getting-started/network-use.md +33 -15
- package/docs/getting-started/project-structure.md +33 -12
- package/docs/getting-started/third-party-notices.md +12 -14
- package/docs/guides/accessibility.md +5 -5
- package/docs/guides/add-ons.md +86 -15
- package/docs/guides/agents.md +16 -9
- package/docs/guides/assets-pipeline.md +259 -82
- package/docs/guides/audio.md +115 -128
- package/docs/guides/baked-light-data.md +44 -23
- package/docs/guides/car-paint.md +38 -32
- package/docs/guides/content-pages.md +63 -35
- package/docs/guides/custom-passes.md +65 -22
- package/docs/guides/custom-shaders.md +59 -39
- package/docs/guides/debugging.md +74 -10
- package/docs/guides/deploying.md +85 -6
- package/docs/guides/deterministic-simulation.md +24 -17
- package/docs/guides/first-use-shaders.md +83 -45
- package/docs/guides/lens-kit.md +29 -26
- package/docs/guides/loading-screens.md +132 -47
- package/docs/guides/multiple-views.md +63 -13
- package/docs/guides/performance.md +192 -38
- package/docs/guides/phones.md +78 -15
- package/docs/guides/physics.md +7 -11
- package/docs/guides/screens.md +47 -33
- package/docs/guides/start-time.md +363 -0
- package/docs/guides/testing.md +152 -95
- package/docs/guides/ui-overlays.md +19 -14
- package/docs/guides/video-textures.md +14 -13
- package/docs/images/api/animation/character.webp +0 -0
- package/docs/images/api/animation/look-at-ring.webp +0 -0
- package/docs/images/api/animation/morph-tulips.webp +0 -0
- package/docs/images/api/animation/skeleton-lines.webp +0 -0
- package/docs/images/api/controls/gizmo-handles.webp +0 -0
- package/docs/images/api/controls/walk-and-fly.webp +0 -0
- package/docs/images/api/debug/debug-shapes.webp +0 -0
- package/docs/images/api/debug/levels-view.webp +0 -0
- package/docs/images/api/engine/transparent-canvas.webp +0 -0
- package/docs/images/api/feature-draws/feature-draw-clouds.webp +0 -0
- package/docs/images/api/feature-instances/compute-instances.webp +0 -0
- package/docs/images/api/feature-instances/instances-shadow.webp +0 -0
- package/docs/images/api/geometry/extra-shapes.webp +0 -0
- package/docs/images/api/geometry/generators.webp +0 -0
- package/docs/images/api/geometry/mesh-arrays.webp +0 -0
- package/docs/images/api/geometry/vertex-updates.webp +0 -0
- package/docs/images/api/grass/grass-grove.webp +0 -0
- package/docs/images/api/grass/grass-presets.webp +0 -0
- package/docs/images/api/grass/grass-shadow.webp +0 -0
- package/docs/images/api/impostors/impostor-handover.webp +0 -0
- package/docs/images/api/impostors/impostor-shadow.webp +0 -0
- package/docs/images/api/impostors/impostors-forest.webp +0 -0
- package/docs/images/api/lights/spot-cookies.webp +0 -0
- package/docs/images/api/lines/lines-lit.webp +0 -0
- package/docs/images/api/lines/lines-widths.webp +0 -0
- package/docs/images/api/materials/coat-and-sheen.webp +0 -0
- package/docs/images/api/materials/decals.webp +0 -0
- package/docs/images/api/materials/iridescence-and-anisotropy.webp +0 -0
- package/docs/images/api/materials/relief.webp +0 -0
- package/docs/images/api/materials/shader-inputs.webp +0 -0
- package/docs/images/api/materials/standard-grid.webp +0 -0
- package/docs/images/api/materials/subsurface.webp +0 -0
- package/docs/images/api/materials/translucency.webp +0 -0
- package/docs/images/api/objects/objects-turntable.webp +0 -0
- package/docs/images/api/particles/campfire.webp +0 -0
- package/docs/images/api/points/galaxy.webp +0 -0
- package/docs/images/api/reference/textures/texture-wrap.webp +0 -0
- package/docs/images/api/render/fullscreen-glow.webp +0 -0
- package/docs/images/api/render/reflection-mirror.webp +0 -0
- package/docs/images/api/render/security-camera.webp +0 -0
- package/docs/images/api/scene/aurora-sky-layer.webp +0 -0
- package/docs/images/api/sound/sound-demo.webp +0 -0
- package/docs/images/api/splats/splats-demo.webp +0 -0
- package/docs/images/api/sprites/sprites-lines.webp +0 -0
- package/docs/images/api/terrain/terrain-demo.webp +0 -0
- package/docs/images/api/textures/canvas-screen.webp +0 -0
- package/docs/images/api/textures/mipmaps.webp +0 -0
- package/docs/images/api/vertex-draws/rain.webp +0 -0
- package/docs/images/api/water/ocean.webp +0 -0
- package/docs/images/api/water/water-demo.webp +0 -0
- package/docs/images/api/water/water-rain.webp +0 -0
- package/docs/images/api/water/waterfall.webp +0 -0
- package/docs/images/concepts/assets/gltf-model.webp +0 -0
- package/docs/images/concepts/color-management/tone-mapped.webp +0 -0
- package/docs/images/concepts/culling/far-from-origin.webp +0 -0
- package/docs/images/concepts/instances/instances.webp +0 -0
- package/docs/images/concepts/instances/per-row-colors.webp +0 -0
- package/docs/images/concepts/large-worlds/large-world.webp +0 -0
- package/docs/images/concepts/lighting/area-lights.webp +0 -0
- package/docs/images/concepts/lighting/atmosphere.webp +0 -0
- package/docs/images/concepts/lighting/environment.webp +0 -0
- package/docs/images/concepts/lighting/light-shafts.webp +0 -0
- package/docs/images/concepts/lighting/reflection-probes.webp +0 -0
- package/docs/images/concepts/lod/forest.webp +0 -0
- package/docs/images/concepts/materials/weighted-transparency.webp +0 -0
- package/docs/images/concepts/post-processing/auto-exposure.webp +0 -0
- package/docs/images/concepts/post-processing/bounce-light.webp +0 -0
- package/docs/images/concepts/post-processing/depth-of-field.webp +0 -0
- package/docs/images/concepts/post-processing/post-effects-alley.webp +0 -0
- package/docs/images/concepts/post-processing/sharpen.webp +0 -0
- package/docs/images/concepts/post-processing/ssr-wet-street.webp +0 -0
- package/docs/images/concepts/render-layers/layers-cottages.webp +0 -0
- package/docs/images/concepts/shadows/hero-shadow.webp +0 -0
- package/docs/images/cookbook/index/picking.webp +0 -0
- package/docs/images/cookbook/index/time-of-day.webp +0 -0
- package/docs/images/errors/E1431/area-lights-no-tables.webp +0 -0
- package/docs/images/guides/custom-passes/reflection-water.webp +0 -0
- package/docs/images/guides/deterministic-simulation/replay-demo.webp +0 -0
- package/docs/images/guides/multiple-views/split-screen.webp +0 -0
- package/docs/images/guides/performance/overdraw-view.webp +0 -0
- package/docs/images/guides/testing/hold-mode-frame.webp +0 -0
- package/docs/images/index/showcase-island.webp +0 -0
- package/docs/images/porting/threejs-shaders/dissolve.webp +0 -0
- package/docs/images/shaders/builtins/builtins.webp +0 -0
- package/docs/images/shaders/surface-functions/custom-surface.webp +0 -0
- package/docs/images/shaders/surface-functions/vertex-offset.webp +0 -0
- package/docs/images/shots.json +2231 -0
- package/docs/index.md +18 -23
- package/docs/moves.json +1 -0
- package/docs/nav.json +300 -0
- package/docs/pages.md +230 -209
- package/docs/porting/react-three-fiber.md +225 -6
- package/docs/porting/threejs-loop-and-threads.md +217 -7
- package/docs/porting/threejs-mapping.md +1249 -233
- package/docs/porting/threejs-materials.md +218 -6
- package/docs/porting/threejs-overview.md +240 -7
- package/docs/porting/threejs-postprocessing.md +4 -8
- package/docs/porting/threejs-shaders.md +301 -6
- package/docs/porting/threejs-unsupported.md +83 -7
- package/docs/porting/verification.md +178 -6
- package/docs/shaders/builtins.md +15 -4
- package/docs/shaders/library.md +72 -45
- package/docs/shaders/surface-functions.md +59 -23
- package/docs/shaders/wgsl-rules.md +12 -5
- package/lib/debug/channel.d.ts +103 -0
- package/lib/debug/channel.js +269 -0
- package/lib/debug/debug.d.ts +11 -9
- package/lib/debug/draw.d.ts +11 -2
- package/lib/debug/draw.js +57 -6
- package/lib/debug/inspector.d.ts +60 -0
- package/lib/debug/inspector.js +475 -0
- package/lib/debug/overlay-look.d.ts +6 -0
- package/lib/debug/overlay-look.js +29 -7
- package/lib/debug/overlay.js +15 -11
- package/lib/debug/stats-options.d.ts +13 -0
- package/lib/debug/stats-panel.d.ts +22 -7
- package/lib/debug/stats-panel.js +80 -13
- package/lib/debug/stats.d.ts +2 -3
- package/lib/errors/codes.d.ts +17 -3
- package/lib/errors/codes.js +117 -105
- package/lib/errors/engine-error.js +25 -10
- package/lib/errors/fixes.d.ts +1 -0
- package/lib/errors/fixes.js +20 -19
- 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/variants.d.ts +8 -2
- package/lib/gpu/variants.js +39 -7
- 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 +5 -2
- 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 +28 -14
- package/lib/index.d.ts +7 -5
- 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 +8 -8
- 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 +117 -31
- package/lib/page/engine.js +438 -99
- 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 +26 -14
- 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/stats-switch.js +2 -0
- package/lib/page/switches.d.ts +38 -6
- package/lib/page/switches.js +29 -5
- 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/baked-light.d.ts +2 -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 +3 -3
- package/lib/scene/fog.d.ts +11 -4
- package/lib/scene/fog.js +8 -2
- package/lib/scene/frame-cameras.d.ts +35 -4
- package/lib/scene/frame-cameras.js +86 -10
- package/lib/scene/gltf.d.ts +33 -3
- 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 +121 -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/particles.d.ts +7 -3
- package/lib/scene/particles.js +3 -1
- package/lib/scene/picks.d.ts +2 -2
- package/lib/scene/pointer-events.d.ts +4 -7
- package/lib/scene/post.d.ts +39 -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 +238 -261
- package/lib/scene/resources.js +179 -81
- package/lib/scene/scene.d.ts +167 -120
- package/lib/scene/scene.js +243 -103
- 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 +11 -7
- package/lib/scene/time-of-day.js +11 -8
- 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/labels.d.ts +5 -2
- package/lib/shared/labels.js +5 -2
- package/lib/shared/metrics.d.ts +38 -0
- package/lib/shared/metrics.js +62 -1
- package/lib/shared/permutation-words.d.ts +2 -0
- package/lib/shared/permutation-words.js +8 -0
- package/lib/shared/recording.d.ts +13 -5
- package/lib/shared/recording.js +31 -10
- package/lib/shared/run-task.js +7 -1
- package/lib/shared/sketch-data.d.ts +9 -0
- package/lib/shared/sketch-data.js +57 -0
- 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 +51 -7
- package/lib/sketch/define-sketch.js +2 -1
- 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 +80 -9
- package/lib/sketch/runner.js +390 -52
- package/lib/sketch/ui.d.ts +5 -8
- package/lib/sketch/ui.js +4 -2
- package/lib/stats.d.ts +1 -0
- package/lib/workers/probe-worker.d.ts +5 -0
- package/lib/workers/probe-worker.js +13 -4
- package/lib/workers/protocol.d.ts +71 -13
- package/lib/workers/protocol.js +4 -0
- package/lib/workers/render-worker.js +29 -5
- package/lib/workers/sketch-worker.js +108 -16
- package/package.json +2 -2
package/docs/api/materials.md
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: api/materials
|
|
3
3
|
title: Materials
|
|
4
|
-
status: experimental
|
|
5
|
-
since: "0.1"
|
|
6
4
|
summary: "standard, unlit, shader, shadowCatcher; every option."
|
|
7
5
|
---
|
|
8
6
|
|
|
9
7
|
# Materials
|
|
10
8
|
|
|
11
|
-
> Roadmap step 0.1, first released in null3D 0.1.0. Step 0.2 adds typed uniforms, custom material textures, `destroy`, the specular and index of refraction values, transmission, light through thin surfaces and under the surface, decals, the weighted blending, the clear coat and sheen layers, the shadow catcher, bump maps, displacement maps, parallax and wireframes. The API is experimental, so it can still change between versions. `materials.shader` takes no standard texture maps. Coding agents must not use the parts that are not built.
|
|
12
|
-
|
|
13
9
|
A material sets how the surfaces of the objects that use it look. `materials.standard` makes a lit material, and `materials.unlit` makes one that ignores lights. Create materials in the setup, and share each one between the objects that look alike.
|
|
14
10
|
|
|
15
11
|
```ts
|
|
@@ -35,17 +31,17 @@ export default defineSketch(({ scene, geometry, materials, page }) => {
|
|
|
35
31
|
|
|
36
32
|
| Factory | How it looks |
|
|
37
33
|
| --- | --- |
|
|
38
|
-
| `materials.standard(options)` | Lit by the scene's lights with glTF's metallic-roughness model
|
|
39
|
-
| `materials.unlit(options)` | Its color as it is, whatever the lights
|
|
34
|
+
| `materials.standard(options)` | Lit by the scene's lights, with glTF's metallic-roughness model |
|
|
35
|
+
| `materials.unlit(options)` | Its color as it is, whatever the lights. The exposure and the tone mapping still apply to it. |
|
|
40
36
|
| `materials.shader(options)` | A standard material whose WGSL changes its look before the engine lights it, or moves its vertices |
|
|
41
|
-
| `materials.shadowCatcher(options)` | Only the shadows that fall on it
|
|
42
|
-
| `materials.decal(options)` | A standard material that a box projects onto the surfaces inside it
|
|
37
|
+
| `materials.shadowCatcher(options)` | Only the shadows that fall on it |
|
|
38
|
+
| `materials.decal(options)` | A standard material that a box projects onto the surfaces inside it ([Decals](#decals)) |
|
|
43
39
|
|
|
44
40
|
Without lights, a standard material draws black, apart from its emissive color. [Lights](lights.md) explains how light colors and intensities shade it.
|
|
45
41
|
|
|
46
42
|
## Shadow catchers
|
|
47
43
|
|
|
48
|
-
`materials.shadowCatcher({ color, opacity })` draws a surface that shows only the shadows that fall on it
|
|
44
|
+
`materials.shadowCatcher({ color, opacity })` draws a surface that shows only the shadows that fall on it. It shows its `color` where the main directional light's shadow falls, and nothing at all where the light reaches it. The shadows of point and spot lights do not show on it. The mesh must receive shadows with `setReceiveShadows(true)`.
|
|
49
45
|
|
|
50
46
|
The default color is black and the default opacity is 1. The material blends, so it draws in the transparent pass after the opaque objects, and the scene's fog leaves it alone. It takes no texture maps. Its shadows are the main directional light's, so a scene needs a directional light that casts shadows.
|
|
51
47
|
|
|
@@ -64,6 +60,10 @@ Put the catcher a little above the surface it lies on, so its shadows show over
|
|
|
64
60
|
|
|
65
61
|
## Standard values
|
|
66
62
|
|
|
63
|
+

|
|
64
|
+
|
|
65
|
+
Roughness and metalness.
|
|
66
|
+
|
|
67
67
|
| Option | Range | Default | What it does |
|
|
68
68
|
| --- | --- | --- | --- |
|
|
69
69
|
| `color` | A [color](#color) | White | The base color: the color of diffuse light, and of a metal's reflections |
|
|
@@ -73,10 +73,10 @@ Put the catcher a little above the surface it lies on, so its shadows show over
|
|
|
73
73
|
| `roughness` | 0 to 1 | 1 | 0 is a mirror finish with a small, sharp highlight, and 1 is fully matte |
|
|
74
74
|
| `emissive` | An sRGB color | Black | Light that the surface gives off itself, whatever the lights |
|
|
75
75
|
| `emissiveIntensity` | 0 or more | 1 | The factor of the emissive color |
|
|
76
|
-
| `normalScale` | Two numbers | `[1, 1]` | How strongly the normal map bends normals along u and v |
|
|
77
|
-
| `bumpScale` | A number | 1 | How strongly the bump map bends normals. Negative values turn bumps into dents |
|
|
78
|
-
| `displacementScale` | A number | 1 | How far the displacement map's white moves a vertex, in the mesh's units |
|
|
79
|
-
| `displacementBias` | A number | 0 | How far the displacement map moves every vertex, added to its height's share |
|
|
76
|
+
| `normalScale` | Two finite numbers | `[1, 1]` | How strongly the normal map bends normals along u and v |
|
|
77
|
+
| `bumpScale` | A finite number | 1 | How strongly the bump map bends normals. Negative values turn bumps into dents |
|
|
78
|
+
| `displacementScale` | A finite number | 1 | How far the displacement map's white moves a vertex, in the mesh's units |
|
|
79
|
+
| `displacementBias` | A finite number | 0 | How far the displacement map moves every vertex, added to its height's share |
|
|
80
80
|
| `aoMapIntensity` | 0 to 1 | 1 | How much the occlusion map darkens ambient light |
|
|
81
81
|
| `lightMapIntensity` | 0 or more | 1 | The factor of the light map's light |
|
|
82
82
|
| `lightMapOffset` | Two numbers | `[0, 0]` | Where the light map's texture coordinates start. It is fixed when the material is created |
|
|
@@ -85,7 +85,7 @@ Put the catcher a little above the surface it lies on, so its shadows show over
|
|
|
85
85
|
| `ior` | 1 or more | 1.5 | The index of refraction of the non-metallic part. It sets how much light the surface reflects head on |
|
|
86
86
|
| `specularIntensity` | 0 to 1 | 1 | The strength of the non-metallic part's specular reflection, at every angle |
|
|
87
87
|
| `specularColor` | A [color](#color), or linear components of 0 or more | White | Tints the non-metallic part's specular reflection head on |
|
|
88
|
-
| `envIntensity` | 0 or more | 1 | The factor of the scene environment's light on the surface
|
|
88
|
+
| `envIntensity` | 0 or more | 1 | The factor of the scene environment's light on the surface. It multiplies the intensity that `scene.setEnvironment` gives |
|
|
89
89
|
| `transmission` | 0 to 1 | 0 | How much of the light behind the surface passes through it, for glass and clear water. See "Transmission" |
|
|
90
90
|
| `thickness` | 0 or more | 0 | The thickness of the volume under a surface that lets light through, in the mesh's own units |
|
|
91
91
|
| `attenuationColor` | A [color](#color) | White | The color that white light takes inside the volume over `attenuationDistance` |
|
|
@@ -96,7 +96,7 @@ Put the catcher a little above the surface it lies on, so its shadows show over
|
|
|
96
96
|
| `subsurfaceColor` | A [color](#color) | White | Each color channel's share of `subsurfaceRadius` |
|
|
97
97
|
| `clearcoat` | 0 to 1 | 0 | How much of a thin, shiny coat covers the surface, as on car paint or varnish. See "Clear coat and sheen" |
|
|
98
98
|
| `clearcoatRoughness` | 0 to 1 | 0 | How rough the coat is |
|
|
99
|
-
| `clearcoatNormalScale` | Two numbers | `[1, 1]` | How strongly the coat normal map bends the coat's normals along u and v |
|
|
99
|
+
| `clearcoatNormalScale` | Two finite numbers | `[1, 1]` | How strongly the coat normal map bends the coat's normals along u and v |
|
|
100
100
|
| `sheenColor` | A [color](#color) | Black | The color of the soft glow of cloth and velvet at grazing angles. Black gives none |
|
|
101
101
|
| `sheenRoughness` | 0 to 1 | 1 | How wide the sheen spreads |
|
|
102
102
|
| `iridescence` | 0 to 1 | 0 | How much a thin film above the surface tints its reflection, as on a soap bubble or a beetle's shell. See "Iridescence and anisotropy" |
|
|
@@ -107,11 +107,13 @@ Put the catcher a little above the surface it lies on, so its shadows show over
|
|
|
107
107
|
| `uvTransform` | An offset, a repeat and a rotation | None | Where every map sits on the texture coordinates |
|
|
108
108
|
| `mapUvTransforms` | A transform for a map, by the map's option name | None | Where one map sits, where it differs from the others |
|
|
109
109
|
|
|
110
|
-
The
|
|
110
|
+
The next sections explain the specular, transmission, diffuse transmission and layer values. The two diffuse transmission values follow glTF's `KHR_materials_diffuse_transmission`. A metal takes its color from what it reflects. Without an environment, a smooth metal shows little more than its highlights, so give the scene one with [`scene.setEnvironment`](scene.md#the-environment).
|
|
111
111
|
|
|
112
112
|
## Specular reflection and index of refraction
|
|
113
113
|
|
|
114
|
-
A surface reflects some light like a mirror, blurred by its roughness. This is its specular reflection. A metal's reflection takes its base color. A non-metal's reflection is white, and weak when you look at the surface head on: 4% of the light with the defaults. It grows to all the light at grazing angles.
|
|
114
|
+
A surface reflects some light like a mirror, blurred by its roughness. This is its specular reflection. A metal's reflection takes its base color. A non-metal's reflection is white, and weak when you look at the surface head on: 4% of the light with the defaults. It grows to all the light at grazing angles.
|
|
115
|
+
|
|
116
|
+
Three values change the non-metallic part, as glTF's `KHR_materials_ior` and `KHR_materials_specular` extensions do. The standard material's own lighting and shaders draw them, with the formulas in this table.
|
|
115
117
|
|
|
116
118
|
| Value | Head on | At grazing angles |
|
|
117
119
|
| --- | --- | --- |
|
|
@@ -130,7 +132,7 @@ const cloth = materials.standard({ color: '#4a5a70', roughness: 0.8, specularInt
|
|
|
130
132
|
|
|
131
133
|
## Transmission
|
|
132
134
|
|
|
133
|
-
A surface with `transmission` lets the light behind it through
|
|
135
|
+
A surface with `transmission` lets the light behind it through. Use it for glass, ice, gems and clear water. The `blend` alpha mode only mixes the surface's color over what lies behind it. Light that passes through a surface bends, blurs and takes the color of the volume under it:
|
|
134
136
|
|
|
135
137
|
| Value | What it does |
|
|
136
138
|
| --- | --- |
|
|
@@ -139,7 +141,7 @@ A surface with `transmission` lets the light behind it through, as three.js's `M
|
|
|
139
141
|
| `ior` | How far the light bends where it enters the volume. Glass is 1.5, water 1.33 |
|
|
140
142
|
| `dispersion` | How strongly the light that passes through separates into colors, 0 or more: 20 divided by the Abbe number, as glTF's `KHR_materials_dispersion` gives it. A diamond's 0.36 is weak and rutile's 2.04 is strong. Each color bends by its own index of refraction, so the edges of a prism or a gem show a rainbow. 0 bends every color alike |
|
|
141
143
|
| `thickness` | How deep the volume is. The light leaves it this far along the bent direction, so a thicker volume shows what lies behind it farther away. 0 is a thin wall, such as a window pane, which bends nothing |
|
|
142
|
-
| `thicknessMap` | The thickness, per texel, in green. Its green multiplies `thickness`. It samples the specular color slot's texture array at a layer of its own, so a
|
|
144
|
+
| `thicknessMap` | The thickness, per texel, in green. Its green multiplies `thickness`. It samples the specular color slot's texture array at a layer of its own, so a material with a thickness map takes no specular color map |
|
|
143
145
|
| `roughness` | How much the light from behind blurs: none at 0, and very blurred at 1. An `ior` of 1 blurs nothing |
|
|
144
146
|
| `attenuationColor`, `attenuationDistance` | The color of the volume. White light takes `attenuationColor` after `attenuationDistance` inside it, and a deeper color farther in. The default absorbs nothing |
|
|
145
147
|
|
|
@@ -157,26 +159,35 @@ Give `transmission` when you create the material, even as 0, to change it later
|
|
|
157
159
|
|
|
158
160
|
### How it draws
|
|
159
161
|
|
|
160
|
-
After the camera's view draws its opaque objects, the engine copies their colors into a texture with a chain of smaller, blurred copies. Surfaces that let light through then draw with the blended objects, farthest first. Each one samples the copy where its bent light ray leaves the volume, at a blur that its roughness picks.
|
|
162
|
+
After the camera's view draws its opaque objects, the engine copies their colors into a texture with a chain of smaller, blurred copies. Surfaces that let light through then draw with the blended objects, farthest first. Each one samples the copy where its bent light ray leaves the volume, at a blur that its roughness picks.
|
|
161
163
|
|
|
162
164
|
- Only opaque objects show through. Another surface that lets light through, or a blended one, does not show through glass in front of it.
|
|
163
|
-
- The copy keeps the opaque objects' depth too. A bent ray can land on an opaque object in front of the surface, such as a flower on the bank of a stream. The surface then shows what lies straight behind it instead.
|
|
164
|
-
- The volume is a model, not a ray through the real shape. A ball with `thickness` set to its diameter looks right through its middle.
|
|
165
|
-
- With `dispersion`, light follows three rays, one per color, each bent by a slightly different index of refraction. Red takes the lowest index
|
|
165
|
+
- The copy keeps the opaque objects' depth too. A bent ray can land on an opaque object in front of the surface, such as a flower on the bank of a stream. The surface then shows what lies straight behind it instead.
|
|
166
|
+
- The volume is a model, not a ray through the real shape. A ball with `thickness` set to its diameter looks right through its middle.
|
|
167
|
+
- With `dispersion`, light follows three rays, one per color, each bent by a slightly different index of refraction. Red takes the lowest index. Each color keeps the light that its own ray reaches, so a gem's edges separate white light into colors.
|
|
166
168
|
- `thickness` is in the mesh's own units, and the object's scale multiplies it.
|
|
167
169
|
- Such a surface takes the `opaque`, `mask` or `blend` alpha mode. A mask decides which pixels draw, and the light from behind fills the pixels that remain. `hash` throws E1217.
|
|
168
170
|
- Views other than the camera's, such as [scene passes](render.md#scene-passes) and [reflection passes](render.md#reflection-passes), have no copy. There the surface shows the environment's light along the bent ray.
|
|
169
|
-
- A material with `transmissionMap` or `thicknessMap` may also give the specular maps
|
|
170
|
-
- A layered material keeps the two maps beside a clear coat, a sheen, iridescence or anisotropy,
|
|
171
|
+
- A material with `transmissionMap` or `thicknessMap` may also give the specular maps, except for the pairs in [Texture maps](#texture-maps).
|
|
172
|
+
- A layered material keeps the two maps beside a clear coat, a sheen, iridescence or anisotropy, except for the pairs in [Texture maps](#texture-maps).
|
|
171
173
|
|
|
172
|
-
|
|
174
|
+
Nothing runs until the first surface that lets light through draws. To load its shaders before the first frame, list `'transmission'` in `createEngine`'s `preload` option.
|
|
173
175
|
|
|
174
|
-
|
|
176
|
+
<details>
|
|
177
|
+
<summary>Technical details: what transmission costs</summary>
|
|
178
|
+
|
|
179
|
+
Then each frame copies the camera's opaque colors once and makes the blurred copies. The camera's opaque and see-through objects then draw in two render passes instead of one. A material with `dispersion` samples the copy three times, once for each color; a material without it samples the copy once.
|
|
180
|
+
|
|
181
|
+
</details>
|
|
175
182
|
|
|
176
183
|
## Light through thin surfaces
|
|
177
184
|
|
|
178
185
|
A surface with `diffuseTransmission` lets the light that reaches its back through to its front, as glTF's `KHR_materials_diffuse_transmission` describes. A leaf, a petal, a lampshade or an ear then glows where the sun or a lamp shines behind it. The light from behind spreads out evenly, as the diffuse light does, so the surface does not show what lies behind it. For glass and water, which do, use `transmission`.
|
|
179
186
|
|
|
187
|
+

|
|
188
|
+
|
|
189
|
+
Diffuse transmission.
|
|
190
|
+
|
|
180
191
|
| Value | What it does |
|
|
181
192
|
| --- | --- |
|
|
182
193
|
| `diffuseTransmission` | The share of the surface's diffuse light that passes through to the other side. The front keeps the rest, and the specular reflection stays. 0 lets nothing through, and 1 lets all the diffuse light through, as a sheet of paper does |
|
|
@@ -195,11 +206,12 @@ const shade = materials.standard({
|
|
|
195
206
|
});
|
|
196
207
|
```
|
|
197
208
|
|
|
198
|
-
A measured leaf reflects about 7 to 11
|
|
199
|
-
|
|
209
|
+
A measured leaf reflects about 7 to 11 percent of visible light and transmits about 4 to 6
|
|
210
|
+
percent of it, and almost all of that comes out diffuse. The share of its diffuse light that passes
|
|
200
211
|
through therefore sits near a third: 0.25 to 0.45. Its gloss is a dielectric's, with a reflectance
|
|
201
|
-
at normal incidence of about 0.03 to 0.04 and a perceptual roughness of 0.35 to 0.6.
|
|
202
|
-
|
|
212
|
+
at normal incidence of about 0.03 to 0.04 and a perceptual roughness of 0.35 to 0.6.
|
|
213
|
+
|
|
214
|
+
Give a leaf material values from these ranges. Petals and paper are
|
|
203
215
|
thinner than leaves and let more through, so the translucency demo keeps its petals at 0.7 and its
|
|
204
216
|
paper lantern at 0.85; the measured range is for leaves.
|
|
205
217
|
|
|
@@ -212,14 +224,23 @@ Give `diffuseTransmission` when you create the material, even as 0, to change it
|
|
|
212
224
|
- `diffuseTransmissionMap` and `diffuseTransmissionColorMap` vary the two values across the surface. They take the places of the specular maps, which such a material does not take. See "Texture maps".
|
|
213
225
|
- A material with a clear coat, a sheen, iridescence or anisotropy, or with the `weighted` blending, takes no `diffuseTransmission`. Development builds throw E1217 for it. A glTF file's layers win over its diffuse transmission.
|
|
214
226
|
|
|
215
|
-
|
|
227
|
+
Nothing runs while no material has `diffuseTransmission`. To load its shaders before the first frame, list `'translucency'` in `createEngine`'s `preload` option.
|
|
228
|
+
|
|
229
|
+
<details>
|
|
230
|
+
<summary>Technical details: what light through thin surfaces costs</summary>
|
|
216
231
|
|
|
217
|
-
|
|
232
|
+
Each pixel of such a surface adds one product per light, and one more reading of the ambient light and the environment, from behind. The sun's shadow lookup runs on both faces of such a surface, where other surfaces skip it on the side away from the sun.
|
|
233
|
+
|
|
234
|
+
</details>
|
|
218
235
|
|
|
219
236
|
## Light under the surface
|
|
220
237
|
|
|
221
238
|
Light that enters skin, wax or marble leaves it a little way from where it entered, redder the further it went. A material with `subsurfaceRadius` draws that: the subsurface blur spreads the surface's diffuse light over the radius. The edges of its shadows, the light at the side of a nose and the detail of its maps then go soft. Its highlights stay sharp, since only the diffuse light spreads.
|
|
222
239
|
|
|
240
|
+

|
|
241
|
+
|
|
242
|
+
Light under the surface. It shows on High and Ultra.
|
|
243
|
+
|
|
223
244
|
| Value | Meaning |
|
|
224
245
|
| --- | --- |
|
|
225
246
|
| `subsurfaceRadius` | How far light spreads under the surface, in world units taken as meters. Skin takes about 0.01, wax about 0.02, and marble a few millimeters |
|
|
@@ -245,13 +266,22 @@ Give `subsurfaceRadius` when you create the material, even as 0, to change it la
|
|
|
245
266
|
- A blur narrower than a pixel draws nothing, so distant objects cost nothing more.
|
|
246
267
|
- The glTF loader reads the draft `KHR_materials_volume_scatter`: each channel spreads `attenuationDistance` times its `multiscatterColor`. See [Assets](assets.md).
|
|
247
268
|
|
|
248
|
-
|
|
269
|
+
Nothing runs while no material has `subsurfaceRadius` or the quality setting gives it no taps. To load its shaders before the first frame, list `'subsurface'` in `createEngine`'s `preload` option.
|
|
270
|
+
|
|
271
|
+
<details>
|
|
272
|
+
<summary>Technical details: what light under the surface costs</summary>
|
|
249
273
|
|
|
250
|
-
|
|
274
|
+
While it draws, the objects with a radius draw a second time, in a skin pass that shades their diffuse light into a target of their own. Two full-screen steps then blur it across and down. Each reads its taps only at skin pixels whose blur covers a pixel or more, and every other pixel reads one texel. The targets take 36 bytes per pixel of the render size.
|
|
275
|
+
|
|
276
|
+
</details>
|
|
251
277
|
|
|
252
278
|
## Clear coat and sheen
|
|
253
279
|
|
|
254
|
-
Two layers can lie over the standard material's surface, as
|
|
280
|
+
Two layers can lie over the standard material's surface, as glTF's `KHR_materials_clearcoat` and `KHR_materials_sheen` extensions describe them:
|
|
281
|
+
|
|
282
|
+

|
|
283
|
+
|
|
284
|
+
Clear coat and sheen.
|
|
255
285
|
|
|
256
286
|
- A **clear coat** is a thin, clear, shiny film, such as the lacquer of car paint, varnish on wood, or water on a stone. It has highlights and a reflection of its own, at its own roughness. Where it reflects light, it dims what lies under it. So a rough red paint under a smooth coat shows a sharp reflection over a soft color.
|
|
257
287
|
- A **sheen** is the soft glow that cloth, velvet and fuzz take at grazing angles, where the light catches the tips of their fibers. Its color tints the glow. Light that the sheen reflects does not reach the surface under it.
|
|
@@ -291,28 +321,37 @@ Give any of these values, or a layer map, when you create the material, to chang
|
|
|
291
321
|
| `sheenColorMap` | RGB, sRGB | Multiplies `sheenColor` |
|
|
292
322
|
| `sheenRoughnessMap` | A | Multiplies `sheenRoughness` |
|
|
293
323
|
|
|
294
|
-
The layers' maps take the places of the light map and the specular maps. So a material with a clear coat, a sheen, iridescence or anisotropy takes no `lightMap`, `specularIntensityMap` or `specularColorMap`, and no `diffuseTransmission`. Development builds throw E1217 for them, and production builds draw the material without them. Its `specularIntensity` and `specularColor` values still apply.
|
|
324
|
+
The layers' maps take the places of the light map and the specular maps. So a material with a clear coat, a sheen, iridescence or anisotropy takes no `lightMap`, `specularIntensityMap` or `specularColorMap`, and no `diffuseTransmission`. Development builds throw E1217 for them, and production builds draw the material without them. Its `specularIntensity` and `specularColor` values still apply.
|
|
295
325
|
|
|
296
|
-
|
|
326
|
+
Give `clearcoatMap` and `clearcoatRoughnessMap` as one texture, with the coat in red and its roughness in green, and `sheenColorMap` and `sheenRoughnessMap` as one texture, with the roughness in alpha. glTF packs them this way, and two textures for a pair throw E1217. An sRGB texture keeps its alpha linear, so one sRGB texture holds the sheen's color and roughness.
|
|
297
327
|
|
|
298
|
-
|
|
328
|
+
A material with `transmission` keeps its `transmissionMap` and `thicknessMap` beside the layers, except for the pairs in [Texture maps](#texture-maps).
|
|
299
329
|
|
|
300
|
-
|
|
330
|
+
### How the layers draw
|
|
301
331
|
|
|
302
332
|
- The coat is a second GGX highlight, which reflects 4% of the light head on and all of it at grazing angles. It reflects the scene's environment at its own roughness, and the occlusion map and ambient occlusion darken that reflection.
|
|
303
|
-
- The sheen is the Charlie highlight of cloth (Estevez and Kulla), lit by each light, and by the ambient light and the environment.
|
|
333
|
+
- The sheen is the Charlie highlight of cloth (Estevez and Kulla), lit by each light, and by the ambient light and the environment. A curve fit of the sheen's reflectance, which needs no lookup table, gives how much light the sheen keeps from the surface under it. At grazing angles the fit gives a little less than the exact value. So the surface under a strong sheen shows slightly brighter there than the extension's reference.
|
|
304
334
|
- Emitted light lies under the coat too, so a coat dims a glowing surface where it reflects.
|
|
305
335
|
|
|
306
|
-
|
|
336
|
+
The layers' shaders load the first time you create a material with layers. To load them before the first frame, list `'coat_sheen'` in `createEngine`'s `preload` option.
|
|
337
|
+
|
|
338
|
+
<details>
|
|
339
|
+
<summary>Technical details: what the layers cost</summary>
|
|
307
340
|
|
|
308
|
-
|
|
341
|
+
A layered material costs each of its pixels, per light, one more highlight for the coat and one for the sheen, and one more environment read for the coat. A layer that a material does not use costs almost nothing. Materials without layers draw with no extra texture and their shaders do not change.
|
|
342
|
+
|
|
343
|
+
</details>
|
|
309
344
|
|
|
310
345
|
## Iridescence and anisotropy
|
|
311
346
|
|
|
312
347
|
Two more effects sit in the same shaders as the clear coat and the sheen, and a material takes them with the same options:
|
|
313
348
|
|
|
314
|
-
|
|
315
|
-
|
|
349
|
+

|
|
350
|
+
|
|
351
|
+
Iridescence and anisotropy.
|
|
352
|
+
|
|
353
|
+
- **Iridescence** is the color that a thin film adds to a reflection, as on a soap bubble, an oil slick, a beetle's shell or a pearl. The film reflects each wavelength by its own phase, so the color depends on the film's thickness and on the angle you see it from. The engine uses Belcour and Barla's thin-film formulas.
|
|
354
|
+
- **Anisotropy** stretches the surface's highlight along one direction, as the grain of brushed metal spreads it across the grooves instead of around them. The engine uses an anisotropic GGX lobe, after Filament.
|
|
316
355
|
|
|
317
356
|
| Value | What it does |
|
|
318
357
|
| --- | --- |
|
|
@@ -345,24 +384,36 @@ Give any of these values, or a map, when you create the material, to change the
|
|
|
345
384
|
| `iridescenceThicknessMap` | G, linear | Mixes `iridescenceThicknessRange` between its two values |
|
|
346
385
|
| `anisotropyMap` | RG direction, B strength, linear | Red and green give the direction in the tangent plane, and blue multiplies `anisotropy` |
|
|
347
386
|
|
|
348
|
-
A material with these maps takes no `lightMap` and no specular maps, since the maps take their places. A material takes the maps of a clear coat and a sheen, or the maps of iridescence and the anisotropy: the coat's and the sheen's maps fill every place. Development builds throw E1217 for a material that asks for both families.
|
|
387
|
+
A material with these maps takes no `lightMap` and no specular maps, since the maps take their places. A material takes the maps of a clear coat and a sheen, or the maps of iridescence and the anisotropy: the coat's and the sheen's maps fill every place. Development builds throw E1217 for a material that asks for both families.
|
|
388
|
+
|
|
389
|
+
Production builds keep the coat's and the sheen's maps and draw the others' values alone. The glTF loader keeps the coat's and the sheen's maps and notes the others. A material with `transmission` keeps its `transmissionMap` and `thicknessMap` beside these maps, except for the pairs in [Texture maps](#texture-maps).
|
|
349
390
|
|
|
350
|
-
A material with `anisotropy` draws with or without a map. The direction that it stretches along comes from the surface's tangent frame. The frame is the mesh's tangents where it has them, else the texture coordinates, else the normal map's coordinates where the material also has a normal map. A material without a map and with no texture coordinates takes any frame square to the surface.
|
|
391
|
+
A material with `anisotropy` draws with or without a map. The direction that it stretches along comes from the surface's tangent frame. The frame is the mesh's tangents where it has them, else the texture coordinates, else the normal map's coordinates where the material also has a normal map. A material without a map and with no texture coordinates takes any frame square to the surface.
|
|
351
392
|
|
|
352
393
|
### How the film and the stretch draw
|
|
353
394
|
|
|
354
395
|
- The film's Fresnel term takes the place of the surface's own where `iridescence` applies. So the highlight and the reflection both take the film's colors, and a metal shows them over its base color.
|
|
355
396
|
- The film does not change the shape of the highlight, the diffuse light or the light that passes through the surface.
|
|
356
|
-
- The stretched lobe changes how each light's highlight spreads.
|
|
357
|
-
-
|
|
397
|
+
- The stretched lobe changes how each light's highlight spreads.
|
|
398
|
+
- The reflection of the environment bends away from the normal across the stretched direction. So brushed metal shows a long reflection rather than a dot.
|
|
399
|
+
- Rectangles and tubes of light shade the surface without the stretch.
|
|
358
400
|
|
|
359
|
-
|
|
401
|
+
These effects add nothing to a material without them. To load their shaders before the first frame, list `'coat_sheen'` in `createEngine`'s `preload` option.
|
|
360
402
|
|
|
361
|
-
|
|
403
|
+
<details>
|
|
404
|
+
<summary>Technical details: what iridescence and anisotropy cost</summary>
|
|
405
|
+
|
|
406
|
+
They run in the shaders of the layers above the surface, which load the first time you create a material with a clear coat, a sheen, iridescence or anisotropy. A film costs one short series of cosines per pixel, and a stretched lobe costs a few more terms per light.
|
|
407
|
+
|
|
408
|
+
</details>
|
|
362
409
|
|
|
363
410
|
## Decals
|
|
364
411
|
|
|
365
|
-
A decal material projects a standard material onto every opaque surface inside a box
|
|
412
|
+
A decal material projects a standard material onto every opaque surface inside a box. Use decals for scorch marks, mud, puddles, road paint, moss, cracks and posters. Give the material to a mesh of `geometry.box()`: the object's position, rotation and scale place the box.
|
|
413
|
+
|
|
414
|
+

|
|
415
|
+
|
|
416
|
+
Decals.
|
|
366
417
|
|
|
367
418
|
```ts
|
|
368
419
|
// sketch.ts: a scorch mark on the ground, and cracks on a wall. The maps come from textures.
|
|
@@ -376,7 +427,7 @@ const cracks = materials.decal({ map: crackColors, normalMap: crackBumps });
|
|
|
376
427
|
scene.createMesh({ mesh: box, material: cracks, position: [0, 1.5, -2], scale: [2, 2, 0.5] });
|
|
377
428
|
```
|
|
378
429
|
|
|
379
|
-
The box's z axis is the decal's direction: it points out of the surfaces that the decal marks. The maps lie across the box's x and y sides, with u along x and v along y
|
|
430
|
+
The box's z axis is the decal's direction: it points out of the surfaces that the decal marks. The maps lie across the box's x and y sides, with u along x and v along y. The box's z size sets how far into and out of a surface the decal reaches, so a deep box marks a bumpy or curved surface all over.
|
|
380
431
|
|
|
381
432
|
A decal takes the standard material's values and maps. They light it as they light any surface, at the place where the decal lies:
|
|
382
433
|
|
|
@@ -386,7 +437,7 @@ A decal takes the standard material's values and maps. They light it as they lig
|
|
|
386
437
|
| `metalnessRoughnessMap`, `metalness`, `roughness` | How the decal reflects light. A puddle is smooth, and scorch is rough |
|
|
387
438
|
| `normalMap`, `normalScale` | Bumps of the decal, such as the edges of a crack or the grain of moss |
|
|
388
439
|
| `aoMap`, `aoMapIntensity`, `emissive`, `emissiveMap`, `emissiveIntensity` | Occlusion and light of the decal's own, such as glowing paint |
|
|
389
|
-
| `angleFade` | The angles from the decal's direction at which it starts to fade and past which it shows nothing, in radians. The default, 60 and 80 degrees, keeps a decal on the ground from smearing up a wall |
|
|
440
|
+
| `angleFade` | The angles from the decal's direction at which it starts to fade and past which it shows nothing, in radians. Two angles from 0 to π, the first no larger than the second. The default, 60 and 80 degrees, keeps a decal on the ground from smearing up a wall |
|
|
390
441
|
| `edgeFade` | The share of the box's depth, from 0 to 1, over which the decal fades toward each end along z. The default is 0.2 |
|
|
391
442
|
|
|
392
443
|
A batch of boxes with one decal material draws in one draw. With `colors: true`, each row's color tints its decal, and the row's alpha fades it, as for bullet holes that fade with time.
|
|
@@ -414,9 +465,14 @@ After the camera's view draws its opaque objects, the decals draw in a pass of t
|
|
|
414
465
|
- Only the camera's view shows decals. [Scene passes](render.md#scene-passes) and [reflection passes](render.md#reflection-passes) show none.
|
|
415
466
|
- A decal casts no shadow. Raycasts and pointer events hit its box, as they hit any mesh. Put decals on a layer of their own, and leave that layer out of the raycast's `layers`.
|
|
416
467
|
|
|
417
|
-
|
|
468
|
+
Nothing runs until the first decal material. To load its shaders before the first frame, list `'decals'` in `createEngine`'s `preload` option.
|
|
418
469
|
|
|
419
|
-
|
|
470
|
+
<details>
|
|
471
|
+
<summary>Technical details: what decals cost</summary>
|
|
472
|
+
|
|
473
|
+
Then each frame culls the decals on the engine's workers and draws them in one render pass, with one draw for each run of decals that share their maps. Each pixel that a decal covers reads five depths and lights the surface once more.
|
|
474
|
+
|
|
475
|
+
</details>
|
|
420
476
|
|
|
421
477
|
## Texture maps
|
|
422
478
|
|
|
@@ -460,13 +516,27 @@ const brick = materials.standard({
|
|
|
460
516
|
|
|
461
517
|
A material with `diffuseTransmission` takes the two diffuse transmission maps in the places of the specular maps, and takes no specular maps. A material without it, or with a clear coat, a sheen, iridescence or anisotropy, takes no diffuse transmission maps. Development builds throw E1217 for either.
|
|
462
518
|
|
|
463
|
-
A material with `transmission` may take `transmissionMap` and `thicknessMap` beside the specular maps
|
|
519
|
+
A material with `transmission` may take `transmissionMap` and `thicknessMap` beside the specular maps or the layers' maps, except for a few pairs that share a texture array. Development builds throw E1217 for those pairs, and for the two maps without `transmission`.
|
|
520
|
+
|
|
521
|
+
<details>
|
|
522
|
+
<summary>Technical details: which maps share a texture array</summary>
|
|
523
|
+
|
|
524
|
+
| Array of the slot | Maps that may fill it | Clashes that throw E1217 |
|
|
525
|
+
| --- | --- | --- |
|
|
526
|
+
| Specular intensity | `specularIntensityMap`, `transmissionMap`, `clearcoatNormalMap`, `iridescenceThicknessMap` | `transmissionMap` with `clearcoatNormalMap` or `iridescenceThicknessMap` |
|
|
527
|
+
| Specular color | `specularColorMap`, `thicknessMap`, `sheenColorMap`, `sheenRoughnessMap`, `anisotropyMap` | `thicknessMap` with `specularColorMap` (sRGB and linear never share an array), or with a sheen map or `anisotropyMap` |
|
|
528
|
+
|
|
529
|
+
Two maps of one slot draw together only when their images have one size and format.
|
|
530
|
+
|
|
531
|
+
</details>
|
|
464
532
|
|
|
465
533
|
The maps of a material are fixed when you create it. A mesh needs texture coordinates to show them, and a mesh without them draws the material without its maps. A map reads the set of coordinates that its texture's `uvSet` names. Light maps usually use the second set, so load them with `uvSet: 1`. A mesh without a second set gives its first set to such a map.
|
|
466
534
|
|
|
467
|
-
A light map adds baked light to the ambient light. A bake often places its light map on each mesh with its own scale and offset, which `lightMapOffset` and `lightMapRepeat` give; the other maps keep their coordinates.
|
|
535
|
+
A light map adds baked light to the ambient light. A bake often places its light map on each mesh with its own scale and offset, which `lightMapOffset` and `lightMapRepeat` give; the other maps keep their coordinates.
|
|
468
536
|
|
|
469
|
-
A
|
|
537
|
+
A directional light map also stores the light's direction at each texel: give its `lightMapDirection` and the material's normal map bends the baked light, so relief faces the light of the bake and turns away from it. `assets.loadLightMap` reads a directional map from a [baked light file](../guides/baked-light-data.md). A material made from a model for Needle's viewer takes that model's light maps with their RGBM decode.
|
|
538
|
+
|
|
539
|
+
A normal map takes its frame from the mesh's tangents when the mesh has them, as `geometry.fromArrays` with `computeTangents` makes them. Otherwise the shader finds the frame from how the positions and the coordinates change between pixels.
|
|
470
540
|
|
|
471
541
|
Until a map's image reaches the GPU, the material draws as without that map.
|
|
472
542
|
|
|
@@ -474,7 +544,11 @@ On WebGL2, the maps of one material share at most six textures on the GPU. Maps
|
|
|
474
544
|
|
|
475
545
|
## Relief
|
|
476
546
|
|
|
477
|
-
Three maps give a surface relief. Each reads heights from its red channel, in the `linear` color space.
|
|
547
|
+
Three maps give a surface relief. Each reads heights from its red channel, in the `linear` color space.
|
|
548
|
+
|
|
549
|
+

|
|
550
|
+
|
|
551
|
+
Relief maps.
|
|
478
552
|
|
|
479
553
|
```ts
|
|
480
554
|
// sketch.ts
|
|
@@ -495,18 +569,18 @@ scene.createMesh({ mesh: geometry.sphere({ radius: 1, widthSegments: 128, height
|
|
|
495
569
|
|
|
496
570
|
| Option | What it does | Cost |
|
|
497
571
|
| --- | --- | --- |
|
|
498
|
-
| `bumpMap` | Bends the normals by the change of its heights from one pixel to the next, times `bumpScale
|
|
572
|
+
| `bumpMap` | Bends the normals by the change of its heights from one pixel to the next, times `bumpScale`. The shape stays flat | Three texture reads per pixel |
|
|
499
573
|
| `displacementMap` | Moves each vertex along its normal by its height times `displacementScale`, plus `displacementBias`, in the mesh's units. The shape changes | One texture read per vertex in each pass that draws it, and three per pixel where it bends the normals |
|
|
500
574
|
| `parallax: true` | With a displacement map, shifts where each pixel reads the maps, so relief finer than the vertices hides and shows the surface behind it as the view turns | 8 to 32 texture reads per pixel, more at grazing views |
|
|
501
575
|
|
|
502
|
-
A bump map gives fine relief to a flat surface, such as the grain of stone. Its bend depends on the surface's size on the screen
|
|
576
|
+
A bump map gives fine relief to a flat surface, such as the grain of stone. Its bend depends on the surface's size on the screen. A normal map wins over a bump map, so a material draws one or the other.
|
|
503
577
|
|
|
504
|
-
A displacement map changes the shape itself, so its silhouette and its shadows move too. The vertex shader reads the map at its full size
|
|
578
|
+
A displacement map changes the shape itself, so its silhouette and its shadows move too. The vertex shader reads the map at its full size. So the mesh needs about as many vertices as the detail it should show. `geometry.plane` and `geometry.sphere` take segment counts for this. The map moves vertices after skinning and morph targets.
|
|
505
579
|
|
|
506
|
-
- Without a normal map or a bump map, the displacement map's slope also bends the normals, so the light follows the moved surface.
|
|
507
|
-
- With a normal map, the normal map bends the normals
|
|
580
|
+
- Without a normal map or a bump map, the displacement map's slope also bends the normals, so the light follows the moved surface.
|
|
581
|
+
- With a normal map, the normal map bends the normals. A normal map made from the same heights already holds their slope.
|
|
508
582
|
- Shadows and the depth prepass follow the moved vertices. Culling grows each object's bounds by the farthest that the material has moved a vertex, so no `setBounds` call is needed.
|
|
509
|
-
- Raycasts, outlines and debug views see the mesh before it moves
|
|
583
|
+
- Raycasts, outlines and debug views see the mesh before it moves.
|
|
510
584
|
|
|
511
585
|
`parallax` adds the detail that the vertices cannot hold, such as the joints between bricks or cobbles. Silhouettes and shadows keep the vertices' shape. It takes only opaque and masked surfaces: the `blend` alpha mode and `transmission` with `parallax` throw E1217. The quality preset's `parallax` setting turns it off on Low, where such materials draw with their displacement alone.
|
|
512
586
|
|
|
@@ -514,23 +588,34 @@ A page without relief pays nothing for it. The first material with a bump map lo
|
|
|
514
588
|
|
|
515
589
|
## Texture coordinate transform
|
|
516
590
|
|
|
517
|
-
`uvTransform` places every map of a material on the texture coordinates: `offset`, `repeat` and `rotation` in radians.
|
|
591
|
+
`uvTransform` places every map of a material on the texture coordinates: `offset`, `repeat` and `rotation` in radians. The engine turns the coordinates by `rotation` about their origin, scales them by `repeat`, and then adds `offset`: u' = repeat.u × (u cos r + v sin r) + offset.u, and v' = repeat.v × (v cos r − u sin r) + offset.v. A transform that leaves a value out takes its default. `set` changes the transform at any time.
|
|
592
|
+
|
|
593
|
+
`mapUvTransforms` places one map by its option name, such as `emissiveMap`, where it differs from the others. A map without one keeps the transform that `uvTransform` gives it. Two maps that share a slot, as a sheen map and an anisotropy map do, share one transform too. A glTF file keeps a transform for each of its textures, so the loader places each map with its own.
|
|
518
594
|
|
|
519
595
|
## Color
|
|
520
596
|
|
|
521
|
-
`color`, `emissive` and `specularColor` take an sRGB color
|
|
597
|
+
`color`, `emissive` and `specularColor` take an sRGB color. That is a hex string such as `'#4a8cff'` or `'#48f'`, a number such as `0x4a8cff`, or three linear components from 0 to 1. The engine converts the color to linear once, when the call receives it. Any other value, such as the name `'red'`, throws E1204. The linear components of `specularColor` may also exceed 1, as glTF allows.
|
|
522
598
|
|
|
523
599
|
## Changing a material
|
|
524
600
|
|
|
525
601
|
`set(options)` changes a material's values at any time, and every object that uses the material changes with it. It changes only the options that you pass. The others keep their values, so `set({ roughness: 0.5 })` keeps the color. A standard material's `set` takes every value in the table above, and an unlit material's `set` takes `color`, `opacity`, `alphaCutoff`, `uvTransform` and `mapUvTransforms`.
|
|
526
602
|
|
|
527
|
-
`set` is for setup, and for several values at once.
|
|
603
|
+
`set` is for setup, and for several values at once. Change the values that a frame changes with `setUniform(name, value)`, which allocates nothing: `material.setUniform('roughness', 0.5 + 0.1 * Math.sin(t))`. On a standard material it takes these numbers: `opacity`, `alphaCutoff`, `metalness`, `roughness`, `emissiveIntensity`, `aoMapIntensity`, `lightMapIntensity`, `specularIntensity`, `envIntensity`, `transmission`, `thickness`, `dispersion`, `diffuseTransmission`, `subsurfaceRadius`, `clearcoat`, `clearcoatRoughness`, `sheenRoughness`, `iridescence`, `iridescenceIor`, `anisotropy`, `anisotropyRotation` and, on a decal, `edgeFade`. It also takes these colors: `color`, `emissive`, `specularColor`, `attenuationColor` and `sheenColor`.
|
|
604
|
+
|
|
605
|
+
Give a color in an array that you change in place. Every other value goes through `set`, and `setUniform` throws [E1216](../errors/E1216.md) for it. A custom material's `setUniform` also changes one of its WGSL uniforms, by the name in its `struct Uniforms`. The engine's allocation benchmark checks `setUniform` in every frame and `set` at setup.
|
|
606
|
+
|
|
607
|
+
<details>
|
|
608
|
+
<summary>Technical details: why set can allocate</summary>
|
|
609
|
+
|
|
610
|
+
`set` reads each number from a field of the options object that you pass. The browser boxes such a read when it cannot keep the field's number unboxed. This happens when the object's fields hold other kinds of value too, and when one call site sees objects of more than a few shapes. `setUniform` takes the value itself, so nothing is read from an object.
|
|
611
|
+
|
|
612
|
+
</details>
|
|
528
613
|
|
|
529
614
|
`set` checks every value before it changes any, so a call that throws changes nothing. It converts a color without allocating, and it reads each number by its name. Keep one options object for each material that changes. To change one object alone, give it another material with `mesh.setMaterial(material)`.
|
|
530
615
|
|
|
531
616
|
## Destroying a material
|
|
532
617
|
|
|
533
|
-
`material.destroy()` frees a material that the sketch no longer needs
|
|
618
|
+
`material.destroy()` frees a material that the sketch no longer needs. From the next frame, objects and instance batches that still use it draw nothing, until `setMaterial` gives them another material. Once no object or batch uses it, its place in the engine's table of materials goes to the next material that you create. When the last material of a custom material's WGSL goes, the engine also frees that WGSL's pipelines.
|
|
534
619
|
|
|
535
620
|
`destroy` leaves the material's textures, which other materials may share. Destroy them apart with `texture.destroy()`. Calls on a destroyed material, and calls that pass it, such as `createMesh`, throw [E1101](../errors/E1101.md). Destroying a material changes which objects draw, so the next frame rebuilds the engine's draw tables, as creating one does.
|
|
536
621
|
|
|
@@ -540,25 +625,25 @@ These options are fixed when you create the material. Most of them choose the ma
|
|
|
540
625
|
|
|
541
626
|
| Option | Materials | Default | What it does |
|
|
542
627
|
| --- | --- | --- | --- |
|
|
543
|
-
| `doubleSided` | Both | false | Draws both faces of each triangle. A back face lights as if it faced the camera
|
|
628
|
+
| `doubleSided` | Both | false | Draws both faces of each triangle. A back face lights as if it faced the camera |
|
|
544
629
|
| `vertexColors` | Both | false | Multiplies the base color by the mesh's vertex colors, on meshes that have them. [Geometry](geometry.md) makes meshes with colors |
|
|
545
630
|
| `flatShading` | Standard | false | Lights each triangle with the normal of its face, so the mesh looks faceted |
|
|
546
631
|
| `alphaMode` | Both | `'opaque'` | How the material uses its alpha: `'opaque'`, `'mask'`, `'hash'` or `'blend'`. See "Alpha modes" |
|
|
547
|
-
| `alphaToCoverage` | Both | true | With the `mask` alpha mode, smooths the cut edges with MSAA
|
|
632
|
+
| `alphaToCoverage` | Both | true | With the `mask` alpha mode, smooths the cut edges with MSAA. `false` gives hard cut edges. See "Alpha to coverage" |
|
|
548
633
|
| `blending` | Both | `'normal'` | With the `blend` alpha mode, how the surface meets what lies behind it: `'normal'`, `'additive'`, `'multiply'` or `'weighted'`. See "Blending" |
|
|
549
634
|
| `depthWrite` | Both | true | False writes no depth, so the surface hides nothing that draws after it |
|
|
550
|
-
| `depthTest` | Both | true | False draws the surface whatever lies in front of it. It then writes no depth either
|
|
551
|
-
| `colorWrite` | Both | true | False writes no color, so the surface shows nothing itself and hides what lies behind it
|
|
552
|
-
| `depthBias` | Both | No bias | Moves the surface's depth
|
|
553
|
-
| `forceSinglePass` | Both | false | With the `blend` alpha mode and `doubleSided`, draws both faces in one draw
|
|
635
|
+
| `depthTest` | Both | true | False draws the surface whatever lies in front of it. It then writes no depth either |
|
|
636
|
+
| `colorWrite` | Both | true | False writes no color, so the surface shows nothing itself and hides what lies behind it. See "Invisible surfaces that hide" |
|
|
637
|
+
| `depthBias` | Both | No bias | Moves the surface's depth before the depth test. See "Depth bias" |
|
|
638
|
+
| `forceSinglePass` | Both | false | With the `blend` alpha mode and `doubleSided`, draws both faces in one draw. See "Double-sided blended surfaces" |
|
|
554
639
|
| `transmission` | Standard | None | Given at all, even as 0, lets light through the surface, and `set` can then change its value. See "Transmission" |
|
|
555
640
|
| `diffuseTransmission` | Standard | None | Given at all, even as 0, lets light through to the surface's other side, and `set` can then change its value. See "Light through thin surfaces" |
|
|
556
641
|
| `subsurfaceRadius` | Standard | None | Given at all, even as 0, spreads the surface's light under it, and `set` can then change its value. See "Light under the surface" |
|
|
557
642
|
| The layer values and maps | Standard | None | Any of them gives the material its layers above the surface, even a coat of 0, and `set` can then change their values. See "Clear coat and sheen" and "Iridescence and anisotropy" |
|
|
558
|
-
| `fog` | Both | true | Takes the scene's fog. With `false`, the material keeps its color at every distance
|
|
559
|
-
| `toneMapped` | Both | true | With `false`,
|
|
643
|
+
| `fog` | Both | true | Takes the scene's fog. With `false`, the material keeps its color at every distance. [Scene](scene.md#fog) sets the fog |
|
|
644
|
+
| `toneMapped` | Both | true | With `false`, the tone curve leaves the color alone, so it shows as the display shows it. The exposure still scales it, so it shows brighter than the same color tone mapped. On the HDR path a blended surface keeps the curve. [Color management](../concepts/color-management.md#materials-that-keep-their-display-color) explains each path |
|
|
560
645
|
| `contactShadows` | Standard | true | Takes the main directional light's contact shadows. With `false`, the surface takes none and keeps the shadow map's shadows. Use it on grass, leaf cards and other thin surfaces that crowd together or sway, where contact shadows make them dark and grainy and flicker as they move. [Shadows](../concepts/shadows.md#grass-and-other-thin-surfaces) explains why |
|
|
561
|
-
| `wireframe` | Both | false | Draws the edges of each triangle as lines one pixel wide, with the material's own shading
|
|
646
|
+
| `wireframe` | Both | false | Draws the edges of each triangle as lines one pixel wide, with the material's own shading. See "Wireframe" |
|
|
562
647
|
| `parallax` | Standard | false | With a `displacementMap`, adds parallax occlusion mapping. See "Relief" |
|
|
563
648
|
| `sceneInputs` | Custom | None | The scene inputs that the material's WGSL reads, which fix its shader. `['sceneDepth']` binds the copy of the opaque scene's depth. See "The scene behind a surface" |
|
|
564
649
|
|
|
@@ -566,26 +651,30 @@ A material with `vertexColors` draws a mesh without colors in its base color alo
|
|
|
566
651
|
|
|
567
652
|
### Wireframe
|
|
568
653
|
|
|
569
|
-
A material with `wireframe: true` draws each triangle's three edges as lines
|
|
654
|
+
A material with `wireframe: true` draws each triangle's three edges as lines. An edge that two triangles share draws twice. The engine keeps an edge list for each mesh from the first wireframe on, which takes twice the GPU memory of the mesh's triangle indices. Its shadows draw lines too.
|
|
655
|
+
|
|
656
|
+
Flat shading and bump maps have no effect, because lines have no faces. Lines are one pixel wide on every GPU path. For wide lines, or for a mesh's outline edges alone, use [Lines](lines.md). The [relief demo](https://github.com/null3d-engine/null3d/tree/main/examples/relief) draws a geodesic frame with `wireframe: true`, and its shadow is a shadow of lines.
|
|
570
657
|
|
|
571
658
|
## Alpha modes
|
|
572
659
|
|
|
573
660
|
A surface's alpha is its `opacity`, times the alpha of its base color map. With `vertexColors`, the alpha of the mesh's vertex colors multiplies it too. `alphaMode` says how the material uses the alpha:
|
|
574
661
|
|
|
575
|
-
| Mode | What it draws |
|
|
576
|
-
| --- | --- |
|
|
577
|
-
| `'opaque'` | The whole surface, opaque. The alpha has no effect |
|
|
578
|
-
| `'mask'` | Nothing where the alpha is below `alphaCutoff`, and the rest opaque |
|
|
579
|
-
| `'hash'` | Each point of the surface opaque or not at all, so the alpha sets how much of the surface draws |
|
|
580
|
-
| `'blend'` | The surface blended over what lies behind it, as far as the alpha says |
|
|
662
|
+
| Mode | What it draws |
|
|
663
|
+
| --- | --- |
|
|
664
|
+
| `'opaque'` | The whole surface, opaque. The alpha has no effect |
|
|
665
|
+
| `'mask'` | Nothing where the alpha is below `alphaCutoff`, and the rest opaque |
|
|
666
|
+
| `'hash'` | Each point of the surface opaque or not at all, so the alpha sets how much of the surface draws |
|
|
667
|
+
| `'blend'` | The surface blended over what lies behind it, as far as the alpha says |
|
|
581
668
|
|
|
582
669
|
A masked surface has hard edges, and it hides what lies behind it as an opaque one does, so its objects draw in any order. Use it for leaves, fences and cut-out shapes. Only masked and hashed materials draw with the shader that drops fragments, so opaque ones keep the GPU's early depth test.
|
|
583
670
|
|
|
584
|
-
A hashed surface draws a share of its points that its alpha sets: half of them at an alpha of 0.5. A hash of each point's place on the mesh picks the points
|
|
671
|
+
A hashed surface draws a share of its points that its alpha sets: half of them at an alpha of 0.5. A hash of each point's place on the mesh picks the points. So the pattern moves with the object and does not crawl as the camera moves. The hash uses integer math, so every GPU draws the same pattern.
|
|
672
|
+
|
|
673
|
+
Hashed objects draw in any order, as masked ones do. They suit fades and see-through surfaces that cross each other, where blending would need a sort. The pattern is noisy up close. `alphaCutoff` has no effect in this mode.
|
|
585
674
|
|
|
586
675
|
A blended surface lets what lies behind it show through. Blended objects draw after the opaque ones, farthest first, so each one blends over the objects behind it. A call to `mesh.setRenderOrder(order)` draws an object before or after the others, whatever its depth. The rows of an instance batch sort one by one. The page [Materials and pipelines](../concepts/materials.md#the-transparent-pass) explains the sort. It also says where the sort cannot help.
|
|
587
676
|
|
|
588
|
-
A blended material writes depth
|
|
677
|
+
A blended material writes depth by default. Give particles, glows and other surfaces that cross `depthWrite: false`, so they never hide each other.
|
|
589
678
|
|
|
590
679
|
```ts
|
|
591
680
|
// sketch.ts: leaves whose vertex alpha cuts their shape.
|
|
@@ -596,11 +685,13 @@ leaves.set({ alphaCutoff: 0.2 });
|
|
|
596
685
|
|
|
597
686
|
### Alpha to coverage
|
|
598
687
|
|
|
599
|
-
A masked surface's cut edges are as smooth as its outer edges, as `alphaToCoverage` is on by default. The alpha fades from nothing at `alphaCutoff` to full over about one pixel
|
|
688
|
+
A masked surface's cut edges are as smooth as its outer edges, as `alphaToCoverage` is on by default. The alpha fades from nothing at `alphaCutoff` to full over about one pixel. MSAA then draws the surface on that share of each edge pixel's samples. Foliage and fences lose their stair steps, and their objects still draw in any order.
|
|
689
|
+
|
|
690
|
+
This is the best technique for cut-out shapes, so it is the default, as in Filament. For hard cut edges, give `alphaToCoverage: false`. The option needs MSAA, the default anti-aliasing. With FXAA or no anti-aliasing, as on the Low preset, the mask cuts as without it. On WebGPU, where the scene's colors have no alpha channel, the shader sets the covered samples itself, with the same look.
|
|
600
691
|
|
|
601
|
-
|
|
692
|
+
The first such material loads the shader builds of alpha to coverage, and the first hashed material those of the hash. To load them before the first frame instead, list `'coverage'` and `'hash'` in `createEngine`'s `preload` option.
|
|
602
693
|
|
|
603
|
-
A [custom material](materials.md#custom-materials) takes both, but only where its WGSL sets or reads the surface's `alpha`. Such a material's shadow caster and motion build run that alpha too, so its shadow and its motion keep the mask's holes. WGSL that never names the alpha throws E1217 for `alphaToCoverage` and for the `hash` mode, and it casts its mesh's whole shape
|
|
694
|
+
A [custom material](materials.md#custom-materials) takes both, but only where its WGSL sets or reads the surface's `alpha`. Such a material's shadow caster and motion build run that alpha too, so its shadow and its motion keep the mask's holes. WGSL that never names the alpha throws E1217 for `alphaToCoverage` and for the `hash` mode, and it casts its mesh's whole shape.
|
|
604
695
|
|
|
605
696
|
```ts
|
|
606
697
|
// sketch.ts: grass cards whose cut edges MSAA smooths, and a fence with hard pixel edges.
|
|
@@ -610,7 +701,7 @@ const fence = materials.standard({ map: fenceTexture, alphaMode: 'mask', alphaTo
|
|
|
610
701
|
|
|
611
702
|
## Invisible surfaces that hide
|
|
612
703
|
|
|
613
|
-
`colorWrite: false` draws a surface that shows nothing itself. It still writes depth, so it hides what lies behind it. Its objects draw before the opaque objects that write color, so the depth it writes holds back their color. Use it for a plane that hides the scene behind a page
|
|
704
|
+
`colorWrite: false` draws a surface that shows nothing itself. It still writes depth, so it hides what lies behind it. Its objects draw before the opaque objects that write color, so the depth it writes holds back their color. Use it for a plane that hides the scene behind a page.
|
|
614
705
|
|
|
615
706
|
With the `mask` or `hash` alpha mode, the parts that the alpha drops write no depth either. The surface then cuts a shape out of the space it holds.
|
|
616
707
|
|
|
@@ -624,9 +715,9 @@ scene.createMesh({ mesh: geometry.plane({ width: 8, height: 6 }), material: hold
|
|
|
624
715
|
|
|
625
716
|
## Double-sided blended surfaces
|
|
626
717
|
|
|
627
|
-
A blended surface with `doubleSided: true` draws in two draws
|
|
718
|
+
A blended surface with `doubleSided: true` draws in two draws. Its back faces draw first, then its front faces. So the near side of a glass box or a sphere always covers its far side, whatever the order of the mesh's triangles. Neighbors that share the mesh and the material draw together: all their back faces, then all their front faces.
|
|
628
719
|
|
|
629
|
-
`forceSinglePass: true` draws both faces in one draw
|
|
720
|
+
`forceSinglePass: true` draws both faces in one draw. The triangles then cover each other in the mesh's order. Use it for flat surfaces, such as leaves and planes of glass, whose two faces never overlap on screen: it saves one draw per object. The second draw costs about as much as the first, so it is the speed setting for scenes with many double-sided blended objects. Solid double-sided materials always draw once. The [depth-only demo](https://github.com/null3d-engine/null3d/tree/main/examples/depth-only) sets it on its double-sided glass panes.
|
|
630
721
|
|
|
631
722
|
```ts
|
|
632
723
|
// sketch.ts: a glass globe that shows its far side, and a flat pane that needs one draw.
|
|
@@ -645,9 +736,9 @@ const pane = materials.standard({ color: '#a8d8ff', opacity: 0.3, alphaMode: 'bl
|
|
|
645
736
|
| `'multiply'` | Tints what lies behind by the surface's color, as far as the alpha says | Stains, shadows painted on, tinted film |
|
|
646
737
|
| `'weighted'` | Covers what lies behind as `'normal'` does, but blends with the other weighted surfaces in any order | Smoke, dust, clouds of particles, many panes of glass that cross |
|
|
647
738
|
|
|
648
|
-
The engine blends colors multiplied by their alpha
|
|
739
|
+
The engine blends colors multiplied by their alpha (premultiplied alpha). Textures loaded with `premultipliedAlpha: true` blend correctly too.
|
|
649
740
|
|
|
650
|
-
The engine blends in linear color, before the tone mapping
|
|
741
|
+
The engine blends in linear color, before the tone mapping. The [8-bit path](../concepts/color-management.md#the-8-bit-path) of some devices is the exception: it tone maps each surface and encodes it as sRGB first, and then blends it. On the HDR path, a see-through surface over a different color therefore looks a little lighter than on the 8-bit path, and an additive glow a little weaker.
|
|
651
742
|
|
|
652
743
|
```ts
|
|
653
744
|
// sketch.ts: a pane of glass and a glow that never hides what it crosses.
|
|
@@ -659,7 +750,7 @@ const glow = materials.unlit({ color: '#ffb040', alphaMode: 'blend', blending: '
|
|
|
659
750
|
|
|
660
751
|
Blended objects draw farthest first, and the sort orders whole objects, or the rows of a batch. Surfaces that cross, a large surface around a small one, and puffs of smoke inside each other have no right order. The sort then puts some of them in the wrong order, and they pop as the camera moves. Additive and multiply blending give the same result in any order, so only normal blending needs the sort.
|
|
661
752
|
|
|
662
|
-
`blending: 'weighted'` blends such surfaces without a sort. The engine uses weighted blended order-independent transparency (McGuire and Bavoil, 2013)
|
|
753
|
+
`blending: 'weighted'` blends such surfaces without a sort. The engine uses weighted blended order-independent transparency (McGuire and Bavoil, 2013). Each weighted surface adds its color and its coverage into two targets, in any order, and near surfaces weigh more than far ones. A full-screen step then blends the average color over the scene, as far as the surfaces cover it.
|
|
663
754
|
|
|
664
755
|
```ts
|
|
665
756
|
// sketch.ts: smoke puffs that cross each other, and panes of glass that cross, without popping.
|
|
@@ -674,13 +765,20 @@ const glass = materials.standard({ color: '#a8d8ff', opacity: 0.3, roughness: 0.
|
|
|
674
765
|
- Views other than the camera's, such as [scene passes](render.md#scene-passes) and [reflection passes](render.md#reflection-passes), draw weighted surfaces farthest first, as `'normal'` ones. So do WebGL2 devices that cannot draw into 16-bit float targets, and frames before the layer's shaders have loaded.
|
|
675
766
|
- Materials with `transmission`, custom materials and lines do not take the `weighted` blending. They throw E1217.
|
|
676
767
|
|
|
677
|
-
|
|
768
|
+
The layer costs nothing until the first weighted surface draws. To load its shaders before the first frame, list `'weighted'` in `createEngine`'s `preload` option.
|
|
769
|
+
|
|
770
|
+
<details>
|
|
771
|
+
<summary>Technical details: what weighted blending costs</summary>
|
|
772
|
+
|
|
773
|
+
Each frame then draws the camera's weighted surfaces into two targets of the render size, 10 bytes per pixel together. A full-screen step blends them over the scene. With MSAA, the layer first copies one sample of each pixel's depth. The camera's other blended objects and the weighted layer draw in separate render passes.
|
|
678
774
|
|
|
679
|
-
|
|
775
|
+
</details>
|
|
680
776
|
|
|
681
777
|
### Moment transparency
|
|
682
778
|
|
|
683
|
-
The quality setting `momentTransparency` blends the blended surfaces in a second layer that needs no sort. It is nearer an exact back-to-front blend than the weighted blending
|
|
779
|
+
The quality setting `momentTransparency` blends the blended surfaces in a second layer that needs no sort. It is nearer an exact back-to-front blend than the weighted blending in the engine's test of five overlapping glass panes: more than twice nearer when the panes sit within a few meters, and about two and a half times nearer when they spread from 1 to 30 meters.
|
|
780
|
+
|
|
781
|
+
The engine stores four depth moments of each pixel, then draws the surfaces a second time and weights each fragment's color by the light that the moments say survives in front of it. A last step blends the result over the scene. The fit is exact for one surface and for two, and closest to the exact blend of every method the engine has for overlapping glass, foliage and particles.
|
|
684
782
|
|
|
685
783
|
```ts
|
|
686
784
|
// The page turns the layer on when the engine starts, and every blended material draws in it.
|
|
@@ -688,24 +786,24 @@ const engine = await createEngine({ canvas, sketch, momentTransparency: true });
|
|
|
688
786
|
// Or the engine's own switch does: ?moments=on
|
|
689
787
|
```
|
|
690
788
|
|
|
691
|
-
- The setting covers
|
|
789
|
+
- The setting covers standard and unlit materials, and [sprite batches](sprites.md), whose blending is normal or weighted. A surface with another feature that the layer has no shader for, such as `transmission`, a custom material, a line or a masked surface, keeps the transparent pass's sort.
|
|
692
790
|
- The layer draws at one sample per pixel, so MSAA does not smooth its surfaces' edges. SMAA 1x smooths them under the share that the layer covers, and the opaque edges keep MSAA's samples.
|
|
693
791
|
- It costs more than the weighted blending: two draws of the surfaces, 16 bytes per pixel written a frame at the render size, one more full-screen pass, and SMAA's three steps. It is off on every preset, and [Quality presets](../concepts/quality-presets.md#moment-transparency) gives its cost.
|
|
694
|
-
- A page without the setting
|
|
792
|
+
- A page without the setting sorts its blended surfaces in the transparent pass. Views other than the camera's, and devices that cannot draw into 16-bit float targets, draw blended surfaces farthest first, as `'normal'` ones.
|
|
695
793
|
|
|
696
794
|
## Depth bias
|
|
697
795
|
|
|
698
796
|
`depthBias: { constant, slopeScale }` moves a surface's depth before the depth test. A decal that lies on a wall has the wall's depth, so without a bias the two fight pixel by pixel. Where the depths are exactly equal, no surface is defined to win, and the winner may differ between GPU paths ([The depth prepass](../concepts/quality-presets.md#the-depth-prepass)). A bias toward the camera makes the decal win.
|
|
699
797
|
|
|
700
|
-
| Field |
|
|
701
|
-
| --- | --- |
|
|
702
|
-
| `constant` |
|
|
703
|
-
| `slopeScale` |
|
|
798
|
+
| Field | What it does |
|
|
799
|
+
| --- | --- |
|
|
800
|
+
| `constant` | Steps of the depth buffer's smallest difference. A fraction rounds to the nearest whole number |
|
|
801
|
+
| `slopeScale` | A factor of how steeply the surface's depth changes across the screen. It moves surfaces seen at a grazing angle further |
|
|
704
802
|
|
|
705
|
-
Negative values pull the surface toward the camera, and positive values push it away
|
|
803
|
+
Negative values pull the surface toward the camera, and positive values push it away. The engine draws with reversed depth, and it turns the signs for you. Both fields default to 0.
|
|
706
804
|
|
|
707
805
|
```ts
|
|
708
|
-
// sketch.ts: a poster on a wall,
|
|
806
|
+
// sketch.ts: a poster on a wall, pulled toward the camera so that it wins the depth test.
|
|
709
807
|
const poster = materials.standard({ color: '#e8554e', depthBias: { constant: -4, slopeScale: -4 } });
|
|
710
808
|
```
|
|
711
809
|
|
|
@@ -713,6 +811,10 @@ const poster = materials.standard({ color: '#e8554e', depthBias: { constant: -4,
|
|
|
713
811
|
|
|
714
812
|
`materials.shader(options)` takes every option of `materials.standard` but the texture maps, and a `wgsl` option: WGSL that the null3D Vite plugin compiled. The WGSL declares a surface function, which starts from the look that the standard options make:
|
|
715
813
|
|
|
814
|
+

|
|
815
|
+
|
|
816
|
+
A custom material that reads row and object values.
|
|
817
|
+
|
|
716
818
|
```ts
|
|
717
819
|
const rings = /* wgsl */ `
|
|
718
820
|
fn surface(input: SurfaceInput) -> Surface {
|
|
@@ -767,22 +869,30 @@ The WGSL can also declare a texture array, `var name: texture_2d_array<f32>;`, a
|
|
|
767
869
|
|
|
768
870
|
A texture samples as white until its image is on the GPU.
|
|
769
871
|
|
|
872
|
+
- A material made with `alphaMode: 'mask'` draws nothing where the surface function's `alpha` is below `alphaCutoff`.
|
|
873
|
+
- Materials made from the same WGSL share one shader. Each one has its own uniforms.
|
|
874
|
+
- A mesh needs texture coordinates to draw with a custom material.
|
|
875
|
+
- WGSL as plain text, which the plugin did not compile, throws E1215. So does a whole shader that is not a [full shader](../guides/custom-shaders.md#full-shaders) of a material.
|
|
876
|
+
- A uniform or a texture that the WGSL does not declare, or a value of the wrong kind, throws E1216.
|
|
877
|
+
|
|
770
878
|
### The scene behind a surface
|
|
771
879
|
|
|
772
880
|
A surface function can read the depth of the opaque scene behind it. This gives water its shallow color near a shore and its deep color farther out, and foam where a rock nearly touches the surface. Call `sceneDistance(uv)` for the distance in front of the camera of the surface behind the point at the screen's place `uv`, or `sceneDepth(uv)` for its depth value. Declare the input in the `sceneInputs` option:
|
|
773
881
|
|
|
774
882
|
```ts
|
|
775
883
|
const water = /* wgsl */ `
|
|
884
|
+
#import null3d::depth::{is_orthographic}
|
|
885
|
+
|
|
776
886
|
struct Uniforms { shallow: vec3f, deep: vec3f, foam: vec3f }
|
|
777
887
|
|
|
778
888
|
/// The distance in front of the camera of a depth value, as sceneDistance converts the copy's.
|
|
779
889
|
fn distance_of(depth: f32) -> f32 {
|
|
780
|
-
let near =
|
|
781
|
-
let far =
|
|
782
|
-
if
|
|
783
|
-
return
|
|
890
|
+
let near = camera.near;
|
|
891
|
+
let far = camera.far;
|
|
892
|
+
if is_orthographic(camera.projection) {
|
|
893
|
+
return far - depth * (far - near);
|
|
784
894
|
}
|
|
785
|
-
return far
|
|
895
|
+
return near * far / (near + depth * (far - near));
|
|
786
896
|
}
|
|
787
897
|
|
|
788
898
|
fn surface(input: SurfaceInput) -> Surface {
|
|
@@ -807,14 +917,14 @@ const sheet = materials.shader({
|
|
|
807
917
|
|
|
808
918
|
- `sceneDepth(uv)` gives the scene's depth with 1 at the camera's near plane and 0 at its far plane, and 0 where nothing drew.
|
|
809
919
|
- `sceneDistance(uv)` gives the distance in front of the camera of that surface, in world units.
|
|
810
|
-
- The water's depth is the gap between the sheet and the surface behind it. Convert the sheet's own depth, `input.fragCoord.z`, to a distance with `
|
|
920
|
+
- The water's depth is the gap between the sheet and the surface behind it. Convert the sheet's own depth, `input.fragCoord.z`, to a distance with `camera.near` and `camera.far`, and subtract it from `sceneDistance(uv)`. A shore that fades over that gap ends softly against the bank instead of on the sheet's edge.
|
|
811
921
|
- `input.fragCoord` counts pixels from the top left of the render target on both GPU paths, so `input.fragCoord.xy / frame.resolution` is the `uv` of the point.
|
|
812
922
|
- The engine copies the opaque scene's depth after the opaque pass and before the transparent pass. A blended surface therefore reads the surfaces behind it.
|
|
813
923
|
- A surface in the opaque pass reads 0, the far plane, because the copy comes later. A surface in a scene pass or a reflection pass reads 0 too, because its view makes no copy.
|
|
814
924
|
- The copy is made while a material that declares the input draws, whatever the quality preset says. It costs one full-screen pass and one texture of four bytes for each pixel.
|
|
815
925
|
- On WebGL2 the copy holds the depth that the device stores. Where the device draws `reversed-gl` depth, `sceneDistance` is less precise. The engine draws `reversed` depth where the browser has `EXT_clip_control`.
|
|
816
|
-
- A material that reads the scene's depth
|
|
817
|
-
- The declaration and the WGSL must agree. Development builds throw E1217 for a declaration that the WGSL never uses, and for WGSL that reads the depth without the declaration. They throw it for a scene input that custom materials do not read
|
|
926
|
+
- A material that reads the scene's depth samples up to 6 textures of its own, as every custom material does. The copy of the depth takes a slot of its maps' group that those textures leave free. So the fragment stage stays under WebGPU's limit of 16 sampled textures.
|
|
927
|
+
- The declaration and the WGSL must agree. Development builds throw E1217 for a declaration that the WGSL never uses, and for WGSL that reads the depth without the declaration. They throw it too for a scene input that custom materials do not read.
|
|
818
928
|
|
|
819
929
|
[Surface functions](../shaders/surface-functions.md#the-scenes-depth) shows the helpers among the WGSL.
|
|
820
930
|
|
|
@@ -845,19 +955,25 @@ A material with a vertex offset moves its shadows too: its casters draw with the
|
|
|
845
955
|
|
|
846
956
|
An offset that fades out with distance, such as wind, declares `swayDistance`: the distance from the camera out to which the offset moves. The material's WGSL fades its offset to nothing by that distance, and the engine counts a caster of the material as moving only while its bounding sphere reaches within it. A plant past the distance stands still, so a far shadow cascade that only its sway reached keeps the layer it holds. Leave it out for an offset that moves at every distance.
|
|
847
957
|
|
|
848
|
-
A masked custom material cuts its shadow at its cutoff only when its WGSL declares `fn coverage(input: SurfaceInput) -> f32`. The function returns the opacity of the point, and the engine calls it in the material's shadow caster builds, so a card casts the shape of the object it shows rather than its whole quad. A material that declares neither a coverage function nor a surface alpha casts its mesh's whole shape, whatever its mask.
|
|
958
|
+
A masked custom material cuts its shadow at its cutoff only when its WGSL declares `fn coverage(input: SurfaceInput) -> f32`. The function returns the opacity of the point, and the engine calls it in the material's shadow caster builds, so a card casts the shape of the object it shows rather than its whole quad. A material that declares neither a coverage function nor a surface alpha casts its mesh's whole shape, whatever its mask.
|
|
959
|
+
|
|
960
|
+
WGSL that declares a vertex offset, a coverage function or the surface's alpha gets the caster builds; a material with none casts through the engine's own depth template. A flat caster draws both faces, or it casts nothing: the shadow pass culls the front faces of single-sided geometry, so a single-sided quad is culled whole. Give a material whose caster is flat geometry `doubleSided: true`.
|
|
961
|
+
|
|
962
|
+
The caster tests the coverage under the material's `alphaCutoff`, so it needs the `mask` alpha mode: a development build refuses a coverage function on a material that is not masked, because its caster would drop no texel and cast the whole shape.
|
|
849
963
|
|
|
850
964
|
A surface function can move where the sun's shadow lookup reads by setting `s.shadowOffset`, a position in world space relative to the surface. A stand-in card sets it to the surface that its stored depth shows, so its own cast does not fall on it. [Surface functions](../shaders/surface-functions.md#shadows) shows the WGSL.
|
|
851
965
|
|
|
852
966
|
### Mirrors, polished floors and water
|
|
853
967
|
|
|
854
|
-
A custom material can reflect a [reflection pass](render.md#reflection-passes). Its surface function reads the pass's texture where the surface shows on the screen, and sets the surface's `reflection`. The engine lights that color as the light from the mirror direction. The material's Fresnel, metalness and specular values weigh it as they weigh the environment's reflection. [Surface functions](../shaders/surface-functions.md#reflections) shows the WGSL, and [Custom passes](../guides/custom-passes.md#a-water-recipe) a water recipe. Standard materials take no reflection
|
|
855
|
-
|
|
856
|
-
With `alphaMode: 'mask'`, the pixels where the surface function's `alpha` falls below `alphaCutoff` draw nothing. Materials made from the same WGSL share one shader, and each has its own uniforms. A mesh needs texture coordinates to draw with a custom material. WGSL as plain text, which the plugin did not compile, throws E1215. So does a whole shader that is not a [full shader](../guides/custom-shaders.md#full-shaders) of a material. A uniform or a texture that the WGSL does not declare, or a value of the wrong kind, throws E1216. The WGSL can also move the mesh's vertices with a vertex offset. [Surface functions](../shaders/surface-functions.md) describes the WGSL.
|
|
968
|
+
A custom material can reflect a [reflection pass](render.md#reflection-passes). Its surface function reads the pass's texture where the surface shows on the screen, and sets the surface's `reflection`. The engine lights that color as the light from the mirror direction. The material's Fresnel, metalness and specular values weigh it as they weigh the environment's reflection. [Surface functions](../shaders/surface-functions.md#reflections) shows the WGSL, and [Custom passes](../guides/custom-passes.md#a-water-recipe) a water recipe. Standard materials take no reflection: give a polished floor a custom material with the floor's values.
|
|
857
969
|
|
|
858
970
|
## Ranges
|
|
859
971
|
|
|
860
|
-
|
|
972
|
+
When a factory or `set` gets a value that the tables above do not allow, development builds throw an error:
|
|
973
|
+
|
|
974
|
+
- A value outside its range in the Standard values or Decals table throws E1108. So does a number in `uvTransform` or `mapUvTransforms` that is not finite.
|
|
975
|
+
- An `alphaMode` or `blending` that the engine does not know throws E1217. So does the `weighted` blending on a custom material or on a material with `transmission`.
|
|
976
|
+
- A depth bias that is not a finite number throws E1203.
|
|
861
977
|
|
|
862
978
|
## Limits
|
|
863
979
|
|
|
@@ -870,6 +986,17 @@ One engine holds up to 1,024 materials at once. One more throws E1501. A materia
|
|
|
870
986
|
- [Lights](lights.md): what lights a standard material.
|
|
871
987
|
- [Surface functions](../shaders/surface-functions.md): the WGSL of a custom material.
|
|
872
988
|
- [Math helpers](math.md#colors): sRGB and linear colors.
|
|
989
|
+
- [Clear coat and sheen](https://github.com/null3d-engine/null3d/tree/main/examples/coat-and-sheen): candy paint, carbon fiber and velvet in a rainy showroom.
|
|
990
|
+
- [Iridescence and anisotropy](https://github.com/null3d-engine/null3d/tree/main/examples/iridescence-and-anisotropy): a beetle's shell, soap bubbles and an oil slick.
|
|
991
|
+
- [Diffuse transmission](https://github.com/null3d-engine/null3d/tree/main/examples/translucency): broad leaves and coral petals let the low sun through.
|
|
992
|
+
- [Subsurface light](https://github.com/null3d-engine/null3d/tree/main/examples/subsurface): wax, jade and soap glow under the surface.
|
|
993
|
+
- [Decals](https://github.com/null3d-engine/null3d/tree/main/examples/decals): road paint, posters and stains projected onto a street.
|
|
994
|
+
- [Bump, displacement and parallax](https://github.com/null3d-engine/null3d/tree/main/examples/relief): hills and a brick wall whose depth comes from maps made in code.
|
|
995
|
+
- [Weighted blending](https://github.com/null3d-engine/null3d/tree/main/examples/weighted-transparency): eight crossing glass panes and 600 smoke puffs blend in any order.
|
|
996
|
+
- [Custom materials](https://github.com/null3d-engine/null3d/tree/main/examples/shader-inputs): 900 crystals from one material that reads each row.
|
|
997
|
+
- [Scene depth behind a surface](https://github.com/null3d-engine/null3d/tree/main/examples/water): the water add-on reads the bed's depth through the surface.
|
|
998
|
+
- [Invisible surfaces that hide](https://github.com/null3d-engine/null3d/tree/main/examples/depth-only): a plane with `colorWrite: false` holds back a hall while the page shows through.
|
|
999
|
+
- [Dispersion in glass](https://github.com/null3d-engine/null3d/tree/main/examples/extra-shapes): a torus knot and polyhedra in glass that separates the light into colors.
|
|
873
1000
|
|
|
874
1001
|
## API reference
|
|
875
1002
|
|