@driftengine/core 4.4.2 → 4.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +97 -0
- package/README.md +1 -1
- package/dist/geometry/boxCsg.d.ts +28 -0
- package/dist/geometry/boxCsg.js +139 -0
- package/dist/geometry/csg.d.ts +36 -0
- package/dist/geometry/csg.js +329 -0
- package/dist/geometry/meshBuilder.js +13 -0
- package/dist/geometry/meshConcat.js +1 -0
- package/dist/geometry/pixelFont.js +2 -0
- package/dist/geometry/solid.d.ts +61 -0
- package/dist/geometry/solid.js +152 -0
- package/dist/geometry/solidFlat.d.ts +35 -0
- package/dist/geometry/solidFlat.js +428 -0
- package/dist/geometry/solidHarness.d.ts +19 -0
- package/dist/geometry/solidHarness.js +66 -0
- package/dist/geometry/solidNormals.d.ts +17 -0
- package/dist/geometry/solidNormals.js +86 -0
- package/dist/geometry/solidRound.d.ts +41 -0
- package/dist/geometry/solidRound.js +323 -0
- package/dist/geometry/solidWriter.d.ts +16 -0
- package/dist/geometry/solidWriter.js +42 -0
- package/dist/index.d.ts +28 -3
- package/dist/index.js +20 -1
- package/dist/render/backend/api.d.ts +34 -14
- package/dist/render/backend/drawFog.d.ts +26 -0
- package/dist/render/backend/drawFog.js +30 -0
- package/dist/render/backend/materialChanges.d.ts +2 -1
- package/dist/render/backend/materialChanges.js +6 -1
- package/dist/render/backend/webgl2/glassTintPrograms.d.ts +13 -0
- package/dist/render/backend/webgl2/glassTintPrograms.js +38 -0
- package/dist/render/backend/webgl2/instanced.d.ts +24 -5
- package/dist/render/backend/webgl2/instanced.js +72 -15
- package/dist/render/backend/webgl2/renderer.d.ts +201 -16
- package/dist/render/backend/webgl2/renderer.js +596 -224
- package/dist/render/backend/webgpu/buffers.d.ts +29 -1
- package/dist/render/backend/webgpu/buffers.js +61 -4
- package/dist/render/backend/webgpu/depthPass.d.ts +1 -1
- package/dist/render/backend/webgpu/depthPass.js +7 -2
- package/dist/render/backend/webgpu/drawCommand.d.ts +5 -0
- package/dist/render/backend/webgpu/drawCommand.js +1 -0
- package/dist/render/backend/webgpu/flatPass.d.ts +6 -1
- package/dist/render/backend/webgpu/flatPass.js +57 -9
- package/dist/render/backend/webgpu/glassTintPass.d.ts +28 -0
- package/dist/render/backend/webgpu/glassTintPass.js +206 -0
- package/dist/render/backend/webgpu/gpuDrivenPass.d.ts +60 -1
- package/dist/render/backend/webgpu/gpuDrivenPass.js +305 -5
- package/dist/render/backend/webgpu/instanceCullPass.d.ts +34 -0
- package/dist/render/backend/webgpu/instanceCullPass.js +144 -0
- package/dist/render/backend/webgpu/instanced.d.ts +23 -2
- package/dist/render/backend/webgpu/instanced.js +41 -4
- package/dist/render/backend/webgpu/latePass.d.ts +30 -0
- package/dist/render/backend/webgpu/latePass.js +140 -0
- package/dist/render/backend/webgpu/lightVolumePass.js +5 -1
- package/dist/render/backend/webgpu/motionPass.d.ts +95 -0
- package/dist/render/backend/webgpu/motionPass.js +491 -0
- package/dist/render/backend/webgpu/pipelineCache.d.ts +10 -1
- package/dist/render/backend/webgpu/pipelineCache.js +11 -1
- package/dist/render/backend/webgpu/pointGlassTintPass.d.ts +32 -0
- package/dist/render/backend/webgpu/pointGlassTintPass.js +193 -0
- package/dist/render/backend/webgpu/pointShadowPass.d.ts +35 -6
- package/dist/render/backend/webgpu/pointShadowPass.js +105 -20
- package/dist/render/backend/webgpu/postPass.d.ts +3 -13
- package/dist/render/backend/webgpu/renderer.d.ts +271 -64
- package/dist/render/backend/webgpu/renderer.js +1395 -580
- package/dist/render/backend/webgpu/scatterPass.js +2 -1
- package/dist/render/backend/webgpu/sdfTextPass.js +6 -1
- package/dist/render/backend/webgpu/shaders/instanceCull.wgsl.d.ts +18 -0
- package/dist/render/backend/webgpu/shaders/instanceCull.wgsl.js +59 -0
- package/dist/render/backend/webgpu/skinPaletteRing.d.ts +4 -0
- package/dist/render/backend/webgpu/skinPaletteRing.js +4 -0
- package/dist/render/backend/webgpu/snapshotMips.d.ts +29 -0
- package/dist/render/backend/webgpu/snapshotMips.js +52 -0
- package/dist/render/backend/webgpu/surfaceTexturePass.d.ts +22 -3
- package/dist/render/backend/webgpu/surfaceTexturePass.js +78 -39
- package/dist/render/driftLight/bake.d.ts +7 -0
- package/dist/render/driftLight/bake.js +61 -56
- package/dist/render/driftLight/denseField.d.ts +46 -0
- package/dist/render/driftLight/denseField.js +109 -0
- package/dist/render/driftLight/lightField.d.ts +10 -5
- package/dist/render/driftLight/lightField.js +25 -19
- package/dist/render/driftLight/presence.d.ts +50 -0
- package/dist/render/driftLight/presence.js +43 -0
- package/dist/render/driftLight/uniforms.d.ts +3 -3
- package/dist/render/driftLight/uniforms.js +5 -6
- package/dist/render/driftLight/worldLightField.d.ts +41 -0
- package/dist/render/driftLight/worldLightField.js +66 -0
- package/dist/render/fixtureAtlas.d.ts +20 -0
- package/dist/render/fixtureAtlas.js +49 -0
- package/dist/render/glass.d.ts +45 -0
- package/dist/render/glass.js +39 -0
- package/dist/render/glassCasters.d.ts +40 -0
- package/dist/render/glassCasters.js +84 -0
- package/dist/render/glassShadow.d.ts +78 -0
- package/dist/render/glassShadow.js +125 -0
- package/dist/render/globalMediumPass.d.ts +2 -3
- package/dist/render/globalMediumPass.js +2 -8
- package/dist/render/gpudriven/lit.d.ts +12 -0
- package/dist/render/gpudriven/lit.js +23 -0
- package/dist/render/gpudriven/materialTable.d.ts +15 -5
- package/dist/render/gpudriven/materialTable.js +26 -6
- package/dist/render/gpudriven/pipeline.d.ts +1 -1
- package/dist/render/gpudriven/pipeline.js +4 -3
- package/dist/render/gpudriven/sunGlass.d.ts +35 -0
- package/dist/render/gpudriven/sunGlass.js +89 -0
- package/dist/render/instanceCull.d.ts +63 -0
- package/dist/render/instanceCull.js +160 -0
- package/dist/render/instances.d.ts +15 -0
- package/dist/render/lightBudget.d.ts +36 -35
- package/dist/render/lightBudget.js +38 -37
- package/dist/render/lightGrid.d.ts +42 -0
- package/dist/render/lightGrid.js +87 -0
- package/dist/render/mesh.d.ts +18 -24
- package/dist/render/mesh.js +51 -68
- package/dist/render/occlusion.d.ts +10 -0
- package/dist/render/occlusion.js +36 -7
- package/dist/render/pointGlassTint.d.ts +59 -0
- package/dist/render/pointGlassTint.js +198 -0
- package/dist/render/pointLightSelection.d.ts +7 -0
- package/dist/render/pointLightSelection.js +29 -4
- package/dist/render/pointShadowArray.d.ts +56 -3
- package/dist/render/pointShadowArray.js +127 -16
- package/dist/render/pointShadowMap.d.ts +23 -1
- package/dist/render/pointShadowMap.js +27 -1
- package/dist/render/rainField.d.ts +13 -0
- package/dist/render/rainField.js +27 -5
- package/dist/render/recon/changeFrames.d.ts +15 -0
- package/dist/render/recon/changeFrames.js +21 -0
- package/dist/render/recon/lateDepth.d.ts +11 -0
- package/dist/render/recon/lateDepth.js +70 -0
- package/dist/render/recon/lateRouting.d.ts +14 -0
- package/dist/render/recon/lateRouting.js +18 -0
- package/dist/render/recon/mover.d.ts +57 -0
- package/dist/render/recon/mover.js +86 -0
- package/dist/render/recon/resolve.d.ts +34 -4
- package/dist/render/recon/resolve.js +161 -20
- package/dist/render/renderQuality.d.ts +35 -0
- package/dist/render/renderQuality.js +7 -0
- package/dist/render/rendererHarness.js +16 -0
- package/dist/render/sceneTarget.d.ts +9 -1
- package/dist/render/sceneTarget.js +60 -12
- package/dist/render/shaders/depth.d.ts +16 -1
- package/dist/render/shaders/depth.js +94 -15
- package/dist/render/shaders/flat/directionalShadow.js +91 -6
- package/dist/render/shaders/flat/driftLight.d.ts +1 -1
- package/dist/render/shaders/flat/driftLight.js +32 -7
- package/dist/render/shaders/flat/glassTint.d.ts +6 -0
- package/dist/render/shaders/flat/glassTint.js +25 -0
- package/dist/render/shaders/flat/index.d.ts +13 -0
- package/dist/render/shaders/flat/index.js +9 -3
- package/dist/render/shaders/flat/lampGlass.d.ts +1 -0
- package/dist/render/shaders/flat/lampGlass.js +183 -0
- package/dist/render/shaders/flat/main.d.ts +1 -1
- package/dist/render/shaders/flat/main.js +190 -38
- package/dist/render/shaders/flat/pointShadow.d.ts +1 -1
- package/dist/render/shaders/flat/pointShadow.js +2 -0
- package/dist/render/shaders/flat/preamble.js +96 -26
- package/dist/render/shaders/flat/surfaceEffects.d.ts +29 -0
- package/dist/render/shaders/flat/surfaceEffects.js +152 -0
- package/dist/render/shaders/generated/depth.wgsl.d.ts +230 -7
- package/dist/render/shaders/generated/depth.wgsl.js +230 -7
- package/dist/render/shaders/generated/flat.wgsl.d.ts +1644 -1596
- package/dist/render/shaders/generated/flat.wgsl.js +1683 -1621
- package/dist/render/shaders/generated/globalMedium.wgsl.d.ts +3 -13
- package/dist/render/shaders/generated/globalMedium.wgsl.js +3 -13
- package/dist/render/shaders/generated/lightVolume.wgsl.d.ts +3 -13
- package/dist/render/shaders/generated/lightVolume.wgsl.js +21 -17
- package/dist/render/shaders/generated/octahedralResolve.wgsl.d.ts +29 -0
- package/dist/render/shaders/generated/octahedralResolve.wgsl.js +29 -0
- package/dist/render/shaders/generated/rush.wgsl.d.ts +21 -16
- package/dist/render/shaders/generated/rush.wgsl.js +21 -16
- package/dist/render/shaders/generated/sdfText.wgsl.d.ts +2 -2
- package/dist/render/shaders/generated/sdfText.wgsl.js +2 -2
- package/dist/render/shaders/generated/text.wgsl.d.ts +1 -1
- package/dist/render/shaders/generated/text.wgsl.js +1 -1
- package/dist/render/shaders/gi/driftLight.wgsl.d.ts +1 -1
- package/dist/render/shaders/gi/driftLight.wgsl.js +27 -4
- package/dist/render/shaders/globalMedium.js +6 -6
- package/dist/render/shaders/gpudriven/blendRaster.wgsl.d.ts +7 -0
- package/dist/render/shaders/gpudriven/blendRaster.wgsl.js +86 -1
- package/dist/render/shaders/gpudriven/cull.wgsl.d.ts +1 -1
- package/dist/render/shaders/gpudriven/cull.wgsl.js +11 -2
- package/dist/render/shaders/gpudriven/materialTable.wgsl.d.ts +1 -1
- package/dist/render/shaders/gpudriven/materialTable.wgsl.js +3 -1
- package/dist/render/shaders/gpudriven/shade.wgsl.js +50 -1
- package/dist/render/shaders/gpudriven/sunGlass.wgsl.d.ts +9 -0
- package/dist/render/shaders/gpudriven/sunGlass.wgsl.js +133 -0
- package/dist/render/shaders/lightVolume.js +6 -6
- package/dist/render/shaders/octahedralResolve.d.ts +8 -0
- package/dist/render/shaders/octahedralResolve.js +48 -17
- package/dist/render/shaders/recon/lateDepth.wgsl.d.ts +1 -0
- package/dist/render/shaders/recon/lateDepth.wgsl.js +69 -0
- package/dist/render/shaders/recon/motion.wgsl.d.ts +1 -1
- package/dist/render/shaders/recon/motion.wgsl.js +84 -0
- package/dist/render/shaders/recon/resolve.wgsl.d.ts +8 -7
- package/dist/render/shaders/recon/resolve.wgsl.js +161 -27
- package/dist/render/shaders/rush.js +11 -1
- package/dist/render/shaders/sdfText.d.ts +1 -1
- package/dist/render/shaders/sdfText.js +3 -2
- package/dist/render/shaders/text.d.ts +1 -1
- package/dist/render/shaders/text.js +18 -9
- package/dist/render/shadowCasters.d.ts +20 -1
- package/dist/render/shadowCasters.js +15 -1
- package/dist/render/shadowMap.d.ts +54 -5
- package/dist/render/shadowMap.js +190 -36
- package/dist/render/sunGlassTint.d.ts +25 -0
- package/dist/render/sunGlassTint.js +79 -0
- package/dist/render/surfaceEffects.d.ts +83 -0
- package/dist/render/surfaceEffects.js +75 -0
- package/dist/render/surfaceScene.d.ts +8 -0
- package/dist/render/surfaceScene.js +8 -0
- package/dist/render/surfaceTexture.d.ts +18 -2
- package/dist/render/surfaceTexture.js +68 -15
- package/dist/render/temporalAa.d.ts +25 -6
- package/dist/render/temporalAa.js +45 -15
- package/dist/render/textureSource.d.ts +30 -0
- package/dist/render/textureSource.js +53 -0
- package/dist/render/translucentQueue.d.ts +6 -0
- package/dist/render/translucentQueue.js +15 -1
- package/dist/render/vertexDefaults.js +2 -0
- package/dist/world/hlod.d.ts +104 -0
- package/dist/world/hlod.js +214 -0
- package/package.json +6 -6
- package/src/geometry/boxCsg.ts +186 -0
- package/src/geometry/csg.ts +384 -0
- package/src/geometry/meshBuilder.ts +15 -0
- package/src/geometry/meshConcat.ts +1 -0
- package/src/geometry/pixelFont.ts +2 -0
- package/src/geometry/solid.ts +189 -0
- package/src/geometry/solidFlat.ts +522 -0
- package/src/geometry/solidHarness.ts +83 -0
- package/src/geometry/solidNormals.ts +103 -0
- package/src/geometry/solidRound.ts +443 -0
- package/src/geometry/solidWriter.ts +58 -0
- package/src/index.ts +61 -1
- package/src/render/backend/api.ts +36 -11
- package/src/render/backend/drawFog.ts +31 -0
- package/src/render/backend/materialChanges.ts +9 -2
- package/src/render/backend/webgl2/glassTintPrograms.ts +58 -0
- package/src/render/backend/webgl2/instanced.ts +80 -14
- package/src/render/backend/webgl2/renderer.ts +700 -250
- package/src/render/backend/webgpu/buffers.ts +92 -5
- package/src/render/backend/webgpu/depthPass.ts +7 -2
- package/src/render/backend/webgpu/drawCommand.ts +6 -0
- package/src/render/backend/webgpu/flatPass.ts +62 -11
- package/src/render/backend/webgpu/glassTintPass.ts +245 -0
- package/src/render/backend/webgpu/gpuDrivenPass.ts +349 -5
- package/src/render/backend/webgpu/instanceCullPass.ts +165 -0
- package/src/render/backend/webgpu/instanced.ts +42 -4
- package/src/render/backend/webgpu/latePass.ts +161 -0
- package/src/render/backend/webgpu/lightVolumePass.ts +5 -1
- package/src/render/backend/webgpu/motionPass.ts +535 -0
- package/src/render/backend/webgpu/pipelineCache.ts +12 -1
- package/src/render/backend/webgpu/pointGlassTintPass.ts +233 -0
- package/src/render/backend/webgpu/pointShadowPass.ts +158 -26
- package/src/render/backend/webgpu/renderer.ts +1671 -670
- package/src/render/backend/webgpu/scatterPass.ts +2 -1
- package/src/render/backend/webgpu/sdfTextPass.ts +6 -1
- package/src/render/backend/webgpu/shaders/instanceCull.wgsl.ts +61 -0
- package/src/render/backend/webgpu/skinPaletteRing.ts +4 -0
- package/src/render/backend/webgpu/snapshotMips.ts +80 -0
- package/src/render/backend/webgpu/surfaceTexturePass.ts +91 -51
- package/src/render/driftLight/bake.ts +85 -62
- package/src/render/driftLight/denseField.ts +149 -0
- package/src/render/driftLight/lightField.ts +33 -18
- package/src/render/driftLight/presence.ts +69 -0
- package/src/render/driftLight/uniforms.ts +8 -9
- package/src/render/driftLight/worldLightField.ts +83 -0
- package/src/render/fixtureAtlas.ts +63 -0
- package/src/render/glass.ts +74 -0
- package/src/render/glassCasters.ts +164 -0
- package/src/render/glassShadow.ts +153 -0
- package/src/render/globalMediumPass.ts +4 -11
- package/src/render/gpudriven/lit.ts +31 -0
- package/src/render/gpudriven/materialTable.ts +28 -6
- package/src/render/gpudriven/pipeline.ts +4 -3
- package/src/render/gpudriven/sunGlass.ts +117 -0
- package/src/render/instanceCull.ts +205 -0
- package/src/render/instances.ts +16 -0
- package/src/render/lightBudget.ts +41 -38
- package/src/render/lightGrid.ts +130 -0
- package/src/render/mesh.ts +59 -72
- package/src/render/occlusion.ts +51 -7
- package/src/render/pointGlassTint.ts +250 -0
- package/src/render/pointLightSelection.ts +72 -4
- package/src/render/pointShadowArray.ts +188 -22
- package/src/render/pointShadowMap.ts +41 -0
- package/src/render/rainField.ts +39 -5
- package/src/render/recon/changeFrames.ts +24 -0
- package/src/render/recon/lateDepth.ts +83 -0
- package/src/render/recon/lateRouting.ts +29 -0
- package/src/render/recon/mover.ts +118 -0
- package/src/render/recon/resolve.ts +206 -20
- package/src/render/renderQuality.ts +47 -0
- package/src/render/rendererHarness.ts +16 -0
- package/src/render/sceneTarget.ts +62 -11
- package/src/render/shaders/depth.ts +118 -15
- package/src/render/shaders/flat/directionalShadow.ts +97 -6
- package/src/render/shaders/flat/driftLight.ts +32 -7
- package/src/render/shaders/flat/glassTint.ts +25 -0
- package/src/render/shaders/flat/index.ts +22 -3
- package/src/render/shaders/flat/lampGlass.ts +185 -0
- package/src/render/shaders/flat/main.ts +190 -38
- package/src/render/shaders/flat/pointShadow.ts +2 -0
- package/src/render/shaders/flat/preamble.ts +96 -26
- package/src/render/shaders/flat/surfaceEffects.ts +152 -0
- package/src/render/shaders/generated/depth.wgsl.ts +237 -7
- package/src/render/shaders/generated/flat.wgsl.ts +1685 -1621
- package/src/render/shaders/generated/globalMedium.wgsl.ts +3 -13
- package/src/render/shaders/generated/lightVolume.wgsl.ts +23 -17
- package/src/render/shaders/generated/octahedralResolve.wgsl.ts +30 -0
- package/src/render/shaders/generated/rush.wgsl.ts +21 -16
- package/src/render/shaders/generated/sdfText.wgsl.ts +2 -2
- package/src/render/shaders/generated/text.wgsl.ts +1 -1
- package/src/render/shaders/gi/driftLight.wgsl.ts +27 -4
- package/src/render/shaders/globalMedium.ts +6 -6
- package/src/render/shaders/gpudriven/blendRaster.wgsl.ts +88 -1
- package/src/render/shaders/gpudriven/cull.wgsl.ts +11 -2
- package/src/render/shaders/gpudriven/materialTable.wgsl.ts +3 -1
- package/src/render/shaders/gpudriven/shade.wgsl.ts +50 -1
- package/src/render/shaders/gpudriven/sunGlass.wgsl.ts +139 -0
- package/src/render/shaders/lightVolume.ts +6 -6
- package/src/render/shaders/octahedralResolve.ts +50 -17
- package/src/render/shaders/recon/lateDepth.wgsl.ts +72 -0
- package/src/render/shaders/recon/motion.wgsl.ts +84 -0
- package/src/render/shaders/recon/resolve.wgsl.ts +161 -27
- package/src/render/shaders/rush.ts +11 -1
- package/src/render/shaders/sdfText.ts +3 -2
- package/src/render/shaders/text.ts +18 -9
- package/src/render/shadowCasters.ts +28 -1
- package/src/render/shadowMap.ts +231 -37
- package/src/render/sunGlassTint.ts +86 -0
- package/src/render/surfaceEffects.ts +132 -0
- package/src/render/surfaceScene.ts +16 -0
- package/src/render/surfaceTexture.ts +110 -19
- package/src/render/temporalAa.ts +78 -14
- package/src/render/textureSource.ts +72 -0
- package/src/render/translucentQueue.ts +20 -1
- package/src/render/vertexDefaults.ts +2 -0
- package/src/world/hlod.ts +290 -0
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
import { SolidWriter } from './solidWriter.js';
|
|
2
|
+
/**
|
|
3
|
+
* Revolve one or more strips — runs of profile points whose normals are continuous — around +Y.
|
|
4
|
+
* A strip's normals are used when smooth; faceted quads take the normal their corners imply.
|
|
5
|
+
*/
|
|
6
|
+
function revolve(strips, segments, smooth) {
|
|
7
|
+
const n = Math.max(3, Math.floor(segments));
|
|
8
|
+
const out = new SolidWriter();
|
|
9
|
+
let total = 0;
|
|
10
|
+
for (const strip of strips) {
|
|
11
|
+
for (let i = 0; i + 1 < strip.length; i++)
|
|
12
|
+
total += span(strip[i], strip[i + 1]);
|
|
13
|
+
}
|
|
14
|
+
let walked = 0;
|
|
15
|
+
for (const strip of strips) {
|
|
16
|
+
const v = [];
|
|
17
|
+
for (let i = 0; i < strip.length; i++) {
|
|
18
|
+
if (i > 0)
|
|
19
|
+
walked += span(strip[i - 1], strip[i]);
|
|
20
|
+
v.push(total > 0 ? walked / total : 0);
|
|
21
|
+
}
|
|
22
|
+
if (smooth)
|
|
23
|
+
revolveSmooth(out, strip, v, n);
|
|
24
|
+
else
|
|
25
|
+
revolveFaceted(out, strip, v, n);
|
|
26
|
+
}
|
|
27
|
+
return out.finish();
|
|
28
|
+
}
|
|
29
|
+
function span(a, b) {
|
|
30
|
+
return a && b ? Math.hypot(b.r - a.r, b.y - a.y) : 0;
|
|
31
|
+
}
|
|
32
|
+
function revolveSmooth(out, strip, v, n) {
|
|
33
|
+
const base = out.vertexCount;
|
|
34
|
+
const row = n + 1;
|
|
35
|
+
for (let i = 0; i < strip.length; i++) {
|
|
36
|
+
const p = strip[i];
|
|
37
|
+
if (!p)
|
|
38
|
+
continue;
|
|
39
|
+
for (let j = 0; j <= n; j++) {
|
|
40
|
+
const t = (2 * Math.PI * (j % n)) / n;
|
|
41
|
+
const c = Math.cos(t);
|
|
42
|
+
const s = Math.sin(t);
|
|
43
|
+
out.vertex(p.r * c, p.y, p.r * s, p.nr * c, p.ny, p.nr * s, j / n, v[i] ?? 0);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
for (let i = 0; i + 1 < strip.length; i++) {
|
|
47
|
+
const r0 = strip[i]?.r ?? 0;
|
|
48
|
+
const r1 = strip[i + 1]?.r ?? 0;
|
|
49
|
+
for (let j = 0; j < n; j++) {
|
|
50
|
+
const a = base + i * row + j;
|
|
51
|
+
const b = a + row;
|
|
52
|
+
const c = b + 1;
|
|
53
|
+
const d = a + 1;
|
|
54
|
+
emit(out, a, b, c, d, r0, r1);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function revolveFaceted(out, strip, v, n) {
|
|
59
|
+
for (let i = 0; i + 1 < strip.length; i++) {
|
|
60
|
+
const p = strip[i];
|
|
61
|
+
const q = strip[i + 1];
|
|
62
|
+
if (!p || !q)
|
|
63
|
+
continue;
|
|
64
|
+
for (let j = 0; j < n; j++) {
|
|
65
|
+
const t0 = (2 * Math.PI * j) / n;
|
|
66
|
+
const t1 = (2 * Math.PI * ((j + 1) % n)) / n;
|
|
67
|
+
const c0 = Math.cos(t0);
|
|
68
|
+
const s0 = Math.sin(t0);
|
|
69
|
+
const c1 = Math.cos(t1);
|
|
70
|
+
const s1 = Math.sin(t1);
|
|
71
|
+
const ax = p.r * c0;
|
|
72
|
+
const az = p.r * s0;
|
|
73
|
+
const bx = q.r * c0;
|
|
74
|
+
const bz = q.r * s0;
|
|
75
|
+
const cx = q.r * c1;
|
|
76
|
+
const cz = q.r * s1;
|
|
77
|
+
const dx = p.r * c1;
|
|
78
|
+
const dz = p.r * s1;
|
|
79
|
+
/* The normal from the diagonals, (c − a) × (d − b): right for a quad and for the triangle a
|
|
80
|
+
quad collapses to at the axis, where the edge-based cross product is zero. */
|
|
81
|
+
const ex = cx - ax;
|
|
82
|
+
const ey = q.y - p.y;
|
|
83
|
+
const ez = cz - az;
|
|
84
|
+
const fx = dx - bx;
|
|
85
|
+
const fy = p.y - q.y;
|
|
86
|
+
const fz = dz - bz;
|
|
87
|
+
let nx = ey * fz - ez * fy;
|
|
88
|
+
let ny = ez * fx - ex * fz;
|
|
89
|
+
let nz = ex * fy - ey * fx;
|
|
90
|
+
const len = Math.hypot(nx, ny, nz) || 1;
|
|
91
|
+
nx /= len;
|
|
92
|
+
ny /= len;
|
|
93
|
+
nz /= len;
|
|
94
|
+
const u0 = j / n;
|
|
95
|
+
const u1 = (j + 1) / n;
|
|
96
|
+
const a = out.vertex(ax, p.y, az, nx, ny, nz, u0, v[i] ?? 0);
|
|
97
|
+
const b = out.vertex(bx, q.y, bz, nx, ny, nz, u0, v[i + 1] ?? 0);
|
|
98
|
+
const c = out.vertex(cx, q.y, cz, nx, ny, nz, u1, v[i + 1] ?? 0);
|
|
99
|
+
const d = out.vertex(dx, p.y, dz, nx, ny, nz, u1, v[i] ?? 0);
|
|
100
|
+
emit(out, a, b, c, d, p.r, q.r);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/** Quad `a b c d`, or the one triangle left of it where either end of the profile step is on the axis. */
|
|
105
|
+
function emit(out, a, b, c, d, r0, r1) {
|
|
106
|
+
if (r0 <= 1e-12 && r1 <= 1e-12)
|
|
107
|
+
return;
|
|
108
|
+
if (r0 <= 1e-12)
|
|
109
|
+
out.triangle(a, b, c);
|
|
110
|
+
else if (r1 <= 1e-12)
|
|
111
|
+
out.triangle(a, b, d);
|
|
112
|
+
else
|
|
113
|
+
out.quad(a, b, c, d);
|
|
114
|
+
}
|
|
115
|
+
/** Points along a polyline profile, each segment its own strip so every corner creases. */
|
|
116
|
+
function creasedStrips(points) {
|
|
117
|
+
const strips = [];
|
|
118
|
+
for (let i = 0; i + 1 < points.length; i++) {
|
|
119
|
+
const [r0, y0] = points[i] ?? [0, 0];
|
|
120
|
+
const [r1, y1] = points[i + 1] ?? [0, 0];
|
|
121
|
+
const len = Math.hypot(r1 - r0, y1 - y0) || 1;
|
|
122
|
+
const nr = (y1 - y0) / len;
|
|
123
|
+
const ny = -(r1 - r0) / len;
|
|
124
|
+
strips.push([
|
|
125
|
+
{ r: r0, y: y0, nr, ny },
|
|
126
|
+
{ r: r1, y: y1, nr, ny },
|
|
127
|
+
]);
|
|
128
|
+
}
|
|
129
|
+
return strips;
|
|
130
|
+
}
|
|
131
|
+
/** An arc of the circle centred (cr, cy), radius `radius`, from angle `a0` to `a1` in `steps`. */
|
|
132
|
+
function arc(cr, cy, radius, a0, a1, steps) {
|
|
133
|
+
const points = [];
|
|
134
|
+
for (let s = 0; s <= steps; s++) {
|
|
135
|
+
const a = a0 + ((a1 - a0) * s) / steps;
|
|
136
|
+
const c = Math.cos(a);
|
|
137
|
+
const sn = Math.sin(a);
|
|
138
|
+
points.push({ r: Math.max(0, cr + radius * c), y: cy + radius * sn, nr: c, ny: sn });
|
|
139
|
+
}
|
|
140
|
+
return points;
|
|
141
|
+
}
|
|
142
|
+
/** A cylinder of `radius` and `length` along Y, centred, capped. */
|
|
143
|
+
export function solidCylinder(radius, length, segments, smooth = false) {
|
|
144
|
+
return solidFrustum(radius, radius, length, segments, smooth);
|
|
145
|
+
}
|
|
146
|
+
/** A cone: base `radius` at −length/2, apex at +length/2. */
|
|
147
|
+
export function solidCone(radius, length, segments, smooth = false) {
|
|
148
|
+
return solidFrustum(radius, 0, length, segments, smooth);
|
|
149
|
+
}
|
|
150
|
+
/** A frustum with explicit radii at its bottom (−length/2) and top (+length/2), capped. */
|
|
151
|
+
export function solidFrustum(radiusBottom, radiusTop, length, segments, smooth = false) {
|
|
152
|
+
const h = length / 2;
|
|
153
|
+
return revolve(creasedStrips([
|
|
154
|
+
[0, -h],
|
|
155
|
+
[radiusBottom, -h],
|
|
156
|
+
[radiusTop, h],
|
|
157
|
+
[0, h],
|
|
158
|
+
]), segments, smooth);
|
|
159
|
+
}
|
|
160
|
+
/** A hollow cylinder: outer `radius`, wall `thickness`, `length` along Y, centred. Four segments make a square frame. */
|
|
161
|
+
export function solidTube(radius, thickness, length, segments, smooth = false) {
|
|
162
|
+
const h = length / 2;
|
|
163
|
+
const inner = Math.max(0, radius - thickness);
|
|
164
|
+
return revolve(creasedStrips([
|
|
165
|
+
[inner, -h],
|
|
166
|
+
[radius, -h],
|
|
167
|
+
[radius, h],
|
|
168
|
+
[inner, h],
|
|
169
|
+
[inner, -h],
|
|
170
|
+
]), segments, smooth);
|
|
171
|
+
}
|
|
172
|
+
/** A sphere of `radius`: `segments` around, half as many from pole to pole. */
|
|
173
|
+
export function solidSphere(radius, segments, smooth = false) {
|
|
174
|
+
const rings = Math.max(2, Math.floor(segments / 2));
|
|
175
|
+
return revolve([arc(0, 0, radius, -Math.PI / 2, Math.PI / 2, rings)], segments, smooth);
|
|
176
|
+
}
|
|
177
|
+
/** A dome toward +Y on a flat base at the origin. */
|
|
178
|
+
export function solidHemisphere(radius, segments, smooth = false) {
|
|
179
|
+
const rings = Math.max(1, Math.floor(segments / 4));
|
|
180
|
+
const base = [
|
|
181
|
+
{ r: 0, y: 0, nr: 0, ny: -1 },
|
|
182
|
+
{ r: radius, y: 0, nr: 0, ny: -1 },
|
|
183
|
+
];
|
|
184
|
+
return revolve([base, arc(0, 0, radius, 0, Math.PI / 2, rings)], segments, smooth);
|
|
185
|
+
}
|
|
186
|
+
/** A capsule: a cylinder of `length` (excluding the caps) with hemispherical ends, along Y. */
|
|
187
|
+
export function solidCapsule(radius, length, segments, smooth = false) {
|
|
188
|
+
const rings = Math.max(1, Math.floor(segments / 4));
|
|
189
|
+
const h = length / 2;
|
|
190
|
+
return revolve([
|
|
191
|
+
arc(0, -h, radius, -Math.PI / 2, 0, rings),
|
|
192
|
+
[
|
|
193
|
+
{ r: radius, y: -h, nr: 1, ny: 0 },
|
|
194
|
+
{ r: radius, y: h, nr: 1, ny: 0 },
|
|
195
|
+
],
|
|
196
|
+
arc(0, h, radius, 0, Math.PI / 2, rings),
|
|
197
|
+
], segments, smooth);
|
|
198
|
+
}
|
|
199
|
+
/** A torus around +Y: ring radius `major`, tube radius `minor`, `segments` around and `sides` across. */
|
|
200
|
+
export function solidTorus(major, minor, segments, sides, smooth = false) {
|
|
201
|
+
return revolve([arc(major, 0, minor, 0, 2 * Math.PI, Math.max(3, Math.floor(sides)))], segments, smooth);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* A profile (`r, y` pairs, bottom to top) revolved around +Y. An end off the axis is closed with a
|
|
205
|
+
* flat cap, so any profile makes a solid. Every profile corner creases, faceted or smooth.
|
|
206
|
+
*/
|
|
207
|
+
export function solidLathe(profile, segments, smooth = false) {
|
|
208
|
+
const points = [];
|
|
209
|
+
for (let i = 0; i + 1 < profile.length; i += 2)
|
|
210
|
+
points.push([profile[i] ?? 0, profile[i + 1] ?? 0]);
|
|
211
|
+
const first = points[0];
|
|
212
|
+
const last = points[points.length - 1];
|
|
213
|
+
if (first && first[0] > 1e-12)
|
|
214
|
+
points.unshift([0, first[1]]);
|
|
215
|
+
if (last && last[0] > 1e-12)
|
|
216
|
+
points.push([0, last[1]]);
|
|
217
|
+
return revolve(creasedStrips(points), segments, smooth);
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* An icosahedron subdivided `level` times onto a sphere of `radius`. Faceted by default — every
|
|
221
|
+
* triangle its own vertices and face normal — or smooth, sharing vertices with radial normals.
|
|
222
|
+
*/
|
|
223
|
+
export function solidIcosphere(radius, level, smooth = false) {
|
|
224
|
+
const t = (1 + Math.sqrt(5)) / 2;
|
|
225
|
+
const verts = [
|
|
226
|
+
[-1, t, 0],
|
|
227
|
+
[1, t, 0],
|
|
228
|
+
[-1, -t, 0],
|
|
229
|
+
[1, -t, 0],
|
|
230
|
+
[0, -1, t],
|
|
231
|
+
[0, 1, t],
|
|
232
|
+
[0, -1, -t],
|
|
233
|
+
[0, 1, -t],
|
|
234
|
+
[t, 0, -1],
|
|
235
|
+
[t, 0, 1],
|
|
236
|
+
[-t, 0, -1],
|
|
237
|
+
[-t, 0, 1],
|
|
238
|
+
].map(unit);
|
|
239
|
+
let faces = [
|
|
240
|
+
[0, 11, 5],
|
|
241
|
+
[0, 5, 1],
|
|
242
|
+
[0, 1, 7],
|
|
243
|
+
[0, 7, 10],
|
|
244
|
+
[0, 10, 11],
|
|
245
|
+
[1, 5, 9],
|
|
246
|
+
[5, 11, 4],
|
|
247
|
+
[11, 10, 2],
|
|
248
|
+
[10, 7, 6],
|
|
249
|
+
[7, 1, 8],
|
|
250
|
+
[3, 9, 4],
|
|
251
|
+
[3, 4, 2],
|
|
252
|
+
[3, 2, 6],
|
|
253
|
+
[3, 6, 8],
|
|
254
|
+
[3, 8, 9],
|
|
255
|
+
[4, 9, 5],
|
|
256
|
+
[2, 4, 11],
|
|
257
|
+
[6, 2, 10],
|
|
258
|
+
[8, 6, 7],
|
|
259
|
+
[9, 8, 1],
|
|
260
|
+
];
|
|
261
|
+
for (let l = 0; l < Math.floor(level); l++) {
|
|
262
|
+
const cache = new Map();
|
|
263
|
+
const mid = (a, b) => {
|
|
264
|
+
const key = a < b ? `${a},${b}` : `${b},${a}`;
|
|
265
|
+
const hit = cache.get(key);
|
|
266
|
+
if (hit !== undefined)
|
|
267
|
+
return hit;
|
|
268
|
+
const va = verts[a] ?? [0, 0, 0];
|
|
269
|
+
const vb = verts[b] ?? [0, 0, 0];
|
|
270
|
+
verts.push(unit([
|
|
271
|
+
(va[0] ?? 0) + (vb[0] ?? 0),
|
|
272
|
+
(va[1] ?? 0) + (vb[1] ?? 0),
|
|
273
|
+
(va[2] ?? 0) + (vb[2] ?? 0),
|
|
274
|
+
]));
|
|
275
|
+
cache.set(key, verts.length - 1);
|
|
276
|
+
return verts.length - 1;
|
|
277
|
+
};
|
|
278
|
+
const next = [];
|
|
279
|
+
for (const [a = 0, b = 0, c = 0] of faces) {
|
|
280
|
+
const ab = mid(a, b);
|
|
281
|
+
const bc = mid(b, c);
|
|
282
|
+
const ca = mid(c, a);
|
|
283
|
+
next.push([a, ab, ca], [b, bc, ab], [c, ca, bc], [ab, bc, ca]);
|
|
284
|
+
}
|
|
285
|
+
faces = next;
|
|
286
|
+
}
|
|
287
|
+
const out = new SolidWriter();
|
|
288
|
+
const uv = (p) => [
|
|
289
|
+
0.5 + Math.atan2(p[2] ?? 0, p[0] ?? 0) / (2 * Math.PI),
|
|
290
|
+
0.5 + Math.asin(Math.max(-1, Math.min(1, p[1] ?? 0))) / Math.PI,
|
|
291
|
+
];
|
|
292
|
+
if (smooth) {
|
|
293
|
+
for (const p of verts) {
|
|
294
|
+
const [u, v] = uv(p);
|
|
295
|
+
out.vertex((p[0] ?? 0) * radius, (p[1] ?? 0) * radius, (p[2] ?? 0) * radius, p[0] ?? 0, p[1] ?? 0, p[2] ?? 0, u, v);
|
|
296
|
+
}
|
|
297
|
+
/* The table's faces run counter-clockwise seen from outside, as every face here does. */
|
|
298
|
+
for (const [a = 0, b = 0, c = 0] of faces)
|
|
299
|
+
out.triangle(a, b, c);
|
|
300
|
+
return out.finish();
|
|
301
|
+
}
|
|
302
|
+
for (const [a = 0, b = 0, c = 0] of faces) {
|
|
303
|
+
const pa = verts[a] ?? [0, 0, 0];
|
|
304
|
+
const pb = verts[b] ?? [0, 0, 0];
|
|
305
|
+
const pc = verts[c] ?? [0, 0, 0];
|
|
306
|
+
const n = unit([
|
|
307
|
+
((pa[0] ?? 0) + (pb[0] ?? 0) + (pc[0] ?? 0)) / 3,
|
|
308
|
+
((pa[1] ?? 0) + (pb[1] ?? 0) + (pc[1] ?? 0)) / 3,
|
|
309
|
+
((pa[2] ?? 0) + (pb[2] ?? 0) + (pc[2] ?? 0)) / 3,
|
|
310
|
+
]);
|
|
311
|
+
const base = out.vertexCount;
|
|
312
|
+
for (const p of [pa, pb, pc]) {
|
|
313
|
+
const [u, v] = uv(p);
|
|
314
|
+
out.vertex((p[0] ?? 0) * radius, (p[1] ?? 0) * radius, (p[2] ?? 0) * radius, n[0] ?? 0, n[1] ?? 0, n[2] ?? 0, u, v);
|
|
315
|
+
}
|
|
316
|
+
out.triangle(base, base + 1, base + 2);
|
|
317
|
+
}
|
|
318
|
+
return out.finish();
|
|
319
|
+
}
|
|
320
|
+
function unit(p) {
|
|
321
|
+
const len = Math.hypot(p[0] ?? 0, p[1] ?? 0, p[2] ?? 0) || 1;
|
|
322
|
+
return [(p[0] ?? 0) / len, (p[1] ?? 0) / len, (p[2] ?? 0) / len];
|
|
323
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Solid } from './solid.ts';
|
|
2
|
+
export declare class SolidWriter {
|
|
3
|
+
private readonly positions;
|
|
4
|
+
private readonly normals;
|
|
5
|
+
private readonly uvs;
|
|
6
|
+
private readonly indices;
|
|
7
|
+
private count;
|
|
8
|
+
/** Add one vertex and return its index. The normal is taken as given; pass it unit length. */
|
|
9
|
+
vertex(px: number, py: number, pz: number, nx: number, ny: number, nz: number, u: number, v: number): number;
|
|
10
|
+
triangle(a: number, b: number, c: number): void;
|
|
11
|
+
/** Two triangles over a counter-clockwise quad `a b c d`. */
|
|
12
|
+
quad(a: number, b: number, c: number, d: number): void;
|
|
13
|
+
/** How many vertices so far, which is the index the next `vertex` returns. */
|
|
14
|
+
get vertexCount(): number;
|
|
15
|
+
finish(): Solid;
|
|
16
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The accumulator every solid primitive writes through: a vertex at a time, a triangle or a quad at
|
|
3
|
+
* a time, finished into a `Solid`.
|
|
4
|
+
*
|
|
5
|
+
* Internal to the geometry modules and not in the barrel — a caller building geometry of its own
|
|
6
|
+
* wants `MeshBuilder` or typed arrays, and this exists so the primitives share one place that
|
|
7
|
+
* decides how a vertex is laid out.
|
|
8
|
+
*/
|
|
9
|
+
import { GrowableF32, GrowableU32 } from './growable.js';
|
|
10
|
+
export class SolidWriter {
|
|
11
|
+
positions = new GrowableF32();
|
|
12
|
+
normals = new GrowableF32();
|
|
13
|
+
uvs = new GrowableF32();
|
|
14
|
+
indices = new GrowableU32();
|
|
15
|
+
count = 0;
|
|
16
|
+
/** Add one vertex and return its index. The normal is taken as given; pass it unit length. */
|
|
17
|
+
vertex(px, py, pz, nx, ny, nz, u, v) {
|
|
18
|
+
this.positions.push(px, py, pz);
|
|
19
|
+
this.normals.push(nx, ny, nz);
|
|
20
|
+
this.uvs.push(u, v);
|
|
21
|
+
return this.count++;
|
|
22
|
+
}
|
|
23
|
+
triangle(a, b, c) {
|
|
24
|
+
this.indices.push(a, b, c);
|
|
25
|
+
}
|
|
26
|
+
/** Two triangles over a counter-clockwise quad `a b c d`. */
|
|
27
|
+
quad(a, b, c, d) {
|
|
28
|
+
this.indices.push(a, b, c, a, c, d);
|
|
29
|
+
}
|
|
30
|
+
/** How many vertices so far, which is the index the next `vertex` returns. */
|
|
31
|
+
get vertexCount() {
|
|
32
|
+
return this.count;
|
|
33
|
+
}
|
|
34
|
+
finish() {
|
|
35
|
+
return {
|
|
36
|
+
positions: this.positions.toTyped(),
|
|
37
|
+
normals: this.normals.toTyped(),
|
|
38
|
+
uvs: this.uvs.toTyped(),
|
|
39
|
+
indices: this.indices.toTyped(),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -71,6 +71,10 @@ export type { PassAttachmentOptions, PassTarget } from './render/passTarget.ts';
|
|
|
71
71
|
export { generateMipChain, mipLevelCount, type MipPipelines, } from './render/backend/webgpu/surfaceTexturePass.ts';
|
|
72
72
|
export { createPassAttachment } from './render/passTarget.ts';
|
|
73
73
|
export { jitterClip } from './render/recon/jitter.ts';
|
|
74
|
+
export { resolveGlass } from './render/glass.ts';
|
|
75
|
+
export type { GlassOptions, ResolvedGlass } from './render/glass.ts';
|
|
76
|
+
export { createMover } from './render/recon/mover.ts';
|
|
77
|
+
export type { Mover } from './render/recon/mover.ts';
|
|
74
78
|
export type { FrameResource } from './render/frame/index.ts';
|
|
75
79
|
export type { OcclusionOptions } from './render/occlusion.ts';
|
|
76
80
|
export { OcclusionBuffer } from './render/occlusion.ts';
|
|
@@ -119,6 +123,13 @@ export { GLOBAL_FIELD_BLEND, composeGlobalField, createGlobalField, sampleGlobal
|
|
|
119
123
|
export type { FieldSource, GlobalField, GlobalFieldCascade, GlobalFieldInstance, } from './render/gi/globalField.ts';
|
|
120
124
|
export { FIELD_FADE_SEC, LightField } from './render/driftLight/lightField.ts';
|
|
121
125
|
export type { LightFieldOptions, LightFieldSource } from './render/driftLight/lightField.ts';
|
|
126
|
+
export { DENSE_MAX_AXIS, DENSE_MAX_HEIGHT, bakeDenseField, } from './render/driftLight/denseField.ts';
|
|
127
|
+
export type { DenseLightVolume } from './render/driftLight/denseField.ts';
|
|
128
|
+
export { WorldLightField } from './render/driftLight/worldLightField.ts';
|
|
129
|
+
export type { WorldLightFieldOptions } from './render/driftLight/worldLightField.ts';
|
|
130
|
+
export { SURFACE_EFFECT_TEXELS, packSurfaceEffects } from './render/surfaceEffects.ts';
|
|
131
|
+
export type { SurfaceLayerEffect } from './render/surfaceEffects.ts';
|
|
132
|
+
export type { FieldLight } from './render/driftLight/bake.ts';
|
|
122
133
|
export { GI_SCREEN_MARCH, SCREEN_TRACE_BIAS_M, screenRayOrigin, traceScreen, } from './render/gi/traceScreen.ts';
|
|
123
134
|
export { FIELD_MARCH, coneRadiusAt, newFieldHit, traceField } from './render/gi/traceField.ts';
|
|
124
135
|
export type { FieldHit, FieldMarch } from './render/gi/traceField.ts';
|
|
@@ -193,7 +204,7 @@ export type { PrefilterQuality } from './render/prefilterEnvMap.ts';
|
|
|
193
204
|
* `ProbeBakeOptions`, which is the whole of the reasoning.
|
|
194
205
|
*/
|
|
195
206
|
export type { ProbeBakeOptions } from './render/reflectionProbe.ts';
|
|
196
|
-
export type { DirectionalShadowDepthLayers, OutputTransform, RenderQuality, RenderQualityOptions, ShadowFilterTaps, WaterReflectionFilterTaps, } from './render/renderQuality.ts';
|
|
207
|
+
export type { DirectionalShadowDepthLayers, GlassShadows, OutputTransform, RenderQuality, RenderQualityOptions, ShadowFilterTaps, WaterReflectionFilterTaps, } from './render/renderQuality.ts';
|
|
197
208
|
export { MAX_POINT_LIGHTS, SURFACE_TEXTURE_UNIT } from './render/lightBudget.ts';
|
|
198
209
|
export { MAX_CLUSTERED_LIGHTS } from './render/clusteredLights.ts';
|
|
199
210
|
export { SurfaceTexture } from './render/surfaceTexture.ts';
|
|
@@ -209,7 +220,9 @@ export { isWeakGpuFamily } from './render/gpuCapability.ts';
|
|
|
209
220
|
*/
|
|
210
221
|
export { describeGpu } from './render/gpuCapability.ts';
|
|
211
222
|
export type { GpuIdentity, DescribeGpuOptions } from './render/gpuCapability.ts';
|
|
212
|
-
export { DEFAULT_POINT_LIGHT_VIEW_RANGE, createPointLightBuffer, selectPointLights, } from './render/pointLightSelection.ts';
|
|
223
|
+
export { DEFAULT_POINT_LIGHT_VIEW_RANGE, createPointLightBuffer, selectGridLights, selectPointLights, } from './render/pointLightSelection.ts';
|
|
224
|
+
export { LIGHT_GRID_MAX_CELLS, createLightGrid, gatherLights } from './render/lightGrid.ts';
|
|
225
|
+
export type { LightGrid } from './render/lightGrid.ts';
|
|
213
226
|
export type { PointLightBuffer, PointLightSource } from './render/pointLightSelection.ts';
|
|
214
227
|
export { createFlame, flameFrequencyHz, updateFlame } from './render/flameLight.ts';
|
|
215
228
|
export type { Flame, FlameOptions } from './render/flameLight.ts';
|
|
@@ -234,6 +247,14 @@ export { WaterRenderer } from './render/waterRenderer.ts';
|
|
|
234
247
|
export type { WaterBody, WaterBounds, WaterSettings } from './render/waterRenderer.ts';
|
|
235
248
|
export { MeshBuilder } from './geometry/meshBuilder.ts';
|
|
236
249
|
export { concatMeshes, placeMesh } from './geometry/meshConcat.ts';
|
|
250
|
+
export { emptySolid, mergeSolids, solidToMesh, solidVolume, transformSolid, } from './geometry/solid.ts';
|
|
251
|
+
export type { Solid } from './geometry/solid.ts';
|
|
252
|
+
export { solidBox, solidExtrude, solidPrism, solidQuad, solidRoundedBox, solidSweep, } from './geometry/solidFlat.ts';
|
|
253
|
+
export { solidCapsule, solidCone, solidCylinder, solidFrustum, solidHemisphere, solidIcosphere, solidLathe, solidSphere, solidTorus, solidTube, } from './geometry/solidRound.ts';
|
|
254
|
+
export { solidIntersect, solidSubtract, solidUnion } from './geometry/csg.ts';
|
|
255
|
+
export { boxBooleanCells, solidBoxBoolean } from './geometry/boxCsg.ts';
|
|
256
|
+
export type { BoxOperation } from './geometry/boxCsg.ts';
|
|
257
|
+
export { smoothSolidNormals } from './geometry/solidNormals.ts';
|
|
237
258
|
export { generateTangents } from './geometry/tangents.ts';
|
|
238
259
|
export type { MeshBuildOptions } from './geometry/meshBuilder.ts';
|
|
239
260
|
export { Spline, createSplineSample } from './geometry/spline.ts';
|
|
@@ -354,7 +375,9 @@ export type { FlockParams } from './render/flockRenderer.ts';
|
|
|
354
375
|
export { buildTree } from './geometry/treeBuilder.ts';
|
|
355
376
|
export type { TreeParams, TreeGeometry } from './geometry/treeBuilder.ts';
|
|
356
377
|
export type { InstanceData } from './render/instancedMesh.ts';
|
|
357
|
-
export type { MeshInstances } from './render/instances.ts';
|
|
378
|
+
export type { InstancedOptions, MeshInstances } from './render/instances.ts';
|
|
379
|
+
export { batchBoxVisible, cullInstances, instancesBox } from './render/instanceCull.ts';
|
|
380
|
+
export type { BoxOccluder } from './render/instanceCull.ts';
|
|
358
381
|
export type { WindProfile, WindState } from './render/wind.ts';
|
|
359
382
|
export { cellBounds, cellCoord, cellCoordInRange, cellCoordsOf, cellIdFor, cellIdFrom, cellsInFrustum, cellsInRadius, createCellGrid, } from './world/cell.ts';
|
|
360
383
|
export type { CellGrid } from './world/cell.ts';
|
|
@@ -363,3 +386,5 @@ export { cameraPositionFrom, cellPredictor, createCellStream, pumpCellStream, se
|
|
|
363
386
|
export type { CellStore, CellStream, CellStreamOptions } from './world/cellStream.ts';
|
|
364
387
|
export { createFrozenCells, freezeCell, frozenEntities, frozenFingerprintContribution, isCellFrozen, thawCell, } from './world/freeze.ts';
|
|
365
388
|
export type { FreezableWorld, FrozenCell, FrozenCells } from './world/freeze.ts';
|
|
389
|
+
export { HLOD_NONE, HlodSet, createHlodDraws, projectionScaleOf } from './world/hlod.ts';
|
|
390
|
+
export type { HlodDraws, HlodOptions } from './world/hlod.ts';
|
package/dist/index.js
CHANGED
|
@@ -86,6 +86,13 @@ export { createPassAttachment } from './render/passTarget.js';
|
|
|
86
86
|
* resolve finds its geometry where the renderer's own verbs put theirs.
|
|
87
87
|
*/
|
|
88
88
|
export { jitterClip } from './render/recon/jitter.js';
|
|
89
|
+
/*
|
|
90
|
+
* Which object a draw is, for a reconstruction that has to find where it was last frame. See
|
|
91
|
+
* `RendererApi.drawMesh`.
|
|
92
|
+
*/
|
|
93
|
+
/* Glass: a pane that shows what is behind it, clear or frosted. See `TranslucentMeshOptions.glass`. */
|
|
94
|
+
export { resolveGlass } from './render/glass.js';
|
|
95
|
+
export { createMover } from './render/recon/mover.js';
|
|
89
96
|
export { OcclusionBuffer } from './render/occlusion.js';
|
|
90
97
|
/*
|
|
91
98
|
* `Renderer` above stays exported and is not deprecated. `createRenderer` is the way to get
|
|
@@ -173,6 +180,9 @@ export { countSplatTiles, fillSplatTiles, splatPixelBox, splatTileGrid, splatTil
|
|
|
173
180
|
export { GI_SOURCE_FIELD, GI_SOURCE_PROBES, GI_SOURCE_SCREEN, newIndirectResult, traceIndirect, } from './render/gi/chain.js';
|
|
174
181
|
export { GLOBAL_FIELD_BLEND, composeGlobalField, createGlobalField, sampleGlobalField, } from './render/gi/globalField.js';
|
|
175
182
|
export { FIELD_FADE_SEC, LightField } from './render/driftLight/lightField.js';
|
|
183
|
+
export { DENSE_MAX_AXIS, DENSE_MAX_HEIGHT, bakeDenseField, } from './render/driftLight/denseField.js';
|
|
184
|
+
export { WorldLightField } from './render/driftLight/worldLightField.js';
|
|
185
|
+
export { SURFACE_EFFECT_TEXELS, packSurfaceEffects } from './render/surfaceEffects.js';
|
|
176
186
|
export { GI_SCREEN_MARCH, SCREEN_TRACE_BIAS_M, screenRayOrigin, traceScreen, } from './render/gi/traceScreen.js';
|
|
177
187
|
export { FIELD_MARCH, coneRadiusAt, newFieldHit, traceField } from './render/gi/traceField.js';
|
|
178
188
|
export { PROBE_VISIBILITY_SHARPNESS, bakeProbeVisibility, createProbeVisibility, probeUpdateSchedule, probeVisibilityWeight, sampleProbeVolume, visibleProbes, } from './render/gi/probeVolume.js';
|
|
@@ -259,7 +269,8 @@ export { isWeakGpuFamily } from './render/gpuCapability.js';
|
|
|
259
269
|
* which is the right time for a boot log and too late for a decision.
|
|
260
270
|
*/
|
|
261
271
|
export { describeGpu } from './render/gpuCapability.js';
|
|
262
|
-
export { DEFAULT_POINT_LIGHT_VIEW_RANGE, createPointLightBuffer, selectPointLights, } from './render/pointLightSelection.js';
|
|
272
|
+
export { DEFAULT_POINT_LIGHT_VIEW_RANGE, createPointLightBuffer, selectGridLights, selectPointLights, } from './render/pointLightSelection.js';
|
|
273
|
+
export { LIGHT_GRID_MAX_CELLS, createLightGrid, gatherLights } from './render/lightGrid.js';
|
|
263
274
|
export { createFlame, flameFrequencyHz, updateFlame } from './render/flameLight.js';
|
|
264
275
|
export { computeLightMatrix } from './render/lightMatrix.js';
|
|
265
276
|
export { PlumeRenderer } from './render/plumeRenderer.js';
|
|
@@ -299,6 +310,12 @@ export { SMOKE_FRAG } from './render/shaders/smoke.js';
|
|
|
299
310
|
export { WaterRenderer } from './render/waterRenderer.js';
|
|
300
311
|
export { MeshBuilder } from './geometry/meshBuilder.js';
|
|
301
312
|
export { concatMeshes, placeMesh } from './geometry/meshConcat.js';
|
|
313
|
+
export { emptySolid, mergeSolids, solidToMesh, solidVolume, transformSolid, } from './geometry/solid.js';
|
|
314
|
+
export { solidBox, solidExtrude, solidPrism, solidQuad, solidRoundedBox, solidSweep, } from './geometry/solidFlat.js';
|
|
315
|
+
export { solidCapsule, solidCone, solidCylinder, solidFrustum, solidHemisphere, solidIcosphere, solidLathe, solidSphere, solidTorus, solidTube, } from './geometry/solidRound.js';
|
|
316
|
+
export { solidIntersect, solidSubtract, solidUnion } from './geometry/csg.js';
|
|
317
|
+
export { boxBooleanCells, solidBoxBoolean } from './geometry/boxCsg.js';
|
|
318
|
+
export { smoothSolidNormals } from './geometry/solidNormals.js';
|
|
302
319
|
/* A tangent frame, which every map in the material track reads. */
|
|
303
320
|
export { generateTangents } from './geometry/tangents.js';
|
|
304
321
|
export { Spline, createSplineSample } from './geometry/spline.js';
|
|
@@ -467,6 +484,7 @@ export { parseSdfFont } from './render/sdfFont.js';
|
|
|
467
484
|
export { DEFAULT_SDF_TEXT_STYLE, SdfTextLayout } from './render/sdfTextLayout.js';
|
|
468
485
|
export { WindStreakRenderer } from './render/windStreakRenderer.js';
|
|
469
486
|
export { buildTree } from './geometry/treeBuilder.js';
|
|
487
|
+
export { batchBoxVisible, cullInstances, instancesBox } from './render/instanceCull.js';
|
|
470
488
|
/*
|
|
471
489
|
* Large worlds: the cell grid that streams and freezes, and the origin that rendering rebases
|
|
472
490
|
* against while the simulation never does. See `world/rebase.ts` for why that asymmetry is the
|
|
@@ -476,3 +494,4 @@ export { cellBounds, cellCoord, cellCoordInRange, cellCoordsOf, cellIdFor, cellI
|
|
|
476
494
|
export { renderOrigin, toRenderSpace, toWorldSpace } from './world/rebase.js';
|
|
477
495
|
export { cameraPositionFrom, cellPredictor, createCellStream, pumpCellStream, setCellStreamOrigin, } from './world/cellStream.js';
|
|
478
496
|
export { createFrozenCells, freezeCell, frozenEntities, frozenFingerprintContribution, isCellFrozen, thawCell, } from './world/freeze.js';
|
|
497
|
+
export { HLOD_NONE, HlodSet, createHlodDraws, projectionScaleOf } from './world/hlod.js';
|
|
@@ -4,12 +4,13 @@ import type { ReadonlyMat4 } from 'gl-matrix';
|
|
|
4
4
|
import type { MeshData } from '../mesh.ts';
|
|
5
5
|
import type { ProbeBakeOptions } from '../reflectionProbe.ts';
|
|
6
6
|
import type { Renderer, TranslucentMeshOptions } from './webgl2/renderer.ts';
|
|
7
|
-
import type { MeshInstances } from '../instances.ts';
|
|
7
|
+
import type { InstancedOptions, MeshInstances } from '../instances.ts';
|
|
8
8
|
import type { SurfaceMaterial } from '../surfaceTexture.ts';
|
|
9
9
|
import type { TextStyle } from '../textLayout.ts';
|
|
10
10
|
import type { SdfFont } from '../sdfFont.ts';
|
|
11
11
|
import type { SdfTextStyle } from '../sdfTextLayout.ts';
|
|
12
12
|
import type { FrameTimer } from './timer.ts';
|
|
13
|
+
import type { Mover } from '../recon/mover.ts';
|
|
13
14
|
/**
|
|
14
15
|
* Geometry on the device, as something a consumer holds and hands back.
|
|
15
16
|
*
|
|
@@ -174,9 +175,23 @@ export interface MeshOptions {
|
|
|
174
175
|
}
|
|
175
176
|
export type RendererApi = Omit<{
|
|
176
177
|
[K in keyof Renderer]: Renderer[K];
|
|
177
|
-
}, 'gpuTimer' | 'createMesh' | 'createMeshIncremental' | 'updateMesh' | 'drawMesh' | 'disposeMesh' | 'drawTranslucentMesh' | 'drawLightVolume' | 'drawFilm' | 'createScatter' | 'drawScatter' | 'uploadScatter' | 'disposeScatter' | 'createInstanced' | 'uploadInstanced' | 'drawInstanced' | 'drawTranslucentInstanced' | 'disposeInstanced' | 'createWater' | 'drawWater' | 'disposeWater' | 'createPlumes' | 'drawPlumes' | 'disposePlumes' | 'setPlumeScale' | 'createCaustics' | 'drawCaustics' | 'disposeCaustics' | 'createParticles' | 'drawParticles' | 'disposeParticles' | 'createWindStreaks' | 'drawWindStreaks' | 'disposeWindStreaks' | 'createFlock' | 'drawFlock' | 'disposeFlock' | 'createBolts' | 'drawBolts' | 'disposeBolts' | 'createLines' | 'drawLines' | 'disposeLines' | 'createText' | 'setText' | 'setPlate' | 'drawText' | 'textWidth' | 'disposeText' | 'createSdfText' | 'setSdfText' | 'drawSdfText' | 'disposeSdfText' | 'createSurfaceTexture' | 'updateSurfaceTexture' | 'disposeSurfaceTexture' | 'setSurfaceTexture' | 'setMaterial'> & {
|
|
178
|
+
}, 'gpuTimer' | 'createMesh' | 'createMeshIncremental' | 'updateMesh' | 'drawMesh' | 'disposeMesh' | 'drawTranslucentMesh' | 'drawLightVolume' | 'drawFilm' | 'createScatter' | 'drawScatter' | 'uploadScatter' | 'disposeScatter' | 'createInstanced' | 'uploadInstanced' | 'drawInstanced' | 'drawTranslucentInstanced' | 'disposeInstanced' | 'createWater' | 'drawWater' | 'disposeWater' | 'createPlumes' | 'drawPlumes' | 'disposePlumes' | 'setPlumeScale' | 'createCaustics' | 'drawCaustics' | 'disposeCaustics' | 'createParticles' | 'drawParticles' | 'disposeParticles' | 'createWindStreaks' | 'drawWindStreaks' | 'disposeWindStreaks' | 'createFlock' | 'drawFlock' | 'disposeFlock' | 'createBolts' | 'drawBolts' | 'disposeBolts' | 'createLines' | 'drawLines' | 'disposeLines' | 'createText' | 'setText' | 'setPlate' | 'drawText' | 'textWidth' | 'disposeText' | 'createSdfText' | 'setSdfText' | 'drawSdfText' | 'disposeSdfText' | 'createSurfaceTexture' | 'createSurfaceTextureArray' | 'updateSurfaceTexture' | 'disposeSurfaceTexture' | 'setSurfaceTexture' | 'setMaterial'> & {
|
|
178
179
|
/** Upload a caller's image. See `SurfaceTextureHandle` for the boundary this guards. */
|
|
179
180
|
createSurfaceTexture(source: TexImageSource, options?: Parameters<Renderer['createSurfaceTexture']>[1]): SurfaceTextureHandle;
|
|
181
|
+
/**
|
|
182
|
+
* Upload several images of one size as the layers of one array texture.
|
|
183
|
+
*
|
|
184
|
+
* The same handle a single image returns — every surface texture is an array, and a plain image
|
|
185
|
+
* is an array of one — so it goes wherever a texture goes: any map of `setMaterial`. A mesh picks
|
|
186
|
+
* its image per vertex with `MeshData.layers`, and every map of the material is read at that
|
|
187
|
+
* layer, so an albedo array and an emissive array built in one order pair image with glow by
|
|
188
|
+
* index. **A merged mesh wearing many images is then one draw and one material change.**
|
|
189
|
+
*
|
|
190
|
+
* Every image must be the same size: the device allocates one size for every layer, and the
|
|
191
|
+
* refusal names the first image that differs. A layer past the end reads the last one.
|
|
192
|
+
* `updateSurfaceTexture` refuses an array.
|
|
193
|
+
*/
|
|
194
|
+
createSurfaceTextureArray(sources: readonly TexImageSource[], options?: Parameters<Renderer['createSurfaceTexture']>[1]): SurfaceTextureHandle;
|
|
180
195
|
/**
|
|
181
196
|
* Replace a texture's pixels, keeping the GPU object and its sampler state.
|
|
182
197
|
*
|
|
@@ -323,7 +338,7 @@ export type RendererApi = Omit<{
|
|
|
323
338
|
* would wear one expression. Both are refused where the variant is built rather than dropped
|
|
324
339
|
* quietly.
|
|
325
340
|
*/
|
|
326
|
-
createInstanced(mesh: MeshHandle, capacity: number): InstancedHandle;
|
|
341
|
+
createInstanced(mesh: MeshHandle, capacity: number, options?: InstancedOptions): InstancedHandle;
|
|
327
342
|
/**
|
|
328
343
|
* Push placement and colour to the device. Only `data.count` instances are written.
|
|
329
344
|
*
|
|
@@ -466,18 +481,23 @@ export type RendererApi = Omit<{
|
|
|
466
481
|
/** Draw a handle this renderer made. Passing one from the other backend is a caller error. */
|
|
467
482
|
drawMesh(mesh: MeshHandle, model: ReadonlyMat4, depthLayer?: number, tint?: Vec3 | null,
|
|
468
483
|
/**
|
|
469
|
-
* Where this mesh's surface was last frame, for a reconstruction's motion target
|
|
470
|
-
*
|
|
471
|
-
*
|
|
472
|
-
*
|
|
473
|
-
*
|
|
474
|
-
*
|
|
475
|
-
*
|
|
476
|
-
*
|
|
477
|
-
*
|
|
478
|
-
*
|
|
484
|
+
* Where this mesh's surface was last frame, for a reconstruction's motion target: a `Mover`,
|
|
485
|
+
* or last frame's model matrix.
|
|
486
|
+
*
|
|
487
|
+
* **A `Mover` is the ordinary answer.** Make one per moving object with `createMover()` and pass
|
|
488
|
+
* it with every draw of that object; the renderer keeps last frame's model and, for a skinned
|
|
489
|
+
* draw, last frame's palette. A matrix still works exactly as it always has: the *model* matrix
|
|
490
|
+
* this mesh was drawn with last frame, not a velocity, so a rotation and a scale are as correct
|
|
491
|
+
* as a translation. Null and omitted mean the same thing: the camera's motion, derived from the
|
|
492
|
+
* depth, which is exactly right for anything that did not move and wrong in proportion to how
|
|
493
|
+
* far a mover moved.
|
|
494
|
+
*
|
|
495
|
+
* **Only a reconstruction reads it**, and only on WebGPU. A mover drawn twice in one frame is
|
|
496
|
+
* two objects wearing one identity: the second draw is warned about once and records no motion.
|
|
497
|
+
* Instanced batches and meshes rewritten with `updateMesh` need none — the batch and the mesh
|
|
498
|
+
* are their own identity.
|
|
479
499
|
*/
|
|
480
|
-
previousModel?: ReadonlyMat4 | null): void;
|
|
500
|
+
previousModel?: ReadonlyMat4 | Mover | null): void;
|
|
481
501
|
/** Release the geometry behind a handle. */
|
|
482
502
|
disposeMesh(mesh: MeshHandle): void;
|
|
483
503
|
/**
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How a draw meets the medium between it and the eye: the value of the mesh shader's
|
|
3
|
+
* `uFogEnabled`, which both backends write from this one rule.
|
|
4
|
+
*
|
|
5
|
+
* **A surface recedes into the medium; light added to the frame fades in it.** A surface that
|
|
6
|
+
* covers what is behind it is mixed toward the medium's colour with distance, which is the haze
|
|
7
|
+
* standing in front of it. An additive draw covers nothing: what is behind it has already been
|
|
8
|
+
* fogged, and mixing the draw toward the medium's colour and then *adding* it puts that haze into
|
|
9
|
+
* the frame a second time. So a glow by day added the sky's grey in the shape of the glow, and
|
|
10
|
+
* added more of it the thicker the air — reported as solid grey cones under every street lamp on
|
|
11
|
+
* a hazy morning. Faded instead, added light loses what the medium scatters out of it and adds
|
|
12
|
+
* nothing of its own, which is how the same shader already treats the glow behind frosted glass.
|
|
13
|
+
*
|
|
14
|
+
* What fading gives up is the one thing mixing did for a glow: at great distance it disappears
|
|
15
|
+
* into the air instead of greying into it. That is what light in fog does. What would make it
|
|
16
|
+
* wrong is an additive draw standing for *lit air* rather than light — and that is what
|
|
17
|
+
* `drawLightVolume` is for, which is fogged by neither rule.
|
|
18
|
+
*/
|
|
19
|
+
/** Out of the medium entirely: `TranslucentMeshOptions.fog` set to false. */
|
|
20
|
+
export declare const FOG_OFF = 0;
|
|
21
|
+
/** Mixed toward the medium's colour with distance: every surface, and the pass's default. */
|
|
22
|
+
export declare const FOG_RECEDE = 1;
|
|
23
|
+
/** Scaled down by what the medium scatters and given none of its colour: added light. */
|
|
24
|
+
export declare const FOG_FADE = 2;
|
|
25
|
+
/** The medium rule for a draw that asked for fog or not, and adds its light or covers. */
|
|
26
|
+
export declare function fogModeOf(fog: boolean, additive: boolean): number;
|