@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,31 @@
|
|
|
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
|
+
|
|
20
|
+
/** Out of the medium entirely: `TranslucentMeshOptions.fog` set to false. */
|
|
21
|
+
export const FOG_OFF = 0;
|
|
22
|
+
/** Mixed toward the medium's colour with distance: every surface, and the pass's default. */
|
|
23
|
+
export const FOG_RECEDE = 1;
|
|
24
|
+
/** Scaled down by what the medium scatters and given none of its colour: added light. */
|
|
25
|
+
export const FOG_FADE = 2;
|
|
26
|
+
|
|
27
|
+
/** The medium rule for a draw that asked for fog or not, and adds its light or covers. */
|
|
28
|
+
export function fogModeOf(fog: boolean, additive: boolean): number {
|
|
29
|
+
if (!fog) return FOG_OFF;
|
|
30
|
+
return additive ? FOG_FADE : FOG_RECEDE;
|
|
31
|
+
}
|
|
@@ -18,11 +18,14 @@
|
|
|
18
18
|
* slot on the backend that keeps slots, and comparing every field would cost more than the slot.
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
+
import { FOG_RECEDE } from './drawFog.ts';
|
|
22
|
+
|
|
21
23
|
/** What of a draw's own options its material carries. */
|
|
22
24
|
export interface DrawMaterialOptions {
|
|
23
25
|
readonly opacity: number;
|
|
24
26
|
readonly lit: boolean;
|
|
25
|
-
|
|
27
|
+
/** How it meets the medium, as `fogModeOf` says; the pass's own is `FOG_RECEDE`. */
|
|
28
|
+
readonly fog: number;
|
|
26
29
|
readonly toneMapped: boolean;
|
|
27
30
|
/** Whether the draw refracts this time, which a backend decides by whether it has a snapshot. */
|
|
28
31
|
readonly refracting: boolean;
|
|
@@ -31,7 +34,11 @@ export interface DrawMaterialOptions {
|
|
|
31
34
|
/** Whether a draw's options differ from the pass's, so it takes a material and leaves one to restore. */
|
|
32
35
|
export function ownsMaterial(options: DrawMaterialOptions): boolean {
|
|
33
36
|
return (
|
|
34
|
-
options.opacity < 1 ||
|
|
37
|
+
options.opacity < 1 ||
|
|
38
|
+
!options.lit ||
|
|
39
|
+
options.fog !== FOG_RECEDE ||
|
|
40
|
+
!options.toneMapped ||
|
|
41
|
+
options.refracting
|
|
35
42
|
);
|
|
36
43
|
}
|
|
37
44
|
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The five programs a pane casts its colour through, one per way a caster is drawn, compiled the
|
|
3
|
+
* first time glass casts — so a scene with no glass compiles none of them.
|
|
4
|
+
*
|
|
5
|
+
* The vertex stages are the depth pass's with the world position handed on (`depth.ts`), so a
|
|
6
|
+
* pane's colour lands exactly where its depth does; the fragment is `paneTexel` for the device.
|
|
7
|
+
*/
|
|
8
|
+
import { compileProgram, uniformLocations } from '../../shader.ts';
|
|
9
|
+
import {
|
|
10
|
+
GLASS_TINT_CUTOUT_FRAG,
|
|
11
|
+
GLASS_TINT_CUTOUT_VERT,
|
|
12
|
+
GLASS_TINT_FRAG,
|
|
13
|
+
GLASS_TINT_INSTANCED_CUTOUT_VERT,
|
|
14
|
+
GLASS_TINT_INSTANCED_VERT,
|
|
15
|
+
GLASS_TINT_SKINNED_VERT,
|
|
16
|
+
GLASS_TINT_VERT,
|
|
17
|
+
} from '../../shaders/depth.ts';
|
|
18
|
+
|
|
19
|
+
export interface GlassTintProgram {
|
|
20
|
+
readonly program: WebGLProgram;
|
|
21
|
+
readonly uniforms: Record<string, WebGLUniformLocation>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export class GlassTintPrograms {
|
|
25
|
+
readonly rigid: GlassTintProgram;
|
|
26
|
+
readonly instanced: GlassTintProgram;
|
|
27
|
+
readonly skinned: GlassTintProgram;
|
|
28
|
+
readonly cutout: GlassTintProgram;
|
|
29
|
+
readonly instancedCutout: GlassTintProgram;
|
|
30
|
+
|
|
31
|
+
constructor(gl: WebGL2RenderingContext) {
|
|
32
|
+
const build = (vert: string, frag: string, label: string): GlassTintProgram => {
|
|
33
|
+
const program = compileProgram(gl, vert, frag, label);
|
|
34
|
+
return { program, uniforms: uniformLocations(gl, program, label) };
|
|
35
|
+
};
|
|
36
|
+
this.rigid = build(GLASS_TINT_VERT, GLASS_TINT_FRAG, 'glassTint');
|
|
37
|
+
this.instanced = build(GLASS_TINT_INSTANCED_VERT, GLASS_TINT_FRAG, 'glassTint.instanced');
|
|
38
|
+
this.skinned = build(GLASS_TINT_SKINNED_VERT, GLASS_TINT_FRAG, 'glassTint.skinned');
|
|
39
|
+
this.cutout = build(GLASS_TINT_CUTOUT_VERT, GLASS_TINT_CUTOUT_FRAG, 'glassTint.cutout');
|
|
40
|
+
this.instancedCutout = build(
|
|
41
|
+
GLASS_TINT_INSTANCED_CUTOUT_VERT,
|
|
42
|
+
GLASS_TINT_CUTOUT_FRAG,
|
|
43
|
+
'glassTint.instancedCutout',
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
dispose(gl: WebGL2RenderingContext): void {
|
|
48
|
+
for (const { program } of [
|
|
49
|
+
this.rigid,
|
|
50
|
+
this.instanced,
|
|
51
|
+
this.skinned,
|
|
52
|
+
this.cutout,
|
|
53
|
+
this.instancedCutout,
|
|
54
|
+
]) {
|
|
55
|
+
gl.deleteProgram(program);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -1,38 +1,66 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { cullInstances, instancesBox } from '../../instanceCull.ts';
|
|
2
|
+
import {
|
|
3
|
+
INSTANCE_FLOATS,
|
|
4
|
+
INSTANCE_STRIDE,
|
|
5
|
+
createMeshInstances,
|
|
6
|
+
packInstances,
|
|
7
|
+
} from '../../instances.ts';
|
|
2
8
|
import type { MeshInstances } from '../../instances.ts';
|
|
3
9
|
import type { Mesh } from '../../mesh.ts';
|
|
10
|
+
import type { FrustumPlanes } from '../../../math/frustum.ts';
|
|
4
11
|
|
|
5
12
|
/**
|
|
6
|
-
* One mesh
|
|
13
|
+
* One batch of a mesh: its per-instance buffer and a vertex array of its own.
|
|
7
14
|
*
|
|
8
15
|
* The twin of the WebGPU batch and deliberately the same shape, because which floats go where is
|
|
9
|
-
* a decision shared through `instances.ts` and only the binding is per-backend.
|
|
16
|
+
* a decision shared through `instances.ts` and only the binding is per-backend. The vertex array is
|
|
17
|
+
* the batch's rather than the mesh's (`Mesh.createInstanceArray`), which is what lets one mesh carry
|
|
18
|
+
* a batch per region.
|
|
10
19
|
*
|
|
11
|
-
*
|
|
20
|
+
* **A culling batch holds a second buffer and array**, for the instances `cullInstances` keeps each
|
|
21
|
+
* camera draw. The full set stays in the first, because a shadow pass, a mirror and a probe each
|
|
22
|
+
* see a different part of the batch than the camera does, and they draw from it.
|
|
23
|
+
*
|
|
24
|
+
* Staging arrays are allocated here and rewritten in place, so a frame re-uploading or re-culling a
|
|
12
25
|
* batch allocates nothing.
|
|
13
26
|
*/
|
|
14
27
|
export class InstancedBatch {
|
|
15
28
|
readonly mesh: Mesh;
|
|
16
29
|
readonly capacity: number;
|
|
30
|
+
/** Whether the camera draw culls this batch. See `InstancedOptions.cull`. */
|
|
31
|
+
readonly cull: boolean;
|
|
32
|
+
/** The world box around every live instance, fitted at upload. See `instancesBox`. */
|
|
33
|
+
readonly box = new Float32Array([1, 1, 1, -1, -1, -1]);
|
|
17
34
|
private readonly buffer: WebGLBuffer;
|
|
35
|
+
private readonly vao: WebGLVertexArrayObject;
|
|
18
36
|
private readonly staging: Float32Array;
|
|
37
|
+
private readonly kept: {
|
|
38
|
+
readonly buffer: WebGLBuffer;
|
|
39
|
+
readonly vao: WebGLVertexArrayObject;
|
|
40
|
+
readonly instances: MeshInstances;
|
|
41
|
+
} | null;
|
|
19
42
|
|
|
20
|
-
constructor(gl: WebGL2RenderingContext, mesh: Mesh, capacity: number) {
|
|
21
|
-
const buffer = gl.createBuffer();
|
|
22
|
-
if (buffer === null) throw new Error('InstancedBatch: createBuffer failed');
|
|
43
|
+
constructor(gl: WebGL2RenderingContext, mesh: Mesh, capacity: number, cull = false) {
|
|
23
44
|
this.mesh = mesh;
|
|
24
45
|
this.capacity = capacity;
|
|
25
|
-
this.
|
|
46
|
+
this.cull = cull;
|
|
26
47
|
this.staging = new Float32Array(capacity * INSTANCE_FLOATS);
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
48
|
+
this.buffer = allocate(gl, capacity);
|
|
49
|
+
this.vao = mesh.createInstanceArray(gl, this.buffer, INSTANCE_STRIDE);
|
|
50
|
+
if (cull) {
|
|
51
|
+
const buffer = allocate(gl, capacity);
|
|
52
|
+
this.kept = {
|
|
53
|
+
buffer,
|
|
54
|
+
vao: mesh.createInstanceArray(gl, buffer, INSTANCE_STRIDE),
|
|
55
|
+
instances: createMeshInstances(capacity),
|
|
56
|
+
};
|
|
57
|
+
} else {
|
|
58
|
+
this.kept = null;
|
|
59
|
+
}
|
|
32
60
|
}
|
|
33
61
|
|
|
34
|
-
/** Pack and push the live prefix, in one call. */
|
|
35
62
|
upload(gl: WebGL2RenderingContext, data: MeshInstances): void {
|
|
63
|
+
if (this.cull) instancesBox(data, this.mesh.bounds, this.box);
|
|
36
64
|
const count = Math.min(data.count, this.capacity);
|
|
37
65
|
if (count === 0) return;
|
|
38
66
|
packInstances(data, this.staging);
|
|
@@ -40,7 +68,45 @@ export class InstancedBatch {
|
|
|
40
68
|
gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.staging, 0, count * INSTANCE_FLOATS);
|
|
41
69
|
}
|
|
42
70
|
|
|
71
|
+
/** Draw the first `count` uploaded instances: every draw but a culling camera draw. */
|
|
72
|
+
draw(gl: WebGL2RenderingContext, count: number): void {
|
|
73
|
+
this.mesh.drawInstancesThrough(gl, this.vao, count);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Cull `data` against `frustum`, upload what survives into the second buffer and draw it. Returns
|
|
78
|
+
* how many were drawn — 0 draws nothing. Only for a batch made with `cull`.
|
|
79
|
+
*/
|
|
80
|
+
drawCulled(gl: WebGL2RenderingContext, data: MeshInstances, frustum: FrustumPlanes): number {
|
|
81
|
+
const kept = this.kept;
|
|
82
|
+
if (kept === null) return 0;
|
|
83
|
+
const count = cullInstances(data, this.mesh.bounds, frustum, kept.instances);
|
|
84
|
+
if (count === 0) return 0;
|
|
85
|
+
packInstances(kept.instances, this.staging);
|
|
86
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, kept.buffer);
|
|
87
|
+
gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.staging, 0, count * INSTANCE_FLOATS);
|
|
88
|
+
this.mesh.drawInstancesThrough(gl, kept.vao, count);
|
|
89
|
+
return count;
|
|
90
|
+
}
|
|
91
|
+
|
|
43
92
|
dispose(gl: WebGL2RenderingContext): void {
|
|
93
|
+
gl.deleteVertexArray(this.vao);
|
|
44
94
|
gl.deleteBuffer(this.buffer);
|
|
95
|
+
if (this.kept !== null) {
|
|
96
|
+
gl.deleteVertexArray(this.kept.vao);
|
|
97
|
+
gl.deleteBuffer(this.kept.buffer);
|
|
98
|
+
}
|
|
45
99
|
}
|
|
46
100
|
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* An instance buffer sized to capacity. `DYNAMIC_DRAW` because a batch of vehicles is rewritten
|
|
104
|
+
* every frame — advisory, but a driver told the truth can place the buffer where a rewrite is cheap.
|
|
105
|
+
*/
|
|
106
|
+
function allocate(gl: WebGL2RenderingContext, capacity: number): WebGLBuffer {
|
|
107
|
+
const buffer = gl.createBuffer();
|
|
108
|
+
if (buffer === null) throw new Error('InstancedBatch: createBuffer failed');
|
|
109
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
110
|
+
gl.bufferData(gl.ARRAY_BUFFER, Math.max(1, capacity) * INSTANCE_STRIDE, gl.DYNAMIC_DRAW);
|
|
111
|
+
return buffer;
|
|
112
|
+
}
|