@threenative/core 0.3.13 → 0.3.15
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/capabilities.json +299 -10
- package/dist/{chunk-4SRAQFTU.js → chunk-2GPHICV6.js} +1 -1
- package/dist/{chunk-DIPIJICH.js → chunk-GEMQJBY4.js} +70 -18
- package/dist/{chunk-EFWZWLPY.js → chunk-QAMSM3Z5.js} +354 -12
- package/dist/{chunk-SV4QVUTQ.js → chunk-QAQHYOWY.js} +1 -1
- package/dist/{chunk-EEABDLUC.js → chunk-VBBYWGAT.js} +2 -2
- package/dist/{chunk-GYUZJQ7U.js → chunk-VQRPEOKY.js} +4 -1
- package/dist/index.d.ts +605 -7
- package/dist/index.js +1973 -609
- package/dist/playtest.js +3 -3
- package/dist/{quality-BYqKGAwo.d.ts → quality-BADStsTn.d.ts} +2 -2
- package/dist/render-environment.d.ts +1 -1
- package/dist/ui-layer.js +2 -2
- package/dist/worker.js +2 -2
- package/dist/world.d.ts +13 -3
- package/dist/world.js +179 -36
- package/mcp/animation-server.mjs +1 -1
- package/mcp/engine-server.mjs +32 -6
- package/mcp/servers.mjs +3 -3
- package/package.json +5 -5
- package/scripts/ensure-mcp.mjs +6 -1
- package/src/clustered-batch.ts +146 -3
- package/src/clustered-mesh.ts +548 -20
- package/src/debug.ts +16 -0
- package/src/displaced-surface.ts +428 -0
- package/src/frame-budget.ts +16 -0
- package/src/generated/console-markers.ts +1 -0
- package/src/grass-field.ts +628 -0
- package/src/index.ts +112 -0
- package/src/render/material-key.ts +21 -1
- package/src/render/screen-probe-gather.ts +303 -0
- package/src/render/short-range-ao.ts +274 -0
- package/src/render/world-impostor-surface.ts +98 -3
- package/src/render-camera-cull.ts +9 -3
- package/src/renderer.ts +26 -4
- package/src/scatter-field.ts +496 -0
- package/src/startup-offscreen-bytes.ts +11 -5
- package/src/state.ts +16 -3
- package/src/static-transform.ts +75 -6
- package/src/tile-ring.ts +294 -0
- package/src/version.ts +1 -1
- package/src/warmup.ts +15 -2
- package/src/world-cell-batches.ts +4 -0
- package/src/world-cell-data.ts +7 -0
- package/src/world-cell-models.ts +36 -8
- package/src/world-cell-render-gpu-dress.ts +4 -2
- package/src/world-cell-render-util.ts +2 -2
- package/src/world-cells.ts +1 -1
- package/src/world-river-ribbon.ts +13 -22
- package/src/world-water-bodies.ts +113 -3
package/dist/index.js
CHANGED
|
@@ -1,31 +1,32 @@
|
|
|
1
|
-
import { onUiIntent, publishUiState } from './chunk-
|
|
2
|
-
import { installQuietMarkers, uninstallQuietMarkers } from './chunk-
|
|
3
|
-
import { animationPacketReaders, animationPacketTimeReaders, trackAnimationRate, animationPacketTime, animationPacketMethodsPristine, untrackAnimationRate, beginSpan, SPANS, endSpan, autoBatchOf, isAutoBatchMerged, spanRecorder, DEFAULT_CLIP_EXTENTS, DEFAULT_MAX_LEVEL_RATIO, clipLadder, VIRTUAL_SHADOW_MOVER_LAYER, VIRTUAL_SHADOW_WIDE_CASTER_LAYER, VIRTUAL_SHADOW_KEY_LAYER, VIRTUAL_SHADOW_CASTER_LAYER, VIRTUAL_SHADOW_SMALL_CASTER_LAYER, frustumPlanes, rendererFacts, animationPacketField, DEFAULT_TARGET_FPS, worldSilencedByFreeze, composeSilencedByFreeze, isStatic, prepareSceneEnvironment, STARTUP_COMPILE_BUDGET_MS, warmUpComputeNodes, createAssetLoader, AutoBatch, RenderCameraCull, StartupReadiness, measureStartupOffscreenBytes, STARTUP_OFFSCREEN_BYTES_MARKER, reportUnusedModelsLater, warmUpSceneWithCompletion, resolveTargetFps, SpanRecorder, formatSpansWindow, staticTransformCensus, STATIC_TRANSFORM_MARKER, spansRequested, setSpanRecorder, noteSliceFrame, refreshStaticTransforms, spanNow, addSpan, drawWorld, staticRoots, endSliceFrames, warmUpScene, createProjectionScanWorkspace, scanProjection, isRenderable, releaseProjectionScanWorkspace, STARTUP_STALL_MS, sceneNeedsEnvironmentPreparation, STARTUP_STABLE_WINDOW_MS, geometryVersionSum, hasRenderHook, uniformUnchanged, isSimilarityTransform, SkinnedBatch, isLight, baseColorOf, observeAnimationRates, displacesVertices, hasMorphAttributes, MIN_BATCH_MEMBERS } from './chunk-
|
|
4
|
-
export { ASSET_LATE_MARKER, DEFAULT_TARGET_FPS, InstancedBatch, MAX_TARGET_FPS, SPANS, SPANS_FLAG, SPANS_MARKER, SPAN_COUNT, SPAN_NAMES, STATIC_TRANSFORM_MARKER, SpanRecorder, VIRTUAL_SHADOW_CASTER_LAYER, VIRTUAL_SHADOW_MOVER_LAYER, VIRTUAL_SHADOW_WIDE_CASTER_LAYER, addInSlices, addSpan, alwaysRender, beginSpan, createAssetLoader, endSpan, fetchAsset, formatSpansWindow, invalidateStatic, isStatic, loadAll, markStatic, mergeByMaterial, mergeParts, reconcileMirroredClips, refreshStaticTransforms, resetStaticTransforms, resolveTargetFps, setSpanRecorder, snapRefreshRate, spanNow, spanRecorder, spansRequested, staticTransformCensus, unmarkStatic, warmUpScene } from './chunk-
|
|
1
|
+
import { onUiIntent, publishUiState } from './chunk-2GPHICV6.js';
|
|
2
|
+
import { installQuietMarkers, uninstallQuietMarkers } from './chunk-QAQHYOWY.js';
|
|
3
|
+
import { animationPacketReaders, animationPacketTimeReaders, trackAnimationRate, animationPacketTime, animationPacketMethodsPristine, untrackAnimationRate, beginSpan, SPANS, endSpan, autoBatchOf, isAutoBatchMerged, spanRecorder, DEFAULT_CLIP_EXTENTS, DEFAULT_MAX_LEVEL_RATIO, clipLadder, VIRTUAL_SHADOW_MOVER_LAYER, VIRTUAL_SHADOW_WIDE_CASTER_LAYER, VIRTUAL_SHADOW_KEY_LAYER, VIRTUAL_SHADOW_CASTER_LAYER, VIRTUAL_SHADOW_SMALL_CASTER_LAYER, frustumPlanes, rendererFacts, animationPacketField, DEFAULT_TARGET_FPS, worldSilencedByFreeze, composeSilencedByFreeze, isStatic, prepareSceneEnvironment, STARTUP_COMPILE_BUDGET_MS, warmUpComputeNodes, createAssetLoader, AutoBatch, RenderCameraCull, StartupReadiness, measureStartupOffscreenBytes, STARTUP_OFFSCREEN_BYTES_MARKER, reportUnusedModelsLater, warmUpSceneWithCompletion, resolveTargetFps, SpanRecorder, formatSpansWindow, staticTransformCensus, STATIC_TRANSFORM_MARKER, spansRequested, setSpanRecorder, noteSliceFrame, refreshStaticTransforms, spanNow, addSpan, drawWorld, staticRoots, endSliceFrames, warmUpScene, createProjectionScanWorkspace, scanProjection, isRenderable, releaseProjectionScanWorkspace, STARTUP_STALL_MS, sceneNeedsEnvironmentPreparation, STARTUP_STABLE_WINDOW_MS, geometryVersionSum, hasRenderHook, uniformUnchanged, isSimilarityTransform, SkinnedBatch, isLight, baseColorOf, observeAnimationRates, displacesVertices, hasMorphAttributes, MIN_BATCH_MEMBERS } from './chunk-GEMQJBY4.js';
|
|
4
|
+
export { ASSET_LATE_MARKER, DEFAULT_TARGET_FPS, InstancedBatch, MAX_TARGET_FPS, SPANS, SPANS_FLAG, SPANS_MARKER, SPAN_COUNT, SPAN_NAMES, STATIC_TRANSFORM_MARKER, SpanRecorder, VIRTUAL_SHADOW_CASTER_LAYER, VIRTUAL_SHADOW_MOVER_LAYER, VIRTUAL_SHADOW_WIDE_CASTER_LAYER, addInSlices, addSpan, alwaysRender, beginSpan, createAssetLoader, endSpan, fetchAsset, formatSpansWindow, invalidateStatic, isStatic, loadAll, markStatic, mergeByMaterial, mergeParts, reconcileMirroredClips, refreshStaticTransforms, resetStaticTransforms, resolveTargetFps, setSpanRecorder, snapRefreshRate, spanNow, spanRecorder, spansRequested, staticTransformCensus, unmarkStatic, warmUpScene } from './chunk-GEMQJBY4.js';
|
|
5
5
|
export { CameraShake, GPUParticles3D } from './chunk-H4J6IAJE.js';
|
|
6
6
|
import { GPUReadback } from './chunk-QWJEMUUT.js';
|
|
7
7
|
export { GPUReadback } from './chunk-QWJEMUUT.js';
|
|
8
8
|
export { addFoliageBackLight } from './chunk-GXY7B3JG.js';
|
|
9
|
-
import { CORE_VERSION, RENDER_CHAIN_TIERS, publishDirectRenderChainReport, FrameCounters, counterDeviceOf, createCrossingReader, createEngineCounterReader, VelocityTracker, createPipelineCensus, isBatchedMeshVelocityPatched, ensureBatchedMeshVelocity, setBatchedMeshMatrixWithVelocity, setBatchedMeshPreviousMatrix, disposeBatchedMeshVelocity, RenderChain } from './chunk-
|
|
10
|
-
export { DEFAULT_PIPELINE_CENSUS_LIMIT, FrameCounters, PIPELINE_CENSUS_CAPABILITY, PIPELINE_CENSUS_VERSION, PipelineCensus, RENDER_CHAIN_MARKER, RENDER_CHAIN_STAGE_ORDER, RENDER_CHAIN_TIERS, RenderChain, VELOCITY_OUTPUT_NAME, VELOCITY_PREVIOUS_BONE_MATRICES, VELOCITY_PREVIOUS_INSTANCE_MATRICES, VELOCITY_PREVIOUS_WORLD_MATRIX, VelocityTracker, counterDeviceOf, createPipelineCensus, ensureVelocityOutput, readRenderChainObservation, readRenderChainReport, readVelocityPreviousBoneMatrices, readVelocityPreviousMatrices, readVelocityPreviousWorldMatrix, velocityTexture, withVelocityContext } from './chunk-
|
|
11
|
-
import { isLodJoinProxy, baseGeometryOf, pixelsPerUnit, selectClusterCut, lodChainOf, GeometryCapture, updateClusteredMeshes, updateModelLods, rendererBackendIdentity } from './chunk-
|
|
12
|
-
export { ClusteredMesh, DISCRETE_LOD_DEFAULT_ERROR_PIXELS, DISCRETE_LOD_DEFAULT_HYSTERESIS, GEOMETRY_ASSET_KEY, GEOMETRY_CAPTURE_DEFAULT_LIMIT, GEOMETRY_CAPTURE_MAX_LIMIT, GEOMETRY_CAPTURE_SORTS, GEOMETRY_CAPTURE_TIMEOUT_MS, GEOMETRY_CAPTURE_WALK_CAP, baseGeometryOf, isStreamedGeometry, lodChainOf, lodPixelScale, updateClusteredMeshes, updateModelLods } from './chunk-
|
|
13
|
-
import { debugRequested, countDebug, formatDebugReport, debugHotCalls, readLaunchFlag, observeDebugGc, measureDebug } from './chunk-
|
|
14
|
-
export { debugFlag, exposeDebug } from './chunk-
|
|
9
|
+
import { CORE_VERSION, RENDER_CHAIN_TIERS, publishDirectRenderChainReport, FrameCounters, counterDeviceOf, createCrossingReader, createEngineCounterReader, VelocityTracker, createPipelineCensus, isBatchedMeshVelocityPatched, ensureBatchedMeshVelocity, setBatchedMeshMatrixWithVelocity, setBatchedMeshPreviousMatrix, disposeBatchedMeshVelocity, RenderChain } from './chunk-VBBYWGAT.js';
|
|
10
|
+
export { DEFAULT_PIPELINE_CENSUS_LIMIT, FrameCounters, PIPELINE_CENSUS_CAPABILITY, PIPELINE_CENSUS_VERSION, PipelineCensus, RENDER_CHAIN_MARKER, RENDER_CHAIN_STAGE_ORDER, RENDER_CHAIN_TIERS, RenderChain, VELOCITY_OUTPUT_NAME, VELOCITY_PREVIOUS_BONE_MATRICES, VELOCITY_PREVIOUS_INSTANCE_MATRICES, VELOCITY_PREVIOUS_WORLD_MATRIX, VelocityTracker, counterDeviceOf, createPipelineCensus, ensureVelocityOutput, readRenderChainObservation, readRenderChainReport, readVelocityPreviousBoneMatrices, readVelocityPreviousMatrices, readVelocityPreviousWorldMatrix, velocityTexture, withVelocityContext } from './chunk-VBBYWGAT.js';
|
|
11
|
+
import { isLodJoinProxy, baseGeometryOf, ClusterView, DEFAULT_VIEW_MARGIN, assertViewMargin, clusterTableRadius, pixelsPerUnit, worldFrustum, outsideFrustum, selectClusterCut, lodChainOf, GeometryCapture, updateClusteredMeshes, updateModelLods, rendererBackendIdentity } from './chunk-QAMSM3Z5.js';
|
|
12
|
+
export { ClusteredMesh, DISCRETE_LOD_DEFAULT_ERROR_PIXELS, DISCRETE_LOD_DEFAULT_HYSTERESIS, GEOMETRY_ASSET_KEY, GEOMETRY_CAPTURE_DEFAULT_LIMIT, GEOMETRY_CAPTURE_MAX_LIMIT, GEOMETRY_CAPTURE_SORTS, GEOMETRY_CAPTURE_TIMEOUT_MS, GEOMETRY_CAPTURE_WALK_CAP, baseGeometryOf, isStreamedGeometry, lodChainOf, lodPixelScale, updateClusteredMeshes, updateModelLods } from './chunk-QAMSM3Z5.js';
|
|
13
|
+
import { debugRequested, countDebug, formatDebugReport, debugHotCalls, readLaunchFlag, observeDebugGc, measureDebug } from './chunk-VQRPEOKY.js';
|
|
14
|
+
export { debugFlag, debugValue, exposeDebug } from './chunk-VQRPEOKY.js';
|
|
15
15
|
export { AudioBus, resetAudioCueLedger } from './chunk-U4YHUKKL.js';
|
|
16
16
|
import { getPlatform, hostDocument, hostWindow, hostResizeObserver } from './chunk-XDTZ4QMO.js';
|
|
17
17
|
export { getPlatform, isConsole, isMobile, isNative, isPs4, isTouchscreenAvailable, isWeb } from './chunk-XDTZ4QMO.js';
|
|
18
18
|
import { devGlobal, DEV_GLOBAL_KEY } from './chunk-VP43GIWW.js';
|
|
19
19
|
export { DEV_GLOBAL_KEY, devGlobal, publishDevGlobal } from './chunk-VP43GIWW.js';
|
|
20
20
|
import { UI_DEV_METRICS_MESSAGE, UI_STARTUP_MESSAGE, connectUiBridge, UI_READY_INTENT } from './chunk-CFGTPFUH.js';
|
|
21
|
-
import { Vector3, Matrix4, Object3D, RGB_S3TC_DXT1_Format, RGBA_S3TC_DXT1_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT5_Format, RED_RGTC1_Format, SIGNED_RED_RGTC1_Format, RED_GREEN_RGTC2_Format, SIGNED_RED_GREEN_RGTC2_Format, RGBA_BPTC_Format, RGB_BPTC_SIGNED_Format, RGB_BPTC_UNSIGNED_Format, RGB_ETC2_Format, RGB_ETC1_Format, RGBA_ETC2_EAC_Format, R11_EAC_Format, SIGNED_R11_EAC_Format, RG11_EAC_Format, SIGNED_RG11_EAC_Format, RGBA_ASTC_4x4_Format, RGBA_ASTC_5x4_Format, RGBA_ASTC_5x5_Format, RGBA_ASTC_6x5_Format, RGBA_ASTC_6x6_Format, RGBA_ASTC_8x5_Format, RGBA_ASTC_8x6_Format, RGBA_ASTC_8x8_Format, RGBA_ASTC_10x5_Format, RGBA_ASTC_10x6_Format, RGBA_ASTC_10x8_Format, RGBA_ASTC_10x10_Format, RGBA_ASTC_12x10_Format, RGBA_ASTC_12x12_Format, Matrix3, NoToneMapping, NeutralToneMapping, AgXToneMapping, ACESFilmicToneMapping, Scene, OrthographicCamera, Sphere, Box3, Quaternion, AnimationMixer, MathUtils, LoopOnce, LoopRepeat, Vector2, Raycaster, Mesh, CustomToneMapping, EquirectangularReflectionMapping, Group, HalfFloatType, CubeCamera, SphereGeometry, BackSide, Vector4, BufferAttribute, BufferGeometry, InstancedMesh,
|
|
21
|
+
import { Vector3, Matrix4, Object3D, RGB_S3TC_DXT1_Format, RGBA_S3TC_DXT1_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT5_Format, RED_RGTC1_Format, SIGNED_RED_RGTC1_Format, RED_GREEN_RGTC2_Format, SIGNED_RED_GREEN_RGTC2_Format, RGBA_BPTC_Format, RGB_BPTC_SIGNED_Format, RGB_BPTC_UNSIGNED_Format, RGB_ETC2_Format, RGB_ETC1_Format, RGBA_ETC2_EAC_Format, R11_EAC_Format, SIGNED_R11_EAC_Format, RG11_EAC_Format, SIGNED_RG11_EAC_Format, RGBA_ASTC_4x4_Format, RGBA_ASTC_5x4_Format, RGBA_ASTC_5x5_Format, RGBA_ASTC_6x5_Format, RGBA_ASTC_6x6_Format, RGBA_ASTC_8x5_Format, RGBA_ASTC_8x6_Format, RGBA_ASTC_8x8_Format, RGBA_ASTC_10x5_Format, RGBA_ASTC_10x6_Format, RGBA_ASTC_10x8_Format, RGBA_ASTC_10x10_Format, RGBA_ASTC_12x10_Format, RGBA_ASTC_12x12_Format, Matrix3, NoToneMapping, NeutralToneMapping, AgXToneMapping, ACESFilmicToneMapping, Scene, OrthographicCamera, Sphere, Box3, Quaternion, AnimationMixer, MathUtils, LoopOnce, LoopRepeat, Vector2, Raycaster, Mesh, CustomToneMapping, EquirectangularReflectionMapping, Group, HalfFloatType, CubeCamera, SphereGeometry, BackSide, Vector4, Frustum, BufferAttribute, BufferGeometry, InstancedMesh, PlaneGeometry, Box2, FrontSide, VSMShadowMap, PCFSoftShadowMap, PCFShadowMap, HemisphereLight, DirectionalLight, FogExp2, Texture, MaterialBlending, InstancedBufferGeometry, InstancedBufferAttribute, DataTexture as DataTexture$1, RGBAFormat as RGBAFormat$1, UnsignedByteType, CatmullRomCurve3, LessEqualCompare, GreaterEqualCompare, AttachedBindMode, InterpolateLinear, NumberKeyframeTrack, AnimationUtils, AnimationClip, QuaternionKeyframeTrack, InterpolateDiscrete, LinearFilter as LinearFilter$1, ClampToEdgeWrapping as ClampToEdgeWrapping$1, Euler, RenderTarget as RenderTarget$1, NearestFilter as NearestFilter$1, FloatType as FloatType$1, CylinderGeometry, PropertyBinding, getConsoleFunction, setConsoleFunction, NormalAnimationBlendMode, Color, PerspectiveCamera, Plane, AlwaysDepth, SRGBColorSpace, BatchedMesh, SkinnedMesh, Sprite, Points, LineSegments, LineLoop, Line, LOD, ExternalTexture, Source, ColorManagement, SRGBTransfer, StaticDrawUsage } from 'three';
|
|
22
22
|
import { clone } from 'three/addons/utils/SkeletonUtils.js';
|
|
23
23
|
import { MeshBVH, SAH } from 'three-mesh-bvh';
|
|
24
24
|
import { CubeRenderTarget, MeshBasicNodeMaterial, PMREMGenerator, DataTexture, RGBAFormat, FloatType, NearestFilter, HalfFloatType as HalfFloatType$1, LinearFilter, RenderTarget, RenderTarget3D, Data3DTexture, ClampToEdgeWrapping, NodeMaterial, ShadowBaseNode, AssignNode, Node, NodeUpdateType, RendererUtils, BlendMode, Storage3DTexture, StorageTexture, MeshStandardNodeMaterial, MeshPhysicalNodeMaterial, QuadMesh, StorageBufferAttribute, RenderPipeline, ReadbackBuffer } from 'three/webgpu';
|
|
25
25
|
import * as tsl from 'three/tsl';
|
|
26
|
-
import { uniform, vec2, float, exp, vec3, mix, vec4, uniformArray, vertexIndex, texture, smoothstep, clamp, floor, textureLoad, ivec2, int, Fn, Loop, If, Break, max, min, cross as cross$1, dot, abs, texture3D, positionWorld, normalWorld,
|
|
26
|
+
import { uniform, vec2, float, exp, vec3, mix, vec4, uniformArray, vertexIndex, texture, smoothstep, clamp, floor, textureLoad, ivec2, int, Fn, Loop, If, Break, max, min, cross as cross$1, dot, abs, normalize, uv, cos, sin, length, pow, rtt, texture3D, positionWorld, normalWorld, select, cubeTexture, viewportCoordinate, renderGroup, property, shadow, reference, lightShadowMatrix, and, Stack, shadowPositionWorld, dFdx, dFdy, nodeObject, pass, mrt, emissive, diffuseColor, roughness, metalness, output, normalView, convertToTexture, instancedArray, instanceIndex, positionLocal, reflector, screenUV, viewportSharedTexture, viewportLinearDepth, linearDepth, viewportDepthTexture, cameraFar, cameraNear, cameraPosition, sqrt, step, exp2, storage, Return, textureSize, screenCoordinate, getViewPosition, color, compute, storageTexture as storageTexture$1, uvec2, uint, textureStore, sign, atan, log, hash, positionViewDirection, F_Schlick, specularF90, specularColor, reflect, deltaTime, screenSize, positionGeometry, saturate } from 'three/tsl';
|
|
27
27
|
import { createStore } from 'zustand/vanilla';
|
|
28
28
|
import * as upstreamWebGPU from 'three-mesh-bvh/webgpu';
|
|
29
|
+
import { ssgi } from 'three/addons/tsl/display/SSGINode.js';
|
|
29
30
|
import { SkyMesh } from 'three/addons/objects/SkyMesh.js';
|
|
30
31
|
import { bloom } from 'three/addons/tsl/display/BloomNode.js';
|
|
31
32
|
import { denoise } from 'three/addons/tsl/display/DenoiseNode.js';
|
|
@@ -33,7 +34,6 @@ import { fxaa } from 'three/addons/tsl/display/FXAANode.js';
|
|
|
33
34
|
import { ao } from 'three/addons/tsl/display/GTAONode.js';
|
|
34
35
|
import { godrays } from 'three/addons/tsl/display/GodraysNode.js';
|
|
35
36
|
import { smaa } from 'three/addons/tsl/display/SMAANode.js';
|
|
36
|
-
import { ssgi } from 'three/addons/tsl/display/SSGINode.js';
|
|
37
37
|
import { ssr } from 'three/addons/tsl/display/SSRNode.js';
|
|
38
38
|
import { sharpen } from 'three/addons/tsl/display/SharpenNode.js';
|
|
39
39
|
import { traa } from 'three/addons/tsl/display/TRAANode.js';
|
|
@@ -362,17 +362,17 @@ function posedBounds(root, meshes) {
|
|
|
362
362
|
rawBounds(envelope, envelope.raw);
|
|
363
363
|
const raw = envelope.raw;
|
|
364
364
|
const min8 = envelope.result.min;
|
|
365
|
-
const
|
|
365
|
+
const max11 = envelope.result.max;
|
|
366
366
|
const size = envelope.result.size;
|
|
367
367
|
min8[0] = raw.minX;
|
|
368
368
|
min8[1] = raw.minY + envelope.biasY;
|
|
369
369
|
min8[2] = raw.minZ;
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
size[0] =
|
|
374
|
-
size[1] =
|
|
375
|
-
size[2] =
|
|
370
|
+
max11[0] = raw.maxX;
|
|
371
|
+
max11[1] = raw.maxY + envelope.biasY;
|
|
372
|
+
max11[2] = raw.maxZ;
|
|
373
|
+
size[0] = max11[0] - min8[0];
|
|
374
|
+
size[1] = max11[1] - min8[1];
|
|
375
|
+
size[2] = max11[2] - min8[2];
|
|
376
376
|
return envelope.result;
|
|
377
377
|
}
|
|
378
378
|
|
|
@@ -622,8 +622,8 @@ function clipPoseError(subject, reference3, options = {}) {
|
|
|
622
622
|
const world = new Quaternion();
|
|
623
623
|
let elapsedSubject = 0;
|
|
624
624
|
let elapsedReference = 0;
|
|
625
|
-
for (let
|
|
626
|
-
const phase = (
|
|
625
|
+
for (let sample2 = 0; sample2 < samples; sample2 += 1) {
|
|
626
|
+
const phase = (sample2 + 0.5) / samples;
|
|
627
627
|
const subjectTime = subjectSeconds * phase;
|
|
628
628
|
const referenceTime = referenceSeconds * phase;
|
|
629
629
|
subjectMixer.update(subjectTime - elapsedSubject);
|
|
@@ -2551,7 +2551,7 @@ function prepareAnimationLayers(root, sources, samples, layers, consumedRoot) {
|
|
|
2551
2551
|
return { duration: clip.duration, clips: groups };
|
|
2552
2552
|
});
|
|
2553
2553
|
const all = [
|
|
2554
|
-
...preparedSamples.flatMap((
|
|
2554
|
+
...preparedSamples.flatMap((sample2) => sample2.clips),
|
|
2555
2555
|
...preparedLayers.map((layer) => layer.clip)
|
|
2556
2556
|
];
|
|
2557
2557
|
if (all.length > 8)
|
|
@@ -2666,8 +2666,8 @@ var AnimationRootMotion = class {
|
|
|
2666
2666
|
return { duration: clip.duration, position, yaw, cycle, cycleYaw, start, startYaw };
|
|
2667
2667
|
});
|
|
2668
2668
|
const buffers = /* @__PURE__ */ new Set();
|
|
2669
|
-
for (const
|
|
2670
|
-
for (const item of [
|
|
2669
|
+
for (const sample2 of this.#samples)
|
|
2670
|
+
for (const item of [sample2.position, sample2.yaw]) {
|
|
2671
2671
|
if (item === void 0) continue;
|
|
2672
2672
|
for (const values of [item.parameterPositions, item.sampleValues, item.resultBuffer]) {
|
|
2673
2673
|
if (ArrayBuffer.isView(values)) buffers.add(values);
|
|
@@ -2712,9 +2712,9 @@ var AnimationRootMotion = class {
|
|
|
2712
2712
|
for (let i = 0; i < this.#samples.length; i += 1) {
|
|
2713
2713
|
const weight = weights[i];
|
|
2714
2714
|
if (weight === 0) continue;
|
|
2715
|
-
const
|
|
2716
|
-
this.#cycle.addScaledVector(
|
|
2717
|
-
cycleYaw += weight *
|
|
2715
|
+
const sample2 = this.#samples[i];
|
|
2716
|
+
this.#cycle.addScaledVector(sample2.cycle, weight);
|
|
2717
|
+
cycleYaw += weight * sample2.cycleYaw;
|
|
2718
2718
|
}
|
|
2719
2719
|
if (loops === 0) {
|
|
2720
2720
|
rotateYaw(this.proposal.translation.copy(this.#last).sub(this.#first), -firstYaw);
|
|
@@ -2750,13 +2750,13 @@ var AnimationRootMotion = class {
|
|
|
2750
2750
|
for (let i = 0; i < this.#samples.length; i += 1) {
|
|
2751
2751
|
const weight = weights[i];
|
|
2752
2752
|
if (weight === 0) continue;
|
|
2753
|
-
const
|
|
2754
|
-
const time = phase *
|
|
2755
|
-
if (
|
|
2756
|
-
this.#local.fromArray(
|
|
2753
|
+
const sample2 = this.#samples[i];
|
|
2754
|
+
const time = phase * sample2.duration;
|
|
2755
|
+
if (sample2.position !== void 0) {
|
|
2756
|
+
this.#local.fromArray(sample2.position.evaluate(time)).sub(sample2.start);
|
|
2757
2757
|
position.addScaledVector(this.#local, weight);
|
|
2758
2758
|
}
|
|
2759
|
-
yaw += weight * ((
|
|
2759
|
+
yaw += weight * ((sample2.yaw?.evaluate(time)[0] ?? 0) - sample2.startYaw);
|
|
2760
2760
|
}
|
|
2761
2761
|
return yaw;
|
|
2762
2762
|
}
|
|
@@ -2821,9 +2821,9 @@ var AnimationComposer = class {
|
|
|
2821
2821
|
clips: prepared.clips,
|
|
2822
2822
|
strideSync: false
|
|
2823
2823
|
});
|
|
2824
|
-
this.#samples = prepared.samples.map((
|
|
2825
|
-
duration:
|
|
2826
|
-
actions:
|
|
2824
|
+
this.#samples = prepared.samples.map((sample2) => ({
|
|
2825
|
+
duration: sample2.duration,
|
|
2826
|
+
actions: sample2.clips.map((clip) => ({
|
|
2827
2827
|
action: this.mixer.clipAction(clip).setEffectiveTimeScale(0).setEffectiveWeight(0).play(),
|
|
2828
2828
|
masked: clip.name.endsWith(":masked")
|
|
2829
2829
|
}))
|
|
@@ -2860,7 +2860,7 @@ var AnimationComposer = class {
|
|
|
2860
2860
|
return Array.from(this.#weights);
|
|
2861
2861
|
}
|
|
2862
2862
|
get sampleTimes() {
|
|
2863
|
-
return this.#samples.map((
|
|
2863
|
+
return this.#samples.map((sample2) => sample2.actions[0].action.time);
|
|
2864
2864
|
}
|
|
2865
2865
|
get resources() {
|
|
2866
2866
|
return {
|
|
@@ -3021,9 +3021,9 @@ var AnimationComposer = class {
|
|
|
3021
3021
|
}
|
|
3022
3022
|
const overrideWeight = this.#layers.find((layer) => layer.options.mode === "override")?.weight ?? 0;
|
|
3023
3023
|
for (let i = 0; i < this.#samples.length; i += 1) {
|
|
3024
|
-
const
|
|
3025
|
-
for (const { action, masked } of
|
|
3026
|
-
action.time = this.phase *
|
|
3024
|
+
const sample2 = this.#samples[i];
|
|
3025
|
+
for (const { action, masked } of sample2.actions) {
|
|
3026
|
+
action.time = this.phase * sample2.duration;
|
|
3027
3027
|
action.setEffectiveWeight(this.#weights[i] * (masked ? 1 - overrideWeight : 1));
|
|
3028
3028
|
}
|
|
3029
3029
|
}
|
|
@@ -3374,11 +3374,11 @@ function createRandom(seed) {
|
|
|
3374
3374
|
state = Math.imul(1664525, state) + 1013904223 >>> 0;
|
|
3375
3375
|
return state / 4294967296;
|
|
3376
3376
|
});
|
|
3377
|
-
random.range = (min8,
|
|
3378
|
-
if (!Number.isFinite(min8) || !Number.isFinite(
|
|
3377
|
+
random.range = (min8, max11) => {
|
|
3378
|
+
if (!Number.isFinite(min8) || !Number.isFinite(max11) || max11 <= min8) {
|
|
3379
3379
|
throw new RangeError("range requires finite bounds with max greater than min.");
|
|
3380
3380
|
}
|
|
3381
|
-
return min8 + random() * (
|
|
3381
|
+
return min8 + random() * (max11 - min8);
|
|
3382
3382
|
};
|
|
3383
3383
|
random.pick = (items) => {
|
|
3384
3384
|
if (items.length === 0) throw new RangeError("pick requires a non-empty list.");
|
|
@@ -3620,6 +3620,7 @@ function clearScene(scene, computeDriven) {
|
|
|
3620
3620
|
|
|
3621
3621
|
// src/generated/console-markers.ts
|
|
3622
3622
|
var CONSOLE_MARKER = {
|
|
3623
|
+
firstFrame: "TN_FIRST_FRAME",
|
|
3623
3624
|
frameBudget: "TN_FRAME_BUDGET",
|
|
3624
3625
|
frameHitch: "TN_FRAME_HITCH",
|
|
3625
3626
|
projection: "TN_PROJECTION"};
|
|
@@ -3701,17 +3702,17 @@ var UNMEASURED_WITHOUT_TOTALS = [
|
|
|
3701
3702
|
];
|
|
3702
3703
|
var positive = (value) => value > 0 ? value : 0;
|
|
3703
3704
|
function createStageReader(renderer) {
|
|
3704
|
-
const
|
|
3705
|
+
const sample2 = emptyStageSample();
|
|
3705
3706
|
const last = new Float64Array(TOTAL_NAMES.length);
|
|
3706
3707
|
let haveLast = false;
|
|
3707
3708
|
return (jsBefore, engineCall, jsAfter) => {
|
|
3708
|
-
|
|
3709
|
-
|
|
3709
|
+
sample2.jsBefore = positive(jsBefore);
|
|
3710
|
+
sample2.jsAfter = positive(jsAfter);
|
|
3710
3711
|
const totals = renderer()?.info?.engine?.cpuMs;
|
|
3711
3712
|
if (totals === void 0) {
|
|
3712
|
-
|
|
3713
|
-
for (const name of UNMEASURED_WITHOUT_TOTALS)
|
|
3714
|
-
return
|
|
3713
|
+
sample2.engineJs = positive(engineCall);
|
|
3714
|
+
for (const name of UNMEASURED_WITHOUT_TOTALS) sample2[name] = void 0;
|
|
3715
|
+
return sample2;
|
|
3715
3716
|
}
|
|
3716
3717
|
let delta0 = 0;
|
|
3717
3718
|
const delta = (index) => {
|
|
@@ -3741,23 +3742,23 @@ function createStageReader(renderer) {
|
|
|
3741
3742
|
return void 0;
|
|
3742
3743
|
}
|
|
3743
3744
|
const encodeOnly = positive(encode - post);
|
|
3744
|
-
|
|
3745
|
-
|
|
3746
|
-
|
|
3747
|
-
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
|
|
3751
|
-
|
|
3752
|
-
|
|
3753
|
-
|
|
3754
|
-
|
|
3755
|
-
|
|
3756
|
-
|
|
3757
|
-
|
|
3758
|
-
|
|
3759
|
-
|
|
3760
|
-
return
|
|
3745
|
+
sample2.wasmScene = scene;
|
|
3746
|
+
sample2.wasmPlan = prepare;
|
|
3747
|
+
sample2.wasmCompute = compute2;
|
|
3748
|
+
sample2.wasmEncode = encodeOnly;
|
|
3749
|
+
sample2.wasmPost = post;
|
|
3750
|
+
sample2.wasmSubmit = submit;
|
|
3751
|
+
sample2.wasmPoll = poll;
|
|
3752
|
+
sample2.wasmTail = tail;
|
|
3753
|
+
sample2.wasmRendererGap = positive(inRenderer - prepare - encode);
|
|
3754
|
+
sample2.wasmDatabaseGap = positive(inDatabase - scene - inRenderer);
|
|
3755
|
+
sample2.wasmTargets = targets;
|
|
3756
|
+
sample2.planVirtualPages = virtualPages;
|
|
3757
|
+
sample2.planDraws = draws;
|
|
3758
|
+
sample2.planShadowLists = shadowLists;
|
|
3759
|
+
sample2.wasmOther = positive(host - (inDatabase + targets + compute2 + submit + poll + tail));
|
|
3760
|
+
sample2.engineJs = positive(engineCall - host);
|
|
3761
|
+
return sample2;
|
|
3761
3762
|
};
|
|
3762
3763
|
}
|
|
3763
3764
|
function stageMetersRequested() {
|
|
@@ -4144,6 +4145,7 @@ function requireTarget(target) {
|
|
|
4144
4145
|
return target;
|
|
4145
4146
|
}
|
|
4146
4147
|
var FRAME_BUDGET_MARKER = CONSOLE_MARKER.frameBudget;
|
|
4148
|
+
var FIRST_FRAME_MARKER = CONSOLE_MARKER.firstFrame;
|
|
4147
4149
|
var FRAME_HITCH_MARKER = CONSOLE_MARKER.frameHitch;
|
|
4148
4150
|
var FRAME_BUDGET_PHASES = [
|
|
4149
4151
|
"hostGap",
|
|
@@ -4266,21 +4268,21 @@ var Ring = class {
|
|
|
4266
4268
|
this.#total = 0;
|
|
4267
4269
|
}
|
|
4268
4270
|
/** Mean of this series over the frames where `gate` reaches `floor`. The rings fill and reset in step, so a slot is one frame. */
|
|
4269
|
-
meanWhere(gate,
|
|
4271
|
+
meanWhere(gate, floor6) {
|
|
4270
4272
|
let frames = 0;
|
|
4271
4273
|
let total = 0;
|
|
4272
4274
|
for (let index = 0; index < this.#count; index += 1) {
|
|
4273
|
-
if ((gate.#buffer[index] ?? 0) <
|
|
4275
|
+
if ((gate.#buffer[index] ?? 0) < floor6) continue;
|
|
4274
4276
|
frames += 1;
|
|
4275
4277
|
total += this.#buffer[index] ?? 0;
|
|
4276
4278
|
}
|
|
4277
4279
|
return { frames, mean: frames === 0 ? 0 : total / frames };
|
|
4278
4280
|
}
|
|
4279
|
-
summarize(
|
|
4281
|
+
summarize(scratch4) {
|
|
4280
4282
|
const count = this.#count;
|
|
4281
4283
|
if (count === 0) return { max: 0, mean: 0, p50: 0, p95: 0, p99: 0, samples: 0 };
|
|
4282
|
-
for (let index = 0; index < count; index += 1)
|
|
4283
|
-
const view =
|
|
4284
|
+
for (let index = 0; index < count; index += 1) scratch4[index] = this.#buffer[index] ?? 0;
|
|
4285
|
+
const view = scratch4.subarray(0, count);
|
|
4284
4286
|
view.sort();
|
|
4285
4287
|
const rank = (fraction) => round(view[Math.min(count - 1, Math.ceil(fraction * count) - 1)] ?? 0);
|
|
4286
4288
|
return {
|
|
@@ -4408,6 +4410,7 @@ var FrameBudget = class {
|
|
|
4408
4410
|
#lastPresentCount;
|
|
4409
4411
|
#presentsInWindow = 0;
|
|
4410
4412
|
#firstFrameStart;
|
|
4413
|
+
#firstFrameReported = false;
|
|
4411
4414
|
#firstTaskFrameStart;
|
|
4412
4415
|
constructor(options = {}) {
|
|
4413
4416
|
this.#simulation = options.simulation;
|
|
@@ -4644,9 +4647,9 @@ var FrameBudget = class {
|
|
|
4644
4647
|
* p50 of a bucket that was never measured is absent from the window. An unknown bucket name
|
|
4645
4648
|
* throws rather than being dropped, the same fail-closed rule as a phase.
|
|
4646
4649
|
*/
|
|
4647
|
-
addGpuBucketMs(
|
|
4650
|
+
addGpuBucketMs(sample2) {
|
|
4648
4651
|
if (!this.#open) throw new Error("FrameBudget.addGpuBucketMs called outside a frame.");
|
|
4649
|
-
const shadowPasses =
|
|
4652
|
+
const shadowPasses = sample2.shadowPasses;
|
|
4650
4653
|
if (shadowPasses !== void 0) {
|
|
4651
4654
|
if (!Number.isInteger(shadowPasses) || shadowPasses < 0)
|
|
4652
4655
|
throw new Error(
|
|
@@ -4655,7 +4658,7 @@ var FrameBudget = class {
|
|
|
4655
4658
|
this.#gpuShadowPassesThisFrame = shadowPasses;
|
|
4656
4659
|
}
|
|
4657
4660
|
for (const bucket of FRAME_GPU_BUCKETS) {
|
|
4658
|
-
const ms =
|
|
4661
|
+
const ms = sample2[bucket];
|
|
4659
4662
|
if (ms === void 0) continue;
|
|
4660
4663
|
if (!Number.isFinite(ms) || ms < 0)
|
|
4661
4664
|
throw new Error(
|
|
@@ -4748,6 +4751,16 @@ var FrameBudget = class {
|
|
|
4748
4751
|
const simulationEnd = this.#simulationEnd ?? this.#frameStart;
|
|
4749
4752
|
const frameMs = Math.max(0, nowMs - this.#frameStart);
|
|
4750
4753
|
this.#lastFrameEnd = nowMs;
|
|
4754
|
+
if (!this.#firstFrameReported && !this.#covered && !this.#renderSkippedThisFrame) {
|
|
4755
|
+
this.#firstFrameReported = true;
|
|
4756
|
+
const threads = globalThis.__tnWebThreads;
|
|
4757
|
+
console.info(
|
|
4758
|
+
`${FIRST_FRAME_MARKER}:${JSON.stringify({
|
|
4759
|
+
frameMs: round(frameMs),
|
|
4760
|
+
...typeof threads === "string" ? { threads } : {}
|
|
4761
|
+
})}`
|
|
4762
|
+
);
|
|
4763
|
+
}
|
|
4751
4764
|
this.#countPresents();
|
|
4752
4765
|
const drawn = !this.#renderSkippedThisFrame;
|
|
4753
4766
|
const drawnDelta = drawn && this.#lastDrawnTimestamp !== void 0 ? Math.max(0, this.#frameTimestamp - this.#lastDrawnTimestamp) : 0;
|
|
@@ -4755,7 +4768,7 @@ var FrameBudget = class {
|
|
|
4755
4768
|
const update = Math.max(0, simulationEnd - this.#frameStart);
|
|
4756
4769
|
const tail = Math.max(0, nowMs - simulationEnd);
|
|
4757
4770
|
const residual = Math.max(0, tail - this.#renderMs - this.#overlayMs - this.#uiMs);
|
|
4758
|
-
const
|
|
4771
|
+
const sample2 = wantSample ? {
|
|
4759
4772
|
hostGap: round(this.#hostGap),
|
|
4760
4773
|
overlay: round(this.#overlayMs),
|
|
4761
4774
|
render: round(this.#renderMs),
|
|
@@ -4777,7 +4790,7 @@ var FrameBudget = class {
|
|
|
4777
4790
|
})}`
|
|
4778
4791
|
);
|
|
4779
4792
|
this.#maybeReport();
|
|
4780
|
-
return
|
|
4793
|
+
return sample2;
|
|
4781
4794
|
}
|
|
4782
4795
|
this.#frame.push(frameMs);
|
|
4783
4796
|
this.#substeps.push(this.#substepCount);
|
|
@@ -4850,7 +4863,7 @@ var FrameBudget = class {
|
|
|
4850
4863
|
}
|
|
4851
4864
|
this.#framesInWindow += 1;
|
|
4852
4865
|
this.#maybeReport();
|
|
4853
|
-
return
|
|
4866
|
+
return sample2;
|
|
4854
4867
|
}
|
|
4855
4868
|
/** Reads the window in progress without disturbing it. */
|
|
4856
4869
|
window() {
|
|
@@ -5037,13 +5050,13 @@ var FrameBudget = class {
|
|
|
5037
5050
|
}
|
|
5038
5051
|
/** The stages' means over the frames at or above the sum's p95 (see `IFrameBudgetWindow.stagesAtP95`). */
|
|
5039
5052
|
#stagesAtP95(sumRing, stageRings) {
|
|
5040
|
-
const
|
|
5053
|
+
const floor6 = sumRing.summarize(this.#scratch).p95;
|
|
5041
5054
|
const stages = {};
|
|
5042
5055
|
let frames = 0;
|
|
5043
5056
|
for (let index = 0; index < STAGE_NAMES.length; index += 1) {
|
|
5044
5057
|
const ring = stageRings?.[index];
|
|
5045
5058
|
if (ring === void 0 || ring.count === 0 || ring.count !== sumRing.count) continue;
|
|
5046
|
-
const at3 = ring.meanWhere(sumRing,
|
|
5059
|
+
const at3 = ring.meanWhere(sumRing, floor6);
|
|
5047
5060
|
frames = at3.frames;
|
|
5048
5061
|
stages[STAGE_NAMES[index]] = round(at3.mean);
|
|
5049
5062
|
}
|
|
@@ -5051,9 +5064,9 @@ var FrameBudget = class {
|
|
|
5051
5064
|
}
|
|
5052
5065
|
/** Pushes this frame's stages, with the phases that complete the partition of `frame`. */
|
|
5053
5066
|
#pushStages(update, residual) {
|
|
5054
|
-
const
|
|
5067
|
+
const sample2 = this.#stagesThisFrame;
|
|
5055
5068
|
this.#stagesThisFrame = void 0;
|
|
5056
|
-
if (
|
|
5069
|
+
if (sample2 === void 0) return;
|
|
5057
5070
|
let rings = this.#stageRings;
|
|
5058
5071
|
if (rings === void 0) {
|
|
5059
5072
|
rings = STAGE_NAMES.map(() => new Ring(this.#capacity));
|
|
@@ -5063,7 +5076,7 @@ var FrameBudget = class {
|
|
|
5063
5076
|
let sum = 0;
|
|
5064
5077
|
for (let index = 0; index < STAGE_NAMES.length; index += 1) {
|
|
5065
5078
|
const name = STAGE_NAMES[index];
|
|
5066
|
-
const value = name === "update" ? update : name === "overlay" ? this.#overlayMs : name === "ui" ? this.#uiMs : name === "residual" ? residual :
|
|
5079
|
+
const value = name === "update" ? update : name === "overlay" ? this.#overlayMs : name === "ui" ? this.#uiMs : name === "residual" ? residual : sample2[name];
|
|
5067
5080
|
if (value === void 0) continue;
|
|
5068
5081
|
rings[index]?.push(value);
|
|
5069
5082
|
if (!STAGE_PARTS.includes(name)) sum += value;
|
|
@@ -6563,7 +6576,7 @@ var FixedStepLoop = class {
|
|
|
6563
6576
|
return this.#fps;
|
|
6564
6577
|
}
|
|
6565
6578
|
runtimeDiagnosticsSeries() {
|
|
6566
|
-
return this.#renderPerformanceSamples.map((
|
|
6579
|
+
return this.#renderPerformanceSamples.map((sample2) => ({ ...sample2 }));
|
|
6567
6580
|
}
|
|
6568
6581
|
/**
|
|
6569
6582
|
* Forget the render samples taken so far. The game calls it once, when the world first draws:
|
|
@@ -6786,7 +6799,7 @@ var FixedStepLoop = class {
|
|
|
6786
6799
|
const sequence = ++this.#renderCompletionSequence;
|
|
6787
6800
|
if (callbackMs !== void 0) this.#onFrame(callbackMs);
|
|
6788
6801
|
if (this.#collectMetrics && frameMs !== void 0 && frameMs > 0) {
|
|
6789
|
-
const
|
|
6802
|
+
const sample2 = {
|
|
6790
6803
|
frameMs,
|
|
6791
6804
|
sequence,
|
|
6792
6805
|
completedAtMs: callbackFinishedAt,
|
|
@@ -6795,7 +6808,7 @@ var FixedStepLoop = class {
|
|
|
6795
6808
|
...phases === void 0 ? {} : { phases },
|
|
6796
6809
|
...metrics === void 0 || metrics.triangles === void 0 ? {} : { triangles: metrics.triangles }
|
|
6797
6810
|
};
|
|
6798
|
-
this.#renderPerformanceSamples.push(
|
|
6811
|
+
this.#renderPerformanceSamples.push(sample2);
|
|
6799
6812
|
if (this.#renderPerformanceSamples.length > MAX_RENDER_PERFORMANCE_SAMPLES)
|
|
6800
6813
|
this.#renderPerformanceSamples.shift();
|
|
6801
6814
|
}
|
|
@@ -6950,7 +6963,7 @@ var MatrixWorldPass = class {
|
|
|
6950
6963
|
const childForce = composeWorld(root, force || stale) || force || stale;
|
|
6951
6964
|
if (frozenLeaf(root)) return;
|
|
6952
6965
|
const children = root.children;
|
|
6953
|
-
for (let index = 0,
|
|
6966
|
+
for (let index = 0, length8 = children.length; index < length8; index += 1) {
|
|
6954
6967
|
this.#step(children[index], childForce, prune);
|
|
6955
6968
|
}
|
|
6956
6969
|
}
|
|
@@ -7135,8 +7148,8 @@ var ScenePicker = class {
|
|
|
7135
7148
|
/** The hit as the authored source reports it: its object, and a normal in its own space. */
|
|
7136
7149
|
#asSource(hit, source2) {
|
|
7137
7150
|
const face = hit.face;
|
|
7138
|
-
const
|
|
7139
|
-
return { ...hit, face: { ...face, normal }, faceIndex: void 0, object: source2 };
|
|
7151
|
+
const normal2 = face.normal.clone().applyMatrix3(this.#normalMatrix.getNormalMatrix(source2.matrixWorld).invert()).normalize();
|
|
7152
|
+
return { ...hit, face: { ...face, normal: normal2 }, faceIndex: void 0, object: source2 };
|
|
7140
7153
|
}
|
|
7141
7154
|
#hitTest(object3, into) {
|
|
7142
7155
|
if (isLodJoinProxy(object3) || isAutoBatchMerged(object3)) return;
|
|
@@ -8282,8 +8295,8 @@ var ProjectionMirror = class {
|
|
|
8282
8295
|
}
|
|
8283
8296
|
#createBatch(group, first, capacity) {
|
|
8284
8297
|
const startedAt = globalThis.performance?.now() ?? 0;
|
|
8285
|
-
const
|
|
8286
|
-
const material =
|
|
8298
|
+
const uniform23 = group.uniform === true;
|
|
8299
|
+
const material = uniform23 ? whiteClone(first.material) : first.material;
|
|
8287
8300
|
let mesh;
|
|
8288
8301
|
try {
|
|
8289
8302
|
mesh = new InstancedMesh(group.geometry, material, capacity);
|
|
@@ -8292,7 +8305,7 @@ var ProjectionMirror = class {
|
|
|
8292
8305
|
}
|
|
8293
8306
|
for (let slot = 0; slot < capacity; slot += 1) mesh.setMatrixAt(slot, ZERO_MATRIX);
|
|
8294
8307
|
mesh.instanceMatrix.needsUpdate = true;
|
|
8295
|
-
if (
|
|
8308
|
+
if (uniform23) mesh.setColorAt(0, material.color);
|
|
8296
8309
|
mesh.frustumCulled = false;
|
|
8297
8310
|
mesh.castShadow = first.castShadow;
|
|
8298
8311
|
mesh.receiveShadow = first.receiveShadow;
|
|
@@ -8302,7 +8315,7 @@ var ProjectionMirror = class {
|
|
|
8302
8315
|
group,
|
|
8303
8316
|
geometry: group.geometry,
|
|
8304
8317
|
material,
|
|
8305
|
-
uniform:
|
|
8318
|
+
uniform: uniform23,
|
|
8306
8319
|
instances: /* @__PURE__ */ new Map(),
|
|
8307
8320
|
free: [],
|
|
8308
8321
|
used: 0,
|
|
@@ -9911,20 +9924,20 @@ var ResolutionScaler = class {
|
|
|
9911
9924
|
}
|
|
9912
9925
|
#observeContinuous(window, gpuMs, stalled) {
|
|
9913
9926
|
const overBudget = window.fps < this.targetFps && (gpuMs === void 0 || gpuMs > this.budgetMs);
|
|
9914
|
-
const
|
|
9927
|
+
const floor6 = RESOLUTION_SCALER.rungs[this.#limitIndex] ?? 0.23;
|
|
9915
9928
|
if (overBudget) {
|
|
9916
9929
|
this.#cleanWindows = 0;
|
|
9917
9930
|
if (!this.#overBudget(window) || gpuMs === void 0) {
|
|
9918
|
-
this.#atFloor = this.#continuousScale <=
|
|
9931
|
+
this.#atFloor = this.#continuousScale <= floor6;
|
|
9919
9932
|
return void 0;
|
|
9920
9933
|
}
|
|
9921
9934
|
if (this.#insensitiveHold > 0 || this.#insensitiveFloor >= 0) return void 0;
|
|
9922
9935
|
const estimate2 = this.#continuousScale * Math.sqrt(this.budgetMs / gpuMs);
|
|
9923
|
-
const target = this.#quantizeContinuous(Math.max(
|
|
9924
|
-
this.#atFloor = target <=
|
|
9936
|
+
const target = this.#quantizeContinuous(Math.max(floor6, estimate2), window);
|
|
9937
|
+
this.#atFloor = target <= floor6;
|
|
9925
9938
|
const fromIndex = this.#index;
|
|
9926
9939
|
const fromScale = this.#continuousScale;
|
|
9927
|
-
const changed = this.#continuousChange(Math.max(
|
|
9940
|
+
const changed = this.#continuousChange(Math.max(floor6, target), false);
|
|
9928
9941
|
if (changed !== void 0 && this.#scaleSource === "auto" && 1 - (changed / fromScale) ** 2 >= RESOLUTION_SCALER.insensitiveMinPixelDrop)
|
|
9929
9942
|
this.#insensitiveProbe = {
|
|
9930
9943
|
fromIndex,
|
|
@@ -9960,7 +9973,7 @@ var ResolutionScaler = class {
|
|
|
9960
9973
|
const height = Math.max(8, Math.ceil(fullHeight * scale / 8) * 8);
|
|
9961
9974
|
return Math.min(1, width / fullWidth, height / fullHeight);
|
|
9962
9975
|
}
|
|
9963
|
-
#continuousChange(target,
|
|
9976
|
+
#continuousChange(target, up2) {
|
|
9964
9977
|
const current = this.#continuousScale;
|
|
9965
9978
|
const change = Math.abs(target - current) / Math.max(current, Number.EPSILON);
|
|
9966
9979
|
if (change < RESOLUTION_SCALER.continuousChangeThreshold) return void 0;
|
|
@@ -10036,9 +10049,9 @@ var ResolutionScaler = class {
|
|
|
10036
10049
|
* says nothing either way.
|
|
10037
10050
|
*/
|
|
10038
10051
|
#stalled(window) {
|
|
10039
|
-
const { max:
|
|
10040
|
-
if (!(p50 > 0) || !Number.isFinite(p99) || !Number.isFinite(
|
|
10041
|
-
return p99 >= p50 * RESOLUTION_SCALER.stallP99Multiple ||
|
|
10052
|
+
const { max: max11, p50, p99 } = window.presented;
|
|
10053
|
+
if (!(p50 > 0) || !Number.isFinite(p99) || !Number.isFinite(max11)) return false;
|
|
10054
|
+
return p99 >= p50 * RESOLUTION_SCALER.stallP99Multiple || max11 >= p50 * RESOLUTION_SCALER.stallMaxMultiple;
|
|
10042
10055
|
}
|
|
10043
10056
|
/**
|
|
10044
10057
|
* How many rungs one down-step should cross, from the fps deficit alone.
|
|
@@ -10506,11 +10519,11 @@ function planCompressedUpload(source2, block, maxBytesPerWrite) {
|
|
|
10506
10519
|
const tileWidth = Math.min(tileColumns, columns - x);
|
|
10507
10520
|
const tileHeight = Math.min(tileRows, rows - y);
|
|
10508
10521
|
const offset = layer * imageBytes + y * stride + x * block.blockBytes;
|
|
10509
|
-
const
|
|
10522
|
+
const length8 = (tileHeight - 1) * stride + tileWidth * block.blockBytes;
|
|
10510
10523
|
tiles.push({
|
|
10511
10524
|
mipLevel,
|
|
10512
10525
|
origin: { x: x * block.blockWidth, y: y * block.blockHeight, z: layer },
|
|
10513
|
-
data: bytes.subarray(offset, offset +
|
|
10526
|
+
data: bytes.subarray(offset, offset + length8),
|
|
10514
10527
|
layout: { offset: 0, bytesPerRow: stride, rowsPerImage: rows },
|
|
10515
10528
|
extent: {
|
|
10516
10529
|
width: tileWidth * block.blockWidth,
|
|
@@ -10518,7 +10531,7 @@ function planCompressedUpload(source2, block, maxBytesPerWrite) {
|
|
|
10518
10531
|
depthOrArrayLayers: 1
|
|
10519
10532
|
}
|
|
10520
10533
|
});
|
|
10521
|
-
totalBytes +=
|
|
10534
|
+
totalBytes += length8;
|
|
10522
10535
|
}
|
|
10523
10536
|
}
|
|
10524
10537
|
}
|
|
@@ -11070,10 +11083,10 @@ var ComputeTimingScopes = class {
|
|
|
11070
11083
|
);
|
|
11071
11084
|
if (failed) throw failure;
|
|
11072
11085
|
let consumed = false;
|
|
11073
|
-
const queries = Object.freeze(captured.map((
|
|
11086
|
+
const queries = Object.freeze(captured.map((sample2) => Object.freeze(sample2)));
|
|
11074
11087
|
return Object.freeze({
|
|
11075
11088
|
generation: this.#generation,
|
|
11076
|
-
calls: Object.freeze(queries.map((
|
|
11089
|
+
calls: Object.freeze(queries.map((sample2) => sample2.call)),
|
|
11077
11090
|
read: () => {
|
|
11078
11091
|
this.#current(raw);
|
|
11079
11092
|
if (consumed) throw new Error("TN_COMPUTE_TIMING_DUPLICATE: receipt already consumed.");
|
|
@@ -11081,12 +11094,12 @@ var ComputeTimingScopes = class {
|
|
|
11081
11094
|
if (pool === void 0)
|
|
11082
11095
|
throw new Error("TN_COMPUTE_TIMING_MISSING: compute query pool is absent.");
|
|
11083
11096
|
const samples = [];
|
|
11084
|
-
for (const
|
|
11085
|
-
if (!pool.timestamps.has(
|
|
11086
|
-
const gpuMs = pool.timestamps.get(
|
|
11097
|
+
for (const sample2 of queries) {
|
|
11098
|
+
if (!pool.timestamps.has(sample2.uid)) return void 0;
|
|
11099
|
+
const gpuMs = pool.timestamps.get(sample2.uid);
|
|
11087
11100
|
if (typeof gpuMs !== "number" || !Number.isFinite(gpuMs) || gpuMs <= 0)
|
|
11088
|
-
throw new Error(`TN_COMPUTE_TIMING_INVALID: query ${
|
|
11089
|
-
samples.push(Object.freeze({ ...
|
|
11101
|
+
throw new Error(`TN_COMPUTE_TIMING_INVALID: query ${sample2.uid} duration ${gpuMs}.`);
|
|
11102
|
+
samples.push(Object.freeze({ ...sample2, gpuMs }));
|
|
11090
11103
|
}
|
|
11091
11104
|
consumed = true;
|
|
11092
11105
|
return Object.freeze(samples);
|
|
@@ -11761,11 +11774,11 @@ var toDisplay = (c) => blend3(
|
|
|
11761
11774
|
);
|
|
11762
11775
|
var toLinear = (v) => blend3(v.div(12.92), v.add(0.055).div(1.055).pow(2.4), step(vec3(0.04045), v));
|
|
11763
11776
|
function dithered(linear, steps) {
|
|
11764
|
-
const
|
|
11777
|
+
const uniform23 = hash(screenCoordinate.y.mul(4096).add(screenCoordinate.x));
|
|
11765
11778
|
const grain = mix(
|
|
11766
|
-
|
|
11767
|
-
float(1).sub(float(2).sub(
|
|
11768
|
-
step(0.5,
|
|
11779
|
+
uniform23.mul(2).sqrt().sub(1),
|
|
11780
|
+
float(1).sub(float(2).sub(uniform23.mul(2)).sqrt()),
|
|
11781
|
+
step(0.5, uniform23)
|
|
11769
11782
|
);
|
|
11770
11783
|
return toLinear(clamp(toDisplay(linear).add(grain.mul(steps * EIGHT_BIT_STEP)), 0, 1));
|
|
11771
11784
|
}
|
|
@@ -11938,7 +11951,7 @@ var exposureSettings = {
|
|
|
11938
11951
|
maxDelta: 0.1,
|
|
11939
11952
|
reportInterval: 0.5
|
|
11940
11953
|
};
|
|
11941
|
-
function exposureMeter(colour,
|
|
11954
|
+
function exposureMeter(colour, uv8) {
|
|
11942
11955
|
const luminance = dot(colour.rgb, vec3(1 / 3, 1 / 3, 1 / 3)).clamp(1e-4, 65504);
|
|
11943
11956
|
const weight = float(1);
|
|
11944
11957
|
return vec2(luminance, weight);
|
|
@@ -12918,10 +12931,10 @@ function wrapRenderer(raw, kind, applied, state, reapply, alphaAntialiasing, pip
|
|
|
12918
12931
|
firstWorldFrame: () => rendererFirstWorldFrame(raw, presentationSince)
|
|
12919
12932
|
} : {},
|
|
12920
12933
|
gpuFrameAge: () => {
|
|
12921
|
-
const
|
|
12934
|
+
const sample2 = gpuFrameSample();
|
|
12922
12935
|
const frame = currentFrame();
|
|
12923
|
-
if (
|
|
12924
|
-
return frame -
|
|
12936
|
+
if (sample2 === void 0 || frame === void 0 || !Number.isInteger(frame)) return void 0;
|
|
12937
|
+
return frame - sample2.frame;
|
|
12925
12938
|
},
|
|
12926
12939
|
gpuFrameSample,
|
|
12927
12940
|
observeGpuFrames: (options) => {
|
|
@@ -13125,6 +13138,7 @@ function wrapRenderer(raw, kind, applied, state, reapply, alphaAntialiasing, pip
|
|
|
13125
13138
|
prepareTextures: async (textures, signal, onProgress, replacements) => {
|
|
13126
13139
|
if (disposed) throw new Error("Renderer disposed during texture preparation.");
|
|
13127
13140
|
if (kind !== "webgpu") return 0;
|
|
13141
|
+
if (raw.info?.engine !== void 0) return 0;
|
|
13128
13142
|
const inputs = [];
|
|
13129
13143
|
const originals = /* @__PURE__ */ new Set();
|
|
13130
13144
|
for (const texture7 of textures) {
|
|
@@ -13181,11 +13195,11 @@ function wrapRenderer(raw, kind, applied, state, reapply, alphaAntialiasing, pip
|
|
|
13181
13195
|
for (const value of Object.values(entry)) {
|
|
13182
13196
|
if (value?.isTexture === true) pending2.add(value);
|
|
13183
13197
|
}
|
|
13184
|
-
for (const
|
|
13198
|
+
for (const uniform23 of Object.values(
|
|
13185
13199
|
entry.uniforms ?? {}
|
|
13186
13200
|
)) {
|
|
13187
|
-
if (
|
|
13188
|
-
pending2.add(
|
|
13201
|
+
if (uniform23?.value?.isTexture === true)
|
|
13202
|
+
pending2.add(uniform23.value);
|
|
13189
13203
|
}
|
|
13190
13204
|
}
|
|
13191
13205
|
});
|
|
@@ -13636,6 +13650,7 @@ async function createRenderer(options = {}) {
|
|
|
13636
13650
|
});
|
|
13637
13651
|
let renderer;
|
|
13638
13652
|
let webgpuFailure;
|
|
13653
|
+
let opening;
|
|
13639
13654
|
if (preferWebGPU && (source2?.hasWebGPU() ?? "gpu" in (globalThis.navigator ?? {}))) {
|
|
13640
13655
|
try {
|
|
13641
13656
|
const raw = options.webgpuFactory ? await options.webgpuFactory(canvas, rendererParameters) : await import('three/webgpu').then(async (webgpu) => {
|
|
@@ -13647,6 +13662,7 @@ async function createRenderer(options = {}) {
|
|
|
13647
13662
|
});
|
|
13648
13663
|
});
|
|
13649
13664
|
const instance = raw;
|
|
13665
|
+
opening = instance;
|
|
13650
13666
|
await instance.init?.();
|
|
13651
13667
|
applyRendererToneMapping(instance, options.toneMapping ?? "filmic", report);
|
|
13652
13668
|
const alphaAntialiasing = arm(instance);
|
|
@@ -13670,8 +13686,14 @@ async function createRenderer(options = {}) {
|
|
|
13670
13686
|
if (adapter.gpuClass !== void 0)
|
|
13671
13687
|
report(`${GPU_CLASS_MARKER}:${JSON.stringify(adapter.gpuClass)}`);
|
|
13672
13688
|
} catch (error) {
|
|
13673
|
-
|
|
13674
|
-
|
|
13689
|
+
try {
|
|
13690
|
+
opening?.dispose?.();
|
|
13691
|
+
} catch {
|
|
13692
|
+
}
|
|
13693
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
13694
|
+
const deviceFault = /^TN_WASM_(?:DEVICE_LOST|DEVICE|ADAPTER|SURFACE|INIT):/u;
|
|
13695
|
+
if (/^TN_(?:WASM|NATIVE|ABI)_/u.test(message) && !deviceFault.test(message)) throw error;
|
|
13696
|
+
webgpuFailure = message;
|
|
13675
13697
|
renderer = void 0;
|
|
13676
13698
|
}
|
|
13677
13699
|
}
|
|
@@ -15829,9 +15851,15 @@ function createGameStore(initial, intervalMs) {
|
|
|
15829
15851
|
gameStore.getState = () => current;
|
|
15830
15852
|
gameStore.set = (patch) => {
|
|
15831
15853
|
const next = typeof patch === "function" ? patch(current) : patch;
|
|
15832
|
-
|
|
15833
|
-
|
|
15834
|
-
|
|
15854
|
+
let changed = false;
|
|
15855
|
+
for (const key in next) {
|
|
15856
|
+
const value = next[key];
|
|
15857
|
+
if (Object.is(value, current[key])) continue;
|
|
15858
|
+
Reflect.set(pending2, key, value);
|
|
15859
|
+
Reflect.set(current, key, value);
|
|
15860
|
+
changed = true;
|
|
15861
|
+
}
|
|
15862
|
+
if (changed) hasPending = true;
|
|
15835
15863
|
};
|
|
15836
15864
|
gameStore.flush = flush;
|
|
15837
15865
|
gameStore.start = () => {
|
|
@@ -16238,8 +16266,8 @@ function directionalTransmittance(parameters, direction2) {
|
|
|
16238
16266
|
const lengthSquared = direction2.lengthSq();
|
|
16239
16267
|
if (!Number.isFinite(lengthSquared) || lengthSquared === 0)
|
|
16240
16268
|
throw new Error("Atmosphere direction must be finite and non-zero.");
|
|
16241
|
-
const
|
|
16242
|
-
const cosine = Math.max(0.05,
|
|
16269
|
+
const normal2 = direction2.clone().normalize();
|
|
16270
|
+
const cosine = Math.max(0.05, normal2.y);
|
|
16243
16271
|
const airMass = 1 / cosine;
|
|
16244
16272
|
const zenith = zenithTransmittance(parameters);
|
|
16245
16273
|
return new Vector3(zenith[0] ** airMass, zenith[1] ** airMass, zenith[2] ** airMass);
|
|
@@ -16396,41 +16424,41 @@ function bake2d(target, resolution, value) {
|
|
|
16396
16424
|
return Fn(() => {
|
|
16397
16425
|
const x = instanceIndex.mod(resolution.width);
|
|
16398
16426
|
const y = instanceIndex.div(resolution.width);
|
|
16399
|
-
const
|
|
16427
|
+
const uv8 = vec2(
|
|
16400
16428
|
float(x).add(0.5).div(resolution.width),
|
|
16401
16429
|
float(y).add(0.5).div(resolution.height)
|
|
16402
16430
|
);
|
|
16403
|
-
textureStore(target, uvec2(x, y), value(
|
|
16431
|
+
textureStore(target, uvec2(x, y), value(uv8, x, y));
|
|
16404
16432
|
})().compute(resolution.width * resolution.height);
|
|
16405
16433
|
}
|
|
16406
16434
|
function bakeTransmittance(target, resolution, parameterUniforms) {
|
|
16407
|
-
return bake2d(target, resolution, (
|
|
16435
|
+
return bake2d(target, resolution, (uv8) => {
|
|
16408
16436
|
const thickness = parameterUniforms.atmosphereRadius.sub(parameterUniforms.planetRadius);
|
|
16409
16437
|
const rayleighColumn = float(8).mul(float(1).sub(exp(thickness.negate().div(8))));
|
|
16410
16438
|
const mieColumn = float(1.2).mul(float(1).sub(exp(thickness.negate().div(1.2))));
|
|
16411
|
-
const airMass = float(1).div(
|
|
16439
|
+
const airMass = float(1).div(uv8.x.max(0.05));
|
|
16412
16440
|
const opticalDepth = parameterUniforms.rayleigh.mul(rayleighColumn).add(parameterUniforms.mie.mul(mieColumn)).add(parameterUniforms.ozone.mul(15)).mul(airMass);
|
|
16413
16441
|
return vec4(exp(opticalDepth.negate()), 1);
|
|
16414
16442
|
});
|
|
16415
16443
|
}
|
|
16416
|
-
function sampleLut(target,
|
|
16417
|
-
return texture(target,
|
|
16444
|
+
function sampleLut(target, uv8) {
|
|
16445
|
+
return texture(target, uv8.clamp(0, 1)).level(float(0));
|
|
16418
16446
|
}
|
|
16419
16447
|
function bakeMultiScattering(target, resolution, parameterUniforms, transmittance) {
|
|
16420
|
-
return bake2d(target, resolution, (
|
|
16421
|
-
const altitudeWeight = float(1).sub(
|
|
16422
|
-
const angularWeight = float(0.5).add(
|
|
16423
|
-
const directTransmittance = sampleLut(transmittance,
|
|
16448
|
+
return bake2d(target, resolution, (uv8) => {
|
|
16449
|
+
const altitudeWeight = float(1).sub(uv8.y);
|
|
16450
|
+
const angularWeight = float(0.5).add(uv8.x.mul(0.5));
|
|
16451
|
+
const directTransmittance = sampleLut(transmittance, uv8).rgb;
|
|
16424
16452
|
const scattering = parameterUniforms.rayleigh.mul(altitudeWeight).add(parameterUniforms.mie.mul(angularWeight)).add(parameterUniforms.ozone.mul(0.02));
|
|
16425
16453
|
return vec4(scattering.mul(directTransmittance), 1);
|
|
16426
16454
|
});
|
|
16427
16455
|
}
|
|
16428
16456
|
function bakeSkyView(target, resolution, parameterUniforms, transmittance, multiScattering) {
|
|
16429
|
-
return bake2d(target, resolution, (
|
|
16430
|
-
const horizonWeight = float(1).sub(
|
|
16431
|
-
const sunWeight = float(0.25).add(
|
|
16432
|
-
const directTransmittance = sampleLut(transmittance,
|
|
16433
|
-
const higherOrderScattering = sampleLut(multiScattering,
|
|
16457
|
+
return bake2d(target, resolution, (uv8) => {
|
|
16458
|
+
const horizonWeight = float(1).sub(uv8.y).max(0);
|
|
16459
|
+
const sunWeight = float(0.25).add(uv8.x.mul(0.75));
|
|
16460
|
+
const directTransmittance = sampleLut(transmittance, uv8).rgb;
|
|
16461
|
+
const higherOrderScattering = sampleLut(multiScattering, uv8).rgb;
|
|
16434
16462
|
const scattering = parameterUniforms.rayleigh.mul(horizonWeight.mul(1.5)).add(parameterUniforms.mie.mul(sunWeight)).add(parameterUniforms.ozone.mul(0.01));
|
|
16435
16463
|
return vec4(scattering.mul(directTransmittance).add(higherOrderScattering), 1);
|
|
16436
16464
|
});
|
|
@@ -16480,11 +16508,11 @@ var AtmosphereLuts = class {
|
|
|
16480
16508
|
this.uniforms.rayleigh.value.copy(resolved.rayleigh);
|
|
16481
16509
|
this.#hash = hashParameters(resolved, this.resolutions);
|
|
16482
16510
|
}
|
|
16483
|
-
sampleTransmittance(
|
|
16484
|
-
return sampleLut(this.transmittance,
|
|
16511
|
+
sampleTransmittance(uv8) {
|
|
16512
|
+
return sampleLut(this.transmittance, uv8);
|
|
16485
16513
|
}
|
|
16486
|
-
sampleSkyView(
|
|
16487
|
-
return sampleLut(this.skyView,
|
|
16514
|
+
sampleSkyView(uv8) {
|
|
16515
|
+
return sampleLut(this.skyView, uv8);
|
|
16488
16516
|
}
|
|
16489
16517
|
dispose() {
|
|
16490
16518
|
for (const node of this.warmupNodes) node.dispose();
|
|
@@ -16609,27 +16637,27 @@ var Atmosphere = class extends Group {
|
|
|
16609
16637
|
/** Return the game-owned sky radiance lookup as a TSL vec3 or a CPU validation sample. */
|
|
16610
16638
|
radiance(direction2) {
|
|
16611
16639
|
if (!isNode(direction2)) {
|
|
16612
|
-
const
|
|
16613
|
-
const horizon = 1 - Math.max(0,
|
|
16614
|
-
const sunWeight2 = Math.max(0,
|
|
16640
|
+
const normal3 = asVector(direction2);
|
|
16641
|
+
const horizon = 1 - Math.max(0, normal3.y);
|
|
16642
|
+
const sunWeight2 = Math.max(0, normal3.dot(this.#sunDirection));
|
|
16615
16643
|
return new Vector3(
|
|
16616
16644
|
this.#parameters.rayleigh.x * (0.75 + horizon) + this.#parameters.mie.x * sunWeight2,
|
|
16617
16645
|
this.#parameters.rayleigh.y * (0.75 + horizon) + this.#parameters.mie.y * sunWeight2,
|
|
16618
16646
|
this.#parameters.rayleigh.z * (0.75 + horizon) + this.#parameters.mie.z * sunWeight2
|
|
16619
16647
|
);
|
|
16620
16648
|
}
|
|
16621
|
-
const
|
|
16622
|
-
const
|
|
16623
|
-
const lookup = nodeRgb(this.luts.sampleSkyView(
|
|
16624
|
-
const sunWeight =
|
|
16649
|
+
const normal2 = directionNode(direction2).normalize();
|
|
16650
|
+
const uv8 = vec2(normal2.x.mul(0.5).add(0.5), normal2.y.mul(0.5).add(0.5));
|
|
16651
|
+
const lookup = nodeRgb(this.luts.sampleSkyView(uv8));
|
|
16652
|
+
const sunWeight = normal2.dot(this.#sunDirectionNode).max(0);
|
|
16625
16653
|
return lookup.mul(float(0.35).add(sunWeight.mul(0.65)));
|
|
16626
16654
|
}
|
|
16627
16655
|
/** Return direct solar transmittance as a TSL vec3 or a CPU validation sample. */
|
|
16628
16656
|
sunTransmittance(direction2) {
|
|
16629
16657
|
if (!isNode(direction2)) return directionalTransmittance(this.#parameters, asVector(direction2));
|
|
16630
|
-
const
|
|
16631
|
-
const
|
|
16632
|
-
return nodeRgb(this.luts.sampleTransmittance(
|
|
16658
|
+
const normal2 = directionNode(direction2).normalize();
|
|
16659
|
+
const uv8 = vec2(normal2.y.max(0.05), float(0.5));
|
|
16660
|
+
return nodeRgb(this.luts.sampleTransmittance(uv8));
|
|
16633
16661
|
}
|
|
16634
16662
|
/**
|
|
16635
16663
|
* Composite scene colour against game-supplied in-scattered radiance using scene-pass depth.
|
|
@@ -16671,11 +16699,11 @@ var SkyCaptureSchedule = class {
|
|
|
16671
16699
|
}
|
|
16672
16700
|
}
|
|
16673
16701
|
next(sunDirection) {
|
|
16674
|
-
const
|
|
16675
|
-
if (!Number.isFinite(
|
|
16702
|
+
const length8 = Math.hypot(sunDirection.x, sunDirection.y, sunDirection.z);
|
|
16703
|
+
if (!Number.isFinite(length8) || length8 === 0) {
|
|
16676
16704
|
throw new Error("SkyCapture sun direction must be finite and nonzero.");
|
|
16677
16705
|
}
|
|
16678
|
-
const sun = sunDirection.clone().divideScalar(
|
|
16706
|
+
const sun = sunDirection.clone().divideScalar(length8);
|
|
16679
16707
|
if (this.#face === 6) {
|
|
16680
16708
|
if (this.#sun !== void 0 && this.#sun.angleTo(sun) <= this.#threshold) return [];
|
|
16681
16709
|
this.#sun = sun;
|
|
@@ -17193,11 +17221,11 @@ var SoftBody3D = class extends Mesh {
|
|
|
17193
17221
|
}
|
|
17194
17222
|
/** Latest asynchronous GPU positions and their age, when readback was requested. */
|
|
17195
17223
|
get sample() {
|
|
17196
|
-
const
|
|
17197
|
-
if (
|
|
17224
|
+
const sample2 = this.#readback?.sample;
|
|
17225
|
+
if (sample2 === void 0) return void 0;
|
|
17198
17226
|
return {
|
|
17199
|
-
data: compactClothVec3Readback(
|
|
17200
|
-
staleFrames:
|
|
17227
|
+
data: compactClothVec3Readback(sample2.data, this.uniqueVertexCount),
|
|
17228
|
+
staleFrames: sample2.staleFrames
|
|
17201
17229
|
};
|
|
17202
17230
|
}
|
|
17203
17231
|
debug() {
|
|
@@ -17411,7 +17439,7 @@ function matrixFor(mesh, instance, target) {
|
|
|
17411
17439
|
}
|
|
17412
17440
|
return target.copy(mesh.matrixWorld);
|
|
17413
17441
|
}
|
|
17414
|
-
function appendVertices(mesh, position,
|
|
17442
|
+
function appendVertices(mesh, position, normal2, matrix, normalMatrix, state) {
|
|
17415
17443
|
const localPosition = new Vector3();
|
|
17416
17444
|
const worldPosition = new Vector3();
|
|
17417
17445
|
const localNormal = new Vector3();
|
|
@@ -17420,8 +17448,8 @@ function appendVertices(mesh, position, normal, matrix, normalMatrix, state) {
|
|
|
17420
17448
|
mesh.getVertexPosition(vertex, localPosition);
|
|
17421
17449
|
worldPosition.copy(localPosition).applyMatrix4(matrix);
|
|
17422
17450
|
state.positions.push(worldPosition.x, worldPosition.y, worldPosition.z);
|
|
17423
|
-
if (
|
|
17424
|
-
else localNormal.set(
|
|
17451
|
+
if (normal2 === void 0) localNormal.set(0, 1, 0);
|
|
17452
|
+
else localNormal.set(normal2.getX(vertex), normal2.getY(vertex), normal2.getZ(vertex));
|
|
17425
17453
|
worldNormal.copy(localNormal).applyNormalMatrix(normalMatrix).normalize();
|
|
17426
17454
|
state.normals.push(worldNormal.x, worldNormal.y, worldNormal.z);
|
|
17427
17455
|
}
|
|
@@ -17470,12 +17498,12 @@ function appendMesh(mesh, state) {
|
|
|
17470
17498
|
const instances = mesh instanceof InstancedMesh ? Math.max(0, mesh.count) : 1;
|
|
17471
17499
|
const matrix = new Matrix4();
|
|
17472
17500
|
const normalMatrix = new Matrix3();
|
|
17473
|
-
const
|
|
17501
|
+
const normal2 = mesh.geometry.getAttribute("normal");
|
|
17474
17502
|
for (let instance = 0; instance < instances; instance += 1) {
|
|
17475
17503
|
const vertexOffset = state.positions.length / 3;
|
|
17476
17504
|
matrixFor(mesh, instance, matrix);
|
|
17477
17505
|
normalMatrix.getNormalMatrix(matrix);
|
|
17478
|
-
appendVertices(mesh, position,
|
|
17506
|
+
appendVertices(mesh, position, normal2, matrix, normalMatrix, state);
|
|
17479
17507
|
appendTriangles(mesh, index, ranges, vertexOffset, state);
|
|
17480
17508
|
}
|
|
17481
17509
|
}
|
|
@@ -17839,10 +17867,10 @@ function flatten(root, include, materials) {
|
|
|
17839
17867
|
const wx = (n[0] ?? 0) * nx + (n[3] ?? 0) * ny + (n[6] ?? 0) * nz;
|
|
17840
17868
|
const wy = (n[1] ?? 0) * nx + (n[4] ?? 0) * ny + (n[7] ?? 0) * nz;
|
|
17841
17869
|
const wz = (n[2] ?? 0) * nx + (n[5] ?? 0) * ny + (n[8] ?? 0) * nz;
|
|
17842
|
-
const
|
|
17843
|
-
normals[target] = wx /
|
|
17844
|
-
normals[target + 1] = wy /
|
|
17845
|
-
normals[target + 2] = wz /
|
|
17870
|
+
const length8 = Math.hypot(wx, wy, wz) || 1;
|
|
17871
|
+
normals[target] = wx / length8;
|
|
17872
|
+
normals[target + 1] = wy / length8;
|
|
17873
|
+
normals[target + 2] = wz / length8;
|
|
17846
17874
|
}
|
|
17847
17875
|
materialIds[filled] = id;
|
|
17848
17876
|
sides[filled] = sideOf(material);
|
|
@@ -18201,7 +18229,7 @@ var TracedReflections = class {
|
|
|
18201
18229
|
const interpolated = normalA.mul(weights.x).add(normalB.mul(weights.y)).add(normalC.mul(weights.z));
|
|
18202
18230
|
const lengthSquared = max(dot(interpolated, interpolated), float(1e-12));
|
|
18203
18231
|
const unit2 = interpolated.div(lengthSquared.sqrt());
|
|
18204
|
-
const
|
|
18232
|
+
const normal2 = dot(unit2, ray.direction).greaterThan(0).select(unit2.negate(), unit2);
|
|
18205
18233
|
const material = corner.w;
|
|
18206
18234
|
const albedo = fetchMaterial(material.mul(MATERIAL_TEXELS));
|
|
18207
18235
|
const emission = fetchMaterial(material.mul(MATERIAL_TEXELS).add(1));
|
|
@@ -18209,7 +18237,7 @@ var TracedReflections = class {
|
|
|
18209
18237
|
hit,
|
|
18210
18238
|
distance: hit.greaterThan(0).select(result.x, float(-1)),
|
|
18211
18239
|
position: ray.origin.add(ray.direction.mul(result.x)),
|
|
18212
|
-
normal,
|
|
18240
|
+
normal: normal2,
|
|
18213
18241
|
triangle,
|
|
18214
18242
|
albedo: albedo.xyz,
|
|
18215
18243
|
roughness: albedo.w,
|
|
@@ -18222,12 +18250,322 @@ var TracedReflections = class {
|
|
|
18222
18250
|
this.scene.dispose();
|
|
18223
18251
|
}
|
|
18224
18252
|
};
|
|
18253
|
+
var SCREEN_PROBE_GATHER_MARKER = "TN_SCREEN_PROBE_GATHER";
|
|
18254
|
+
var SCREEN_PROBE_PASSES = ["trace", "filter", "gather"];
|
|
18255
|
+
var DEFAULT_DOWNSAMPLE = 16;
|
|
18256
|
+
var DEFAULT_OCTAHEDRON = 8;
|
|
18257
|
+
var DEFAULT_CELL_SIZE = 1;
|
|
18258
|
+
var START_OFFSET = 0.01;
|
|
18259
|
+
var START_OFFSET_PER_METRE = 4e-3;
|
|
18260
|
+
var gatherScreenProbes = ssgi;
|
|
18261
|
+
function defineWorldMapping(camera) {
|
|
18262
|
+
const live = (index) => uniform(camera.matrixWorld.elements[index] ?? 0).onRenderUpdate(
|
|
18263
|
+
() => camera.matrixWorld.elements[index] ?? 0
|
|
18264
|
+
);
|
|
18265
|
+
const column = (first) => vec3(live(first), live(first + 1), live(first + 2));
|
|
18266
|
+
const [right, up2, back, at3] = [column(0), column(4), column(8), column(12)];
|
|
18267
|
+
return {
|
|
18268
|
+
/** A view-space vector in world space: the camera's rotation, which is all a direction needs. */
|
|
18269
|
+
direction: (value) => right.mul(value.x).add(up2.mul(value.y)).add(back.mul(value.z)),
|
|
18270
|
+
/** A view-space point in world space. */
|
|
18271
|
+
position: (value) => right.mul(value.x).add(up2.mul(value.y)).add(back.mul(value.z)).add(at3)
|
|
18272
|
+
};
|
|
18273
|
+
}
|
|
18274
|
+
var ScreenProbeGather = class {
|
|
18275
|
+
report;
|
|
18276
|
+
downsampleFactor;
|
|
18277
|
+
tracingOctahedronResolution;
|
|
18278
|
+
cacheCellSize;
|
|
18279
|
+
#camera;
|
|
18280
|
+
#viewport;
|
|
18281
|
+
#fallback;
|
|
18282
|
+
#radiance;
|
|
18283
|
+
#trace;
|
|
18284
|
+
#timedPass;
|
|
18285
|
+
#node;
|
|
18286
|
+
constructor(options) {
|
|
18287
|
+
const downsampleFactor = options.downsampleFactor ?? DEFAULT_DOWNSAMPLE;
|
|
18288
|
+
const tracingOctahedronResolution = options.tracingOctahedronResolution ?? DEFAULT_OCTAHEDRON;
|
|
18289
|
+
const cacheCellSize = options.cacheCellSize ?? DEFAULT_CELL_SIZE;
|
|
18290
|
+
if (!(Number.isInteger(downsampleFactor) && downsampleFactor >= 1))
|
|
18291
|
+
throw new RangeError(
|
|
18292
|
+
`TN_SCREEN_PROBE_GATHER: downsampleFactor ${downsampleFactor} must be a whole number of pixels, at least 1`
|
|
18293
|
+
);
|
|
18294
|
+
if (!(Number.isInteger(tracingOctahedronResolution) && tracingOctahedronResolution >= 2))
|
|
18295
|
+
throw new RangeError(
|
|
18296
|
+
`TN_SCREEN_PROBE_GATHER: tracingOctahedronResolution ${tracingOctahedronResolution} must be a whole number of rays, at least 2`
|
|
18297
|
+
);
|
|
18298
|
+
if (!(options.viewport.width > 0 && options.viewport.height > 0))
|
|
18299
|
+
throw new RangeError(
|
|
18300
|
+
`TN_SCREEN_PROBE_GATHER: viewport ${options.viewport.width}x${options.viewport.height} must be the drawing buffer`
|
|
18301
|
+
);
|
|
18302
|
+
if (options.timedPass != null && !SCREEN_PROBE_PASSES.includes(options.timedPass))
|
|
18303
|
+
throw new TypeError(
|
|
18304
|
+
`TN_SCREEN_PROBE_GATHER: timedPass ${String(options.timedPass)} is not one of ${SCREEN_PROBE_PASSES.join(", ")}`
|
|
18305
|
+
);
|
|
18306
|
+
if (options.trace !== void 0 && !(cacheCellSize > 0))
|
|
18307
|
+
throw new RangeError(
|
|
18308
|
+
`TN_SCREEN_PROBE_GATHER: cacheCellSize ${cacheCellSize} must be metres beyond 0`
|
|
18309
|
+
);
|
|
18310
|
+
if (options.trace !== void 0 && options.radiance === void 0)
|
|
18311
|
+
throw new TypeError(
|
|
18312
|
+
"TN_SCREEN_PROBE_GATHER_RADIANCE: a ray that leaves the screen reads options.radiance, and none was given"
|
|
18313
|
+
);
|
|
18314
|
+
if ((options.radiance !== void 0 || options.trace !== void 0) && options.camera?.matrixWorld === void 0)
|
|
18315
|
+
throw new TypeError(
|
|
18316
|
+
"TN_SCREEN_PROBE_GATHER_CAMERA: a gather that leaves the screen needs the scene camera's matrixWorld"
|
|
18317
|
+
);
|
|
18318
|
+
this.downsampleFactor = downsampleFactor;
|
|
18319
|
+
this.tracingOctahedronResolution = tracingOctahedronResolution;
|
|
18320
|
+
this.cacheCellSize = cacheCellSize;
|
|
18321
|
+
this.#camera = options.camera;
|
|
18322
|
+
this.#viewport = options.viewport;
|
|
18323
|
+
this.#fallback = options.fallback;
|
|
18324
|
+
this.#radiance = options.radiance;
|
|
18325
|
+
this.#trace = options.trace;
|
|
18326
|
+
this.#timedPass = options.timedPass;
|
|
18327
|
+
const tilesX = Math.ceil(options.viewport.width / downsampleFactor);
|
|
18328
|
+
const tilesY = Math.ceil(options.viewport.height / downsampleFactor);
|
|
18329
|
+
this.report = {
|
|
18330
|
+
downsampleFactor,
|
|
18331
|
+
tracingOctahedronResolution,
|
|
18332
|
+
viewportWidth: options.viewport.width,
|
|
18333
|
+
viewportHeight: options.viewport.height,
|
|
18334
|
+
probes: tilesX * tilesY,
|
|
18335
|
+
raysPerProbe: tracingOctahedronResolution * tracingOctahedronResolution,
|
|
18336
|
+
worldTrace: options.trace !== void 0
|
|
18337
|
+
};
|
|
18338
|
+
if (options.marker !== false)
|
|
18339
|
+
console.info(`${SCREEN_PROBE_GATHER_MARKER} ${JSON.stringify(this.report)}`);
|
|
18340
|
+
}
|
|
18341
|
+
/**
|
|
18342
|
+
* The gather itself: `ssgi(base, depth, normal, { camera, probes, fallback, miss })`, with `base` the lit frame the
|
|
18343
|
+
* traces read and the depth and normal of the scene pass. `getGINode()` and `getAONode()` read what it built.
|
|
18344
|
+
*/
|
|
18345
|
+
gather(colorNode, depthNode, normalNode) {
|
|
18346
|
+
const { fallback, miss } = this.#tiers();
|
|
18347
|
+
const node = gatherScreenProbes(colorNode, depthNode, normalNode, {
|
|
18348
|
+
camera: this.#camera,
|
|
18349
|
+
probes: {
|
|
18350
|
+
downsampleFactor: this.downsampleFactor,
|
|
18351
|
+
tracingOctahedronResolution: this.tracingOctahedronResolution,
|
|
18352
|
+
viewport: this.#viewport,
|
|
18353
|
+
...this.#timedPass === void 0 ? {} : { timedPass: this.#timedPass }
|
|
18354
|
+
},
|
|
18355
|
+
...fallback === void 0 ? {} : { fallback },
|
|
18356
|
+
...miss === void 0 ? {} : { miss }
|
|
18357
|
+
});
|
|
18358
|
+
this.#node = node;
|
|
18359
|
+
return node;
|
|
18360
|
+
}
|
|
18361
|
+
/** The gather's radiance, E / pi: multiply by the receiver's albedo and add it after the scene pass. */
|
|
18362
|
+
getGINode() {
|
|
18363
|
+
return this.#built().getGINode();
|
|
18364
|
+
}
|
|
18365
|
+
/** The share of the gather's rays that found nothing, as the occlusion the caller applies to the lit frame. */
|
|
18366
|
+
getAONode() {
|
|
18367
|
+
return this.#built().getAONode();
|
|
18368
|
+
}
|
|
18369
|
+
#built() {
|
|
18370
|
+
if (this.#node === void 0)
|
|
18371
|
+
throw new Error("TN_SCREEN_PROBE_GATHER_UNBUILT: call gather() before reading its nodes");
|
|
18372
|
+
return this.#node;
|
|
18373
|
+
}
|
|
18374
|
+
/**
|
|
18375
|
+
* The two tiers below the screen. Both are asked in view space, because the screen pass works there: the mapping to
|
|
18376
|
+
* the world is this class's, so a game answers one question in world space (what light arrives along this direction
|
|
18377
|
+
* at this point) and not two in two spaces.
|
|
18378
|
+
*/
|
|
18379
|
+
#tiers() {
|
|
18380
|
+
const radiance = this.#radiance;
|
|
18381
|
+
const trace = this.#trace;
|
|
18382
|
+
const given = this.#fallback;
|
|
18383
|
+
if (radiance === void 0) return given === void 0 ? {} : { fallback: given };
|
|
18384
|
+
const mapping = defineWorldMapping(this.#camera);
|
|
18385
|
+
const cellSize = this.cacheCellSize;
|
|
18386
|
+
const fallback = given ?? ((position, direction2) => radiance(mapping.position(position), normalize(mapping.direction(direction2))));
|
|
18387
|
+
if (trace === void 0) return { fallback };
|
|
18388
|
+
return {
|
|
18389
|
+
// The tier below the screen along a ray that hit: what the cache holds there, which the composite already adds.
|
|
18390
|
+
fallback,
|
|
18391
|
+
// The tier past the screen along a ray that missed: the distance field continued to the cache's cell, then the
|
|
18392
|
+
// cache read where the ray ended, less the light this pixel already receives (the composite adds that too).
|
|
18393
|
+
miss: (position, direction2, normal2) => {
|
|
18394
|
+
const at3 = mapping.position(position);
|
|
18395
|
+
const towards = normalize(mapping.direction(direction2));
|
|
18396
|
+
const facing = normalize(mapping.direction(normal2));
|
|
18397
|
+
const offset = max(float(START_OFFSET), position.z.abs().mul(START_OFFSET_PER_METRE));
|
|
18398
|
+
const reached = at3.add(towards.mul(cellSize));
|
|
18399
|
+
const found = trace.trace({
|
|
18400
|
+
origin: at3.add(facing.mul(offset)),
|
|
18401
|
+
direction: towards,
|
|
18402
|
+
far: cellSize
|
|
18403
|
+
});
|
|
18404
|
+
const end = found.hit.greaterThan(0).select(found.position, reached);
|
|
18405
|
+
return radiance(end, towards).sub(radiance(at3, facing));
|
|
18406
|
+
}
|
|
18407
|
+
};
|
|
18408
|
+
}
|
|
18409
|
+
};
|
|
18410
|
+
var SHORT_RANGE_AO_MARKER = "TN_SHORT_RANGE_AO";
|
|
18411
|
+
var SLICE_COUNT = 2;
|
|
18412
|
+
var STEP_COUNT = 3;
|
|
18413
|
+
var REACH_PX = 32;
|
|
18414
|
+
var MAX_SLICES = 8;
|
|
18415
|
+
var MAX_STEPS = 8;
|
|
18416
|
+
var MIN_DISTANCE = 1e-5;
|
|
18417
|
+
var HALF_FLOAT_TYPE = 1016;
|
|
18418
|
+
var ShortRangeAO = class {
|
|
18419
|
+
report;
|
|
18420
|
+
horizonSearchSliceCount;
|
|
18421
|
+
horizonSearchStepCount;
|
|
18422
|
+
reachPx;
|
|
18423
|
+
bentNormal;
|
|
18424
|
+
intensity;
|
|
18425
|
+
#camera;
|
|
18426
|
+
#viewport;
|
|
18427
|
+
constructor(options) {
|
|
18428
|
+
const horizonSearchSliceCount = options.horizonSearchSliceCount ?? SLICE_COUNT;
|
|
18429
|
+
const horizonSearchStepCount = options.horizonSearchStepCount ?? STEP_COUNT;
|
|
18430
|
+
const reachPx = options.reachPx ?? REACH_PX;
|
|
18431
|
+
const intensity = options.intensity ?? 1;
|
|
18432
|
+
if (!(Number.isInteger(horizonSearchSliceCount) && horizonSearchSliceCount >= 1))
|
|
18433
|
+
throw new RangeError(
|
|
18434
|
+
`TN_SHORT_RANGE_AO: horizonSearchSliceCount ${horizonSearchSliceCount} must be a whole number of sweeps, at least 1`
|
|
18435
|
+
);
|
|
18436
|
+
if (!(Number.isInteger(horizonSearchStepCount) && horizonSearchStepCount >= 1))
|
|
18437
|
+
throw new RangeError(
|
|
18438
|
+
`TN_SHORT_RANGE_AO: horizonSearchStepCount ${horizonSearchStepCount} must be a whole number of samples, at least 1`
|
|
18439
|
+
);
|
|
18440
|
+
if (horizonSearchSliceCount > MAX_SLICES || horizonSearchStepCount > MAX_STEPS)
|
|
18441
|
+
throw new RangeError(
|
|
18442
|
+
`TN_SHORT_RANGE_AO: a sweep of ${horizonSearchSliceCount} x ${horizonSearchStepCount} is more than the pass compiles (${MAX_SLICES} x ${MAX_STEPS})`
|
|
18443
|
+
);
|
|
18444
|
+
if (!(reachPx > 0))
|
|
18445
|
+
throw new RangeError(
|
|
18446
|
+
`TN_SHORT_RANGE_AO: reachPx ${reachPx} must be pixels of the drawing buffer beyond 0`
|
|
18447
|
+
);
|
|
18448
|
+
if (!(intensity > 0))
|
|
18449
|
+
throw new RangeError(`TN_SHORT_RANGE_AO: intensity ${intensity} must be beyond 0`);
|
|
18450
|
+
if (!(options.viewport.width > 0 && options.viewport.height > 0))
|
|
18451
|
+
throw new RangeError(
|
|
18452
|
+
`TN_SHORT_RANGE_AO: viewport ${options.viewport.width}x${options.viewport.height} must be the drawing buffer`
|
|
18453
|
+
);
|
|
18454
|
+
if (options.camera?.projectionMatrix === void 0)
|
|
18455
|
+
throw new TypeError(
|
|
18456
|
+
"TN_SHORT_RANGE_AO_CAMERA: the pass needs the scene camera's projectionMatrix"
|
|
18457
|
+
);
|
|
18458
|
+
this.horizonSearchSliceCount = horizonSearchSliceCount;
|
|
18459
|
+
this.horizonSearchStepCount = horizonSearchStepCount;
|
|
18460
|
+
this.reachPx = reachPx;
|
|
18461
|
+
this.bentNormal = options.bentNormal ?? true;
|
|
18462
|
+
this.intensity = intensity;
|
|
18463
|
+
this.#camera = options.camera;
|
|
18464
|
+
this.#viewport = options.viewport;
|
|
18465
|
+
this.report = {
|
|
18466
|
+
horizonSearchSliceCount,
|
|
18467
|
+
horizonSearchStepCount,
|
|
18468
|
+
reachPx,
|
|
18469
|
+
samplesPerPixel: horizonSearchSliceCount * horizonSearchStepCount,
|
|
18470
|
+
bentNormal: this.bentNormal
|
|
18471
|
+
};
|
|
18472
|
+
if (options.marker !== false)
|
|
18473
|
+
console.info(`${SHORT_RANGE_AO_MARKER} ${JSON.stringify(this.report)}`);
|
|
18474
|
+
}
|
|
18475
|
+
/**
|
|
18476
|
+
* The occlusion of one frame: `rgb` the bent normal in view space, `a` the share of the hemisphere left open. `depth`
|
|
18477
|
+
* is the scene pass's depth target and `normal` its view-space normal target.
|
|
18478
|
+
*/
|
|
18479
|
+
occlusion(depthNode, normalNode) {
|
|
18480
|
+
const element = (index) => uniform(this.#camera.projectionMatrix.elements[index] ?? 0).onRenderUpdate(
|
|
18481
|
+
() => this.#camera.projectionMatrix.elements[index] ?? 0
|
|
18482
|
+
);
|
|
18483
|
+
const [p0, p5, p8, p9, p10, p14] = [0, 5, 8, 9, 10, 14].map(element);
|
|
18484
|
+
const viewPosition = (coordinate, depth) => {
|
|
18485
|
+
const z = p14.negate().div(depth.add(p10));
|
|
18486
|
+
const ndc = vec2(coordinate.x.mul(2).sub(1), float(1).sub(coordinate.y).mul(2).sub(1));
|
|
18487
|
+
return vec3(z.negate().mul(ndc.x.add(p8)).div(p0), z.negate().mul(ndc.y.add(p9)).div(p5), z);
|
|
18488
|
+
};
|
|
18489
|
+
const slices = uniform(this.horizonSearchSliceCount);
|
|
18490
|
+
const steps = uniform(this.horizonSearchStepCount);
|
|
18491
|
+
const stepOffset = vec2(
|
|
18492
|
+
this.reachPx / this.#viewport.width,
|
|
18493
|
+
this.reachPx / this.#viewport.height
|
|
18494
|
+
);
|
|
18495
|
+
const intensity = uniform(this.intensity);
|
|
18496
|
+
const bent = this.bentNormal;
|
|
18497
|
+
const graph = Fn(() => {
|
|
18498
|
+
const coordinate = uv();
|
|
18499
|
+
const result = vec4(0, 0, 1, 1).toVar();
|
|
18500
|
+
const centreDepth = depthNode.sample(coordinate).r;
|
|
18501
|
+
const centreNormal = normalNode.sample(coordinate).xyz;
|
|
18502
|
+
If(centreDepth.lessThan(1).and(centreNormal.dot(centreNormal).greaterThan(0.25)), () => {
|
|
18503
|
+
const position = viewPosition(coordinate, centreDepth);
|
|
18504
|
+
const normal2 = normalize(centreNormal);
|
|
18505
|
+
const helper = normal2.y.abs().lessThan(0.99).select(vec3(0, 1, 0), vec3(1, 0, 0));
|
|
18506
|
+
const tangent = normalize(helper.cross(normal2));
|
|
18507
|
+
const bitangent = normal2.cross(tangent);
|
|
18508
|
+
const cell = coordinate.mul(2048).floor();
|
|
18509
|
+
const noise = cell.x.mul(0.06711056).add(cell.y.mul(583715e-8)).fract().mul(52.9829189).fract();
|
|
18510
|
+
const open = float(0).toVar();
|
|
18511
|
+
const direction2 = vec3(0, 0, 1).toVar();
|
|
18512
|
+
const bentNormal = vec3(0, 0, 0).toVar();
|
|
18513
|
+
Loop(
|
|
18514
|
+
{ start: int(0), end: int(MAX_SLICES), type: "int", condition: "<" },
|
|
18515
|
+
({ i: slice }) => {
|
|
18516
|
+
If(float(slice).greaterThanEqual(slices), () => {
|
|
18517
|
+
Break();
|
|
18518
|
+
});
|
|
18519
|
+
const angle = float(slice).add(noise).div(slices).mul(Math.PI);
|
|
18520
|
+
direction2.assign(normalize(tangent.mul(cos(angle)).add(bitangent.mul(sin(angle)))));
|
|
18521
|
+
const horizon = float(-1).toVar();
|
|
18522
|
+
Loop(
|
|
18523
|
+
{ start: int(0), end: int(MAX_STEPS), type: "int", condition: "<" },
|
|
18524
|
+
({ i: step3 }) => {
|
|
18525
|
+
If(float(step3).greaterThanEqual(steps), () => {
|
|
18526
|
+
Break();
|
|
18527
|
+
});
|
|
18528
|
+
const fraction = float(step3).add(1).div(steps);
|
|
18529
|
+
const sampleCoordinate = coordinate.add(
|
|
18530
|
+
stepOffset.mul(direction2.xy).mul(fraction.mul(fraction))
|
|
18531
|
+
);
|
|
18532
|
+
const sampleDepth = depthNode.sample(sampleCoordinate).r;
|
|
18533
|
+
const inside = sampleCoordinate.x.greaterThanEqual(0).and(sampleCoordinate.x.lessThanEqual(1)).and(sampleCoordinate.y.greaterThanEqual(0)).and(sampleCoordinate.y.lessThanEqual(1)).and(sampleDepth.lessThan(1));
|
|
18534
|
+
const delta = viewPosition(sampleCoordinate, sampleDepth).sub(position);
|
|
18535
|
+
const sine = delta.dot(normal2).div(max(length(delta), float(MIN_DISTANCE)));
|
|
18536
|
+
horizon.assign(max(horizon, inside.select(sine, float(-1))));
|
|
18537
|
+
}
|
|
18538
|
+
);
|
|
18539
|
+
const kept = clamp(float(1).sub(max(horizon, float(0))), float(0), float(1));
|
|
18540
|
+
open.assign(open.add(kept));
|
|
18541
|
+
if (bent)
|
|
18542
|
+
bentNormal.assign(
|
|
18543
|
+
bentNormal.add(direction2.mul(kept)).add(normal2.mul(kept.mul(0.5).add(0.25)))
|
|
18544
|
+
);
|
|
18545
|
+
}
|
|
18546
|
+
);
|
|
18547
|
+
const visibility = pow(clamp(open.div(slices), float(0), float(1)), intensity);
|
|
18548
|
+
const axis = bent ? normalize(normalize(bentNormal).add(normal2)) : normal2;
|
|
18549
|
+
result.assign(vec4(axis, visibility));
|
|
18550
|
+
});
|
|
18551
|
+
return result;
|
|
18552
|
+
})();
|
|
18553
|
+
const node = rtt(graph, null, null, { type: HALF_FLOAT_TYPE });
|
|
18554
|
+
return Object.defineProperties(node, {
|
|
18555
|
+
bentNormal: { value: bent },
|
|
18556
|
+
reachPx: { value: this.reachPx },
|
|
18557
|
+
slices: { value: this.horizonSearchSliceCount },
|
|
18558
|
+
steps: { value: this.horizonSearchStepCount }
|
|
18559
|
+
});
|
|
18560
|
+
}
|
|
18561
|
+
};
|
|
18225
18562
|
var RECLAIM_AFTER_EMPTY_UPDATES = 4;
|
|
18226
18563
|
var GROUPS_BUILT_PER_UPDATE = 4;
|
|
18227
18564
|
var DEFAULT_DISTANCE_RATIO = 1.25;
|
|
18228
18565
|
var DEFAULT_RECUT_FRACTION = 0.01;
|
|
18229
18566
|
var DEFAULT_ERROR_PIXELS = 1;
|
|
18230
|
-
var
|
|
18567
|
+
var MIN_DISTANCE2 = 1e-3;
|
|
18568
|
+
var CULLED = -2147483648;
|
|
18231
18569
|
var ClusteredBatchRoot = class _ClusteredBatchRoot extends Object3D {
|
|
18232
18570
|
constructor(batch) {
|
|
18233
18571
|
super();
|
|
@@ -18267,14 +18605,34 @@ var ClusteredBatch = class {
|
|
|
18267
18605
|
#cameraWorld = new Vector3();
|
|
18268
18606
|
#cameraLocal = new Vector3();
|
|
18269
18607
|
#lastCut = new Vector3();
|
|
18608
|
+
#rotation = new Quaternion();
|
|
18609
|
+
#lastRotation = new Quaternion();
|
|
18610
|
+
#view = new ClusterView();
|
|
18270
18611
|
#hasCut = false;
|
|
18271
18612
|
#lastScale = 0;
|
|
18613
|
+
/** The projection the bands were chosen by: an aspect or zoom change keeps the pixel scale. */
|
|
18614
|
+
#lastProjection = new Matrix4();
|
|
18615
|
+
#culled = false;
|
|
18272
18616
|
#distanceRatio;
|
|
18617
|
+
/** Radians the camera may turn before the bands are taken again. */
|
|
18618
|
+
viewMargin;
|
|
18619
|
+
/**
|
|
18620
|
+
* Whether copies the camera cannot see are skipped. Writable; the batch reports what it did
|
|
18621
|
+
* through {@link ClusteredBatch.viewCullReport}.
|
|
18622
|
+
*/
|
|
18623
|
+
viewCull;
|
|
18273
18624
|
/** Bands this camera wants that are not built yet; while any remain the cut cannot settle. */
|
|
18274
18625
|
#pending = 0;
|
|
18275
18626
|
#root = null;
|
|
18276
18627
|
#built = null;
|
|
18277
18628
|
#drawnTriangles = 0;
|
|
18629
|
+
#meshRadius;
|
|
18630
|
+
#frustum = new Frustum();
|
|
18631
|
+
#viewMatrix = new Matrix4();
|
|
18632
|
+
/** The band each copy was drawn in this update, or `CULLED` when it was not drawn at all. */
|
|
18633
|
+
#bandKey;
|
|
18634
|
+
#drawnCopiesOutsideView = 0;
|
|
18635
|
+
#drawnTrianglesOutsideView = 0;
|
|
18278
18636
|
constructor(options) {
|
|
18279
18637
|
this.#options = options;
|
|
18280
18638
|
this.#distanceRatio = options.distanceRatio ?? DEFAULT_DISTANCE_RATIO;
|
|
@@ -18282,8 +18640,13 @@ var ClusteredBatch = class {
|
|
|
18282
18640
|
throw new Error(
|
|
18283
18641
|
`ClusteredBatch distanceRatio must be above one, got ${this.#distanceRatio}.`
|
|
18284
18642
|
);
|
|
18643
|
+
this.viewCull = options.viewCull ?? true;
|
|
18644
|
+
this.viewMargin = options.viewMargin ?? DEFAULT_VIEW_MARGIN;
|
|
18645
|
+
assertViewMargin(this.viewMargin);
|
|
18285
18646
|
this.#selection = new Uint32Array(options.table.ranges.length / 2);
|
|
18286
18647
|
this.#wantedKey = new Int32Array(0);
|
|
18648
|
+
this.#bandKey = new Int32Array(0);
|
|
18649
|
+
this.#meshRadius = clusterTableRadius(options.table);
|
|
18287
18650
|
}
|
|
18288
18651
|
/** How many copies are placed. */
|
|
18289
18652
|
get count() {
|
|
@@ -18299,6 +18662,30 @@ var ClusteredBatch = class {
|
|
|
18299
18662
|
get drawnTriangles() {
|
|
18300
18663
|
return this.#drawnTriangles;
|
|
18301
18664
|
}
|
|
18665
|
+
/**
|
|
18666
|
+
* Copies the current cut submits whose own bounding sphere lies wholly outside the view volume.
|
|
18667
|
+
*
|
|
18668
|
+
* A measurement, not a cull: see {@link ClusteredMesh.drawnTrianglesOutsideView}.
|
|
18669
|
+
*/
|
|
18670
|
+
get drawnCopiesOutsideView() {
|
|
18671
|
+
return this.#drawnCopiesOutsideView;
|
|
18672
|
+
}
|
|
18673
|
+
/** Triangles those copies submit: their own band's cut, times how many copies are outside. */
|
|
18674
|
+
get drawnTrianglesOutsideView() {
|
|
18675
|
+
return this.#drawnTrianglesOutsideView;
|
|
18676
|
+
}
|
|
18677
|
+
/**
|
|
18678
|
+
* What this batch does about copies outside the view, and why.
|
|
18679
|
+
*
|
|
18680
|
+
* `"on"` when copies the camera cannot see are skipped, and a reason when they are not — a batch
|
|
18681
|
+
* that silently kept drawing a whole copy behind the camera would be a cost with no symptom, and
|
|
18682
|
+
* one that silently dropped what a shadow camera can see would be a missing shadow with no cause.
|
|
18683
|
+
*/
|
|
18684
|
+
get viewCullReport() {
|
|
18685
|
+
if (!this.viewCull) return "off (viewCull = false)";
|
|
18686
|
+
if (this.#built?.castShadow === true) return "off (castShadow)";
|
|
18687
|
+
return "on";
|
|
18688
|
+
}
|
|
18302
18689
|
/** Adds one copy. Returns its index, so the game can move it later. */
|
|
18303
18690
|
place(placement) {
|
|
18304
18691
|
if (this.#built !== null)
|
|
@@ -18335,21 +18722,42 @@ var ClusteredBatch = class {
|
|
|
18335
18722
|
const scale = pixelsPerUnit(camera, viewportHeight);
|
|
18336
18723
|
camera.updateWorldMatrix(true, false);
|
|
18337
18724
|
this.#cameraWorld.setFromMatrixPosition(camera.matrixWorld);
|
|
18725
|
+
camera.getWorldQuaternion(this.#rotation);
|
|
18726
|
+
const culled = this.viewCull && this.#built?.castShadow !== true;
|
|
18727
|
+
if (culled) {
|
|
18728
|
+
this.#view.setFromCamera(camera, this.viewMargin);
|
|
18729
|
+
root.updateWorldMatrix(true, false);
|
|
18730
|
+
this.#view.setTransform(root.matrixWorld);
|
|
18731
|
+
}
|
|
18338
18732
|
let nearestCopy = Number.POSITIVE_INFINITY;
|
|
18339
18733
|
for (const placed of this.#placed)
|
|
18340
18734
|
nearestCopy = Math.min(nearestCopy, this.#cameraWorld.distanceTo(placed.position));
|
|
18341
|
-
const settled = this.#hasCut && scale === this.#lastScale && this.#pending === 0 && this.#cameraWorld.distanceTo(this.#lastCut) <= Math.max(nearestCopy,
|
|
18735
|
+
const settled = this.#hasCut && culled === this.#culled && scale === this.#lastScale && camera.projectionMatrix.equals(this.#lastProjection) && this.#pending === 0 && this.#rotation.angleTo(this.#lastRotation) <= this.viewMargin && this.#cameraWorld.distanceTo(this.#lastCut) <= Math.max(nearestCopy, MIN_DISTANCE2) * (this.#options.recutFraction ?? DEFAULT_RECUT_FRACTION);
|
|
18342
18736
|
if (settled) return this.#drawnTriangles;
|
|
18343
18737
|
this.#lastCut.copy(this.#cameraWorld);
|
|
18738
|
+
this.#lastRotation.copy(this.#rotation);
|
|
18344
18739
|
this.#lastScale = scale;
|
|
18740
|
+
this.#lastProjection.copy(camera.projectionMatrix);
|
|
18741
|
+
this.#culled = culled;
|
|
18345
18742
|
this.#hasCut = true;
|
|
18346
|
-
if (this.#wantedKey.length !== this.#placed.length)
|
|
18743
|
+
if (this.#wantedKey.length !== this.#placed.length) {
|
|
18347
18744
|
this.#wantedKey = new Int32Array(this.#placed.length);
|
|
18745
|
+
this.#bandKey = new Int32Array(this.#placed.length);
|
|
18746
|
+
}
|
|
18348
18747
|
for (const group of this.#groups.values()) group.copies.length = 0;
|
|
18349
18748
|
const wantedKeys = /* @__PURE__ */ new Set();
|
|
18350
18749
|
for (let copy = 0; copy < this.#placed.length; copy += 1) {
|
|
18351
18750
|
const placed = this.#placed[copy];
|
|
18352
|
-
|
|
18751
|
+
if (culled && !this.#view.touches(
|
|
18752
|
+
placed.position.x,
|
|
18753
|
+
placed.position.y,
|
|
18754
|
+
placed.position.z,
|
|
18755
|
+
this.#meshRadius * placed.scale
|
|
18756
|
+
)) {
|
|
18757
|
+
this.#wantedKey[copy] = CULLED;
|
|
18758
|
+
continue;
|
|
18759
|
+
}
|
|
18760
|
+
const distance = Math.max(this.#cameraWorld.distanceTo(placed.position), MIN_DISTANCE2);
|
|
18353
18761
|
const wanted = Math.floor(Math.log(distance / placed.scale) / Math.log(this.#distanceRatio));
|
|
18354
18762
|
this.#wantedKey[copy] = wanted;
|
|
18355
18763
|
wantedKeys.add(wanted);
|
|
@@ -18369,7 +18777,12 @@ var ClusteredBatch = class {
|
|
|
18369
18777
|
}
|
|
18370
18778
|
for (let copy = 0; copy < this.#placed.length; copy += 1) {
|
|
18371
18779
|
const wanted = this.#wantedKey[copy];
|
|
18780
|
+
if (wanted === CULLED) {
|
|
18781
|
+
this.#bandKey[copy] = CULLED;
|
|
18782
|
+
continue;
|
|
18783
|
+
}
|
|
18372
18784
|
const key = open.has(wanted) ? wanted : this.#nearestOpenKey(wanted, open);
|
|
18785
|
+
this.#bandKey[copy] = key;
|
|
18373
18786
|
let group = this.#groups.get(key);
|
|
18374
18787
|
if (group === void 0) {
|
|
18375
18788
|
group = { copies: [], cut: new Uint32Array(0), empty: 0, mesh: null };
|
|
@@ -18385,8 +18798,31 @@ var ClusteredBatch = class {
|
|
|
18385
18798
|
this.#groups.delete(key);
|
|
18386
18799
|
}
|
|
18387
18800
|
}
|
|
18801
|
+
this.#countOutsideView(camera);
|
|
18388
18802
|
return this.#drawnTriangles;
|
|
18389
18803
|
}
|
|
18804
|
+
/**
|
|
18805
|
+
* Records how many copies of this batch, and how many of their triangles, lie wholly out of view.
|
|
18806
|
+
*
|
|
18807
|
+
* A copy is tested on its own bounding sphere — the body's radius at the copy's scale — which is
|
|
18808
|
+
* the sphere three itself would cull it by. Read-only, and taken only on a frame that re-cut.
|
|
18809
|
+
*/
|
|
18810
|
+
#countOutsideView(camera) {
|
|
18811
|
+
const frustum = worldFrustum(camera, this.#frustum, this.#viewMatrix);
|
|
18812
|
+
let copies = 0;
|
|
18813
|
+
let triangles = 0;
|
|
18814
|
+
for (let copy = 0; copy < this.#placed.length; copy += 1) {
|
|
18815
|
+
if (this.#bandKey[copy] === CULLED) continue;
|
|
18816
|
+
const placed = this.#placed[copy];
|
|
18817
|
+
if (!outsideFrustum(frustum, placed.position, this.#meshRadius * placed.scale)) continue;
|
|
18818
|
+
copies += 1;
|
|
18819
|
+
const group = this.#groups.get(this.#bandKey[copy]);
|
|
18820
|
+
const mesh = group?.mesh;
|
|
18821
|
+
if (mesh?.visible === true) triangles += mesh.geometry.drawRange.count / 3;
|
|
18822
|
+
}
|
|
18823
|
+
this.#drawnCopiesOutsideView = copies;
|
|
18824
|
+
this.#drawnTrianglesOutsideView = triangles;
|
|
18825
|
+
}
|
|
18390
18826
|
/**
|
|
18391
18827
|
* Gives one group's index buffer back.
|
|
18392
18828
|
*
|
|
@@ -18495,7 +18931,7 @@ var ClusteredBatch = class {
|
|
|
18495
18931
|
#capacityFor(group, anchor, nearestDistance, scale) {
|
|
18496
18932
|
const nearEdge = this.#distanceRatio ** Math.floor(Math.log(nearestDistance) / Math.log(this.#distanceRatio));
|
|
18497
18933
|
const direction2 = this.#cameraLocal.clone().normalize();
|
|
18498
|
-
const probe = direction2.multiplyScalar(Math.max(nearEdge,
|
|
18934
|
+
const probe = direction2.multiplyScalar(Math.max(nearEdge, MIN_DISTANCE2));
|
|
18499
18935
|
const selected = selectClusterCut(
|
|
18500
18936
|
this.#options.table,
|
|
18501
18937
|
probe,
|
|
@@ -19398,8 +19834,8 @@ function octahedralCellCentre(cell, resolution) {
|
|
|
19398
19834
|
v = (1 - Math.abs(u)) * (v >= 0 ? 1 : -1);
|
|
19399
19835
|
u = fu;
|
|
19400
19836
|
}
|
|
19401
|
-
const
|
|
19402
|
-
return [u /
|
|
19837
|
+
const length8 = Math.hypot(u, v, z) || 1;
|
|
19838
|
+
return [u / length8, v / length8, z / length8];
|
|
19403
19839
|
}
|
|
19404
19840
|
function octahedralRayTable(directions, count, resolution) {
|
|
19405
19841
|
const cells = resolution * resolution;
|
|
@@ -19486,7 +19922,7 @@ function createProbeTraceKernels(scene, grid, raysPerProbe, maxBatch, pointCount
|
|
|
19486
19922
|
);
|
|
19487
19923
|
const volumeMin = vec3(grid.min.x, grid.min.y, grid.min.z);
|
|
19488
19924
|
const far = 4 * Math.max(grid.size.x, grid.size.y, grid.size.z, 1) + 1e4;
|
|
19489
|
-
const previousIrradiance = (point,
|
|
19925
|
+
const previousIrradiance = (point, normal2) => {
|
|
19490
19926
|
const local2 = clamp(
|
|
19491
19927
|
point.sub(volumeMin).div(vec3(spacing.x, spacing.y, spacing.z)),
|
|
19492
19928
|
vec3(0),
|
|
@@ -19508,7 +19944,7 @@ function createProbeTraceKernels(scene, grid, raysPerProbe, maxBatch, pointCount
|
|
|
19508
19944
|
);
|
|
19509
19945
|
const weight = (dx ? fraction.x : float(1).sub(fraction.x)).mul(dy ? fraction.y : float(1).sub(fraction.y)).mul(dz ? fraction.z : float(1).sub(fraction.z)).mul(open);
|
|
19510
19946
|
const coefficient = (index) => coefficientNode.element(probe.mul(int(9)).add(int(index))).xyz;
|
|
19511
|
-
sum = sum.add(shIrradiance(coefficient,
|
|
19947
|
+
sum = sum.add(shIrradiance(coefficient, normal2).mul(weight));
|
|
19512
19948
|
total = total.add(weight);
|
|
19513
19949
|
}
|
|
19514
19950
|
return sum.div(max(total, 1e-4));
|
|
@@ -19546,15 +19982,15 @@ function createProbeTraceKernels(scene, grid, raysPerProbe, maxBatch, pointCount
|
|
|
19546
19982
|
for (const light of points) {
|
|
19547
19983
|
const toLight = light.position.sub(point);
|
|
19548
19984
|
const squared = max(dot(toLight, toLight), 1e-4);
|
|
19549
|
-
const
|
|
19550
|
-
const toward = toLight.div(
|
|
19985
|
+
const length8 = sqrt(squared);
|
|
19986
|
+
const toward = toLight.div(length8);
|
|
19551
19987
|
const facingLight = max(dot(facing, toward), 0);
|
|
19552
19988
|
If(facingLight.greaterThan(0), () => {
|
|
19553
|
-
const shadow2 = traceRay(buffers, nodeCount, point, toward,
|
|
19989
|
+
const shadow2 = traceRay(buffers, nodeCount, point, toward, length8.sub(0.02), true);
|
|
19554
19990
|
If(shadow2.triangle.lessThan(0), () => {
|
|
19555
19991
|
const window = select(
|
|
19556
19992
|
light.distance.greaterThan(0),
|
|
19557
|
-
pow(clamp(float(1).sub(pow(
|
|
19993
|
+
pow(clamp(float(1).sub(pow(length8.div(light.distance), 4)), 0, 1), 2),
|
|
19558
19994
|
float(1)
|
|
19559
19995
|
);
|
|
19560
19996
|
direct.addAssign(light.radiance.mul(facingLight.mul(window).div(squared)));
|
|
@@ -19577,9 +20013,9 @@ function createProbeTraceKernels(scene, grid, raysPerProbe, maxBatch, pointCount
|
|
|
19577
20013
|
Loop(
|
|
19578
20014
|
{ start: int(0), end: int(raysPerProbe), type: "int", condition: "<" },
|
|
19579
20015
|
({ i }) => {
|
|
19580
|
-
const
|
|
19581
|
-
const value =
|
|
19582
|
-
backfaces.addAssign(select(
|
|
20016
|
+
const sample2 = radianceNode.element(slot.mul(int(raysPerProbe)).add(i));
|
|
20017
|
+
const value = sample2.xyz;
|
|
20018
|
+
backfaces.addAssign(select(sample2.w.lessThan(0), float(1), float(0)));
|
|
19583
20019
|
const d = directions.element(i);
|
|
19584
20020
|
add(0, value.mul(0.282095));
|
|
19585
20021
|
add(1, value.mul(d.y.mul(0.488603)));
|
|
@@ -19622,9 +20058,9 @@ function createProbeTraceKernels(scene, grid, raysPerProbe, maxBatch, pointCount
|
|
|
19622
20058
|
const depth = float(0).toVar();
|
|
19623
20059
|
Loop({ start: int(0), end: count, type: "int", condition: "<" }, ({ i }) => {
|
|
19624
20060
|
const ray = int(cellRays.element(first.add(i)).x);
|
|
19625
|
-
const
|
|
19626
|
-
sum.addAssign(
|
|
19627
|
-
depth.addAssign(abs(
|
|
20061
|
+
const sample2 = radianceNode.element(slot.mul(int(raysPerProbe)).add(ray));
|
|
20062
|
+
sum.addAssign(sample2.xyz);
|
|
20063
|
+
depth.addAssign(abs(sample2.w));
|
|
19628
20064
|
});
|
|
19629
20065
|
mapNode.element(probe.mul(int(cells)).add(cell)).assign(vec4(sum.div(float(count)), depth.div(float(count))));
|
|
19630
20066
|
})().compute(maxBatch * cells);
|
|
@@ -20108,14 +20544,14 @@ var ProbeVolume = class extends Object3D {
|
|
|
20108
20544
|
sceneOrOptions ?? {}
|
|
20109
20545
|
);
|
|
20110
20546
|
}
|
|
20111
|
-
sample(position = positionWorld,
|
|
20112
|
-
if (position instanceof Vector3 &&
|
|
20113
|
-
return this.sampleIrradiance(position,
|
|
20547
|
+
sample(position = positionWorld, normal2 = normalWorld) {
|
|
20548
|
+
if (position instanceof Vector3 && normal2 instanceof Vector3) {
|
|
20549
|
+
return this.sampleIrradiance(position, normal2);
|
|
20114
20550
|
}
|
|
20115
|
-
return this.sampleNode(position,
|
|
20551
|
+
return this.sampleNode(position, normal2);
|
|
20116
20552
|
}
|
|
20117
|
-
sampleIrradiance(position,
|
|
20118
|
-
return this.#evaluateCpu(position,
|
|
20553
|
+
sampleIrradiance(position, normal2) {
|
|
20554
|
+
return this.#evaluateCpu(position, normal2, SH_IRRADIANCE_WEIGHTS, "sampleIrradiance");
|
|
20119
20555
|
}
|
|
20120
20556
|
/**
|
|
20121
20557
|
* The radiance arriving along `direction` (the SH itself, not convolved with a cosine lobe), clamped at zero. A
|
|
@@ -20125,12 +20561,12 @@ var ProbeVolume = class extends Object3D {
|
|
|
20125
20561
|
sampleRadiance(position, direction2) {
|
|
20126
20562
|
return this.#evaluateCpu(position, direction2, SH_RADIANCE_WEIGHTS, "sampleRadiance");
|
|
20127
20563
|
}
|
|
20128
|
-
#evaluateCpu(position,
|
|
20129
|
-
if (!(position instanceof Vector3) || !(
|
|
20564
|
+
#evaluateCpu(position, normal2, weights, name) {
|
|
20565
|
+
if (!(position instanceof Vector3) || !(normal2 instanceof Vector3)) {
|
|
20130
20566
|
throw new Error(`ProbeVolume.${name} requires Vector3 position and normal values.`);
|
|
20131
20567
|
}
|
|
20132
20568
|
const coefficients = this.#samplePackedCoefficients(position);
|
|
20133
|
-
const direction2 =
|
|
20569
|
+
const direction2 = normal2.clone().normalize();
|
|
20134
20570
|
const result = new Vector3();
|
|
20135
20571
|
result.x = evaluateShChannel(coefficients, 0, direction2, weights);
|
|
20136
20572
|
result.y = evaluateShChannel(coefficients, 1, direction2, weights);
|
|
@@ -20157,8 +20593,8 @@ var ProbeVolume = class extends Object3D {
|
|
|
20157
20593
|
);
|
|
20158
20594
|
}
|
|
20159
20595
|
/** The GPU graph used by `sample`; exposed so generated materials can compose it explicitly. */
|
|
20160
|
-
sampleNode(position = positionWorld,
|
|
20161
|
-
return this.#shNode(position,
|
|
20596
|
+
sampleNode(position = positionWorld, normal2 = normalWorld) {
|
|
20597
|
+
return this.#shNode(position, normal2, SH_IRRADIANCE_WEIGHTS);
|
|
20162
20598
|
}
|
|
20163
20599
|
/** The GPU graph of `sampleRadiance`: the radiance arriving along `direction`, clamped at zero. */
|
|
20164
20600
|
sampleRadianceNode(position = positionWorld, direction2 = normalWorld) {
|
|
@@ -20284,7 +20720,7 @@ var ProbeVolume = class extends Object3D {
|
|
|
20284
20720
|
sum = sum.add(texture(map, this.#mapTexelNode(probe, cell)).rgb.mul(weight));
|
|
20285
20721
|
return sum.div(total.max(1e-6)).max(0);
|
|
20286
20722
|
}
|
|
20287
|
-
#shNode(position,
|
|
20723
|
+
#shNode(position, normal2, w) {
|
|
20288
20724
|
const atlasAt = this.#atlasAt(position);
|
|
20289
20725
|
const packed = this.#visibility ? this.#visiblePacked(position) : (subVolume) => this.#atlasNode.sample(atlasAt(subVolume));
|
|
20290
20726
|
const packedValues = Array.from(
|
|
@@ -20303,7 +20739,7 @@ var ProbeVolume = class extends Object3D {
|
|
|
20303
20739
|
vec3(packedAt(5).y, packedAt(5).z, packedAt(5).w),
|
|
20304
20740
|
vec3(packedAt(6).x, packedAt(6).y, packedAt(6).z)
|
|
20305
20741
|
];
|
|
20306
|
-
const direction2 = normalize(vec3(
|
|
20742
|
+
const direction2 = normalize(vec3(normal2));
|
|
20307
20743
|
const coefficientAt = (index) => valueAt2(coefficients, index, "SH coefficient");
|
|
20308
20744
|
const value = coefficientAt(0).mul(w.l0).add(coefficientAt(1).mul(direction2.y).mul(w.l1)).add(coefficientAt(2).mul(direction2.z).mul(w.l1)).add(coefficientAt(3).mul(direction2.x).mul(w.l1)).add(coefficientAt(4).mul(direction2.x.mul(direction2.y)).mul(w.l2)).add(coefficientAt(5).mul(direction2.y.mul(direction2.z)).mul(w.l2)).add(coefficientAt(6).mul(direction2.z.mul(direction2.z).mul(w.l20).sub(w.l20Offset))).add(coefficientAt(7).mul(direction2.x.mul(direction2.z)).mul(w.l2)).add(
|
|
20309
20745
|
coefficientAt(8).mul(direction2.x.mul(direction2.x).sub(direction2.y.mul(direction2.y))).mul(w.l22)
|
|
@@ -21272,9 +21708,9 @@ function clampedTextureCoordinate(value, size) {
|
|
|
21272
21708
|
function uniquePair(lower, upper) {
|
|
21273
21709
|
return lower === upper ? [lower] : [lower, upper];
|
|
21274
21710
|
}
|
|
21275
|
-
function interpolationFactor(
|
|
21711
|
+
function interpolationFactor(sample2, lower, upper, fraction) {
|
|
21276
21712
|
if (lower === upper) return 1;
|
|
21277
|
-
return
|
|
21713
|
+
return sample2 === lower ? 1 - fraction : fraction;
|
|
21278
21714
|
}
|
|
21279
21715
|
function createCpuAtlas(data, resolution, depth) {
|
|
21280
21716
|
const atlas = new Data3DTexture(data, resolution.x, resolution.y, depth);
|
|
@@ -21338,10 +21774,10 @@ function createRepackMaterials(batchTextureNode, slice, dimensions, probeCount)
|
|
|
21338
21774
|
const ix = floor(viewportCoordinate.x);
|
|
21339
21775
|
const iy = floor(viewportCoordinate.y);
|
|
21340
21776
|
const probe = ix.add(iy.mul(dimensions.x)).add(int(slice).mul(dimensions.x * dimensions.y));
|
|
21341
|
-
const
|
|
21777
|
+
const uv8 = vec2(probe.add(0.5).div(probeCount), 0);
|
|
21342
21778
|
const samples = Array.from(
|
|
21343
21779
|
{ length: SH_COEFFICIENT_COUNT },
|
|
21344
|
-
(_, index) => batchTextureNode.sample(vec2((index + 0.5) / SH_COEFFICIENT_COUNT,
|
|
21780
|
+
(_, index) => batchTextureNode.sample(vec2((index + 0.5) / SH_COEFFICIENT_COUNT, uv8.x))
|
|
21345
21781
|
);
|
|
21346
21782
|
const sampleAt2 = (index) => valueAt2(samples, index, "repack sample");
|
|
21347
21783
|
const values = [
|
|
@@ -21391,27 +21827,27 @@ var SH_RADIANCE_WEIGHTS = {
|
|
|
21391
21827
|
l20Offset: 0.315392,
|
|
21392
21828
|
l22: 0.546274
|
|
21393
21829
|
};
|
|
21394
|
-
function evaluateShChannel(coefficients, channel,
|
|
21830
|
+
function evaluateShChannel(coefficients, channel, normal2, w) {
|
|
21395
21831
|
const c = (index) => coefficients[index * SH_CHANNEL_COUNT + channel] ?? 0;
|
|
21396
|
-
return c(0) * w.l0 + c(1) *
|
|
21832
|
+
return c(0) * w.l0 + c(1) * normal2.y * w.l1 + c(2) * normal2.z * w.l1 + c(3) * normal2.x * w.l1 + c(4) * normal2.x * normal2.y * w.l2 + c(5) * normal2.y * normal2.z * w.l2 + c(6) * (normal2.z * normal2.z * w.l20 - w.l20Offset) + c(7) * normal2.x * normal2.z * w.l2 + c(8) * (normal2.x * normal2.x - normal2.y * normal2.y) * w.l22;
|
|
21397
21833
|
}
|
|
21398
21834
|
function normalizeBounds(value) {
|
|
21399
21835
|
const min8 = new Vector3(value.min.x, value.min.y, value.min.z);
|
|
21400
|
-
const
|
|
21836
|
+
const max11 = new Vector3(value.max.x, value.max.y, value.max.z);
|
|
21401
21837
|
for (const [name, vector3] of [
|
|
21402
21838
|
["min", min8],
|
|
21403
|
-
["max",
|
|
21839
|
+
["max", max11]
|
|
21404
21840
|
]) {
|
|
21405
21841
|
if (![vector3.x, vector3.y, vector3.z].every(Number.isFinite)) {
|
|
21406
21842
|
throw new Error(`ProbeVolume bounds.${name} must contain finite x, y, and z values.`);
|
|
21407
21843
|
}
|
|
21408
21844
|
}
|
|
21409
|
-
if (!(min8.x <
|
|
21845
|
+
if (!(min8.x < max11.x && min8.y < max11.y && min8.z < max11.z)) {
|
|
21410
21846
|
throw new Error(
|
|
21411
21847
|
"ProbeVolume bounds must be non-degenerate and min must be below max on every axis."
|
|
21412
21848
|
);
|
|
21413
21849
|
}
|
|
21414
|
-
return new Box3(min8,
|
|
21850
|
+
return new Box3(min8, max11);
|
|
21415
21851
|
}
|
|
21416
21852
|
function normalizeDensity(value) {
|
|
21417
21853
|
let density;
|
|
@@ -21584,9 +22020,9 @@ function isFiniteNonNegative(value) {
|
|
|
21584
22020
|
function isFinitePositive(value) {
|
|
21585
22021
|
return typeof value === "number" && Number.isFinite(value) && value > 0;
|
|
21586
22022
|
}
|
|
21587
|
-
function validateProbeIndex(index,
|
|
21588
|
-
if (!Number.isSafeInteger(index) || index < 0 || index >=
|
|
21589
|
-
throw new Error(`ProbeVolume ${name} must be an integer in [0, ${
|
|
22023
|
+
function validateProbeIndex(index, length8, name) {
|
|
22024
|
+
if (!Number.isSafeInteger(index) || index < 0 || index >= length8) {
|
|
22025
|
+
throw new Error(`ProbeVolume ${name} must be an integer in [0, ${length8 - 1}].`);
|
|
21590
22026
|
}
|
|
21591
22027
|
}
|
|
21592
22028
|
function valueAt2(values, index, label2) {
|
|
@@ -21801,11 +22237,11 @@ var SurfaceLights = class {
|
|
|
21801
22237
|
#scores;
|
|
21802
22238
|
#order = [];
|
|
21803
22239
|
constructor(lights, options = {}) {
|
|
21804
|
-
const
|
|
21805
|
-
if (!Number.isInteger(
|
|
21806
|
-
throw new RangeError(`maxLights ${
|
|
22240
|
+
const max11 = options.maxLights ?? 8;
|
|
22241
|
+
if (!Number.isInteger(max11) || max11 < 1)
|
|
22242
|
+
throw new RangeError(`maxLights ${max11} must be an integer of 1 or more`);
|
|
21807
22243
|
this.#lights = lights;
|
|
21808
|
-
this.#max =
|
|
22244
|
+
this.#max = max11;
|
|
21809
22245
|
this.#scores = new Array(lights.length).fill(0);
|
|
21810
22246
|
}
|
|
21811
22247
|
/**
|
|
@@ -21813,11 +22249,11 @@ var SurfaceLights = class {
|
|
|
21813
22249
|
* (x cone for a spot). `visible(i)` answers the shadow ray to light `i`; it is not asked for a light behind the
|
|
21814
22250
|
* surface, out of range or outside its cone.
|
|
21815
22251
|
*/
|
|
21816
|
-
shade(point,
|
|
22252
|
+
shade(point, normal2, albedo, out, visible) {
|
|
21817
22253
|
const order = this.#order;
|
|
21818
22254
|
order.length = 0;
|
|
21819
22255
|
for (let i = 0; i < this.#lights.length; i += 1) {
|
|
21820
|
-
const score = this.#score(this.#lights[i], point,
|
|
22256
|
+
const score = this.#score(this.#lights[i], point, normal2);
|
|
21821
22257
|
this.#scores[i] = score;
|
|
21822
22258
|
if (score > 0) order.push(i);
|
|
21823
22259
|
}
|
|
@@ -21837,8 +22273,8 @@ var SurfaceLights = class {
|
|
|
21837
22273
|
const [dx, dy, dz] = [light.position[0] - px, light.position[1] - py, light.position[2] - pz];
|
|
21838
22274
|
const d = Math.hypot(dx, dy, dz);
|
|
21839
22275
|
if (d < 0.02 || light.distance > 0 && d >= light.distance) return 0;
|
|
21840
|
-
const
|
|
21841
|
-
if (
|
|
22276
|
+
const cos3 = (nx * dx + ny * dy + nz * dz) / d;
|
|
22277
|
+
if (cos3 <= 0) return 0;
|
|
21842
22278
|
const window = light.distance > 0 ? Math.min(1, Math.max(0, 1 - (d / light.distance) ** 4)) ** 2 : 1;
|
|
21843
22279
|
let cone = 1;
|
|
21844
22280
|
if (light.kind === "spot") {
|
|
@@ -21849,7 +22285,7 @@ var SurfaceLights = class {
|
|
|
21849
22285
|
const t = Math.min(1, Math.max(0, (toHit - outer) / Math.max(inner - outer, 1e-6)));
|
|
21850
22286
|
cone = t * t * (3 - 2 * t);
|
|
21851
22287
|
}
|
|
21852
|
-
return light.intensity / Math.PI / (d * d) * window *
|
|
22288
|
+
return light.intensity / Math.PI / (d * d) * window * cos3 * cone;
|
|
21853
22289
|
}
|
|
21854
22290
|
};
|
|
21855
22291
|
function shadowInput(node) {
|
|
@@ -21936,7 +22372,7 @@ function sourceAngleShadowFilter({
|
|
|
21936
22372
|
).div(shadowInput(reference("zoom", "float", camera)));
|
|
21937
22373
|
const texel = vec2(1).div(size);
|
|
21938
22374
|
const isArray = "isArrayTexture" in depthTexture && depthTexture.isArrayTexture === true;
|
|
21939
|
-
const withLayer = (
|
|
22375
|
+
const withLayer = (sample2) => isArray ? sample2.depth(float(depthLayer)) : sample2;
|
|
21940
22376
|
const linearDepth2 = (depth) => reversed ? depth.oneMinus() : depth;
|
|
21941
22377
|
return Fn(
|
|
21942
22378
|
(_inputs, builder) => {
|
|
@@ -21945,11 +22381,11 @@ function sourceAngleShadowFilter({
|
|
|
21945
22381
|
const searchRadius = max(texel, vec2(receiver.mul(range).mul(reach)).div(span)).toVar();
|
|
21946
22382
|
const blockerSum = float(0).toVar();
|
|
21947
22383
|
const blockerCount = float(0).toVar();
|
|
21948
|
-
const load = (
|
|
22384
|
+
const load = (uv8) => linearDepth2(
|
|
21949
22385
|
withLayer(
|
|
21950
22386
|
textureLoad(
|
|
21951
22387
|
depthTexture,
|
|
21952
|
-
ivec2(min(max(
|
|
22388
|
+
ivec2(min(max(uv8.mul(size).floor(), vec2(0)), size.sub(1)))
|
|
21953
22389
|
)
|
|
21954
22390
|
).r
|
|
21955
22391
|
);
|
|
@@ -22141,7 +22577,7 @@ function sourceRadiusShadowFilter({
|
|
|
22141
22577
|
const tanHalf = uniform(1).setGroup(renderGroup).onRenderUpdate(() => Math.tan(camera.fov * Math.PI / 360) / camera.zoom);
|
|
22142
22578
|
const uvPerTangent = float(0.5).div(tanHalf);
|
|
22143
22579
|
const sizes = vec2(size);
|
|
22144
|
-
const load = (
|
|
22580
|
+
const load = (uv8) => textureLoad(depthTexture, ivec2(min(max(uv8.mul(sizes).floor(), vec2(0)), sizes.sub(1)))).r;
|
|
22145
22581
|
return Fn(() => {
|
|
22146
22582
|
const receiver = distanceOf(shadowCoord.z).toVar();
|
|
22147
22583
|
const slope = slopeOf(dFdx(shadowCoord.xy), dFdy(shadowCoord.xy), receiver, uvPerTangent);
|
|
@@ -22447,7 +22883,7 @@ function dot5(a, b) {
|
|
|
22447
22883
|
function cross5(a, b) {
|
|
22448
22884
|
return { x: a.y * b.z - a.z * b.y, y: a.z * b.x - a.x * b.z, z: a.x * b.y - a.y * b.x };
|
|
22449
22885
|
}
|
|
22450
|
-
function
|
|
22886
|
+
function normalize5(vector3) {
|
|
22451
22887
|
const magnitude = Math.sqrt(dot5(vector3, vector3));
|
|
22452
22888
|
if (magnitude <= EPSILON3) throw new RangeError("direction must have non-zero length");
|
|
22453
22889
|
return { x: vector3.x / magnitude, y: vector3.y / magnitude, z: vector3.z / magnitude };
|
|
@@ -22545,7 +22981,7 @@ var DirectionalClipmap = class {
|
|
|
22545
22981
|
this.refreshStep = clipExtents.map((_, level) => this.#perLevel(steps, level));
|
|
22546
22982
|
this.selectionGuard = guards;
|
|
22547
22983
|
this.levelCount = clipExtents.length;
|
|
22548
|
-
this.basisW =
|
|
22984
|
+
this.basisW = normalize5(direction2);
|
|
22549
22985
|
this.basisU = { x: 1, y: 0, z: 0 };
|
|
22550
22986
|
this.basisV = { x: 0, y: 0, z: 1 };
|
|
22551
22987
|
this.setDirection(direction2);
|
|
@@ -22553,12 +22989,12 @@ var DirectionalClipmap = class {
|
|
|
22553
22989
|
/** Re-orient the basis; returns true when it changed enough that cached pages are stale. */
|
|
22554
22990
|
setDirection(direction2) {
|
|
22555
22991
|
assertFiniteVector("direction", direction2);
|
|
22556
|
-
const nextW =
|
|
22992
|
+
const nextW = normalize5(direction2);
|
|
22557
22993
|
const unchanged = this.#windows.length > 0 && Math.abs(dot5(nextW, this.basisW) - 1) <= 1e-9;
|
|
22558
22994
|
this.basisW = nextW;
|
|
22559
22995
|
const reference3 = Math.abs(this.basisW.y) > 0.95 ? { x: 0, y: 0, z: 1 } : { x: 0, y: 1, z: 0 };
|
|
22560
|
-
this.basisU =
|
|
22561
|
-
this.basisV =
|
|
22996
|
+
this.basisU = normalize5(cross5(this.basisW, reference3));
|
|
22997
|
+
this.basisV = normalize5(cross5(this.basisW, this.basisU));
|
|
22562
22998
|
this.vScale = Math.abs(this.basisW.y) > 0.95 ? 1 : Math.min(1, Math.max(this.minAspect, Math.abs(this.basisW.y)));
|
|
22563
22999
|
if (!unchanged) this.#windows = [];
|
|
22564
23000
|
this.updateCenter(this.centerWorld);
|
|
@@ -24210,8 +24646,8 @@ var VirtualShadowNode = class extends ShadowBaseNode {
|
|
|
24210
24646
|
const extent = level.extent;
|
|
24211
24647
|
const side = extent * Math.SQRT2;
|
|
24212
24648
|
const fits = extent * 2 * MAX_MASS_WINDOW_WIDTHS;
|
|
24213
|
-
const
|
|
24214
|
-
if (
|
|
24649
|
+
const sin3 = basisW.y;
|
|
24650
|
+
if (sin3 < MIN_SUN_COSINE) return void 0;
|
|
24215
24651
|
const heightReach = extent * (Math.abs(basisU.y) + Math.abs(basisV.y));
|
|
24216
24652
|
let low2 = Number.POSITIVE_INFINITY;
|
|
24217
24653
|
let high2 = Number.NEGATIVE_INFINITY;
|
|
@@ -24229,8 +24665,8 @@ var VirtualShadowNode = class extends ShadowBaseNode {
|
|
|
24229
24665
|
const boxLow = pool[at3 + 5];
|
|
24230
24666
|
const boxHigh = pool[at3 + 6];
|
|
24231
24667
|
if (radius * 2 > fits) {
|
|
24232
|
-
const from = (boxLow - centre.y - heightReach) /
|
|
24233
|
-
const to = (boxHigh - centre.y + heightReach) /
|
|
24668
|
+
const from = (boxLow - centre.y - heightReach) / sin3;
|
|
24669
|
+
const to = (boxHigh - centre.y + heightReach) / sin3;
|
|
24234
24670
|
if (from < low2) low2 = from;
|
|
24235
24671
|
if (to > high2) high2 = to;
|
|
24236
24672
|
continue;
|
|
@@ -24402,10 +24838,10 @@ var VirtualShadowNode = class extends ShadowBaseNode {
|
|
|
24402
24838
|
const filter = stock.setupShadowFilter;
|
|
24403
24839
|
stock.setupShadowFilter = (builder2, inputs) => {
|
|
24404
24840
|
const levelTint = this.#levelTints.get(builder2);
|
|
24405
|
-
const
|
|
24841
|
+
const uv8 = inputs.shadowCoord;
|
|
24406
24842
|
const inside = and(
|
|
24407
|
-
and(
|
|
24408
|
-
and(
|
|
24843
|
+
and(uv8.x.greaterThanEqual(0), uv8.x.lessThanEqual(1)),
|
|
24844
|
+
and(uv8.y.greaterThanEqual(0), uv8.y.lessThanEqual(1))
|
|
24409
24845
|
);
|
|
24410
24846
|
const colour = index === 0 ? vec3(1, 0, 0) : index === 1 ? vec3(0, 1, 0) : index === 2 ? vec3(0, 0, 1) : vec3(1, 1, 0);
|
|
24411
24847
|
if (levelTint === void 0) return filter.call(stock, builder2, inputs);
|
|
@@ -24493,10 +24929,10 @@ var VirtualShadowNode = class extends ShadowBaseNode {
|
|
|
24493
24929
|
this.setupShadowPosition(builder);
|
|
24494
24930
|
if (this.options.receiverPlaneBias) {
|
|
24495
24931
|
const received = vec3(shadowPositionWorld);
|
|
24496
|
-
const
|
|
24497
|
-
const along = max(abs(
|
|
24932
|
+
const normal2 = dFdx(received).cross(dFdy(received)).toVar();
|
|
24933
|
+
const along = max(abs(normal2.dot(this.#basisW)), max(length(normal2).mul(1e-4), 1e-12));
|
|
24498
24934
|
this.#receiverSlope.assign(
|
|
24499
|
-
abs(
|
|
24935
|
+
abs(normal2.dot(basisU)).add(abs(normal2.dot(basisV)).div(basisV.dot(basisV))).div(along)
|
|
24500
24936
|
);
|
|
24501
24937
|
}
|
|
24502
24938
|
const u = positionWorld.dot(vec3(basisU)).sub(centerU);
|
|
@@ -25007,7 +25443,7 @@ function roughDiffuseFactor(albedo, r, nov, nol, vol) {
|
|
|
25007
25443
|
function roughen(model) {
|
|
25008
25444
|
const lambert = model.direct;
|
|
25009
25445
|
model.direct = function direct(input, builder) {
|
|
25010
|
-
const
|
|
25446
|
+
const scratch4 = vec3(0).toVar();
|
|
25011
25447
|
const specular = vec3(0).toVar();
|
|
25012
25448
|
lambert.call(
|
|
25013
25449
|
this,
|
|
@@ -25015,7 +25451,7 @@ function roughen(model) {
|
|
|
25015
25451
|
...input,
|
|
25016
25452
|
reflectedLight: {
|
|
25017
25453
|
...input.reflectedLight,
|
|
25018
|
-
directDiffuse:
|
|
25454
|
+
directDiffuse: scratch4,
|
|
25019
25455
|
directSpecular: specular
|
|
25020
25456
|
}
|
|
25021
25457
|
},
|
|
@@ -25038,7 +25474,7 @@ function roughen(model) {
|
|
|
25038
25474
|
const factor = roughDiffuseFactor(albedo, r, nov, nol, vol).div(
|
|
25039
25475
|
fresnel.oneMinus().max(EPSILON4)
|
|
25040
25476
|
);
|
|
25041
|
-
input.reflectedLight.directDiffuse.addAssign(
|
|
25477
|
+
input.reflectedLight.directDiffuse.addAssign(scratch4.mul(factor));
|
|
25042
25478
|
const weight3 = this.multiScatteringCompensation;
|
|
25043
25479
|
input.reflectedLight.directSpecular.addAssign(
|
|
25044
25480
|
weight3 === void 0 ? specular : specular.div(weight3)
|
|
@@ -25265,10 +25701,10 @@ function adaptExposure(histogram, previous, resetMode, seed, delta, policy, deco
|
|
|
25265
25701
|
const fresh = resetMode.equal(2).or(resetMode.equal(0).and(history.g.lessThanEqual(0)));
|
|
25266
25702
|
const error = goal.sub(old);
|
|
25267
25703
|
const rate = error.greaterThan(0).select(float(policy.rateUp), float(policy.rateDown));
|
|
25268
|
-
const
|
|
25704
|
+
const normal2 = float(1).sub(delta.mul(rate).negate().exp());
|
|
25269
25705
|
const cut = smoothstep(policy.snapLo, policy.snapHi, error.abs()).mul(policy.snapGain);
|
|
25270
25706
|
const adapted = valid.select(
|
|
25271
|
-
fresh.select(goal, mix(old, goal, mix(
|
|
25707
|
+
fresh.select(goal, mix(old, goal, mix(normal2, float(1), cut))),
|
|
25272
25708
|
old
|
|
25273
25709
|
);
|
|
25274
25710
|
const settled = goal.sub(adapted).abs().lessThanEqual(policy.settleStops).select(1, 0);
|
|
@@ -25404,7 +25840,7 @@ var AutoExposureNode = class extends Node {
|
|
|
25404
25840
|
#gateSkips;
|
|
25405
25841
|
// Three's runtime accepts undefined on first use, but its declaration requires a state.
|
|
25406
25842
|
#rendererState;
|
|
25407
|
-
constructor(input, settings, constantExposure, meter = (colour,
|
|
25843
|
+
constructor(input, settings, constantExposure, meter = (colour, uv8) => exposureMeter(colour), decode = (mean2) => exposureLuminance(mean2)) {
|
|
25408
25844
|
super("float");
|
|
25409
25845
|
validateExposureSettings(settings);
|
|
25410
25846
|
if (!Number.isFinite(Math.fround(constantExposure)) || Math.fround(constantExposure) <= 0)
|
|
@@ -25567,9 +26003,9 @@ function cacheFallback(camera) {
|
|
|
25567
26003
|
if (read === void 0) return void 0;
|
|
25568
26004
|
const live = (index) => uniform(0).onRenderUpdate(() => camera.matrixWorld.elements[index] ?? 0);
|
|
25569
26005
|
const column = (a) => vec3(live(a), live(a + 1), live(a + 2));
|
|
25570
|
-
const [right,
|
|
25571
|
-
const toWorld = (v) => right.mul(v.x).add(
|
|
25572
|
-
return (position,
|
|
26006
|
+
const [right, up2, back, at3] = [column(0), column(4), column(8), column(12)];
|
|
26007
|
+
const toWorld = (v) => right.mul(v.x).add(up2.mul(v.y)).add(back.mul(v.z));
|
|
26008
|
+
return (position, normal2) => read(toWorld(position).add(at3), toWorld(normal2).normalize());
|
|
25573
26009
|
}
|
|
25574
26010
|
var localExposureSettings = {
|
|
25575
26011
|
/** Scale on how far a bright base sits above middle grey; 1 leaves the global exposure alone. */
|
|
@@ -25935,14 +26371,14 @@ function motionBlur(colour, velocity) {
|
|
|
25935
26371
|
const timeScale = float(1 / targetFps).div(deltaTime.max(1e-4));
|
|
25936
26372
|
const half = v.mul(vec2(1, -1)).mul(screenSize).mul(0.5).mul(timeScale.mul(amount * 0.5));
|
|
25937
26373
|
const limit = screenSize.x.mul(0.5 * (maxPercent / 100));
|
|
25938
|
-
const
|
|
25939
|
-
const clamped = half.mul(float(1).min(limit.div(
|
|
26374
|
+
const length8 = half.length();
|
|
26375
|
+
const clamped = half.mul(float(1).min(limit.div(length8.max(1e-4))));
|
|
25940
26376
|
const sum = vec4(0).toVar();
|
|
25941
26377
|
Loop({ start: int(0), end: int(SAMPLES), type: "int" }, ({ i }) => {
|
|
25942
26378
|
const t = float(i).div(SAMPLES - 1).mul(2).sub(1);
|
|
25943
26379
|
sum.addAssign(colour.sample(c.add(clamped.mul(t).div(screenSize))).level(float(0)));
|
|
25944
26380
|
});
|
|
25945
|
-
return
|
|
26381
|
+
return length8.lessThan(0.25).select(colour.sample(c), sum.div(SAMPLES));
|
|
25946
26382
|
})();
|
|
25947
26383
|
}
|
|
25948
26384
|
var reflectionTrace = {};
|
|
@@ -25995,16 +26431,16 @@ function skyAmbientCube(environment, intensity = 1) {
|
|
|
25995
26431
|
return sums;
|
|
25996
26432
|
}
|
|
25997
26433
|
var FADE_FROM = 0.5;
|
|
25998
|
-
var
|
|
25999
|
-
var
|
|
26434
|
+
var START_OFFSET2 = 0.01;
|
|
26435
|
+
var START_OFFSET_PER_METRE2 = 4e-3;
|
|
26000
26436
|
var SHADOW_OFFSET = 0.02;
|
|
26001
26437
|
var SHADOW_FAR = 2e3;
|
|
26002
26438
|
var NO_CACHE_RADIANCE = 0;
|
|
26003
|
-
function ambientCube(cube,
|
|
26439
|
+
function ambientCube(cube, normal2) {
|
|
26004
26440
|
if (cube === void 0 || cube.length !== 6) return vec3(NO_CACHE_RADIANCE);
|
|
26005
26441
|
const face = (index) => vec3(...cube[index]);
|
|
26006
|
-
const squared =
|
|
26007
|
-
return select(
|
|
26442
|
+
const squared = normal2.mul(normal2);
|
|
26443
|
+
return select(normal2.x.greaterThanEqual(0), face(0), face(1)).mul(squared.x).add(select(normal2.y.greaterThanEqual(0), face(2), face(3)).mul(squared.y)).add(select(normal2.z.greaterThanEqual(0), face(4), face(5)).mul(squared.z));
|
|
26008
26444
|
}
|
|
26009
26445
|
var METAL_DIFFUSE = 0.12;
|
|
26010
26446
|
function tracedReflections(stage2) {
|
|
@@ -26014,8 +26450,8 @@ function tracedReflections(stage2) {
|
|
|
26014
26450
|
const [p00, p11, p02, p12, p22, p32] = [0, 5, 8, 9, 10, 14].map(projection);
|
|
26015
26451
|
const world = (index) => live(() => camera.matrixWorld.elements[index] ?? 0);
|
|
26016
26452
|
const column = (first) => vec3(world(first), world(first + 1), world(first + 2));
|
|
26017
|
-
const [right,
|
|
26018
|
-
const direction2 = (v) => right.mul(v.x).add(
|
|
26453
|
+
const [right, up2, back, at3] = [column(0), column(4), column(8), column(12)];
|
|
26454
|
+
const direction2 = (v) => right.mul(v.x).add(up2.mul(v.y)).add(back.mul(v.z));
|
|
26019
26455
|
const sun = stage2.sun;
|
|
26020
26456
|
const sunDirection = vec3(
|
|
26021
26457
|
live(() => sunVector(sun)[0]),
|
|
@@ -26089,7 +26525,7 @@ function tracedReflections(stage2) {
|
|
|
26089
26525
|
const incidentView = normalize(position);
|
|
26090
26526
|
const normalWorld3 = direction2(normalView3);
|
|
26091
26527
|
const reflected = normalize(reflect(direction2(incidentView), normalWorld3));
|
|
26092
|
-
const start = max(float(
|
|
26528
|
+
const start = max(float(START_OFFSET2), z.negate().mul(START_OFFSET_PER_METRE2));
|
|
26093
26529
|
const origin = direction2(position).add(at3).add(normalWorld3.mul(start));
|
|
26094
26530
|
const hit = trace.trace({
|
|
26095
26531
|
origin,
|
|
@@ -26139,8 +26575,8 @@ function sunVector(sun) {
|
|
|
26139
26575
|
const x = sun.position.x - sun.target.position.x;
|
|
26140
26576
|
const y = sun.position.y - sun.target.position.y;
|
|
26141
26577
|
const z = sun.position.z - sun.target.position.z;
|
|
26142
|
-
const
|
|
26143
|
-
return [x /
|
|
26578
|
+
const length8 = Math.hypot(x, y, z) || 1;
|
|
26579
|
+
return [x / length8, y / length8, z / length8];
|
|
26144
26580
|
}
|
|
26145
26581
|
var unrealBloomSettings = {
|
|
26146
26582
|
intensity: 0.675,
|
|
@@ -26468,10 +26904,10 @@ function bindSubrectSampler(node, view, bound) {
|
|
|
26468
26904
|
}
|
|
26469
26905
|
function bindSubrectTexture(node, view, bound) {
|
|
26470
26906
|
if (Reflect.get(node, "isRTTNode") === true && !bound.has(node)) {
|
|
26471
|
-
const
|
|
26472
|
-
view.retain(
|
|
26473
|
-
const update =
|
|
26474
|
-
|
|
26907
|
+
const rtt3 = node;
|
|
26908
|
+
view.retain(rtt3, [rtt3.renderTarget]);
|
|
26909
|
+
const update = rtt3.updateBefore;
|
|
26910
|
+
rtt3.updateBefore = function(frame) {
|
|
26475
26911
|
this.width = view.active ? 1 : null;
|
|
26476
26912
|
update.call(this, frame);
|
|
26477
26913
|
};
|
|
@@ -26667,7 +27103,7 @@ var WorldEnvironment = class {
|
|
|
26667
27103
|
const resolutionSubrect = requested.length === 0 || resolutionSubrectRefusal !== void 0 ? void 0 : renderer.createResolutionSubrect?.();
|
|
26668
27104
|
resolutionSubrect?.retain(scenePass, [scenePass.renderTarget]);
|
|
26669
27105
|
const boundSamplers = /* @__PURE__ */ new WeakSet();
|
|
26670
|
-
const
|
|
27106
|
+
const sample2 = (node) => {
|
|
26671
27107
|
if (resolutionSubrect) bindSubrectTexture(node, resolutionSubrect, boundSamplers);
|
|
26672
27108
|
};
|
|
26673
27109
|
if (options.ssgiEnabled || options.ssrEnabled || options.gtaoEnabled) {
|
|
@@ -26696,19 +27132,19 @@ var WorldEnvironment = class {
|
|
|
26696
27132
|
const cached = nodes.get(name);
|
|
26697
27133
|
if (cached !== void 0) return cached;
|
|
26698
27134
|
const node = scenePass.getTextureNode(name);
|
|
26699
|
-
|
|
27135
|
+
sample2(node);
|
|
26700
27136
|
nodes.set(name, node);
|
|
26701
27137
|
return node;
|
|
26702
27138
|
};
|
|
26703
27139
|
const depth = () => textureNode("depth");
|
|
26704
|
-
const
|
|
27140
|
+
const normal2 = () => textureNode("normal");
|
|
26705
27141
|
const metal = () => textureNode("metalness");
|
|
26706
27142
|
const rough = () => textureNode("roughness");
|
|
26707
27143
|
const albedo = () => textureNode("diffuseColor");
|
|
26708
27144
|
const view = camera;
|
|
26709
27145
|
const base = target.baseColour?.(scenePass) ?? scenePass.getTextureNode("output");
|
|
26710
27146
|
const colour = convertToTexture(base);
|
|
26711
|
-
|
|
27147
|
+
sample2(colour);
|
|
26712
27148
|
const exposure = options.autoExposureEnabled ? new AutoExposureNode(colour, options.exposurePolicy, options.exposure) : void 0;
|
|
26713
27149
|
const forgetExposure = publishStartupExposure(raw, exposure);
|
|
26714
27150
|
const localExposure = options.localExposureEnabled ? new LocalExposureNode(colour, exposure?.exposureNode ?? float(options.exposure)) : void 0;
|
|
@@ -26733,14 +27169,14 @@ var WorldEnvironment = class {
|
|
|
26733
27169
|
};
|
|
26734
27170
|
const subrectTexture = (input) => {
|
|
26735
27171
|
const texture7 = convertToTexture(input);
|
|
26736
|
-
|
|
27172
|
+
sample2(texture7);
|
|
26737
27173
|
return texture7;
|
|
26738
27174
|
};
|
|
26739
27175
|
const giDenoise = (node) => {
|
|
26740
27176
|
let result = denoised(node);
|
|
26741
27177
|
if (!options.denoiseEnabled) return result;
|
|
26742
27178
|
for (let pass2 = 0; pass2 < options.giDenoisePasses; pass2 += 1) {
|
|
26743
|
-
const filter = denoise(result, depth(),
|
|
27179
|
+
const filter = denoise(result, depth(), normal2(), view);
|
|
26744
27180
|
filter.index.value = pass2;
|
|
26745
27181
|
filter.resolutionScale = options.ssgiResolutionScale;
|
|
26746
27182
|
if (options.ssgiTimedPass === void 0 || options.ssgiTimedPass === "denoise")
|
|
@@ -26763,11 +27199,11 @@ var WorldEnvironment = class {
|
|
|
26763
27199
|
const base2 = convertToTexture(input);
|
|
26764
27200
|
const wasmEngine = rendererFacts(renderer).ownedEngine;
|
|
26765
27201
|
const cache = wasmEngine ? cacheFallback(view) : void 0;
|
|
26766
|
-
const fallback = cache === void 0 ? void 0 : (position,
|
|
27202
|
+
const fallback = cache === void 0 ? void 0 : (position, normal3) => cache(position, normal3).mul(gain);
|
|
26767
27203
|
const gi = ssgi(
|
|
26768
27204
|
base2,
|
|
26769
27205
|
depth(),
|
|
26770
|
-
|
|
27206
|
+
normal2(),
|
|
26771
27207
|
wasmEngine ? {
|
|
26772
27208
|
camera: view,
|
|
26773
27209
|
fallback,
|
|
@@ -26814,7 +27250,7 @@ var WorldEnvironment = class {
|
|
|
26814
27250
|
const at3 = uv();
|
|
26815
27251
|
const cached = cache?.(
|
|
26816
27252
|
getViewPosition(at3, depth().sample(at3).r, uniform(view.projectionMatrixInverse)),
|
|
26817
|
-
|
|
27253
|
+
normal2().sample(at3).rgb.normalize()
|
|
26818
27254
|
);
|
|
26819
27255
|
const bounce = (cached === void 0 ? indirect.rgb : cached.mul(gain).add(indirect.rgb)).mul(options.ssgiIntensity);
|
|
26820
27256
|
const indirectDiffuse = albedo().rgb.mul(float(1).sub(metal().r)).mul(bounce);
|
|
@@ -26891,7 +27327,7 @@ var WorldEnvironment = class {
|
|
|
26891
27327
|
contact.resolutionScale = options.gtaoResolutionScale;
|
|
26892
27328
|
const retained = contact;
|
|
26893
27329
|
resolutionSubrect?.retain(retained, [retained._aoRenderTarget]);
|
|
26894
|
-
|
|
27330
|
+
sample2(contact.getTextureNode());
|
|
26895
27331
|
let filterTexture;
|
|
26896
27332
|
releaseAo = () => {
|
|
26897
27333
|
if (filterTexture) {
|
|
@@ -26904,7 +27340,7 @@ var WorldEnvironment = class {
|
|
|
26904
27340
|
resolutionSubrect?.release(retained);
|
|
26905
27341
|
contact.dispose();
|
|
26906
27342
|
};
|
|
26907
|
-
const filter = options.denoiseEnabled && options.gtaoDenoiseRadius !== 0 ? denoise(contact.getTextureNode(), depth(),
|
|
27343
|
+
const filter = options.denoiseEnabled && options.gtaoDenoiseRadius !== 0 ? denoise(contact.getTextureNode(), depth(), normal2(), view) : void 0;
|
|
26908
27344
|
if (filter && options.gtaoDenoiseRadius !== void 0)
|
|
26909
27345
|
filter.radius.value = options.gtaoDenoiseRadius;
|
|
26910
27346
|
if (filter)
|
|
@@ -26922,7 +27358,7 @@ var WorldEnvironment = class {
|
|
|
26922
27358
|
filterTexture = convertToTexture(denoised(filter));
|
|
26923
27359
|
filterTexture.setResolutionScale(options.gtaoResolutionScale);
|
|
26924
27360
|
filterTexture.updateBeforeType = NodeUpdateType.FRAME;
|
|
26925
|
-
|
|
27361
|
+
sample2(filterTexture);
|
|
26926
27362
|
}
|
|
26927
27363
|
const occlusion = filterTexture ?? (filter ? denoised(filter) : contact);
|
|
26928
27364
|
const bounce = () => {
|
|
@@ -26972,7 +27408,7 @@ var WorldEnvironment = class {
|
|
|
26972
27408
|
shafts.maxDensity.value = options.godraysMaxDensity;
|
|
26973
27409
|
shafts.raymarchSteps.value = options.godraysSteps;
|
|
26974
27410
|
let shaft = convertToTexture(shafts);
|
|
26975
|
-
if (options.denoiseEnabled) shaft = denoised(denoise(shaft, depth(),
|
|
27411
|
+
if (options.denoiseEnabled) shaft = denoised(denoise(shaft, depth(), normal2(), view));
|
|
26976
27412
|
const cleaned = shaft.rgb.sub(options.godraysFloor).max(0).mul(options.godraysIntensity);
|
|
26977
27413
|
return input.add(cleaned.mul(color(light.color)));
|
|
26978
27414
|
}
|
|
@@ -26992,7 +27428,7 @@ var WorldEnvironment = class {
|
|
|
26992
27428
|
skyIrradiance: skyAmbientCube(scene.environment, scene.environmentIntensity),
|
|
26993
27429
|
base: base2,
|
|
26994
27430
|
depth: depth(),
|
|
26995
|
-
normal:
|
|
27431
|
+
normal: normal2(),
|
|
26996
27432
|
metalness: metal(),
|
|
26997
27433
|
roughness: rough(),
|
|
26998
27434
|
...options.ssgiEnabled ? { albedo: albedo() } : {},
|
|
@@ -27004,7 +27440,7 @@ var WorldEnvironment = class {
|
|
|
27004
27440
|
const reflections = ssr(
|
|
27005
27441
|
base2,
|
|
27006
27442
|
depth(),
|
|
27007
|
-
|
|
27443
|
+
normal2().level(float(0)),
|
|
27008
27444
|
{
|
|
27009
27445
|
camera: view,
|
|
27010
27446
|
metalnessNode: metal().r,
|
|
@@ -27050,7 +27486,7 @@ var WorldEnvironment = class {
|
|
|
27050
27486
|
);
|
|
27051
27487
|
const colour2 = subrectTexture(input);
|
|
27052
27488
|
const velocity = chain2.velocityNode;
|
|
27053
|
-
|
|
27489
|
+
sample2(velocity);
|
|
27054
27490
|
return motionBlur(colour2, velocity);
|
|
27055
27491
|
}
|
|
27056
27492
|
}),
|
|
@@ -27106,22 +27542,22 @@ var WorldEnvironment = class {
|
|
|
27106
27542
|
retained._textureNodeBlur4,
|
|
27107
27543
|
retained._textureOutput
|
|
27108
27544
|
])
|
|
27109
|
-
|
|
27545
|
+
sample2(node);
|
|
27110
27546
|
const material = retained._getSeparableBlurMaterial;
|
|
27111
27547
|
retained._getSeparableBlurMaterial = function(builder, radius) {
|
|
27112
27548
|
const result = material.call(this, builder, radius);
|
|
27113
|
-
|
|
27549
|
+
sample2(result.colorTexture);
|
|
27114
27550
|
return result;
|
|
27115
27551
|
};
|
|
27116
27552
|
}
|
|
27117
27553
|
releaseBloom = () => {
|
|
27118
27554
|
resolutionSubrect?.release(effect);
|
|
27119
27555
|
effect.dispose();
|
|
27120
|
-
const
|
|
27121
|
-
if (texture7 !== input &&
|
|
27556
|
+
const scratch4 = texture7;
|
|
27557
|
+
if (texture7 !== input && scratch4.isRTTNode === true) {
|
|
27122
27558
|
resolutionSubrect?.release(texture7);
|
|
27123
|
-
|
|
27124
|
-
|
|
27559
|
+
scratch4.renderTarget.dispose();
|
|
27560
|
+
scratch4._quadMesh.material.dispose();
|
|
27125
27561
|
}
|
|
27126
27562
|
};
|
|
27127
27563
|
return unreal === void 0 ? colour2.add(effect) : vec4(colour2.rgb.add(unreal.bloomNode), colour2.a);
|
|
@@ -27151,7 +27587,7 @@ var WorldEnvironment = class {
|
|
|
27151
27587
|
const peak = max(colour2.r, max(colour2.g, colour2.b));
|
|
27152
27588
|
const squeezed = lookDiagnostics.aaAlphaSqueezed ? colour2.div(peak.add(1)) : vec4(colour2.rgb.div(peak.add(1)), colour2.a);
|
|
27153
27589
|
const texture7 = convertToTexture(squeezed);
|
|
27154
|
-
|
|
27590
|
+
sample2(texture7);
|
|
27155
27591
|
const effect = options.screenSpaceAA === "fxaa" ? fxaa(texture7) : workerSafeSmaa(texture7);
|
|
27156
27592
|
if (resolutionSubrect && options.screenSpaceAA !== "fxaa") {
|
|
27157
27593
|
const retained = effect;
|
|
@@ -27165,7 +27601,7 @@ var WorldEnvironment = class {
|
|
|
27165
27601
|
retained._weightsTextureUniform,
|
|
27166
27602
|
retained._textureNode
|
|
27167
27603
|
])
|
|
27168
|
-
|
|
27604
|
+
sample2(node);
|
|
27169
27605
|
} else if (resolutionSubrect) {
|
|
27170
27606
|
const filter = effect;
|
|
27171
27607
|
const update = filter.updateBefore;
|
|
@@ -27187,8 +27623,8 @@ var WorldEnvironment = class {
|
|
|
27187
27623
|
};
|
|
27188
27624
|
const filtered = effect;
|
|
27189
27625
|
const back = max(filtered.r, max(filtered.g, filtered.b));
|
|
27190
|
-
const
|
|
27191
|
-
return lookDiagnostics.aaAlphaSqueezed ? filtered.div(
|
|
27626
|
+
const floor6 = float(1).sub(back).max(1e-4);
|
|
27627
|
+
return lookDiagnostics.aaAlphaSqueezed ? filtered.div(floor6) : vec4(filtered.rgb.div(floor6), filtered.a);
|
|
27192
27628
|
}
|
|
27193
27629
|
}
|
|
27194
27630
|
];
|
|
@@ -27624,13 +28060,13 @@ var SpectralOcean = class extends Object3D {
|
|
|
27624
28060
|
*/
|
|
27625
28061
|
sampleHeight(x, z) {
|
|
27626
28062
|
if (this.#readback === void 0) return void 0;
|
|
27627
|
-
const
|
|
27628
|
-
if (
|
|
28063
|
+
const sample2 = this.#readback.sample;
|
|
28064
|
+
if (sample2 === void 0) return void 0;
|
|
27629
28065
|
const patch = this.#cascadeStates[0].patchSize;
|
|
27630
28066
|
return {
|
|
27631
|
-
height: sampleGrid(
|
|
27632
|
-
verticalVelocity: sampleGrid(
|
|
27633
|
-
staleFrames:
|
|
28067
|
+
height: sampleGrid(sample2.data, this.#readbackResolution, patch, x, z, 2),
|
|
28068
|
+
verticalVelocity: sampleGrid(sample2.data, this.#readbackResolution, patch, x, z, 2, 1),
|
|
28069
|
+
staleFrames: sample2.staleFrames
|
|
27634
28070
|
};
|
|
27635
28071
|
}
|
|
27636
28072
|
attachRenderer(renderer) {
|
|
@@ -27681,7 +28117,7 @@ var SpectralOcean = class extends Object3D {
|
|
|
27681
28117
|
"vec4"
|
|
27682
28118
|
);
|
|
27683
28119
|
const work = instancedArray(count, "vec4");
|
|
27684
|
-
const
|
|
28120
|
+
const scratch4 = instancedArray(count, "vec4");
|
|
27685
28121
|
const displacement2 = instancedArray(count, "vec4");
|
|
27686
28122
|
const reversal = instancedArray(
|
|
27687
28123
|
Float32Array.from(bitReverseIndices(size)),
|
|
@@ -27702,11 +28138,11 @@ var SpectralOcean = class extends Object3D {
|
|
|
27702
28138
|
const deepWater = kLength.mul(tuning.gravity);
|
|
27703
28139
|
const dispersion = tuning.capillaryWavenumber === void 0 ? deepWater : deepWater.mul(kLength.div(tuning.capillaryWavenumber).pow(2).add(1));
|
|
27704
28140
|
const omega = dispersion.sqrt().mul(time);
|
|
27705
|
-
const
|
|
27706
|
-
const
|
|
28141
|
+
const cos3 = omega.cos();
|
|
28142
|
+
const sin3 = omega.sin();
|
|
27707
28143
|
const amplitudes = initial.element(instanceIndex);
|
|
27708
|
-
const heightRe = amplitudes.x.mul(
|
|
27709
|
-
const heightIm = amplitudes.x.mul(
|
|
28144
|
+
const heightRe = amplitudes.x.mul(cos3).sub(amplitudes.y.mul(sin3)).add(amplitudes.z.mul(cos3)).add(amplitudes.w.mul(sin3));
|
|
28145
|
+
const heightIm = amplitudes.x.mul(sin3).add(amplitudes.y.mul(cos3)).sub(amplitudes.z.mul(sin3)).add(amplitudes.w.mul(cos3));
|
|
27710
28146
|
const displaceXRe = kx.div(kLength).mul(heightIm);
|
|
27711
28147
|
const displaceXIm = kx.div(kLength).mul(heightRe).negate();
|
|
27712
28148
|
const displaceZRe = kz.div(kLength).mul(heightIm);
|
|
@@ -27723,11 +28159,11 @@ var SpectralOcean = class extends Object3D {
|
|
|
27723
28159
|
);
|
|
27724
28160
|
})().compute(count)
|
|
27725
28161
|
);
|
|
27726
|
-
passes.push(this.#reversePass(work,
|
|
28162
|
+
passes.push(this.#reversePass(work, scratch4, reversal, "row"));
|
|
27727
28163
|
for (let stage2 = 0; stage2 < butterflyStageCount(size); stage2 += 1) {
|
|
27728
|
-
passes.push(this.#butterflyPass(
|
|
28164
|
+
passes.push(this.#butterflyPass(scratch4, stage2, "row"));
|
|
27729
28165
|
}
|
|
27730
|
-
passes.push(this.#reversePass(
|
|
28166
|
+
passes.push(this.#reversePass(scratch4, work, reversal, "column"));
|
|
27731
28167
|
for (let stage2 = 0; stage2 < butterflyStageCount(size); stage2 += 1) {
|
|
27732
28168
|
passes.push(this.#butterflyPass(work, stage2, "column"));
|
|
27733
28169
|
}
|
|
@@ -27755,7 +28191,7 @@ var SpectralOcean = class extends Object3D {
|
|
|
27755
28191
|
kMax: band.kMax,
|
|
27756
28192
|
initialSpectrum: initial,
|
|
27757
28193
|
work,
|
|
27758
|
-
scratch:
|
|
28194
|
+
scratch: scratch4,
|
|
27759
28195
|
displacement: displacement2,
|
|
27760
28196
|
passes
|
|
27761
28197
|
};
|
|
@@ -27835,6 +28271,934 @@ var SpectralOcean = class extends Object3D {
|
|
|
27835
28271
|
return { field, pass: pass2 };
|
|
27836
28272
|
}
|
|
27837
28273
|
};
|
|
28274
|
+
|
|
28275
|
+
// src/tile-ring.ts
|
|
28276
|
+
var CREATE_BAND = 1.3;
|
|
28277
|
+
var DISCARD_BAND = 1.4;
|
|
28278
|
+
var TileRing = class {
|
|
28279
|
+
stats = { built: 0, pending: 0, tiles: 0, visible: 0 };
|
|
28280
|
+
#field;
|
|
28281
|
+
#tiles = /* @__PURE__ */ new Map();
|
|
28282
|
+
#queue = [];
|
|
28283
|
+
#frame = 0;
|
|
28284
|
+
#prewarm = false;
|
|
28285
|
+
constructor(field) {
|
|
28286
|
+
this.#field = field;
|
|
28287
|
+
}
|
|
28288
|
+
/** Every live tile, for a field that has to re-scatter or re-key its own build. */
|
|
28289
|
+
tiles() {
|
|
28290
|
+
return this.#tiles.values();
|
|
28291
|
+
}
|
|
28292
|
+
/** Builds every tile in range on the next `update` regardless of budget: on load or after a teleport. */
|
|
28293
|
+
prewarm() {
|
|
28294
|
+
this.#prewarm = true;
|
|
28295
|
+
}
|
|
28296
|
+
/** Drops every live tile: the field's density or layout changed. */
|
|
28297
|
+
clear() {
|
|
28298
|
+
for (const entry of this.#tiles.values())
|
|
28299
|
+
if (entry.tile !== null) this.#field.dispose(entry.tile);
|
|
28300
|
+
this.#tiles.clear();
|
|
28301
|
+
}
|
|
28302
|
+
/** Frees the tiles touching a rectangle, so only what changed re-scatters. */
|
|
28303
|
+
disposeInside(rect) {
|
|
28304
|
+
const S = this.#field.chunkSize;
|
|
28305
|
+
for (const [k, entry] of this.#tiles) {
|
|
28306
|
+
if (entry.ix * S > rect.maxX || (entry.ix + 1) * S < rect.minX || entry.iz * S > rect.maxZ || (entry.iz + 1) * S < rect.minZ)
|
|
28307
|
+
continue;
|
|
28308
|
+
if (entry.tile !== null) this.#field.dispose(entry.tile);
|
|
28309
|
+
this.#tiles.delete(k);
|
|
28310
|
+
}
|
|
28311
|
+
}
|
|
28312
|
+
/** Streams, shows and frees the tiles round `(cx, cz)`. Call once per rendered frame. */
|
|
28313
|
+
update(cx, cz) {
|
|
28314
|
+
const field = this.#field;
|
|
28315
|
+
const R = field.drawDistance;
|
|
28316
|
+
const frame = ++this.#frame;
|
|
28317
|
+
this.stats.visible = 0;
|
|
28318
|
+
this.#visit(cx, cz, R, frame);
|
|
28319
|
+
this.#buildQueued(frame);
|
|
28320
|
+
this.#prewarm = false;
|
|
28321
|
+
this.#evict(cx, cz, R, frame);
|
|
28322
|
+
this.stats.tiles = this.#tiles.size;
|
|
28323
|
+
}
|
|
28324
|
+
/** Marks the tiles inside the create band and queues the missing ones. */
|
|
28325
|
+
#visit(cx, cz, R, frame) {
|
|
28326
|
+
const S = this.#field.chunkSize;
|
|
28327
|
+
const reach = R * CREATE_BAND;
|
|
28328
|
+
const queue2 = this.#queue;
|
|
28329
|
+
queue2.length = 0;
|
|
28330
|
+
for (let iz = Math.floor((cz - reach) / S); iz <= Math.floor((cz + reach) / S); iz++) {
|
|
28331
|
+
for (let ix = Math.floor((cx - reach) / S); ix <= Math.floor((cx + reach) / S); ix++) {
|
|
28332
|
+
const d = tileDistance(ix, iz, cx, cz, S);
|
|
28333
|
+
if (d >= reach || !this.#field.inBounds(ix, iz)) continue;
|
|
28334
|
+
const k = tileKey(ix, iz);
|
|
28335
|
+
const entry = this.#tiles.get(k);
|
|
28336
|
+
if (!entry) {
|
|
28337
|
+
queue2.push({ d, ix, iz, k });
|
|
28338
|
+
continue;
|
|
28339
|
+
}
|
|
28340
|
+
entry.seen = frame;
|
|
28341
|
+
if (entry.tile !== null) this.#field.show(entry.tile, d);
|
|
28342
|
+
}
|
|
28343
|
+
}
|
|
28344
|
+
}
|
|
28345
|
+
/** Builds queued tiles nearest first; one always builds, the rest only inside the budget. */
|
|
28346
|
+
#buildQueued(frame) {
|
|
28347
|
+
const queue2 = this.#queue;
|
|
28348
|
+
queue2.sort((a, c) => a.d - c.d);
|
|
28349
|
+
const budget = this.#prewarm ? Number.POSITIVE_INFINITY : this.#field.buildBudgetMs;
|
|
28350
|
+
const t0 = performance.now();
|
|
28351
|
+
let built = 0;
|
|
28352
|
+
for (const q of queue2) {
|
|
28353
|
+
if (built > 0 && performance.now() - t0 > budget) break;
|
|
28354
|
+
const tile = this.#field.build(q.ix, q.iz);
|
|
28355
|
+
this.#tiles.set(q.k, { ix: q.ix, iz: q.iz, seen: frame, tile });
|
|
28356
|
+
if (tile !== null) this.#field.show(tile, q.d);
|
|
28357
|
+
built++;
|
|
28358
|
+
}
|
|
28359
|
+
this.stats.built += built;
|
|
28360
|
+
this.stats.pending = queue2.length - built;
|
|
28361
|
+
}
|
|
28362
|
+
/** Hides tiles that left the view radius and frees those past the discard band. */
|
|
28363
|
+
#evict(cx, cz, R, frame) {
|
|
28364
|
+
const S = this.#field.chunkSize;
|
|
28365
|
+
for (const [k, entry] of this.#tiles) {
|
|
28366
|
+
if (entry.seen === frame) continue;
|
|
28367
|
+
if (tileDistance(entry.ix, entry.iz, cx, cz, S) > R * DISCARD_BAND) {
|
|
28368
|
+
if (entry.tile !== null) this.#field.dispose(entry.tile);
|
|
28369
|
+
this.#tiles.delete(k);
|
|
28370
|
+
} else if (entry.tile !== null) this.#field.hide(entry.tile);
|
|
28371
|
+
}
|
|
28372
|
+
}
|
|
28373
|
+
};
|
|
28374
|
+
function tileDistance(ix, iz, cx, cz, S) {
|
|
28375
|
+
const dx = Math.max(ix * S - cx, 0, cx - (ix + 1) * S);
|
|
28376
|
+
const dz = Math.max(iz * S - cz, 0, cz - (iz + 1) * S);
|
|
28377
|
+
return Math.sqrt(dx * dx + dz * dz);
|
|
28378
|
+
}
|
|
28379
|
+
var tileKey = (ix, iz) => (ix + 32768) * 65536 + (iz + 32768);
|
|
28380
|
+
function hashInt(x, y, s) {
|
|
28381
|
+
let h = Math.imul(x | 0, 668265261) ^ Math.imul(y | 0, 374761393) ^ Math.imul(s | 0, 2654435761);
|
|
28382
|
+
h = Math.imul(h ^ h >>> 15, 2246822507);
|
|
28383
|
+
h = Math.imul(h ^ h >>> 13, 3266489909);
|
|
28384
|
+
return (h ^ h >>> 16) >>> 0;
|
|
28385
|
+
}
|
|
28386
|
+
function mulberry32(seed) {
|
|
28387
|
+
let a = seed >>> 0;
|
|
28388
|
+
return () => {
|
|
28389
|
+
a = a + 1831565813 | 0;
|
|
28390
|
+
let t = Math.imul(a ^ a >>> 15, 1 | a);
|
|
28391
|
+
t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t;
|
|
28392
|
+
return ((t ^ t >>> 14) >>> 0) / 4294967296;
|
|
28393
|
+
};
|
|
28394
|
+
}
|
|
28395
|
+
function shuffled(total, rng) {
|
|
28396
|
+
const order = new Uint32Array(total);
|
|
28397
|
+
for (let i = 0; i < total; i++) order[i] = i;
|
|
28398
|
+
for (let i = total - 1; i > 0; i--) {
|
|
28399
|
+
const j = rng() * (i + 1) | 0;
|
|
28400
|
+
const tmp = order[i];
|
|
28401
|
+
order[i] = order[j];
|
|
28402
|
+
order[j] = tmp;
|
|
28403
|
+
}
|
|
28404
|
+
return order;
|
|
28405
|
+
}
|
|
28406
|
+
var sample = new Float64Array(3);
|
|
28407
|
+
function groundGrid(getHeight, ox, oz, S, spacing) {
|
|
28408
|
+
const G = Math.max(1, Math.ceil(S / Math.max(spacing, 0.05)));
|
|
28409
|
+
const gs = S / G;
|
|
28410
|
+
const N = G + 3;
|
|
28411
|
+
const hg = new Float32Array(N * N);
|
|
28412
|
+
for (let j = 0; j < N; j++)
|
|
28413
|
+
for (let i = 0; i < N; i++)
|
|
28414
|
+
hg[j * N + i] = getHeight(ox + (i - 1) * gs, oz + (j - 1) * gs) || 0;
|
|
28415
|
+
const gx = new Float32Array(N * N);
|
|
28416
|
+
const gz = new Float32Array(N * N);
|
|
28417
|
+
const inv2 = 1 / (2 * gs);
|
|
28418
|
+
for (let j = 1; j < N - 1; j++)
|
|
28419
|
+
for (let i = 1; i < N - 1; i++) {
|
|
28420
|
+
const o = j * N + i;
|
|
28421
|
+
gx[o] = (hg[o + 1] - hg[o - 1]) * inv2;
|
|
28422
|
+
gz[o] = (hg[o + N] - hg[o - N]) * inv2;
|
|
28423
|
+
}
|
|
28424
|
+
return {
|
|
28425
|
+
sample(lx, lz) {
|
|
28426
|
+
const fx = lx / gs + 1;
|
|
28427
|
+
const fz = lz / gs + 1;
|
|
28428
|
+
const i0 = Math.min(fx | 0, G);
|
|
28429
|
+
const j0 = Math.min(fz | 0, G);
|
|
28430
|
+
const u = fx - i0;
|
|
28431
|
+
const v = fz - j0;
|
|
28432
|
+
const o = j0 * N + i0;
|
|
28433
|
+
const w00 = (1 - u) * (1 - v);
|
|
28434
|
+
const w10 = u * (1 - v);
|
|
28435
|
+
const w01 = (1 - u) * v;
|
|
28436
|
+
const w11 = u * v;
|
|
28437
|
+
const o1 = o + 1;
|
|
28438
|
+
const oN = o + N;
|
|
28439
|
+
const oN1 = oN + 1;
|
|
28440
|
+
sample[0] = hg[o] * w00 + hg[o1] * w10 + hg[oN] * w01 + hg[oN1] * w11;
|
|
28441
|
+
sample[1] = gx[o] * w00 + gx[o1] * w10 + gx[oN] * w01 + gx[oN1] * w11;
|
|
28442
|
+
sample[2] = gz[o] * w00 + gz[o1] * w10 + gz[oN] * w01 + gz[oN1] * w11;
|
|
28443
|
+
}
|
|
28444
|
+
};
|
|
28445
|
+
}
|
|
28446
|
+
var clamp01 = (v) => v < 0 ? 0 : v > 1 ? 1 : v;
|
|
28447
|
+
function smoothstep6(e0, e1, x) {
|
|
28448
|
+
const t = clamp01((x - e0) / Math.max(e1 - e0, 1e-6));
|
|
28449
|
+
return t * t * (3 - 2 * t);
|
|
28450
|
+
}
|
|
28451
|
+
|
|
28452
|
+
// src/grass-field.ts
|
|
28453
|
+
var MAX_PUSHERS = 4;
|
|
28454
|
+
var DEG = Math.PI / 180;
|
|
28455
|
+
var GRASS_FIELD_ATTRIBUTES = {
|
|
28456
|
+
/** vec3: the blade's root, chunk-local (the chunk mesh sits at its corner). */
|
|
28457
|
+
root: "grassRoot",
|
|
28458
|
+
/** vec4: facing 0..1, height 0..1, thinning priority 0..1, coverage scale 0..1. */
|
|
28459
|
+
rand: "grassRand",
|
|
28460
|
+
/** vec4: angle away from the tuft centre, tuft random 0..1, ground normal x, ground normal z. */
|
|
28461
|
+
clump: "grassClump"
|
|
28462
|
+
};
|
|
28463
|
+
var GrassField3D = class extends Group {
|
|
28464
|
+
blade;
|
|
28465
|
+
material;
|
|
28466
|
+
nodes;
|
|
28467
|
+
/** x, y, z world position and w radius (0 = off) of what flattens the grass. */
|
|
28468
|
+
pushers;
|
|
28469
|
+
/** Chunks and budget from the shared ring; blades and triangles from this frame's LOD pass. */
|
|
28470
|
+
get stats() {
|
|
28471
|
+
return {
|
|
28472
|
+
blades: this.#shown.blades,
|
|
28473
|
+
built: this.#ring.stats.built,
|
|
28474
|
+
chunks: this.#ring.stats.tiles,
|
|
28475
|
+
pending: this.#ring.stats.pending,
|
|
28476
|
+
triangles: this.#shown.triangles,
|
|
28477
|
+
visibleChunks: this.#shown.visibleChunks
|
|
28478
|
+
};
|
|
28479
|
+
}
|
|
28480
|
+
getHeight;
|
|
28481
|
+
getDensity;
|
|
28482
|
+
bounds;
|
|
28483
|
+
density;
|
|
28484
|
+
chunkSize;
|
|
28485
|
+
seed;
|
|
28486
|
+
heightSampleSpacing;
|
|
28487
|
+
maxSlope;
|
|
28488
|
+
slopeFade;
|
|
28489
|
+
minAltitude;
|
|
28490
|
+
maxAltitude;
|
|
28491
|
+
clumpSize;
|
|
28492
|
+
drawDistance;
|
|
28493
|
+
fadeRange;
|
|
28494
|
+
lodDistances;
|
|
28495
|
+
thinStart;
|
|
28496
|
+
thinEnd;
|
|
28497
|
+
farDensity;
|
|
28498
|
+
buildBudgetMs;
|
|
28499
|
+
receiveShadow;
|
|
28500
|
+
densityScale;
|
|
28501
|
+
cullDistanceScale;
|
|
28502
|
+
#ring;
|
|
28503
|
+
#shown = { blades: 0, triangles: 0, visibleChunks: 0 };
|
|
28504
|
+
#version = 0;
|
|
28505
|
+
#layout = "";
|
|
28506
|
+
constructor(options) {
|
|
28507
|
+
super();
|
|
28508
|
+
this.name = "GrassField3D";
|
|
28509
|
+
if (typeof options.getHeight !== "function")
|
|
28510
|
+
throw new Error("GrassField3D.getHeight must be a function (x, z) => height.");
|
|
28511
|
+
if (typeof options.material !== "function")
|
|
28512
|
+
throw new Error("GrassField3D.material must be a function (nodes) => Material.");
|
|
28513
|
+
const lods = options.blade?.lods;
|
|
28514
|
+
if (!Array.isArray(lods) || lods.length === 0)
|
|
28515
|
+
throw new Error("GrassField3D.blade.lods must list at least one draw range.");
|
|
28516
|
+
this.blade = options.blade;
|
|
28517
|
+
this.getHeight = options.getHeight;
|
|
28518
|
+
this.getDensity = options.getDensity ?? null;
|
|
28519
|
+
this.bounds = options.bounds ?? null;
|
|
28520
|
+
this.density = options.density ?? 30;
|
|
28521
|
+
this.chunkSize = options.chunkSize ?? 12;
|
|
28522
|
+
this.seed = options.seed ?? 1337;
|
|
28523
|
+
this.heightSampleSpacing = options.heightSampleSpacing ?? 0.75;
|
|
28524
|
+
this.maxSlope = options.maxSlope ?? 42;
|
|
28525
|
+
this.slopeFade = options.slopeFade ?? 12;
|
|
28526
|
+
this.minAltitude = options.minAltitude ?? Number.NEGATIVE_INFINITY;
|
|
28527
|
+
this.maxAltitude = options.maxAltitude ?? Number.POSITIVE_INFINITY;
|
|
28528
|
+
this.clumpSize = options.clumpSize ?? 1.4;
|
|
28529
|
+
this.drawDistance = options.drawDistance ?? 75;
|
|
28530
|
+
this.fadeRange = options.fadeRange ?? 0.3;
|
|
28531
|
+
this.lodDistances = options.lodDistances ?? [16, 38];
|
|
28532
|
+
this.thinStart = options.thinStart ?? 10;
|
|
28533
|
+
this.thinEnd = options.thinEnd ?? 62;
|
|
28534
|
+
this.farDensity = options.farDensity ?? 0.22;
|
|
28535
|
+
this.buildBudgetMs = options.buildBudgetMs ?? 4;
|
|
28536
|
+
this.receiveShadow = options.receiveShadow ?? true;
|
|
28537
|
+
this.densityScale = options.densityScale ?? 1;
|
|
28538
|
+
this.cullDistanceScale = options.cullDistanceScale ?? 1;
|
|
28539
|
+
this.#validate();
|
|
28540
|
+
this.#ring = new TileRing(this.#hooks());
|
|
28541
|
+
this.pushers = Array.from({ length: MAX_PUSHERS }, () => new Vector4());
|
|
28542
|
+
const pushers = this.pushers.map((v) => uniform(v));
|
|
28543
|
+
this.nodes = {
|
|
28544
|
+
thinStart: uniform(0),
|
|
28545
|
+
thinEnd: uniform(0),
|
|
28546
|
+
farDensity: uniform(0),
|
|
28547
|
+
fadeStart: uniform(0),
|
|
28548
|
+
drawDistance: uniform(0),
|
|
28549
|
+
pushers,
|
|
28550
|
+
push: (root) => {
|
|
28551
|
+
let dir = vec2(0, 0);
|
|
28552
|
+
let press = float(0);
|
|
28553
|
+
for (const pu of pushers) {
|
|
28554
|
+
const d = root.sub(pu.xyz);
|
|
28555
|
+
const f = float(1).sub(d.length().div(pu.w.max(1e-3)).smoothstep(0, 1)).mul(pu.w.step(1e-3).oneMinus());
|
|
28556
|
+
dir = dir.add(d.xz.add(vec2(1e-4, 1e-4)).normalize().mul(f));
|
|
28557
|
+
press = press.max(f);
|
|
28558
|
+
}
|
|
28559
|
+
return vec3(dir.x, dir.y, press);
|
|
28560
|
+
}
|
|
28561
|
+
};
|
|
28562
|
+
this.#syncNodes();
|
|
28563
|
+
this.material = options.material(this.nodes);
|
|
28564
|
+
}
|
|
28565
|
+
/** The pushers' press 0..1 at a world point: the CPU mirror of `nodes.push`'s z. */
|
|
28566
|
+
pressAt(x, y, z) {
|
|
28567
|
+
let press = 0;
|
|
28568
|
+
for (const pu of this.pushers) {
|
|
28569
|
+
if (pu.w < 1e-3) continue;
|
|
28570
|
+
const f = 1 - smoothstep6(0, 1, Math.hypot(x - pu.x, y - pu.y, z - pu.z) / pu.w);
|
|
28571
|
+
press = Math.max(press, f);
|
|
28572
|
+
}
|
|
28573
|
+
return press;
|
|
28574
|
+
}
|
|
28575
|
+
/** Builds every chunk in range on the next `update` regardless of budget: on load or after a teleport. */
|
|
28576
|
+
prewarm() {
|
|
28577
|
+
this.#ring.prewarm();
|
|
28578
|
+
}
|
|
28579
|
+
/** Re-scatter after the ground or the density changed: all chunks, or those touching a rectangle. */
|
|
28580
|
+
refresh(rect) {
|
|
28581
|
+
if (rect === void 0) {
|
|
28582
|
+
this.#version++;
|
|
28583
|
+
return;
|
|
28584
|
+
}
|
|
28585
|
+
this.#ring.disposeInside(rect);
|
|
28586
|
+
}
|
|
28587
|
+
/** Streams, thins and LODs the chunks around `camera`. Call once per rendered frame. */
|
|
28588
|
+
update(camera) {
|
|
28589
|
+
this.#validate();
|
|
28590
|
+
this.#syncNodes();
|
|
28591
|
+
const layout = this.#layoutKey();
|
|
28592
|
+
if (layout !== this.#layout) {
|
|
28593
|
+
this.#ring.clear();
|
|
28594
|
+
this.#layout = layout;
|
|
28595
|
+
}
|
|
28596
|
+
camera.getWorldPosition(scratch3);
|
|
28597
|
+
this.worldToLocal(scratch3);
|
|
28598
|
+
this.#shown.visibleChunks = this.#shown.blades = this.#shown.triangles = 0;
|
|
28599
|
+
this.#ring.update(scratch3.x, scratch3.z);
|
|
28600
|
+
}
|
|
28601
|
+
#inBounds(ix, iz) {
|
|
28602
|
+
const b = this.bounds;
|
|
28603
|
+
const S = this.chunkSize;
|
|
28604
|
+
return b === null || !(ix * S >= b.maxX || (ix + 1) * S <= b.minX || iz * S >= b.maxZ || (iz + 1) * S <= b.minZ);
|
|
28605
|
+
}
|
|
28606
|
+
/** The ring's hooks: a chunk that leaves the radius hides, one past the band is freed. */
|
|
28607
|
+
#hooks() {
|
|
28608
|
+
const field = this;
|
|
28609
|
+
return {
|
|
28610
|
+
build: (ix, iz) => this.#build(ix, iz),
|
|
28611
|
+
get buildBudgetMs() {
|
|
28612
|
+
return field.buildBudgetMs;
|
|
28613
|
+
},
|
|
28614
|
+
get chunkSize() {
|
|
28615
|
+
return field.chunkSize;
|
|
28616
|
+
},
|
|
28617
|
+
get drawDistance() {
|
|
28618
|
+
return field.drawDistance * field.cullDistanceScale;
|
|
28619
|
+
},
|
|
28620
|
+
dispose: (chunk) => this.#dispose(chunk),
|
|
28621
|
+
hide: (chunk) => {
|
|
28622
|
+
if (chunk.mesh?.visible) chunk.mesh.visible = false;
|
|
28623
|
+
},
|
|
28624
|
+
inBounds: (ix, iz) => this.#inBounds(ix, iz),
|
|
28625
|
+
show: (chunk, distance) => this.#applyLod(chunk, distance)
|
|
28626
|
+
};
|
|
28627
|
+
}
|
|
28628
|
+
dispose() {
|
|
28629
|
+
this.#ring.clear();
|
|
28630
|
+
this.material.dispose();
|
|
28631
|
+
}
|
|
28632
|
+
#validate() {
|
|
28633
|
+
if (!(this.chunkSize > 0))
|
|
28634
|
+
throw new Error(`GrassField3D.chunkSize must be > 0, got ${this.chunkSize}.`);
|
|
28635
|
+
if (!(this.density >= 0))
|
|
28636
|
+
throw new Error(`GrassField3D.density must be >= 0, got ${this.density}.`);
|
|
28637
|
+
if (!(this.drawDistance > 0))
|
|
28638
|
+
throw new Error(`GrassField3D.drawDistance must be > 0, got ${this.drawDistance}.`);
|
|
28639
|
+
if (!(this.buildBudgetMs >= 0))
|
|
28640
|
+
throw new Error(`GrassField3D.buildBudgetMs must be >= 0, got ${this.buildBudgetMs}.`);
|
|
28641
|
+
if (!(this.densityScale >= 0) || !(this.cullDistanceScale > 0))
|
|
28642
|
+
throw new Error("GrassField3D.densityScale must be >= 0 and cullDistanceScale > 0.");
|
|
28643
|
+
const b = this.bounds;
|
|
28644
|
+
if (b === null) return;
|
|
28645
|
+
for (const key of ["minX", "minZ", "maxX", "maxZ"])
|
|
28646
|
+
if (!Number.isFinite(b[key])) throw new Error(`GrassField3D.bounds.${key} must be finite.`);
|
|
28647
|
+
if (b.minX >= b.maxX) throw new Error("GrassField3D.bounds.minX must be below bounds.maxX.");
|
|
28648
|
+
if (b.minZ >= b.maxZ) throw new Error("GrassField3D.bounds.minZ must be below bounds.maxZ.");
|
|
28649
|
+
}
|
|
28650
|
+
#syncNodes() {
|
|
28651
|
+
const k = this.cullDistanceScale;
|
|
28652
|
+
const n = this.nodes;
|
|
28653
|
+
setIfChanged(n.thinStart, this.thinStart * k);
|
|
28654
|
+
setIfChanged(n.thinEnd, Math.max(this.thinEnd, this.thinStart + 0.01) * k);
|
|
28655
|
+
setIfChanged(n.farDensity, this.farDensity);
|
|
28656
|
+
setIfChanged(n.drawDistance, this.drawDistance * k);
|
|
28657
|
+
setIfChanged(
|
|
28658
|
+
n.fadeStart,
|
|
28659
|
+
this.drawDistance * k * (1 - Math.min(Math.max(this.fadeRange, 0.01), 1))
|
|
28660
|
+
);
|
|
28661
|
+
}
|
|
28662
|
+
#layoutKey() {
|
|
28663
|
+
return [
|
|
28664
|
+
this.#version,
|
|
28665
|
+
this.density * this.densityScale,
|
|
28666
|
+
this.chunkSize,
|
|
28667
|
+
this.seed,
|
|
28668
|
+
this.heightSampleSpacing,
|
|
28669
|
+
this.maxSlope,
|
|
28670
|
+
this.slopeFade,
|
|
28671
|
+
this.minAltitude,
|
|
28672
|
+
this.maxAltitude,
|
|
28673
|
+
this.clumpSize
|
|
28674
|
+
].join("|");
|
|
28675
|
+
}
|
|
28676
|
+
#applyLod(chunk, d) {
|
|
28677
|
+
const mesh = chunk.mesh;
|
|
28678
|
+
if (!mesh || !chunk.priority) return;
|
|
28679
|
+
const k = this.cullDistanceScale;
|
|
28680
|
+
const geo = mesh.geometry;
|
|
28681
|
+
const thinEnd = Math.max(this.thinEnd, this.thinStart + 0.01) * k;
|
|
28682
|
+
const edge = 1.1 + (this.farDensity - 1.1) * smoothstep6(this.thinStart * k, thinEnd, d);
|
|
28683
|
+
let n = chunk.count;
|
|
28684
|
+
if (edge < 1) {
|
|
28685
|
+
const pr = chunk.priority;
|
|
28686
|
+
let lo = 0;
|
|
28687
|
+
let hi = n;
|
|
28688
|
+
while (lo < hi) {
|
|
28689
|
+
const mid = lo + hi >> 1;
|
|
28690
|
+
if (pr[mid] < edge) lo = mid + 1;
|
|
28691
|
+
else hi = mid;
|
|
28692
|
+
}
|
|
28693
|
+
n = lo;
|
|
28694
|
+
}
|
|
28695
|
+
if (geo.instanceCount !== n) geo.instanceCount = n;
|
|
28696
|
+
const visible = n > 0 && d < this.drawDistance * this.cullDistanceScale;
|
|
28697
|
+
if (mesh.visible !== visible) mesh.visible = visible;
|
|
28698
|
+
if (!visible) return;
|
|
28699
|
+
const lods = this.blade.lods;
|
|
28700
|
+
let lod = 0;
|
|
28701
|
+
while (lod < lods.length - 1 && d >= (this.lodDistances[lod] ?? Number.POSITIVE_INFINITY) * k)
|
|
28702
|
+
lod++;
|
|
28703
|
+
const range = lods[lod];
|
|
28704
|
+
if (geo.drawRange.start !== range.start || geo.drawRange.count !== range.count)
|
|
28705
|
+
geo.setDrawRange(range.start, range.count);
|
|
28706
|
+
if (mesh.receiveShadow !== this.receiveShadow) mesh.receiveShadow = this.receiveShadow;
|
|
28707
|
+
this.#shown.visibleChunks++;
|
|
28708
|
+
this.#shown.blades += n;
|
|
28709
|
+
this.#shown.triangles += n * (range.count / 3);
|
|
28710
|
+
}
|
|
28711
|
+
#build(ix, iz) {
|
|
28712
|
+
const S = this.chunkSize;
|
|
28713
|
+
const ox = ix * S;
|
|
28714
|
+
const oz = iz * S;
|
|
28715
|
+
const seed = this.seed | 0;
|
|
28716
|
+
const rng = mulberry32(hashInt(ix, iz, seed));
|
|
28717
|
+
const b = this.bounds;
|
|
28718
|
+
const getHeight = this.getHeight;
|
|
28719
|
+
const height = b === null ? getHeight : (x, z) => getHeight(Math.min(b.maxX, Math.max(b.minX, x)), Math.min(b.maxZ, Math.max(b.minZ, z)));
|
|
28720
|
+
const ground = groundGrid(height, ox, oz, S, this.heightSampleSpacing);
|
|
28721
|
+
const n = Math.max(1, Math.ceil(Math.sqrt(this.density * this.densityScale * S * S)));
|
|
28722
|
+
const total = this.density * this.densityScale > 0 ? n * n : 0;
|
|
28723
|
+
const cell = S / n;
|
|
28724
|
+
const order = shuffled(total, rng);
|
|
28725
|
+
const pos = new Float32Array(total * 3);
|
|
28726
|
+
const rand = new Float32Array(total * 4);
|
|
28727
|
+
const clump = new Float32Array(total * 4);
|
|
28728
|
+
const priority = new Float32Array(total);
|
|
28729
|
+
const cosMax = Math.cos(this.maxSlope * DEG);
|
|
28730
|
+
const slopeSpan = Math.max(
|
|
28731
|
+
Math.cos(Math.max(this.maxSlope - this.slopeFade, 0) * DEG) - cosMax,
|
|
28732
|
+
1e-5
|
|
28733
|
+
);
|
|
28734
|
+
const cs = Math.max(this.clumpSize, 0.05);
|
|
28735
|
+
prepareTufts(ox, oz, S, cs, seed);
|
|
28736
|
+
let k = 0;
|
|
28737
|
+
let minY = Number.POSITIVE_INFINITY;
|
|
28738
|
+
let maxY = Number.NEGATIVE_INFINITY;
|
|
28739
|
+
for (let q = 0; q < total; q++) {
|
|
28740
|
+
const c = order[q];
|
|
28741
|
+
const lx = (c % n + rng()) * cell;
|
|
28742
|
+
const lz = ((c / n | 0) + rng()) * cell;
|
|
28743
|
+
const rFacing = rng();
|
|
28744
|
+
const rHeight = rng();
|
|
28745
|
+
const rKeep = rng();
|
|
28746
|
+
const wx = ox + lx;
|
|
28747
|
+
const wz = oz + lz;
|
|
28748
|
+
if (!this.#pointInBounds(wx, wz)) continue;
|
|
28749
|
+
ground.sample(lx, lz);
|
|
28750
|
+
const y = sample[0];
|
|
28751
|
+
const dx = sample[1];
|
|
28752
|
+
const dz = sample[2];
|
|
28753
|
+
if (y < this.minAltitude || y > this.maxAltitude) continue;
|
|
28754
|
+
const ny = 1 / Math.sqrt(dx * dx + dz * dz + 1);
|
|
28755
|
+
const m = this.#coverage(wx, wz, y, ny, cosMax, slopeSpan);
|
|
28756
|
+
if (m <= 1e-3 || rKeep > m * 2) continue;
|
|
28757
|
+
nearestTuft(wx, wz, cs);
|
|
28758
|
+
pos[k * 3] = lx;
|
|
28759
|
+
pos[k * 3 + 1] = y;
|
|
28760
|
+
pos[k * 3 + 2] = lz;
|
|
28761
|
+
priority[k] = q / total;
|
|
28762
|
+
rand[k * 4] = rFacing;
|
|
28763
|
+
rand[k * 4 + 1] = rHeight;
|
|
28764
|
+
rand[k * 4 + 2] = q / total;
|
|
28765
|
+
rand[k * 4 + 3] = 0.45 + 0.55 * m;
|
|
28766
|
+
clump[k * 4] = fastAtan2(wz - tuft[1], wx - tuft[0]);
|
|
28767
|
+
clump[k * 4 + 1] = tuft[2];
|
|
28768
|
+
clump[k * 4 + 2] = -dx * ny;
|
|
28769
|
+
clump[k * 4 + 3] = -dz * ny;
|
|
28770
|
+
minY = Math.min(minY, y);
|
|
28771
|
+
maxY = Math.max(maxY, y);
|
|
28772
|
+
k++;
|
|
28773
|
+
}
|
|
28774
|
+
if (k === 0) return null;
|
|
28775
|
+
const blade = this.blade.geometry;
|
|
28776
|
+
const geo = new InstancedBufferGeometry();
|
|
28777
|
+
if (blade.index) geo.setIndex(new BufferAttribute(blade.index.array, 1));
|
|
28778
|
+
for (const [name, attr] of Object.entries(blade.attributes))
|
|
28779
|
+
geo.setAttribute(name, new BufferAttribute(attr.array, attr.itemSize, attr.normalized));
|
|
28780
|
+
geo.setAttribute(
|
|
28781
|
+
GRASS_FIELD_ATTRIBUTES.root,
|
|
28782
|
+
new InstancedBufferAttribute(pos.slice(0, k * 3), 3)
|
|
28783
|
+
);
|
|
28784
|
+
geo.setAttribute(
|
|
28785
|
+
GRASS_FIELD_ATTRIBUTES.rand,
|
|
28786
|
+
new InstancedBufferAttribute(rand.slice(0, k * 4), 4)
|
|
28787
|
+
);
|
|
28788
|
+
geo.setAttribute(
|
|
28789
|
+
GRASS_FIELD_ATTRIBUTES.clump,
|
|
28790
|
+
new InstancedBufferAttribute(clump.slice(0, k * 4), 4)
|
|
28791
|
+
);
|
|
28792
|
+
geo.instanceCount = k;
|
|
28793
|
+
const halfY = (maxY - minY) / 2;
|
|
28794
|
+
const radius = Math.sqrt(S * S * 0.5 + halfY * halfY);
|
|
28795
|
+
const pad = Math.max(this.blade.reach, 0) * 1.5 + 1;
|
|
28796
|
+
geo.boundingSphere = new Sphere(new Vector3(S / 2, minY + halfY, S / 2), radius + pad);
|
|
28797
|
+
geo.boundingBox = new Box3(
|
|
28798
|
+
new Vector3(-pad, minY - 1, -pad),
|
|
28799
|
+
new Vector3(S + pad, maxY + pad, S + pad)
|
|
28800
|
+
);
|
|
28801
|
+
const mesh = new Mesh(geo, this.material);
|
|
28802
|
+
mesh.name = `grass ${ix},${iz}`;
|
|
28803
|
+
mesh.position.set(ox, 0, oz);
|
|
28804
|
+
mesh.matrixAutoUpdate = false;
|
|
28805
|
+
mesh.updateMatrix();
|
|
28806
|
+
mesh.raycast = () => {
|
|
28807
|
+
};
|
|
28808
|
+
this.add(mesh);
|
|
28809
|
+
return { ix, iz, count: k, mesh, priority: priority.slice(0, k), radius };
|
|
28810
|
+
}
|
|
28811
|
+
#pointInBounds(x, z) {
|
|
28812
|
+
const b = this.bounds;
|
|
28813
|
+
return b === null || x >= b.minX && x <= b.maxX && z >= b.minZ && z <= b.maxZ;
|
|
28814
|
+
}
|
|
28815
|
+
/** Slope limit times the game's mask, 0..1. */
|
|
28816
|
+
#coverage(x, z, y, ny, cosMax, span) {
|
|
28817
|
+
const m = clamp01((ny - cosMax) / span);
|
|
28818
|
+
return m > 0 && this.getDensity ? m * clamp01(this.getDensity(x, z, y, ny)) : m;
|
|
28819
|
+
}
|
|
28820
|
+
#dispose(chunk) {
|
|
28821
|
+
if (!chunk.mesh) return;
|
|
28822
|
+
this.remove(chunk.mesh);
|
|
28823
|
+
chunk.mesh.geometry.dispose();
|
|
28824
|
+
}
|
|
28825
|
+
};
|
|
28826
|
+
var scratch3 = new Vector3();
|
|
28827
|
+
function setIfChanged(node, value) {
|
|
28828
|
+
if (node.value !== value) node.value = value;
|
|
28829
|
+
}
|
|
28830
|
+
var tuft = new Float64Array(3);
|
|
28831
|
+
var tuftCells = new Float64Array(0);
|
|
28832
|
+
var tuftX0 = 0;
|
|
28833
|
+
var tuftZ0 = 0;
|
|
28834
|
+
var tuftW = 0;
|
|
28835
|
+
function prepareTufts(ox, oz, S, cs, seed) {
|
|
28836
|
+
tuftX0 = Math.floor(ox / cs) - 1;
|
|
28837
|
+
tuftZ0 = Math.floor(oz / cs) - 1;
|
|
28838
|
+
tuftW = Math.floor((ox + S) / cs) - tuftX0 + 2;
|
|
28839
|
+
const rows = Math.floor((oz + S) / cs) - tuftZ0 + 2;
|
|
28840
|
+
if (tuftCells.length < tuftW * rows * 3) tuftCells = new Float64Array(tuftW * rows * 3);
|
|
28841
|
+
for (let r = 0; r < rows; r++)
|
|
28842
|
+
for (let c = 0; c < tuftW; c++) {
|
|
28843
|
+
const cx = tuftX0 + c;
|
|
28844
|
+
const cz = tuftZ0 + r;
|
|
28845
|
+
const h = hashInt(cx, cz, seed + 7919);
|
|
28846
|
+
const o = (r * tuftW + c) * 3;
|
|
28847
|
+
tuftCells[o] = (cx + (h & 1023) / 1023) * cs;
|
|
28848
|
+
tuftCells[o + 1] = (cz + (h >>> 10 & 1023) / 1023) * cs;
|
|
28849
|
+
tuftCells[o + 2] = (h >>> 20 & 1023) / 1023;
|
|
28850
|
+
}
|
|
28851
|
+
}
|
|
28852
|
+
function nearestTuft(wx, wz, cs) {
|
|
28853
|
+
const ccx = Math.floor(wx / cs);
|
|
28854
|
+
const ccz = Math.floor(wz / cs);
|
|
28855
|
+
let best = Number.POSITIVE_INFINITY;
|
|
28856
|
+
for (let jz = -1; jz <= 1; jz++)
|
|
28857
|
+
for (let jx = -1; jx <= 1; jx++) {
|
|
28858
|
+
const o = ((ccz + jz - tuftZ0) * tuftW + (ccx + jx - tuftX0)) * 3;
|
|
28859
|
+
const px = tuftCells[o];
|
|
28860
|
+
const pz = tuftCells[o + 1];
|
|
28861
|
+
const dd = (px - wx) * (px - wx) + (pz - wz) * (pz - wz);
|
|
28862
|
+
if (dd >= best) continue;
|
|
28863
|
+
best = dd;
|
|
28864
|
+
tuft[0] = px;
|
|
28865
|
+
tuft[1] = pz;
|
|
28866
|
+
tuft[2] = tuftCells[o + 2];
|
|
28867
|
+
}
|
|
28868
|
+
}
|
|
28869
|
+
function fastAtan2(y, x) {
|
|
28870
|
+
const ax = Math.abs(x);
|
|
28871
|
+
const ay = Math.abs(y);
|
|
28872
|
+
const hi = Math.max(ax, ay);
|
|
28873
|
+
if (hi === 0) return 0;
|
|
28874
|
+
const a = Math.min(ax, ay) / hi;
|
|
28875
|
+
const s = a * a;
|
|
28876
|
+
let r = ((((-0.01348047 * s + 0.057477314) * s - 0.121239071) * s + 0.195635925) * s - 0.332994597) * s * a + 0.99999563 * a;
|
|
28877
|
+
if (ay > ax) r = 1.57079637 - r;
|
|
28878
|
+
if (x < 0) r = 3.14159274 - r;
|
|
28879
|
+
return y < 0 ? -r : r;
|
|
28880
|
+
}
|
|
28881
|
+
var DEG2 = Math.PI / 180;
|
|
28882
|
+
var scratchPosition = new Vector3();
|
|
28883
|
+
var scratchScale2 = new Vector3();
|
|
28884
|
+
var scratchQuaternion = new Quaternion();
|
|
28885
|
+
var scratchTilt = new Quaternion();
|
|
28886
|
+
var scratchMatrix = new Matrix4();
|
|
28887
|
+
var up = new Vector3(0, 1, 0);
|
|
28888
|
+
var normal = new Vector3();
|
|
28889
|
+
var ScatterField3D = class extends Group {
|
|
28890
|
+
parts;
|
|
28891
|
+
place;
|
|
28892
|
+
getHeight;
|
|
28893
|
+
getDensity;
|
|
28894
|
+
bounds;
|
|
28895
|
+
density;
|
|
28896
|
+
chunkSize;
|
|
28897
|
+
seed;
|
|
28898
|
+
heightSampleSpacing;
|
|
28899
|
+
maxSlope;
|
|
28900
|
+
slopeFade;
|
|
28901
|
+
minAltitude;
|
|
28902
|
+
maxAltitude;
|
|
28903
|
+
drawDistance;
|
|
28904
|
+
lodDistances;
|
|
28905
|
+
thinStart;
|
|
28906
|
+
thinEnd;
|
|
28907
|
+
farDensity;
|
|
28908
|
+
buildBudgetMs;
|
|
28909
|
+
alignToGround;
|
|
28910
|
+
receiveShadow;
|
|
28911
|
+
castShadow;
|
|
28912
|
+
densityScale;
|
|
28913
|
+
cullDistanceScale;
|
|
28914
|
+
#ring;
|
|
28915
|
+
#shown = { instances: 0, visibleTiles: 0 };
|
|
28916
|
+
#version = 0;
|
|
28917
|
+
#layout = "";
|
|
28918
|
+
constructor(options) {
|
|
28919
|
+
super();
|
|
28920
|
+
this.name = "ScatterField3D";
|
|
28921
|
+
if (typeof options.place !== "function")
|
|
28922
|
+
throw new Error("ScatterField3D.place must be a function (point, out) => boolean.");
|
|
28923
|
+
if (typeof options.getHeight !== "function")
|
|
28924
|
+
throw new Error("ScatterField3D.getHeight must be a function (x, z) => height.");
|
|
28925
|
+
if (!Array.isArray(options.parts) || options.parts.length === 0)
|
|
28926
|
+
throw new Error("ScatterField3D.parts must list at least one part.");
|
|
28927
|
+
options.parts.forEach((part, index) => {
|
|
28928
|
+
if (!Array.isArray(part.lods) || part.lods.length === 0)
|
|
28929
|
+
throw new Error(`ScatterField3D.parts[${index}].lods must list at least one geometry.`);
|
|
28930
|
+
if (!part.material)
|
|
28931
|
+
throw new Error(`ScatterField3D.parts[${index}] has no material; the game owns the look.`);
|
|
28932
|
+
});
|
|
28933
|
+
this.parts = options.parts;
|
|
28934
|
+
this.place = options.place;
|
|
28935
|
+
this.getHeight = options.getHeight;
|
|
28936
|
+
this.getDensity = options.getDensity ?? null;
|
|
28937
|
+
this.bounds = options.bounds ?? null;
|
|
28938
|
+
this.density = options.density ?? 0.1;
|
|
28939
|
+
this.chunkSize = options.chunkSize ?? 16;
|
|
28940
|
+
this.seed = options.seed ?? 1337;
|
|
28941
|
+
this.heightSampleSpacing = options.heightSampleSpacing ?? 0.75;
|
|
28942
|
+
this.maxSlope = options.maxSlope ?? 42;
|
|
28943
|
+
this.slopeFade = options.slopeFade ?? 12;
|
|
28944
|
+
this.minAltitude = options.minAltitude ?? Number.NEGATIVE_INFINITY;
|
|
28945
|
+
this.maxAltitude = options.maxAltitude ?? Number.POSITIVE_INFINITY;
|
|
28946
|
+
this.drawDistance = options.drawDistance ?? 60;
|
|
28947
|
+
this.lodDistances = options.lodDistances ?? [20, 45];
|
|
28948
|
+
this.thinStart = options.thinStart ?? 10;
|
|
28949
|
+
this.thinEnd = options.thinEnd ?? 50;
|
|
28950
|
+
this.farDensity = options.farDensity ?? 0.3;
|
|
28951
|
+
this.buildBudgetMs = options.buildBudgetMs ?? 4;
|
|
28952
|
+
this.alignToGround = options.alignToGround ?? true;
|
|
28953
|
+
this.receiveShadow = options.receiveShadow ?? true;
|
|
28954
|
+
this.castShadow = options.castShadow ?? true;
|
|
28955
|
+
this.densityScale = options.densityScale ?? 1;
|
|
28956
|
+
this.cullDistanceScale = options.cullDistanceScale ?? 1;
|
|
28957
|
+
this.#validate();
|
|
28958
|
+
this.#ring = new TileRing(this.#hooks());
|
|
28959
|
+
}
|
|
28960
|
+
get stats() {
|
|
28961
|
+
return {
|
|
28962
|
+
built: this.#ring.stats.built,
|
|
28963
|
+
instances: this.#shown.instances,
|
|
28964
|
+
pending: this.#ring.stats.pending,
|
|
28965
|
+
tiles: this.#ring.stats.tiles,
|
|
28966
|
+
visibleTiles: this.#shown.visibleTiles
|
|
28967
|
+
};
|
|
28968
|
+
}
|
|
28969
|
+
/** Builds every tile in range on the next `update` regardless of budget: on load or after a teleport. */
|
|
28970
|
+
prewarm() {
|
|
28971
|
+
this.#ring.prewarm();
|
|
28972
|
+
}
|
|
28973
|
+
/** Re-scatter after the ground or the coverage changed: all tiles, or those touching a rectangle. */
|
|
28974
|
+
refresh(rect) {
|
|
28975
|
+
if (rect === void 0) {
|
|
28976
|
+
this.#version++;
|
|
28977
|
+
return;
|
|
28978
|
+
}
|
|
28979
|
+
this.#ring.disposeInside(rect);
|
|
28980
|
+
}
|
|
28981
|
+
/** Streams, thins and LODs the tiles round `follow`. Call once per rendered frame. */
|
|
28982
|
+
update(follow) {
|
|
28983
|
+
this.#validate();
|
|
28984
|
+
const layout = this.#layoutKey();
|
|
28985
|
+
if (layout !== this.#layout) {
|
|
28986
|
+
this.#ring.clear();
|
|
28987
|
+
this.#layout = layout;
|
|
28988
|
+
}
|
|
28989
|
+
scratchPosition.copy(follow);
|
|
28990
|
+
this.worldToLocal(scratchPosition);
|
|
28991
|
+
this.#shown.visibleTiles = this.#shown.instances = 0;
|
|
28992
|
+
this.#ring.update(scratchPosition.x, scratchPosition.z);
|
|
28993
|
+
}
|
|
28994
|
+
dispose() {
|
|
28995
|
+
this.#ring.clear();
|
|
28996
|
+
}
|
|
28997
|
+
#hooks() {
|
|
28998
|
+
const field = this;
|
|
28999
|
+
return {
|
|
29000
|
+
build: (ix, iz) => this.#build(ix, iz),
|
|
29001
|
+
get buildBudgetMs() {
|
|
29002
|
+
return field.buildBudgetMs;
|
|
29003
|
+
},
|
|
29004
|
+
get chunkSize() {
|
|
29005
|
+
return field.chunkSize;
|
|
29006
|
+
},
|
|
29007
|
+
get drawDistance() {
|
|
29008
|
+
return field.drawDistance * field.cullDistanceScale;
|
|
29009
|
+
},
|
|
29010
|
+
dispose: (tile) => this.#disposeTile(tile),
|
|
29011
|
+
hide: (tile) => {
|
|
29012
|
+
for (const part of tile.meshes)
|
|
29013
|
+
for (const mesh of part) if (mesh.visible) mesh.visible = false;
|
|
29014
|
+
},
|
|
29015
|
+
inBounds: (ix, iz) => this.#inBounds(ix, iz),
|
|
29016
|
+
show: (tile, distance) => this.#show(tile, distance)
|
|
29017
|
+
};
|
|
29018
|
+
}
|
|
29019
|
+
#validate() {
|
|
29020
|
+
if (!(this.chunkSize > 0))
|
|
29021
|
+
throw new Error(`ScatterField3D.chunkSize must be > 0, got ${this.chunkSize}.`);
|
|
29022
|
+
if (!(this.density >= 0))
|
|
29023
|
+
throw new Error(`ScatterField3D.density must be >= 0, got ${this.density}.`);
|
|
29024
|
+
if (!(this.drawDistance > 0))
|
|
29025
|
+
throw new Error(`ScatterField3D.drawDistance must be > 0, got ${this.drawDistance}.`);
|
|
29026
|
+
if (!(this.buildBudgetMs >= 0))
|
|
29027
|
+
throw new Error(`ScatterField3D.buildBudgetMs must be >= 0, got ${this.buildBudgetMs}.`);
|
|
29028
|
+
if (!(this.densityScale >= 0) || !(this.cullDistanceScale > 0))
|
|
29029
|
+
throw new Error("ScatterField3D.densityScale must be >= 0 and cullDistanceScale > 0.");
|
|
29030
|
+
const b = this.bounds;
|
|
29031
|
+
if (b === null) return;
|
|
29032
|
+
for (const key of ["minX", "minZ", "maxX", "maxZ"])
|
|
29033
|
+
if (!Number.isFinite(b[key])) throw new Error(`ScatterField3D.bounds.${key} must be finite.`);
|
|
29034
|
+
if (b.minX >= b.maxX) throw new Error("ScatterField3D.bounds.minX must be below bounds.maxX.");
|
|
29035
|
+
if (b.minZ >= b.maxZ) throw new Error("ScatterField3D.bounds.minZ must be below bounds.maxZ.");
|
|
29036
|
+
}
|
|
29037
|
+
#layoutKey() {
|
|
29038
|
+
return [
|
|
29039
|
+
this.#version,
|
|
29040
|
+
this.density * this.densityScale,
|
|
29041
|
+
this.chunkSize,
|
|
29042
|
+
this.seed,
|
|
29043
|
+
this.heightSampleSpacing,
|
|
29044
|
+
this.maxSlope,
|
|
29045
|
+
this.slopeFade,
|
|
29046
|
+
this.minAltitude,
|
|
29047
|
+
this.maxAltitude,
|
|
29048
|
+
this.alignToGround,
|
|
29049
|
+
this.parts.length
|
|
29050
|
+
].join("|");
|
|
29051
|
+
}
|
|
29052
|
+
#inBounds(ix, iz) {
|
|
29053
|
+
const b = this.bounds;
|
|
29054
|
+
const S = this.chunkSize;
|
|
29055
|
+
return b === null || !(ix * S >= b.maxX || (ix + 1) * S <= b.minX || iz * S >= b.maxZ || (iz + 1) * S <= b.minZ);
|
|
29056
|
+
}
|
|
29057
|
+
#pointInBounds(x, z) {
|
|
29058
|
+
const b = this.bounds;
|
|
29059
|
+
return b === null || x >= b.minX && x <= b.maxX && z >= b.minZ && z <= b.maxZ;
|
|
29060
|
+
}
|
|
29061
|
+
/** Slope limit times the game's coverage mask, 0..1. */
|
|
29062
|
+
#coverage(x, z, y, ny, cosMax, span) {
|
|
29063
|
+
const m = clamp01((ny - cosMax) / span);
|
|
29064
|
+
return m > 0 && this.getDensity ? m * clamp01(this.getDensity(x, z, y, ny)) : m;
|
|
29065
|
+
}
|
|
29066
|
+
/** The thinning cut-off at a tile's nearest point: the same rule the material cannot apply here. */
|
|
29067
|
+
#kept(tile, distance) {
|
|
29068
|
+
const k = this.cullDistanceScale;
|
|
29069
|
+
const thinEnd = Math.max(this.thinEnd, this.thinStart + 0.01) * k;
|
|
29070
|
+
const edge = 1.1 + (this.farDensity - 1.1) * smoothstep6(this.thinStart * k, thinEnd, distance);
|
|
29071
|
+
if (edge >= 1) return tile.count;
|
|
29072
|
+
const pr = tile.priority;
|
|
29073
|
+
let lo = 0;
|
|
29074
|
+
let hi = tile.count;
|
|
29075
|
+
while (lo < hi) {
|
|
29076
|
+
const mid = lo + hi >> 1;
|
|
29077
|
+
if (pr[mid] < edge) lo = mid + 1;
|
|
29078
|
+
else hi = mid;
|
|
29079
|
+
}
|
|
29080
|
+
return lo;
|
|
29081
|
+
}
|
|
29082
|
+
#show(tile, distance) {
|
|
29083
|
+
const R = this.drawDistance * this.cullDistanceScale;
|
|
29084
|
+
const k = this.cullDistanceScale;
|
|
29085
|
+
const n = this.#kept(tile, distance);
|
|
29086
|
+
const inRange = n > 0 && distance < R;
|
|
29087
|
+
if (inRange) {
|
|
29088
|
+
this.#shown.visibleTiles++;
|
|
29089
|
+
this.#shown.instances += n;
|
|
29090
|
+
}
|
|
29091
|
+
for (let part = 0; part < this.parts.length; part++) {
|
|
29092
|
+
const meshes = tile.meshes[part];
|
|
29093
|
+
let level = 0;
|
|
29094
|
+
while (level < meshes.length - 1 && distance >= (this.lodDistances[level] ?? Number.POSITIVE_INFINITY) * k)
|
|
29095
|
+
level++;
|
|
29096
|
+
for (let l = 0; l < meshes.length; l++) {
|
|
29097
|
+
const mesh = meshes[l];
|
|
29098
|
+
const visible = inRange && l === level;
|
|
29099
|
+
if (mesh.visible !== visible) mesh.visible = visible;
|
|
29100
|
+
if (mesh.count !== n) mesh.count = n;
|
|
29101
|
+
if (mesh.receiveShadow !== this.receiveShadow) mesh.receiveShadow = this.receiveShadow;
|
|
29102
|
+
if (mesh.castShadow !== this.castShadow) mesh.castShadow = this.castShadow;
|
|
29103
|
+
}
|
|
29104
|
+
}
|
|
29105
|
+
}
|
|
29106
|
+
#build(ix, iz) {
|
|
29107
|
+
const S = this.chunkSize;
|
|
29108
|
+
const ox = ix * S;
|
|
29109
|
+
const oz = iz * S;
|
|
29110
|
+
const rng = mulberry32(hashInt(ix, iz, this.seed | 0));
|
|
29111
|
+
const ground = groundGrid(this.getHeight, ox, oz, S, this.heightSampleSpacing);
|
|
29112
|
+
const n = Math.max(1, Math.ceil(Math.sqrt(this.density * this.densityScale * S * S)));
|
|
29113
|
+
const total = this.density * this.densityScale > 0 ? n * n : 0;
|
|
29114
|
+
const cell = S / n;
|
|
29115
|
+
const order = shuffled(total, rng);
|
|
29116
|
+
const matrices = [];
|
|
29117
|
+
const priority = new Float32Array(total);
|
|
29118
|
+
const cosMax = Math.cos(this.maxSlope * DEG2);
|
|
29119
|
+
const slopeSpan = Math.max(
|
|
29120
|
+
Math.cos(Math.max(this.maxSlope - this.slopeFade, 0) * DEG2) - cosMax,
|
|
29121
|
+
1e-5
|
|
29122
|
+
);
|
|
29123
|
+
const out = { priority: 0, scale: 1, x: 0, y: 0, z: 0, yaw: 0 };
|
|
29124
|
+
let k = 0;
|
|
29125
|
+
for (let q = 0; q < total; q++) {
|
|
29126
|
+
const c = order[q];
|
|
29127
|
+
const lx = (c % n + rng()) * cell;
|
|
29128
|
+
const lz = ((c / n | 0) + rng()) * cell;
|
|
29129
|
+
const rKeep = rng();
|
|
29130
|
+
const wx = ox + lx;
|
|
29131
|
+
const wz = oz + lz;
|
|
29132
|
+
if (!this.#pointInBounds(wx, wz)) continue;
|
|
29133
|
+
ground.sample(lx, lz);
|
|
29134
|
+
const y = sample[0];
|
|
29135
|
+
const dx = sample[1];
|
|
29136
|
+
const dz = sample[2];
|
|
29137
|
+
if (y < this.minAltitude || y > this.maxAltitude) continue;
|
|
29138
|
+
const ny = 1 / Math.sqrt(dx * dx + dz * dz + 1);
|
|
29139
|
+
const m = this.#coverage(wx, wz, y, ny, cosMax, slopeSpan);
|
|
29140
|
+
if (m <= 1e-3 || rKeep > m * 2) continue;
|
|
29141
|
+
out.x = wx;
|
|
29142
|
+
out.y = y;
|
|
29143
|
+
out.z = wz;
|
|
29144
|
+
out.yaw = 0;
|
|
29145
|
+
out.scale = 1;
|
|
29146
|
+
out.priority = q / total;
|
|
29147
|
+
const placed = this.place({ nx: -dx * ny, ny, nz: -dz * ny, x: wx, y, z: wz }, out);
|
|
29148
|
+
if (!placed) continue;
|
|
29149
|
+
if (!Number.isFinite(out.scale) || out.scale <= 0 || !Number.isFinite(out.yaw))
|
|
29150
|
+
throw new Error(
|
|
29151
|
+
`ScatterField3D.place returned scale ${out.scale} and yaw ${out.yaw} at (${wx}, ${wz}); both must be finite and the scale positive.`
|
|
29152
|
+
);
|
|
29153
|
+
priority[k] = q / total;
|
|
29154
|
+
scratchPosition.set(out.x, out.y, out.z);
|
|
29155
|
+
scratchScale2.setScalar(out.scale);
|
|
29156
|
+
if (this.alignToGround) {
|
|
29157
|
+
normal.set(-dx, 1, -dz).normalize();
|
|
29158
|
+
scratchTilt.setFromUnitVectors(up, normal);
|
|
29159
|
+
scratchQuaternion.setFromAxisAngle(up, out.yaw);
|
|
29160
|
+
scratchQuaternion.premultiply(scratchTilt);
|
|
29161
|
+
} else {
|
|
29162
|
+
scratchQuaternion.setFromAxisAngle(up, out.yaw);
|
|
29163
|
+
}
|
|
29164
|
+
matrices.push(
|
|
29165
|
+
scratchMatrix.clone().compose(scratchPosition, scratchQuaternion, scratchScale2)
|
|
29166
|
+
);
|
|
29167
|
+
k++;
|
|
29168
|
+
}
|
|
29169
|
+
if (k === 0) return null;
|
|
29170
|
+
const meshes = [];
|
|
29171
|
+
for (let part = 0; part < this.parts.length; part++) {
|
|
29172
|
+
const source2 = this.parts[part];
|
|
29173
|
+
const levels = [];
|
|
29174
|
+
for (let l = 0; l < source2.lods.length; l++) {
|
|
29175
|
+
const geometry = source2.lods[l];
|
|
29176
|
+
const mesh = new InstancedMesh(geometry, source2.material, k);
|
|
29177
|
+
mesh.name = `scatter part${part} lod${l} ${ix},${iz}`;
|
|
29178
|
+
for (let i = 0; i < k; i++) mesh.setMatrixAt(i, matrices[i]);
|
|
29179
|
+
mesh.instanceMatrix.needsUpdate = true;
|
|
29180
|
+
mesh.position.set(ox, 0, oz);
|
|
29181
|
+
mesh.matrixAutoUpdate = false;
|
|
29182
|
+
mesh.updateMatrix();
|
|
29183
|
+
mesh.visible = false;
|
|
29184
|
+
mesh.raycast = () => {
|
|
29185
|
+
};
|
|
29186
|
+
mesh.computeBoundingSphere();
|
|
29187
|
+
this.add(mesh);
|
|
29188
|
+
levels.push(mesh);
|
|
29189
|
+
}
|
|
29190
|
+
meshes.push(levels);
|
|
29191
|
+
}
|
|
29192
|
+
return { count: k, meshes, priority: priority.slice(0, k) };
|
|
29193
|
+
}
|
|
29194
|
+
#disposeTile(tile) {
|
|
29195
|
+
for (const part of tile.meshes)
|
|
29196
|
+
for (const mesh of part) {
|
|
29197
|
+
this.remove(mesh);
|
|
29198
|
+
mesh.dispose();
|
|
29199
|
+
}
|
|
29200
|
+
}
|
|
29201
|
+
};
|
|
27838
29202
|
var DEFAULT_MAX_SPLATS = 8;
|
|
27839
29203
|
var DEFAULT_TIME_STEP = 1 / 60;
|
|
27840
29204
|
var DEFAULT_VORTICITY = 0.2;
|
|
@@ -27877,10 +29241,10 @@ function pixelUv(resolution) {
|
|
|
27877
29241
|
function readFluidTexture(texture7) {
|
|
27878
29242
|
return storageTexture$1(texture7).toReadOnly().setSampler(false);
|
|
27879
29243
|
}
|
|
27880
|
-
function sampleAt(texture7,
|
|
29244
|
+
function sampleAt(texture7, uv8, resolution) {
|
|
27881
29245
|
const size = resolution;
|
|
27882
29246
|
return texture7.sample(
|
|
27883
|
-
uvec2(uint(clamp(
|
|
29247
|
+
uvec2(uint(clamp(uv8.x.mul(size), 0, size - 1)), uint(clamp(uv8.y.mul(size), 0, size - 1)))
|
|
27884
29248
|
);
|
|
27885
29249
|
}
|
|
27886
29250
|
var FluidFieldSampler = class {
|
|
@@ -27890,8 +29254,8 @@ var FluidFieldSampler = class {
|
|
|
27890
29254
|
this.#texture = readFluidTexture(texture7);
|
|
27891
29255
|
this.#resolution = resolution;
|
|
27892
29256
|
}
|
|
27893
|
-
sample(
|
|
27894
|
-
return sampleAt(this.#texture,
|
|
29257
|
+
sample(uv8) {
|
|
29258
|
+
return sampleAt(this.#texture, uv8, this.#resolution);
|
|
27895
29259
|
}
|
|
27896
29260
|
setTexture(texture7) {
|
|
27897
29261
|
this.#texture.value = texture7;
|
|
@@ -27904,8 +29268,8 @@ function write(texture7, resolution, value) {
|
|
|
27904
29268
|
value
|
|
27905
29269
|
).toWriteOnly();
|
|
27906
29270
|
}
|
|
27907
|
-
function neighbour(texture7,
|
|
27908
|
-
return sampleAt(texture7, clamp(
|
|
29271
|
+
function neighbour(texture7, uv8, texel, resolution, x, y) {
|
|
29272
|
+
return sampleAt(texture7, clamp(uv8.add(vec2(x, y).mul(texel)), 0, 1), resolution);
|
|
27909
29273
|
}
|
|
27910
29274
|
function pair(first, second) {
|
|
27911
29275
|
return [first, second];
|
|
@@ -28048,9 +29412,9 @@ var FluidField2D = class extends Group {
|
|
|
28048
29412
|
this.#renderer = renderer;
|
|
28049
29413
|
for (const node of this.warmupNodes.slice(0, 8)) renderer.compute(node);
|
|
28050
29414
|
}
|
|
28051
|
-
splat(
|
|
29415
|
+
splat(uv8, velocity, amount) {
|
|
28052
29416
|
if (this.#released) throw new Error("FluidField2D cannot splat after release.");
|
|
28053
|
-
if (![
|
|
29417
|
+
if (![uv8.x, uv8.y, velocity.x, velocity.y, amount].every(Number.isFinite))
|
|
28054
29418
|
throw new Error("FluidField2D.splat arguments must be finite.");
|
|
28055
29419
|
if (amount < 0) throw new Error("FluidField2D.splat amount must be non-negative.");
|
|
28056
29420
|
if (amount === 0) return;
|
|
@@ -28058,7 +29422,7 @@ var FluidField2D = class extends Group {
|
|
|
28058
29422
|
const offset = this.#queuedSplats * 4;
|
|
28059
29423
|
const position = this.#splatPositions.array[offset / 4];
|
|
28060
29424
|
const splatAmount = this.#splatAmounts.array[offset / 4];
|
|
28061
|
-
position.set(clampNumber(
|
|
29425
|
+
position.set(clampNumber(uv8.x, 0, 1), clampNumber(uv8.y, 0, 1), velocity.x, velocity.y);
|
|
28062
29426
|
splatAmount.set(amount, 0, 0, 0);
|
|
28063
29427
|
this.#queuedSplats += 1;
|
|
28064
29428
|
}
|
|
@@ -28145,13 +29509,13 @@ var FluidField2D = class extends Group {
|
|
|
28145
29509
|
#makeVelocitySplatPair() {
|
|
28146
29510
|
return this.#makePair("fluid.splat.velocity", this.#velocityTextures, (source2, target) => {
|
|
28147
29511
|
const sourceNode = readFluidTexture(source2);
|
|
28148
|
-
const
|
|
28149
|
-
const pixel = sampleAt(sourceNode,
|
|
29512
|
+
const uv8 = pixelUv(this.resolution);
|
|
29513
|
+
const pixel = sampleAt(sourceNode, uv8, this.resolution).toVar();
|
|
28150
29514
|
Loop({ type: "uint", start: 0, end: this.#splatCount }, ({ i }) => {
|
|
28151
29515
|
const position = this.#splatPositions.element(i);
|
|
28152
29516
|
const impulse = this.#splatAmounts.element(i).x;
|
|
28153
29517
|
const influence = clamp(
|
|
28154
|
-
float(1).sub(length(
|
|
29518
|
+
float(1).sub(length(uv8.sub(position.xy)).div(this.splatRadius)),
|
|
28155
29519
|
0,
|
|
28156
29520
|
1
|
|
28157
29521
|
);
|
|
@@ -28166,13 +29530,13 @@ var FluidField2D = class extends Group {
|
|
|
28166
29530
|
#makeDyeSplatPair() {
|
|
28167
29531
|
return this.#makePair("fluid.splat.dye", this.#dyeTextures, (source2, target) => {
|
|
28168
29532
|
const sourceNode = readFluidTexture(source2);
|
|
28169
|
-
const
|
|
28170
|
-
const pixel = sampleAt(sourceNode,
|
|
29533
|
+
const uv8 = pixelUv(this.resolution);
|
|
29534
|
+
const pixel = sampleAt(sourceNode, uv8, this.resolution).toVar();
|
|
28171
29535
|
Loop({ type: "uint", start: 0, end: this.#splatCount }, ({ i }) => {
|
|
28172
29536
|
const position = this.#splatPositions.element(i);
|
|
28173
29537
|
const amount = this.#splatAmounts.element(i).x;
|
|
28174
29538
|
const influence = clamp(
|
|
28175
|
-
float(1).sub(length(
|
|
29539
|
+
float(1).sub(length(uv8.sub(position.xy)).div(this.splatRadius)),
|
|
28176
29540
|
0,
|
|
28177
29541
|
1
|
|
28178
29542
|
);
|
|
@@ -28190,13 +29554,13 @@ var FluidField2D = class extends Group {
|
|
|
28190
29554
|
#makeCurlKernel(name, sourceTexture) {
|
|
28191
29555
|
const source2 = readFluidTexture(sourceTexture);
|
|
28192
29556
|
return computeKernel(name, this.resolution, () => {
|
|
28193
|
-
const
|
|
29557
|
+
const uv8 = pixelUv(this.resolution);
|
|
28194
29558
|
const texel = vec2(1 / this.resolution);
|
|
28195
|
-
const center = sampleAt(source2,
|
|
28196
|
-
const l = neighbour(source2,
|
|
28197
|
-
const r = neighbour(source2,
|
|
28198
|
-
const b = neighbour(source2,
|
|
28199
|
-
const t = neighbour(source2,
|
|
29559
|
+
const center = sampleAt(source2, uv8, this.resolution);
|
|
29560
|
+
const l = neighbour(source2, uv8, texel, this.resolution, -1, 0).y;
|
|
29561
|
+
const r = neighbour(source2, uv8, texel, this.resolution, 1, 0).y;
|
|
29562
|
+
const b = neighbour(source2, uv8, texel, this.resolution, 0, -1).x;
|
|
29563
|
+
const t = neighbour(source2, uv8, texel, this.resolution, 0, 1).x;
|
|
28200
29564
|
return write(
|
|
28201
29565
|
this.#curlTexture,
|
|
28202
29566
|
this.resolution,
|
|
@@ -28208,16 +29572,16 @@ var FluidField2D = class extends Group {
|
|
|
28208
29572
|
return this.#makePair("fluid.vorticity", this.#velocityTextures, (source2, target) => {
|
|
28209
29573
|
const velocity = readFluidTexture(source2);
|
|
28210
29574
|
const curl = readFluidTexture(this.#curlTexture);
|
|
28211
|
-
const
|
|
29575
|
+
const uv8 = pixelUv(this.resolution);
|
|
28212
29576
|
const texel = vec2(1 / this.resolution);
|
|
28213
|
-
const center = sampleAt(velocity,
|
|
28214
|
-
const curlCenter = sampleAt(curl,
|
|
29577
|
+
const center = sampleAt(velocity, uv8, this.resolution);
|
|
29578
|
+
const curlCenter = sampleAt(curl, uv8, this.resolution).z;
|
|
28215
29579
|
const gradient = vec2(
|
|
28216
|
-
abs(neighbour(curl,
|
|
28217
|
-
abs(neighbour(curl,
|
|
29580
|
+
abs(neighbour(curl, uv8, texel, this.resolution, 0, 1).z).sub(
|
|
29581
|
+
abs(neighbour(curl, uv8, texel, this.resolution, 0, -1).z)
|
|
28218
29582
|
),
|
|
28219
|
-
abs(neighbour(curl,
|
|
28220
|
-
abs(neighbour(curl,
|
|
29583
|
+
abs(neighbour(curl, uv8, texel, this.resolution, 1, 0).z).sub(
|
|
29584
|
+
abs(neighbour(curl, uv8, texel, this.resolution, -1, 0).z)
|
|
28221
29585
|
)
|
|
28222
29586
|
);
|
|
28223
29587
|
const force = gradient.div(length(gradient).add(1e-4));
|
|
@@ -28237,12 +29601,12 @@ var FluidField2D = class extends Group {
|
|
|
28237
29601
|
#makeDivergenceKernel(name, sourceTexture) {
|
|
28238
29602
|
const source2 = readFluidTexture(sourceTexture);
|
|
28239
29603
|
return computeKernel(name, this.resolution, () => {
|
|
28240
|
-
const
|
|
29604
|
+
const uv8 = pixelUv(this.resolution);
|
|
28241
29605
|
const texel = vec2(1 / this.resolution);
|
|
28242
|
-
const left = neighbour(source2,
|
|
28243
|
-
const right = neighbour(source2,
|
|
28244
|
-
const bottom = neighbour(source2,
|
|
28245
|
-
const top = neighbour(source2,
|
|
29606
|
+
const left = neighbour(source2, uv8, texel, this.resolution, -1, 0).x;
|
|
29607
|
+
const right = neighbour(source2, uv8, texel, this.resolution, 1, 0).x;
|
|
29608
|
+
const bottom = neighbour(source2, uv8, texel, this.resolution, 0, -1).y;
|
|
29609
|
+
const top = neighbour(source2, uv8, texel, this.resolution, 0, 1).y;
|
|
28246
29610
|
return write(
|
|
28247
29611
|
this.#divergenceTexture,
|
|
28248
29612
|
this.resolution,
|
|
@@ -28277,13 +29641,13 @@ var FluidField2D = class extends Group {
|
|
|
28277
29641
|
#makePressureKernel(name, sourceTexture, targetTexture, divergence) {
|
|
28278
29642
|
return computeKernel(name, this.resolution, () => {
|
|
28279
29643
|
const pressure = readFluidTexture(sourceTexture);
|
|
28280
|
-
const
|
|
29644
|
+
const uv8 = pixelUv(this.resolution);
|
|
28281
29645
|
const texel = vec2(1 / this.resolution);
|
|
28282
|
-
const left = neighbour(pressure,
|
|
28283
|
-
const right = neighbour(pressure,
|
|
28284
|
-
const bottom = neighbour(pressure,
|
|
28285
|
-
const top = neighbour(pressure,
|
|
28286
|
-
const value = left.add(right).add(bottom).add(top).sub(sampleAt(divergence,
|
|
29646
|
+
const left = neighbour(pressure, uv8, texel, this.resolution, -1, 0).x;
|
|
29647
|
+
const right = neighbour(pressure, uv8, texel, this.resolution, 1, 0).x;
|
|
29648
|
+
const bottom = neighbour(pressure, uv8, texel, this.resolution, 0, -1).x;
|
|
29649
|
+
const top = neighbour(pressure, uv8, texel, this.resolution, 0, 1).x;
|
|
29650
|
+
const value = left.add(right).add(bottom).add(top).sub(sampleAt(divergence, uv8, this.resolution).w).mul(0.25);
|
|
28287
29651
|
return write(targetTexture, this.resolution, vec4(value, 0, 0, 0));
|
|
28288
29652
|
});
|
|
28289
29653
|
}
|
|
@@ -28323,15 +29687,15 @@ var FluidField2D = class extends Group {
|
|
|
28323
29687
|
return computeKernel(name, this.resolution, () => {
|
|
28324
29688
|
const velocity = readFluidTexture(sourceTexture);
|
|
28325
29689
|
const pressure = readFluidTexture(pressureTexture);
|
|
28326
|
-
const
|
|
29690
|
+
const uv8 = pixelUv(this.resolution);
|
|
28327
29691
|
const texel = vec2(1 / this.resolution);
|
|
28328
|
-
const center = sampleAt(velocity,
|
|
29692
|
+
const center = sampleAt(velocity, uv8, this.resolution);
|
|
28329
29693
|
const gradient = vec2(
|
|
28330
|
-
neighbour(pressure,
|
|
28331
|
-
neighbour(pressure,
|
|
29694
|
+
neighbour(pressure, uv8, texel, this.resolution, 1, 0).x.sub(
|
|
29695
|
+
neighbour(pressure, uv8, texel, this.resolution, -1, 0).x
|
|
28332
29696
|
),
|
|
28333
|
-
neighbour(pressure,
|
|
28334
|
-
neighbour(pressure,
|
|
29697
|
+
neighbour(pressure, uv8, texel, this.resolution, 0, 1).x.sub(
|
|
29698
|
+
neighbour(pressure, uv8, texel, this.resolution, 0, -1).x
|
|
28335
29699
|
)
|
|
28336
29700
|
).mul(0.5);
|
|
28337
29701
|
return write(targetTexture, this.resolution, vec4(center.xy.sub(gradient), center.zw));
|
|
@@ -28340,12 +29704,12 @@ var FluidField2D = class extends Group {
|
|
|
28340
29704
|
#makeAdvectVelocityPair() {
|
|
28341
29705
|
return this.#makePair("fluid.advect.velocity", this.#velocityTextures, (source2, target) => {
|
|
28342
29706
|
const velocity = readFluidTexture(source2);
|
|
28343
|
-
const
|
|
29707
|
+
const uv8 = pixelUv(this.resolution);
|
|
28344
29708
|
const texel = vec2(1 / this.resolution);
|
|
28345
|
-
const center = sampleAt(velocity,
|
|
28346
|
-
const traced = clamp(
|
|
29709
|
+
const center = sampleAt(velocity, uv8, this.resolution);
|
|
29710
|
+
const traced = clamp(uv8.sub(center.xy.mul(this.timeStep)), 0, 1);
|
|
28347
29711
|
const advected = sampleAt(velocity, traced, this.resolution).xy;
|
|
28348
|
-
const laplacian = neighbour(velocity,
|
|
29712
|
+
const laplacian = neighbour(velocity, uv8, texel, this.resolution, -1, 0).xy.add(neighbour(velocity, uv8, texel, this.resolution, 1, 0).xy).add(neighbour(velocity, uv8, texel, this.resolution, 0, -1).xy).add(neighbour(velocity, uv8, texel, this.resolution, 0, 1).xy).sub(center.xy.mul(4));
|
|
28349
29713
|
const next = advected.add(laplacian.mul(this.viscosity * this.timeStep));
|
|
28350
29714
|
return write(target, this.resolution, vec4(next, center.zw));
|
|
28351
29715
|
});
|
|
@@ -28386,9 +29750,9 @@ var FluidField2D = class extends Group {
|
|
|
28386
29750
|
return computeKernel(name, this.resolution, () => {
|
|
28387
29751
|
const dye = readFluidTexture(sourceTexture);
|
|
28388
29752
|
const velocity = readFluidTexture(velocityTexture2);
|
|
28389
|
-
const
|
|
29753
|
+
const uv8 = pixelUv(this.resolution);
|
|
28390
29754
|
const traced = clamp(
|
|
28391
|
-
|
|
29755
|
+
uv8.sub(sampleAt(velocity, uv8, this.resolution).xy.mul(this.timeStep)),
|
|
28392
29756
|
0,
|
|
28393
29757
|
1
|
|
28394
29758
|
);
|
|
@@ -28403,8 +29767,8 @@ var FluidField2D = class extends Group {
|
|
|
28403
29767
|
}
|
|
28404
29768
|
#onRemoved = () => this.detach();
|
|
28405
29769
|
};
|
|
28406
|
-
function clampNumber(value, min8,
|
|
28407
|
-
return Math.min(
|
|
29770
|
+
function clampNumber(value, min8, max11) {
|
|
29771
|
+
return Math.min(max11, Math.max(min8, value));
|
|
28408
29772
|
}
|
|
28409
29773
|
function tupleValue(values, index, name) {
|
|
28410
29774
|
const value = values[index];
|
|
@@ -28416,9 +29780,9 @@ function matrixValue(values, row, column, name) {
|
|
|
28416
29780
|
}
|
|
28417
29781
|
var tslNodes = tsl;
|
|
28418
29782
|
var {
|
|
28419
|
-
Fn:
|
|
28420
|
-
If:
|
|
28421
|
-
Loop:
|
|
29783
|
+
Fn: Fn17,
|
|
29784
|
+
If: If11,
|
|
29785
|
+
Loop: Loop10,
|
|
28422
29786
|
Return: Return2,
|
|
28423
29787
|
abs: abs7,
|
|
28424
29788
|
atomicAdd,
|
|
@@ -28427,28 +29791,28 @@ var {
|
|
|
28427
29791
|
atomicMin,
|
|
28428
29792
|
atomicStore,
|
|
28429
29793
|
ceil,
|
|
28430
|
-
clamp:
|
|
29794
|
+
clamp: clamp9,
|
|
28431
29795
|
dot: dot8,
|
|
28432
29796
|
exp: exp6,
|
|
28433
|
-
float:
|
|
28434
|
-
floor:
|
|
29797
|
+
float: float23,
|
|
29798
|
+
floor: floor5,
|
|
28435
29799
|
hash: hash2,
|
|
28436
29800
|
instanceIndex: instanceIndex6,
|
|
28437
29801
|
instancedArray: instancedArray3,
|
|
28438
|
-
int:
|
|
29802
|
+
int: int8,
|
|
28439
29803
|
ivec3,
|
|
28440
|
-
length:
|
|
28441
|
-
max:
|
|
29804
|
+
length: length7,
|
|
29805
|
+
max: max10,
|
|
28442
29806
|
min: min7,
|
|
28443
29807
|
select: select4,
|
|
28444
29808
|
storageTexture: storageTexture3,
|
|
28445
29809
|
textureStore: textureStore3,
|
|
28446
29810
|
uint: uint2,
|
|
28447
|
-
uniform:
|
|
29811
|
+
uniform: uniform21,
|
|
28448
29812
|
uniformArray: uniformArray3,
|
|
28449
29813
|
uvec3,
|
|
28450
|
-
vec3:
|
|
28451
|
-
vec4:
|
|
29814
|
+
vec3: vec319,
|
|
29815
|
+
vec4: vec419
|
|
28452
29816
|
} = tslNodes;
|
|
28453
29817
|
var DEFAULT_SPACING = 0.22;
|
|
28454
29818
|
var DEFAULT_BOUNDS = { min: [-2.9, 0.0968, -1.6], max: [2.9, 4.65, 1.6] };
|
|
@@ -28475,15 +29839,15 @@ function integerAtLeast(name, value, least) {
|
|
|
28475
29839
|
if (!Number.isInteger(value) || value < least)
|
|
28476
29840
|
throw new Error(`FluidParticles3D.${name} must be an integer of at least ${least}.`);
|
|
28477
29841
|
}
|
|
28478
|
-
function finiteVec(name, value,
|
|
28479
|
-
if (value.length !==
|
|
28480
|
-
throw new Error(`FluidParticles3D.${name} must be ${
|
|
29842
|
+
function finiteVec(name, value, length8) {
|
|
29843
|
+
if (value.length !== length8 || !value.every(Number.isFinite))
|
|
29844
|
+
throw new Error(`FluidParticles3D.${name} must be ${length8} finite numbers.`);
|
|
28481
29845
|
}
|
|
28482
29846
|
function nodeVar(node) {
|
|
28483
29847
|
return node.toVar();
|
|
28484
29848
|
}
|
|
28485
29849
|
function computeKernel2(name, count, body) {
|
|
28486
|
-
const node =
|
|
29850
|
+
const node = Fn17(body)().compute(count);
|
|
28487
29851
|
node.setName(name);
|
|
28488
29852
|
return node;
|
|
28489
29853
|
}
|
|
@@ -28691,24 +30055,24 @@ var FluidParticles3D = class extends Group {
|
|
|
28691
30055
|
this.density.magFilter = LinearFilter;
|
|
28692
30056
|
this.density.generateMipmaps = false;
|
|
28693
30057
|
this.density.needsUpdate = true;
|
|
28694
|
-
this.#viscosity =
|
|
28695
|
-
this.#cohesion =
|
|
28696
|
-
this.#vorticity =
|
|
28697
|
-
this.#gravity =
|
|
28698
|
-
this.#time =
|
|
28699
|
-
this.#slots =
|
|
30058
|
+
this.#viscosity = uniform21(viscosity);
|
|
30059
|
+
this.#cohesion = uniform21(cohesion);
|
|
30060
|
+
this.#vorticity = uniform21(vorticity);
|
|
30061
|
+
this.#gravity = uniform21(gravity);
|
|
30062
|
+
this.#time = uniform21(0);
|
|
30063
|
+
this.#slots = uniform21(0, "uint");
|
|
28700
30064
|
const zeros = (count) => Array.from({ length: count }, () => new Vector4());
|
|
28701
|
-
this.#spawnCount =
|
|
30065
|
+
this.#spawnCount = uniform21(0, "uint");
|
|
28702
30066
|
this.#spawnA = uniformArray3(zeros(maxSpawns), "vec4");
|
|
28703
30067
|
this.#spawnB = uniformArray3(zeros(maxSpawns), "vec4");
|
|
28704
30068
|
this.#spawnC = uniformArray3(zeros(maxSpawns), "vec4");
|
|
28705
|
-
this.#drainCount =
|
|
30069
|
+
this.#drainCount = uniform21(0, "uint");
|
|
28706
30070
|
this.#drainMin = uniformArray3(zeros(MAX_DRAINS), "vec4");
|
|
28707
30071
|
this.#drainMax = uniformArray3(zeros(MAX_DRAINS), "vec4");
|
|
28708
|
-
this.#stirCount =
|
|
30072
|
+
this.#stirCount = uniform21(0, "uint");
|
|
28709
30073
|
this.#stirA = uniformArray3(zeros(MAX_STIRS), "vec4");
|
|
28710
30074
|
this.#stirB = uniformArray3(zeros(MAX_STIRS), "vec4");
|
|
28711
|
-
this.#colliderCount =
|
|
30075
|
+
this.#colliderCount = uniform21(0, "uint");
|
|
28712
30076
|
this.#colliderA = uniformArray3(zeros(maxColliders), "vec4");
|
|
28713
30077
|
this.#colliderB = uniformArray3(zeros(maxColliders), "vec4");
|
|
28714
30078
|
this.#colliderRows = [
|
|
@@ -28716,87 +30080,87 @@ var FluidParticles3D = class extends Group {
|
|
|
28716
30080
|
uniformArray3(zeros(maxColliders), "vec4"),
|
|
28717
30081
|
uniformArray3(zeros(maxColliders), "vec4")
|
|
28718
30082
|
];
|
|
28719
|
-
const dt =
|
|
30083
|
+
const dt = float23(timeStep);
|
|
28720
30084
|
const live = (index) => positions.element(index).w.greaterThan(0.5);
|
|
28721
30085
|
const guard = () => {
|
|
28722
|
-
|
|
30086
|
+
If11(instanceIndex6.greaterThanEqual(this.#slots), () => {
|
|
28723
30087
|
Return2();
|
|
28724
30088
|
});
|
|
28725
|
-
|
|
30089
|
+
If11(live(instanceIndex6).not(), () => {
|
|
28726
30090
|
Return2();
|
|
28727
30091
|
});
|
|
28728
30092
|
};
|
|
28729
30093
|
const cellOf = (point) => ivec3(
|
|
28730
|
-
|
|
28731
|
-
|
|
28732
|
-
|
|
28733
|
-
|
|
30094
|
+
clamp9(
|
|
30095
|
+
floor5(point.sub(vec319(...gridOrigin)).div(h)),
|
|
30096
|
+
vec319(1),
|
|
30097
|
+
vec319(gridDims[0] - 2, gridDims[1] - 2, gridDims[2] - 2)
|
|
28734
30098
|
)
|
|
28735
30099
|
);
|
|
28736
30100
|
const cellId = (cell) => cell.x.add(cell.y.mul(gridDims[0])).add(cell.z.mul(gridDims[0] * gridDims[1])).toUint();
|
|
28737
30101
|
const forNeighbours = (point, self, body) => {
|
|
28738
30102
|
const cell = cellOf(point);
|
|
28739
|
-
|
|
30103
|
+
Loop10(27, ({ i: k }) => {
|
|
28740
30104
|
const dx = k.mod(3).sub(1);
|
|
28741
30105
|
const dy = k.div(3).mod(3).sub(1);
|
|
28742
30106
|
const dz = k.div(9).sub(1);
|
|
28743
30107
|
const id = cellId(cell.add(ivec3(dx, dy, dz)));
|
|
28744
30108
|
const inCell = min7(atomicLoad(cellCount.element(id)), uint2(CELL_CAPACITY)).toVar();
|
|
28745
|
-
|
|
30109
|
+
Loop10({ start: uint2(0), end: inCell, type: "uint" }, ({ i: slot }) => {
|
|
28746
30110
|
const other = cellItems.element(id.mul(CELL_CAPACITY).add(slot));
|
|
28747
|
-
|
|
30111
|
+
If11(other.notEqual(self), () => {
|
|
28748
30112
|
const offset = point.sub(positions.element(other).xyz);
|
|
28749
30113
|
const r2 = dot8(offset, offset);
|
|
28750
|
-
|
|
30114
|
+
If11(r2.lessThan(h2), () => body(other, offset, r2));
|
|
28751
30115
|
});
|
|
28752
30116
|
});
|
|
28753
30117
|
});
|
|
28754
30118
|
};
|
|
28755
|
-
const kernel = (r2) =>
|
|
28756
|
-
const gradientScale = (r) =>
|
|
30119
|
+
const kernel = (r2) => float23(h2).sub(r2).pow(3).mul(poly6);
|
|
30120
|
+
const gradientScale = (r) => float23(h).sub(r).pow(2).mul(volumeOfParticle * spiky).div(r);
|
|
28757
30121
|
const project = (point) => {
|
|
28758
|
-
point.assign(
|
|
28759
|
-
|
|
30122
|
+
point.assign(clamp9(point, vec319(...min32), vec319(...max32)));
|
|
30123
|
+
Loop10({ start: uint2(0), end: this.#colliderCount, type: "uint" }, ({ i }) => {
|
|
28760
30124
|
const a = this.#colliderA.element(i);
|
|
28761
30125
|
const b = this.#colliderB.element(i);
|
|
28762
30126
|
const offset = point.sub(a.xyz);
|
|
28763
|
-
|
|
28764
|
-
|
|
30127
|
+
If11(dot8(offset, offset).lessThan(b.w.add(radius).pow(2)), () => {
|
|
30128
|
+
If11(a.w.lessThan(0.5), () => {
|
|
28765
30129
|
const reach = b.x.add(radius);
|
|
28766
|
-
const distance =
|
|
28767
|
-
|
|
30130
|
+
const distance = length7(offset);
|
|
30131
|
+
If11(distance.lessThan(reach), () => {
|
|
28768
30132
|
const direction2 = select4(
|
|
28769
30133
|
distance.lessThan(1e-9),
|
|
28770
|
-
|
|
28771
|
-
offset.div(
|
|
30134
|
+
vec319(0, 1, 0),
|
|
30135
|
+
offset.div(max10(distance, 1e-9))
|
|
28772
30136
|
);
|
|
28773
30137
|
point.assign(a.xyz.add(direction2.mul(reach)));
|
|
28774
30138
|
});
|
|
28775
30139
|
}).Else(() => {
|
|
28776
30140
|
const rows = this.#colliderRows.map((row) => row.element(i).xyz);
|
|
28777
|
-
const local2 =
|
|
30141
|
+
const local2 = vec319(
|
|
28778
30142
|
dot8(rows[0], offset),
|
|
28779
30143
|
dot8(rows[1], offset),
|
|
28780
30144
|
dot8(rows[2], offset)
|
|
28781
30145
|
);
|
|
28782
30146
|
const half = b.xyz.add(radius);
|
|
28783
30147
|
const absolute = abs7(local2);
|
|
28784
|
-
|
|
30148
|
+
If11(
|
|
28785
30149
|
absolute.x.lessThan(half.x).and(absolute.y.lessThan(half.y)).and(absolute.z.lessThan(half.z)),
|
|
28786
30150
|
() => {
|
|
28787
30151
|
const gap = half.sub(absolute);
|
|
28788
30152
|
const out = nodeVar(local2);
|
|
28789
|
-
|
|
30153
|
+
If11(gap.x.lessThan(gap.y).and(gap.x.lessThan(gap.z)), () => {
|
|
28790
30154
|
out.assign(
|
|
28791
|
-
|
|
30155
|
+
vec319(select4(local2.x.lessThan(0), half.x.negate(), half.x), local2.y, local2.z)
|
|
28792
30156
|
);
|
|
28793
30157
|
}).ElseIf(gap.y.lessThan(gap.z), () => {
|
|
28794
30158
|
out.assign(
|
|
28795
|
-
|
|
30159
|
+
vec319(local2.x, select4(local2.y.lessThan(0), half.y.negate(), half.y), local2.z)
|
|
28796
30160
|
);
|
|
28797
30161
|
}).Else(() => {
|
|
28798
30162
|
out.assign(
|
|
28799
|
-
|
|
30163
|
+
vec319(local2.x, local2.y, select4(local2.z.lessThan(0), half.z.negate(), half.z))
|
|
28800
30164
|
);
|
|
28801
30165
|
});
|
|
28802
30166
|
const world = rows[0].mul(out.x).add(rows[1].mul(out.y)).add(rows[2].mul(out.z));
|
|
@@ -28806,33 +30170,33 @@ var FluidParticles3D = class extends Group {
|
|
|
28806
30170
|
});
|
|
28807
30171
|
});
|
|
28808
30172
|
});
|
|
28809
|
-
point.assign(
|
|
30173
|
+
point.assign(clamp9(point, vec319(...min32), vec319(...max32)));
|
|
28810
30174
|
};
|
|
28811
30175
|
this.#inject = computeKernel2("fluidParticles.inject", capacity, () => {
|
|
28812
30176
|
const slot = instanceIndex6;
|
|
28813
|
-
|
|
30177
|
+
If11(slot.greaterThanEqual(uint2(capacity)), () => {
|
|
28814
30178
|
Return2();
|
|
28815
30179
|
});
|
|
28816
30180
|
const body = positions.element(slot);
|
|
28817
30181
|
const motion = velocities.element(slot);
|
|
28818
|
-
|
|
30182
|
+
Loop10({ start: uint2(0), end: this.#drainCount, type: "uint" }, ({ i }) => {
|
|
28819
30183
|
const low2 = this.#drainMin.element(i).xyz;
|
|
28820
30184
|
const high2 = this.#drainMax.element(i).xyz;
|
|
28821
30185
|
const p = body.xyz;
|
|
28822
|
-
|
|
30186
|
+
If11(
|
|
28823
30187
|
body.w.greaterThan(0.5).and(p.x.greaterThanEqual(low2.x)).and(p.x.lessThanEqual(high2.x)).and(p.y.greaterThanEqual(low2.y)).and(p.y.lessThanEqual(high2.y)).and(p.z.greaterThanEqual(low2.z)).and(p.z.lessThanEqual(high2.z)),
|
|
28824
30188
|
() => {
|
|
28825
|
-
body.assign(
|
|
28826
|
-
motion.assign(
|
|
30189
|
+
body.assign(vec419(p, 0));
|
|
30190
|
+
motion.assign(vec419(0));
|
|
28827
30191
|
}
|
|
28828
30192
|
);
|
|
28829
30193
|
});
|
|
28830
|
-
|
|
30194
|
+
Loop10({ start: uint2(0), end: this.#spawnCount, type: "uint" }, ({ i }) => {
|
|
28831
30195
|
const a = this.#spawnA.element(i);
|
|
28832
30196
|
const b = this.#spawnB.element(i);
|
|
28833
30197
|
const c = this.#spawnC.element(i);
|
|
28834
30198
|
const relative = slot.add(uint2(capacity)).sub(a.w.toUint()).mod(uint2(capacity));
|
|
28835
|
-
|
|
30199
|
+
If11(relative.lessThan(b.w.toUint()), () => {
|
|
28836
30200
|
const nx = b.x.toUint();
|
|
28837
30201
|
const nz = b.z.toUint();
|
|
28838
30202
|
const ix = relative.mod(nx);
|
|
@@ -28840,16 +30204,16 @@ var FluidParticles3D = class extends Group {
|
|
|
28840
30204
|
const iy = relative.div(nx.mul(nz));
|
|
28841
30205
|
const jitter = select4(
|
|
28842
30206
|
b.w.greaterThan(1.5),
|
|
28843
|
-
|
|
30207
|
+
vec319(
|
|
28844
30208
|
hash2(slot.add(relative)).sub(0.5),
|
|
28845
30209
|
hash2(slot.add(relative).add(uint2(104729))).sub(0.5),
|
|
28846
30210
|
hash2(slot.add(relative).add(uint2(7919))).sub(0.5)
|
|
28847
30211
|
).mul(c.w.mul(0.1)),
|
|
28848
|
-
|
|
30212
|
+
vec319(0)
|
|
28849
30213
|
);
|
|
28850
|
-
const placed = a.xyz.add(
|
|
28851
|
-
body.assign(
|
|
28852
|
-
motion.assign(
|
|
30214
|
+
const placed = a.xyz.add(vec319(float23(ix), float23(iy), float23(iz)).mul(c.w)).add(jitter);
|
|
30215
|
+
body.assign(vec419(placed, 1));
|
|
30216
|
+
motion.assign(vec419(c.xyz, 0));
|
|
28853
30217
|
});
|
|
28854
30218
|
});
|
|
28855
30219
|
});
|
|
@@ -28858,15 +30222,15 @@ var FluidParticles3D = class extends Group {
|
|
|
28858
30222
|
const i = instanceIndex6;
|
|
28859
30223
|
const velocity = nodeVar(velocities.element(i).xyz);
|
|
28860
30224
|
const position = nodeVar(positions.element(i).xyz);
|
|
28861
|
-
|
|
30225
|
+
Loop10({ start: uint2(0), end: this.#stirCount, type: "uint" }, ({ i: s }) => {
|
|
28862
30226
|
const centre = this.#stirA.element(s);
|
|
28863
30227
|
const offset = position.sub(centre.xyz);
|
|
28864
|
-
const distance =
|
|
28865
|
-
|
|
28866
|
-
const t =
|
|
30228
|
+
const distance = length7(offset);
|
|
30229
|
+
If11(distance.lessThan(centre.w), () => {
|
|
30230
|
+
const t = float23(1).sub(distance.div(centre.w)).mul(this.#stirB.element(s).x);
|
|
28867
30231
|
velocity.assign(
|
|
28868
30232
|
velocity.add(
|
|
28869
|
-
|
|
30233
|
+
vec319(
|
|
28870
30234
|
offset.x.div(distance.add(0.15)).mul(t),
|
|
28871
30235
|
t.mul(0.65),
|
|
28872
30236
|
offset.z.div(distance.add(0.15)).mul(t)
|
|
@@ -28875,29 +30239,29 @@ var FluidParticles3D = class extends Group {
|
|
|
28875
30239
|
);
|
|
28876
30240
|
});
|
|
28877
30241
|
});
|
|
28878
|
-
velocity.assign(velocity.add(
|
|
30242
|
+
velocity.assign(velocity.add(vec319(0, this.#gravity.negate().mul(dt), 0)));
|
|
28879
30243
|
if (options.force !== void 0)
|
|
28880
30244
|
velocity.assign(
|
|
28881
30245
|
velocity.add(
|
|
28882
30246
|
options.force(position, velocity, this.#time).mul(dt)
|
|
28883
30247
|
)
|
|
28884
30248
|
);
|
|
28885
|
-
velocity.assign(velocity.mul(
|
|
28886
|
-
previous.element(i).assign(
|
|
28887
|
-
const substeps =
|
|
28888
|
-
ceil(
|
|
30249
|
+
velocity.assign(velocity.mul(float23(maxSpeed).div(max10(length7(velocity), maxSpeed))));
|
|
30250
|
+
previous.element(i).assign(vec419(position, 1));
|
|
30251
|
+
const substeps = clamp9(
|
|
30252
|
+
ceil(length7(velocity).mul(dt).div(radius)),
|
|
28889
30253
|
1,
|
|
28890
30254
|
Math.max(1, Math.ceil(maxSpeed * timeStep / radius))
|
|
28891
30255
|
).toUint().toVar("fluidSubsteps");
|
|
28892
|
-
|
|
28893
|
-
position.assign(position.add(velocity.mul(dt).div(
|
|
30256
|
+
Loop10({ start: uint2(0), end: substeps, type: "uint" }, () => {
|
|
30257
|
+
position.assign(position.add(velocity.mul(dt).div(float23(substeps))));
|
|
28894
30258
|
project(position);
|
|
28895
30259
|
});
|
|
28896
|
-
positions.element(i).assign(
|
|
28897
|
-
velocities.element(i).assign(
|
|
30260
|
+
positions.element(i).assign(vec419(position, 1));
|
|
30261
|
+
velocities.element(i).assign(vec419(velocity, velocities.element(i).w));
|
|
28898
30262
|
});
|
|
28899
30263
|
this.#gridClear = computeKernel2("fluidParticles.grid.clear", cells, () => {
|
|
28900
|
-
|
|
30264
|
+
If11(instanceIndex6.greaterThanEqual(uint2(cells)), () => {
|
|
28901
30265
|
Return2();
|
|
28902
30266
|
});
|
|
28903
30267
|
atomicStore(cellCount.element(instanceIndex6), uint2(0));
|
|
@@ -28906,7 +30270,7 @@ var FluidParticles3D = class extends Group {
|
|
|
28906
30270
|
guard();
|
|
28907
30271
|
const id = cellId(cellOf(positions.element(instanceIndex6).xyz));
|
|
28908
30272
|
const slot = atomicAdd(cellCount.element(id), uint2(1)).toVar();
|
|
28909
|
-
|
|
30273
|
+
If11(slot.lessThan(uint2(CELL_CAPACITY)), () => {
|
|
28910
30274
|
cellItems.element(id.mul(CELL_CAPACITY).add(slot)).assign(instanceIndex6);
|
|
28911
30275
|
});
|
|
28912
30276
|
});
|
|
@@ -28914,20 +30278,20 @@ var FluidParticles3D = class extends Group {
|
|
|
28914
30278
|
guard();
|
|
28915
30279
|
const i = instanceIndex6;
|
|
28916
30280
|
const p = positions.element(i).xyz;
|
|
28917
|
-
const rho = nodeVar(
|
|
28918
|
-
const gradient = nodeVar(
|
|
28919
|
-
const sum = nodeVar(
|
|
30281
|
+
const rho = nodeVar(float23(volumeOfParticle * wSelf));
|
|
30282
|
+
const gradient = nodeVar(vec319(0));
|
|
30283
|
+
const sum = nodeVar(float23(0));
|
|
28920
30284
|
forNeighbours(p, i, (_other, offset, r2) => {
|
|
28921
30285
|
rho.addAssign(kernel(r2).mul(volumeOfParticle));
|
|
28922
30286
|
const r = r2.sqrt();
|
|
28923
|
-
|
|
30287
|
+
If11(r.greaterThan(1e-6), () => {
|
|
28924
30288
|
const a = offset.mul(gradientScale(r));
|
|
28925
30289
|
gradient.addAssign(a);
|
|
28926
30290
|
sum.addAssign(dot8(a, a));
|
|
28927
30291
|
});
|
|
28928
30292
|
});
|
|
28929
30293
|
densities.element(i).assign(rho);
|
|
28930
|
-
const constraint =
|
|
30294
|
+
const constraint = max10(rho.sub(1), 0);
|
|
28931
30295
|
lambdas.element(i).assign(constraint.negate().div(sum.add(dot8(gradient, gradient)).add(relaxation)));
|
|
28932
30296
|
});
|
|
28933
30297
|
this.#delta = computeKernel2("fluidParticles.delta", capacity, () => {
|
|
@@ -28935,10 +30299,10 @@ var FluidParticles3D = class extends Group {
|
|
|
28935
30299
|
const i = instanceIndex6;
|
|
28936
30300
|
const p = positions.element(i).xyz;
|
|
28937
30301
|
const own = lambdas.element(i);
|
|
28938
|
-
const total = nodeVar(
|
|
30302
|
+
const total = nodeVar(vec319(0));
|
|
28939
30303
|
forNeighbours(p, i, (other, offset, r2) => {
|
|
28940
30304
|
const r = r2.sqrt();
|
|
28941
|
-
|
|
30305
|
+
If11(r.greaterThan(1e-6), () => {
|
|
28942
30306
|
const ratio = kernel(r2).div(wReference);
|
|
28943
30307
|
const tensile = ratio.pow(4).mul(-1e-3);
|
|
28944
30308
|
const strength = own.add(lambdas.element(other)).add(tensile);
|
|
@@ -28946,31 +30310,31 @@ var FluidParticles3D = class extends Group {
|
|
|
28946
30310
|
});
|
|
28947
30311
|
});
|
|
28948
30312
|
const limit = spacing * 0.24;
|
|
28949
|
-
const magnitude =
|
|
28950
|
-
const scale = select4(magnitude.greaterThan(limit),
|
|
28951
|
-
deltas.element(i).assign(
|
|
30313
|
+
const magnitude = length7(total);
|
|
30314
|
+
const scale = select4(magnitude.greaterThan(limit), float23(limit).div(magnitude), float23(1));
|
|
30315
|
+
deltas.element(i).assign(vec419(total.mul(scale), 0));
|
|
28952
30316
|
});
|
|
28953
30317
|
this.#apply = computeKernel2("fluidParticles.apply", capacity, () => {
|
|
28954
30318
|
guard();
|
|
28955
30319
|
const i = instanceIndex6;
|
|
28956
30320
|
const p = nodeVar(positions.element(i).xyz.add(deltas.element(i).xyz));
|
|
28957
30321
|
project(p);
|
|
28958
|
-
positions.element(i).assign(
|
|
30322
|
+
positions.element(i).assign(vec419(p, 1));
|
|
28959
30323
|
});
|
|
28960
30324
|
this.#velocity = computeKernel2("fluidParticles.velocity", capacity, () => {
|
|
28961
30325
|
guard();
|
|
28962
30326
|
const i = instanceIndex6;
|
|
28963
30327
|
const v = positions.element(i).xyz.sub(previous.element(i).xyz).div(dt);
|
|
28964
|
-
velocities.element(i).assign(
|
|
30328
|
+
velocities.element(i).assign(vec419(v, velocities.element(i).w));
|
|
28965
30329
|
});
|
|
28966
30330
|
this.#smooth = computeKernel2("fluidParticles.smooth", capacity, () => {
|
|
28967
30331
|
guard();
|
|
28968
30332
|
const i = instanceIndex6;
|
|
28969
30333
|
const p = positions.element(i).xyz;
|
|
28970
30334
|
const v = velocities.element(i).xyz;
|
|
28971
|
-
const change = nodeVar(
|
|
28972
|
-
const curl = nodeVar(
|
|
28973
|
-
const neighbours = nodeVar(
|
|
30335
|
+
const change = nodeVar(vec319(0));
|
|
30336
|
+
const curl = nodeVar(vec319(0));
|
|
30337
|
+
const neighbours = nodeVar(float23(0));
|
|
28974
30338
|
forNeighbours(p, i, (other, offset, r2) => {
|
|
28975
30339
|
const w = kernel(r2).mul(volumeOfParticle);
|
|
28976
30340
|
const dv = velocities.element(other).xyz.sub(v);
|
|
@@ -28979,10 +30343,10 @@ var FluidParticles3D = class extends Group {
|
|
|
28979
30343
|
);
|
|
28980
30344
|
neighbours.addAssign(1);
|
|
28981
30345
|
const r = r2.sqrt();
|
|
28982
|
-
|
|
30346
|
+
If11(r.greaterThan(1e-6), () => {
|
|
28983
30347
|
const s = gradientScale(r);
|
|
28984
30348
|
curl.addAssign(
|
|
28985
|
-
|
|
30349
|
+
vec319(
|
|
28986
30350
|
dv.y.mul(offset.z).sub(dv.z.mul(offset.y)),
|
|
28987
30351
|
dv.z.mul(offset.x).sub(dv.x.mul(offset.z)),
|
|
28988
30352
|
dv.x.mul(offset.y).sub(dv.y.mul(offset.x))
|
|
@@ -28990,50 +30354,50 @@ var FluidParticles3D = class extends Group {
|
|
|
28990
30354
|
);
|
|
28991
30355
|
});
|
|
28992
30356
|
});
|
|
28993
|
-
deltas.element(i).assign(
|
|
28994
|
-
omega.element(i).assign(
|
|
30357
|
+
deltas.element(i).assign(vec419(change, 0));
|
|
30358
|
+
omega.element(i).assign(vec419(curl, neighbours));
|
|
28995
30359
|
});
|
|
28996
30360
|
this.#confine = computeKernel2("fluidParticles.confine", capacity, () => {
|
|
28997
30361
|
guard();
|
|
28998
30362
|
const i = instanceIndex6;
|
|
28999
30363
|
const p = positions.element(i).xyz;
|
|
29000
|
-
const own =
|
|
29001
|
-
const eta = nodeVar(
|
|
30364
|
+
const own = length7(omega.element(i).xyz);
|
|
30365
|
+
const eta = nodeVar(vec319(0));
|
|
29002
30366
|
forNeighbours(p, i, (other, offset, r2) => {
|
|
29003
30367
|
const r = r2.sqrt();
|
|
29004
|
-
|
|
29005
|
-
const diff =
|
|
30368
|
+
If11(r.greaterThan(1e-6), () => {
|
|
30369
|
+
const diff = length7(omega.element(other).xyz).sub(own);
|
|
29006
30370
|
eta.addAssign(offset.mul(gradientScale(r).mul(diff)));
|
|
29007
30371
|
});
|
|
29008
30372
|
});
|
|
29009
30373
|
const w = omega.element(i).xyz;
|
|
29010
|
-
const scale = this.#vorticity.mul(dt).div(
|
|
29011
|
-
const force =
|
|
30374
|
+
const scale = this.#vorticity.mul(dt).div(length7(eta).add(1e-5));
|
|
30375
|
+
const force = vec319(
|
|
29012
30376
|
eta.y.mul(w.z).sub(eta.z.mul(w.y)),
|
|
29013
30377
|
eta.z.mul(w.x).sub(eta.x.mul(w.z)),
|
|
29014
30378
|
eta.x.mul(w.y).sub(eta.y.mul(w.x))
|
|
29015
30379
|
).mul(scale);
|
|
29016
|
-
const limited =
|
|
30380
|
+
const limited = clamp9(force, vec319(-0.15), vec319(0.15));
|
|
29017
30381
|
const v = nodeVar(
|
|
29018
|
-
velocities.element(i).xyz.add(deltas.element(i).xyz).add(select4(this.#vorticity.greaterThan(0), limited,
|
|
30382
|
+
velocities.element(i).xyz.add(deltas.element(i).xyz).add(select4(this.#vorticity.greaterThan(0), limited, vec319(0)))
|
|
29019
30383
|
);
|
|
29020
30384
|
const position = positions.element(i).xyz;
|
|
29021
|
-
|
|
29022
|
-
v.assign(
|
|
30385
|
+
If11(position.y.lessThanEqual(min32[1] + 2e-3), () => {
|
|
30386
|
+
v.assign(vec319(v.x.mul(1 - wallFriction), v.y, v.z.mul(1 - wallFriction)));
|
|
29023
30387
|
});
|
|
29024
|
-
v.assign(v.mul(
|
|
29025
|
-
const speed =
|
|
29026
|
-
const source2 =
|
|
29027
|
-
select4(omega.element(i).w.lessThan(22),
|
|
30388
|
+
v.assign(v.mul(float23(maxSpeed).div(max10(length7(v), maxSpeed))));
|
|
30389
|
+
const speed = length7(v);
|
|
30390
|
+
const source2 = clamp9(speed.sub(1.5).mul(0.14), 0, 1).mul(
|
|
30391
|
+
select4(omega.element(i).w.lessThan(22), float23(1), float23(0.2))
|
|
29028
30392
|
);
|
|
29029
|
-
const foam =
|
|
29030
|
-
velocities.element(i).assign(
|
|
30393
|
+
const foam = max10(velocities.element(i).w.mul(exp6(dt.mul(-1.3))), source2);
|
|
30394
|
+
velocities.element(i).assign(vec419(v, foam));
|
|
29031
30395
|
atomicAdd(stats.element(0), uint2(1));
|
|
29032
|
-
atomicAdd(stats.element(1), uint2(
|
|
30396
|
+
atomicAdd(stats.element(1), uint2(max10(densities.element(i).sub(1), 0).mul(COMPRESSION_SCALE)));
|
|
29033
30397
|
atomicMax(stats.element(2), uint2(speed.mul(FIXED_POINT)));
|
|
29034
30398
|
for (let axis = 0; axis < 3; axis += 1) {
|
|
29035
30399
|
const offset = uint2(
|
|
29036
|
-
|
|
30400
|
+
max10(
|
|
29037
30401
|
[position.x, position.y, position.z][axis]?.sub(min32[axis]).add(1),
|
|
29038
30402
|
0
|
|
29039
30403
|
).mul(FIXED_POINT)
|
|
@@ -29043,7 +30407,7 @@ var FluidParticles3D = class extends Group {
|
|
|
29043
30407
|
}
|
|
29044
30408
|
});
|
|
29045
30409
|
this.#statsClear = computeKernel2("fluidParticles.stats.clear", STAT_WORDS, () => {
|
|
29046
|
-
|
|
30410
|
+
If11(instanceIndex6.greaterThanEqual(uint2(STAT_WORDS)), () => {
|
|
29047
30411
|
Return2();
|
|
29048
30412
|
});
|
|
29049
30413
|
const word = instanceIndex6;
|
|
@@ -29053,39 +30417,39 @@ var FluidParticles3D = class extends Group {
|
|
|
29053
30417
|
);
|
|
29054
30418
|
});
|
|
29055
30419
|
this.#statsFinalize = computeKernel2("fluidParticles.stats.finalize", STAT_WORDS, () => {
|
|
29056
|
-
|
|
30420
|
+
If11(instanceIndex6.greaterThanEqual(uint2(STAT_WORDS)), () => {
|
|
29057
30421
|
Return2();
|
|
29058
30422
|
});
|
|
29059
30423
|
const word = instanceIndex6;
|
|
29060
|
-
const count =
|
|
29061
|
-
const raw =
|
|
30424
|
+
const count = float23(atomicLoad(stats.element(0)));
|
|
30425
|
+
const raw = float23(atomicLoad(stats.element(word)));
|
|
29062
30426
|
const axis = word.sub(3).mod(3);
|
|
29063
30427
|
const base = select4(
|
|
29064
30428
|
axis.equal(0),
|
|
29065
|
-
|
|
29066
|
-
select4(axis.equal(1),
|
|
30429
|
+
float23(min32[0]),
|
|
30430
|
+
select4(axis.equal(1), float23(min32[1]), float23(min32[2]))
|
|
29067
30431
|
);
|
|
29068
|
-
const spatial = select4(count.lessThan(0.5),
|
|
30432
|
+
const spatial = select4(count.lessThan(0.5), float23(0), raw.div(FIXED_POINT).sub(1).add(base));
|
|
29069
30433
|
const value = select4(
|
|
29070
30434
|
word.equal(0),
|
|
29071
30435
|
raw,
|
|
29072
30436
|
select4(
|
|
29073
30437
|
word.equal(1),
|
|
29074
|
-
raw.div(COMPRESSION_SCALE).div(
|
|
30438
|
+
raw.div(COMPRESSION_SCALE).div(max10(count, 1)),
|
|
29075
30439
|
select4(word.equal(2), raw.div(FIXED_POINT), spatial)
|
|
29076
30440
|
)
|
|
29077
30441
|
);
|
|
29078
30442
|
readout.element(word).assign(value);
|
|
29079
30443
|
});
|
|
29080
30444
|
this.#volume = computeKernel2("fluidParticles.volume", voxels, () => {
|
|
29081
|
-
|
|
30445
|
+
If11(instanceIndex6.greaterThanEqual(uint2(voxels)), () => {
|
|
29082
30446
|
Return2();
|
|
29083
30447
|
});
|
|
29084
30448
|
const ix = instanceIndex6.mod(uint2(vx));
|
|
29085
30449
|
const iy = instanceIndex6.div(uint2(vx)).mod(uint2(vy));
|
|
29086
30450
|
const iz = instanceIndex6.div(uint2(vx * vy));
|
|
29087
|
-
const centre =
|
|
29088
|
-
const total = nodeVar(
|
|
30451
|
+
const centre = vec319(float23(ix), float23(iy), float23(iz)).add(0.5).mul(voxelSize).add(vec319(...min32));
|
|
30452
|
+
const total = nodeVar(float23(0));
|
|
29089
30453
|
forNeighbours(centre, uint2(4294967295), (_other, _offset, r2) => {
|
|
29090
30454
|
total.addAssign(kernel(r2).mul(volumeOfParticle));
|
|
29091
30455
|
});
|
|
@@ -29093,62 +30457,62 @@ var FluidParticles3D = class extends Group {
|
|
|
29093
30457
|
textureStore3(
|
|
29094
30458
|
storageTexture3(this.density).toWriteOnly(),
|
|
29095
30459
|
uvec3(ix, iy, iz),
|
|
29096
|
-
|
|
30460
|
+
vec419(total, 0, 0, 1)
|
|
29097
30461
|
).toWriteOnly();
|
|
29098
30462
|
});
|
|
29099
30463
|
const insideCollider = (point) => {
|
|
29100
|
-
const inside = nodeVar(
|
|
29101
|
-
|
|
30464
|
+
const inside = nodeVar(float23(0));
|
|
30465
|
+
Loop10({ start: uint2(0), end: this.#colliderCount, type: "uint" }, ({ i }) => {
|
|
29102
30466
|
const a = this.#colliderA.element(i);
|
|
29103
30467
|
const b = this.#colliderB.element(i);
|
|
29104
30468
|
const offset = point.sub(a.xyz);
|
|
29105
|
-
|
|
29106
|
-
|
|
29107
|
-
inside.assign(
|
|
30469
|
+
If11(a.w.lessThan(0.5), () => {
|
|
30470
|
+
If11(length7(offset).lessThan(b.x), () => {
|
|
30471
|
+
inside.assign(float23(1));
|
|
29108
30472
|
});
|
|
29109
30473
|
}).Else(() => {
|
|
29110
30474
|
const rows = this.#colliderRows.map((row) => row.element(i).xyz);
|
|
29111
30475
|
const local2 = abs7(
|
|
29112
|
-
|
|
30476
|
+
vec319(
|
|
29113
30477
|
dot8(rows[0], offset),
|
|
29114
30478
|
dot8(rows[1], offset),
|
|
29115
30479
|
dot8(rows[2], offset)
|
|
29116
30480
|
)
|
|
29117
30481
|
);
|
|
29118
|
-
|
|
29119
|
-
inside.assign(
|
|
30482
|
+
If11(local2.x.lessThan(b.x).and(local2.y.lessThan(b.y)).and(local2.z.lessThan(b.z)), () => {
|
|
30483
|
+
inside.assign(float23(1));
|
|
29120
30484
|
});
|
|
29121
30485
|
});
|
|
29122
30486
|
});
|
|
29123
30487
|
return inside;
|
|
29124
30488
|
};
|
|
29125
30489
|
this.#columnHeights = computeKernel2("fluidParticles.columns", vx * vz, () => {
|
|
29126
|
-
|
|
30490
|
+
If11(instanceIndex6.greaterThanEqual(uint2(vx * vz)), () => {
|
|
29127
30491
|
Return2();
|
|
29128
30492
|
});
|
|
29129
30493
|
const ix = instanceIndex6.mod(uint2(vx));
|
|
29130
30494
|
const iz = instanceIndex6.div(uint2(vx));
|
|
29131
|
-
const top = nodeVar(
|
|
29132
|
-
const topLayer = nodeVar(
|
|
29133
|
-
|
|
30495
|
+
const top = nodeVar(float23(min32[1]));
|
|
30496
|
+
const topLayer = nodeVar(int8(-1));
|
|
30497
|
+
Loop10({ start: int8(0), end: int8(vy), type: "int" }, ({ i: layer }) => {
|
|
29134
30498
|
const voxel = ix.add(uint2(layer).mul(uint2(vx))).add(iz.mul(uint2(vx * vy)));
|
|
29135
|
-
|
|
29136
|
-
top.assign(
|
|
30499
|
+
If11(volumeBuffer.element(voxel).greaterThan(0.5), () => {
|
|
30500
|
+
top.assign(float23(layer).add(1).mul(voxelSize).add(min32[1]));
|
|
29137
30501
|
topLayer.assign(layer);
|
|
29138
30502
|
});
|
|
29139
30503
|
});
|
|
29140
|
-
const covered = nodeVar(
|
|
30504
|
+
const covered = nodeVar(float23(0));
|
|
29141
30505
|
for (const above of [0, 1, 2]) {
|
|
29142
|
-
const centre =
|
|
29143
|
-
|
|
29144
|
-
|
|
29145
|
-
|
|
30506
|
+
const centre = vec319(
|
|
30507
|
+
float23(ix).add(0.5).mul(voxelSize).add(min32[0]),
|
|
30508
|
+
float23(topLayer.add(1 + above)).add(0.5).mul(voxelSize).add(min32[1]),
|
|
30509
|
+
float23(iz).add(0.5).mul(voxelSize).add(min32[2])
|
|
29146
30510
|
);
|
|
29147
|
-
|
|
29148
|
-
covered.assign(
|
|
30511
|
+
If11(insideCollider(centre).greaterThan(0.5), () => {
|
|
30512
|
+
covered.assign(float23(1));
|
|
29149
30513
|
});
|
|
29150
30514
|
}
|
|
29151
|
-
readout.element(uint2(READOUT_HEADER).add(instanceIndex6)).assign(select4(covered.greaterThan(0.5),
|
|
30515
|
+
readout.element(uint2(READOUT_HEADER).add(instanceIndex6)).assign(select4(covered.greaterThan(0.5), float23(COVERED), top));
|
|
29152
30516
|
});
|
|
29153
30517
|
this.#readback = new GPUReadback({ attribute: readout.value, everyFrames: readbackEvery });
|
|
29154
30518
|
this.warmupNodes = [
|
|
@@ -29222,13 +30586,13 @@ var FluidParticles3D = class extends Group {
|
|
|
29222
30586
|
* Place a lattice of particles in `[min, max]`, one per `spacing`, and return how many fit.
|
|
29223
30587
|
* Particles never wrap: a full solver places none.
|
|
29224
30588
|
*/
|
|
29225
|
-
fill(min8,
|
|
30589
|
+
fill(min8, max11, velocity = [0, 0, 0]) {
|
|
29226
30590
|
this.#assertLive("fill");
|
|
29227
30591
|
finiteVec("fill.min", min8, 3);
|
|
29228
|
-
finiteVec("fill.max",
|
|
30592
|
+
finiteVec("fill.max", max11, 3);
|
|
29229
30593
|
finiteVec("fill.velocity", velocity, 3);
|
|
29230
30594
|
const dims = [0, 1, 2].map(
|
|
29231
|
-
(axis) => Math.floor((
|
|
30595
|
+
(axis) => Math.floor((max11[axis] - min8[axis]) / this.spacing + 1e-6) + 1
|
|
29232
30596
|
);
|
|
29233
30597
|
if (dims.some((dim) => dim < 1)) throw new Error("FluidParticles3D.fill needs max >= min.");
|
|
29234
30598
|
const wanted = dims[0] * dims[1] * dims[2];
|
|
@@ -29253,13 +30617,13 @@ var FluidParticles3D = class extends Group {
|
|
|
29253
30617
|
return true;
|
|
29254
30618
|
}
|
|
29255
30619
|
/** Free every live particle inside the box on the next step. */
|
|
29256
|
-
drain(min8,
|
|
30620
|
+
drain(min8, max11) {
|
|
29257
30621
|
this.#assertLive("drain");
|
|
29258
30622
|
finiteVec("drain.min", min8, 3);
|
|
29259
|
-
finiteVec("drain.max",
|
|
30623
|
+
finiteVec("drain.max", max11, 3);
|
|
29260
30624
|
if (this.#queuedDrains >= MAX_DRAINS) return false;
|
|
29261
30625
|
this.#drainMin.array[this.#queuedDrains].set(min8[0], min8[1], min8[2], 0);
|
|
29262
|
-
this.#drainMax.array[this.#queuedDrains].set(
|
|
30626
|
+
this.#drainMax.array[this.#queuedDrains].set(max11[0], max11[1], max11[2], 0);
|
|
29263
30627
|
this.#queuedDrains += 1;
|
|
29264
30628
|
return true;
|
|
29265
30629
|
}
|
|
@@ -29314,9 +30678,9 @@ var FluidParticles3D = class extends Group {
|
|
|
29314
30678
|
*/
|
|
29315
30679
|
sample(x, z, _time = 0) {
|
|
29316
30680
|
const data = this.#readback.data;
|
|
29317
|
-
const
|
|
30681
|
+
const floor6 = this.bounds.min[1];
|
|
29318
30682
|
if (data === void 0 || x < this.bounds.min[0] || x > this.bounds.max[0] || z < this.bounds.min[2] || z > this.bounds.max[2])
|
|
29319
|
-
return { height:
|
|
30683
|
+
return { height: floor6 };
|
|
29320
30684
|
const [columns, rows] = this.#columns;
|
|
29321
30685
|
const minimumOpen = Math.min(MIN_OPEN_COLUMNS, columns * rows);
|
|
29322
30686
|
const cx = Math.round(
|
|
@@ -29338,7 +30702,7 @@ var FluidParticles3D = class extends Group {
|
|
|
29338
30702
|
}
|
|
29339
30703
|
if (found >= minimumOpen) return { height: sum / found };
|
|
29340
30704
|
}
|
|
29341
|
-
return { height:
|
|
30705
|
+
return { height: floor6 };
|
|
29342
30706
|
}
|
|
29343
30707
|
/** Surface height at `(x, z)`; see {@link sample}. */
|
|
29344
30708
|
heightAt(x, z) {
|
|
@@ -29353,16 +30717,16 @@ var FluidParticles3D = class extends Group {
|
|
|
29353
30717
|
}
|
|
29354
30718
|
/** Counts and extremes from the newest landed GPU copy, or `undefined` before one lands. */
|
|
29355
30719
|
get stats() {
|
|
29356
|
-
const
|
|
29357
|
-
if (
|
|
29358
|
-
const d =
|
|
30720
|
+
const sample2 = this.#readback.sample;
|
|
30721
|
+
if (sample2 === void 0) return void 0;
|
|
30722
|
+
const d = sample2.data;
|
|
29359
30723
|
return {
|
|
29360
30724
|
count: d[0] ?? 0,
|
|
29361
30725
|
meanCompression: d[1] ?? 0,
|
|
29362
30726
|
maxSpeed: d[2] ?? 0,
|
|
29363
30727
|
min: [d[3] ?? 0, d[4] ?? 0, d[5] ?? 0],
|
|
29364
30728
|
max: [d[6] ?? 0, d[7] ?? 0, d[8] ?? 0],
|
|
29365
|
-
staleFrames:
|
|
30729
|
+
staleFrames: sample2.staleFrames
|
|
29366
30730
|
};
|
|
29367
30731
|
}
|
|
29368
30732
|
process(renderer = this.#renderer) {
|
|
@@ -29428,7 +30792,7 @@ function clampNumber2(value, low2, high2) {
|
|
|
29428
30792
|
}
|
|
29429
30793
|
|
|
29430
30794
|
// src/ripple-field.ts
|
|
29431
|
-
var
|
|
30795
|
+
var clamp10 = (x, lo, hi) => Math.max(lo, Math.min(hi, x));
|
|
29432
30796
|
var finite3 = (value, label2) => {
|
|
29433
30797
|
if (!Number.isFinite(value)) throw new TypeError(`${label2} must be finite`);
|
|
29434
30798
|
return value;
|
|
@@ -29504,7 +30868,7 @@ var RippleField = class {
|
|
|
29504
30868
|
for (let j = 0; j < resolution; j++)
|
|
29505
30869
|
for (let i = 0; i < resolution; i++) {
|
|
29506
30870
|
const edge = Math.min(i, j, resolution - 1 - i, resolution - 1 - j);
|
|
29507
|
-
const sponge = 1 -
|
|
30871
|
+
const sponge = 1 - clamp10(edge / 12, 0, 1);
|
|
29508
30872
|
this.#loss[j * resolution + i] = this.damping + 6 * sponge * sponge;
|
|
29509
30873
|
}
|
|
29510
30874
|
}
|
|
@@ -29541,17 +30905,17 @@ var RippleField = class {
|
|
|
29541
30905
|
}
|
|
29542
30906
|
#shift(data, di, dj) {
|
|
29543
30907
|
const n = this.resolution;
|
|
29544
|
-
const
|
|
29545
|
-
|
|
30908
|
+
const scratch4 = this.#scratch;
|
|
30909
|
+
scratch4.fill(0);
|
|
29546
30910
|
const i0 = Math.max(0, -di);
|
|
29547
30911
|
const i1 = Math.min(n, n - di);
|
|
29548
30912
|
const j0 = Math.max(0, -dj);
|
|
29549
30913
|
const j1 = Math.min(n, n - dj);
|
|
29550
30914
|
for (let j = j0; j < j1; j++) {
|
|
29551
30915
|
const source2 = (j + dj) * n + i0 + di;
|
|
29552
|
-
|
|
30916
|
+
scratch4.set(data.subarray(source2, source2 + (i1 - i0)), j * n + i0);
|
|
29553
30917
|
}
|
|
29554
|
-
data.set(
|
|
30918
|
+
data.set(scratch4);
|
|
29555
30919
|
}
|
|
29556
30920
|
/**
|
|
29557
30921
|
* Push the surface at a point: a Gaussian of the given radius, with the kernel corrected so the
|
|
@@ -29590,7 +30954,7 @@ var RippleField = class {
|
|
|
29590
30954
|
const q = ((i - ix) ** 2 + (j - iz) ** 2) / (r * r);
|
|
29591
30955
|
const g = Math.exp(-q);
|
|
29592
30956
|
this.#velocity[k] = this.#velocity[k] + amplitude * (1 - q - correction) * g;
|
|
29593
|
-
if (foam !== 0) this.foam[k] =
|
|
30957
|
+
if (foam !== 0) this.foam[k] = clamp10(this.foam[k] + g * foam, 0, 1);
|
|
29594
30958
|
}
|
|
29595
30959
|
this.#empty = false;
|
|
29596
30960
|
this.version++;
|
|
@@ -29612,7 +30976,7 @@ var RippleField = class {
|
|
|
29612
30976
|
for (let i = Math.max(1, Math.floor(ix - 2 * r)); i <= Math.min(n - 2, Math.ceil(ix + 2 * r)); i++) {
|
|
29613
30977
|
const k = j * n + i;
|
|
29614
30978
|
const g = Math.exp(-(((i - ix) ** 2 + (j - iz) ** 2) / (r * r)));
|
|
29615
|
-
this.foam[k] =
|
|
30979
|
+
this.foam[k] = clamp10(this.foam[k] + g * amount, 0, 1);
|
|
29616
30980
|
}
|
|
29617
30981
|
this.#empty = false;
|
|
29618
30982
|
this.version++;
|
|
@@ -29658,10 +31022,10 @@ var RippleField = class {
|
|
|
29658
31022
|
next[k] = h[k] + v[k] * dt;
|
|
29659
31023
|
const gx = (b - a) / (2 * dx);
|
|
29660
31024
|
const gz = (e - d) / (2 * dx);
|
|
29661
|
-
flowX[k] =
|
|
29662
|
-
flowZ[k] =
|
|
31025
|
+
flowX[k] = clamp10((flowX[k] - 9.81 * gx * dt) / (1 + 0.65 * dt), -9, 9);
|
|
31026
|
+
flowZ[k] = clamp10((flowZ[k] - 9.81 * gz * dt) / (1 + 0.65 * dt), -9, 9);
|
|
29663
31027
|
const breaking = lap < 0 ? Math.max(0, Math.sqrt(gx * gx + gz * gz) - 0.3) * Math.min(3, Math.abs(v[k])) : 0;
|
|
29664
|
-
if (breaking > 0) foam[k] =
|
|
31028
|
+
if (breaking > 0) foam[k] = clamp10(foam[k] + breaking * dt * 0.55, 0, 1);
|
|
29665
31029
|
}
|
|
29666
31030
|
this.height = next;
|
|
29667
31031
|
this.#scratch = h;
|
|
@@ -29681,8 +31045,8 @@ var RippleField = class {
|
|
|
29681
31045
|
for (let j = 1; j < n - 1; j++)
|
|
29682
31046
|
for (let i = 1; i < n - 1; i++) {
|
|
29683
31047
|
const k = j * n + i;
|
|
29684
|
-
const x =
|
|
29685
|
-
const z =
|
|
31048
|
+
const x = clamp10(i - (current.x + flowX[k]) * dt / dx, 0, n - 1.001);
|
|
31049
|
+
const z = clamp10(j - (current.z + flowZ[k]) * dt / dx, 0, n - 1.001);
|
|
29686
31050
|
const a = Math.floor(x);
|
|
29687
31051
|
const b = Math.floor(z);
|
|
29688
31052
|
const q = b * n + a;
|
|
@@ -29690,7 +31054,7 @@ var RippleField = class {
|
|
|
29690
31054
|
const w = z - b;
|
|
29691
31055
|
const back = (foam[q] * (1 - u) + foam[q + 1] * u) * (1 - w) + (foam[q + n] * (1 - u) + foam[q + n + 1] * u) * w;
|
|
29692
31056
|
const lap = foam[k - 1] + foam[k + 1] + foam[k - n] + foam[k + n] - 4 * foam[k];
|
|
29693
|
-
next[k] =
|
|
31057
|
+
next[k] = clamp10((back + lap * 0.06 * dt) * decay, 0, 1);
|
|
29694
31058
|
}
|
|
29695
31059
|
this.foam = next;
|
|
29696
31060
|
this.#foamScratch = foam;
|
|
@@ -29769,8 +31133,8 @@ function direction(value, name) {
|
|
|
29769
31133
|
if (x === void 0 || z === void 0) throw new Error(`WaveField.${name} is incomplete.`);
|
|
29770
31134
|
finite4(`${name}.x`, x);
|
|
29771
31135
|
finite4(`${name}.z`, z);
|
|
29772
|
-
const
|
|
29773
|
-
if (
|
|
31136
|
+
const length8 = Math.hypot(x, z);
|
|
31137
|
+
if (length8 <= Number.EPSILON) throw new Error(`WaveField.${name} must not be zero.`);
|
|
29774
31138
|
return [x, z];
|
|
29775
31139
|
}
|
|
29776
31140
|
function displacement(value, amplitude) {
|
|
@@ -29815,9 +31179,9 @@ var WaveField = class {
|
|
|
29815
31179
|
if (wave === void 0 || typeof wave !== "object")
|
|
29816
31180
|
throw new Error(`WaveField.waves[${index}] must be an object.`);
|
|
29817
31181
|
const [rawX, rawZ] = direction(wave.direction, `waves[${index}].direction`);
|
|
29818
|
-
const
|
|
29819
|
-
const directionX = rawX /
|
|
29820
|
-
const directionZ = rawZ /
|
|
31182
|
+
const length8 = Math.hypot(rawX, rawZ);
|
|
31183
|
+
const directionX = rawX / length8;
|
|
31184
|
+
const directionZ = rawZ / length8;
|
|
29821
31185
|
const wavelength = positive5(`waves[${index}].wavelength`, wave.wavelength);
|
|
29822
31186
|
const speed = finite4(`waves[${index}].speed`, wave.speed);
|
|
29823
31187
|
const phase = wave.phase === void 0 ? 0 : finite4(`waves[${index}].phase`, wave.phase);
|
|
@@ -29849,8 +31213,8 @@ var WaveField = class {
|
|
|
29849
31213
|
if (warp.direction === void 0)
|
|
29850
31214
|
throw new Error(`WaveField.domainWarp[${index}] requires direction or waveVector.`);
|
|
29851
31215
|
const [rawX, rawZ] = direction(warp.direction, `domainWarp[${index}].direction`);
|
|
29852
|
-
const
|
|
29853
|
-
waveVector = [rawX /
|
|
31216
|
+
const length8 = Math.hypot(rawX, rawZ);
|
|
31217
|
+
waveVector = [rawX / length8, rawZ / length8];
|
|
29854
31218
|
const rawWavelength = warp.wavelength;
|
|
29855
31219
|
if (rawWavelength === void 0)
|
|
29856
31220
|
throw new Error(`WaveField.domainWarp[${index}].wavelength is required.`);
|
|
@@ -29911,9 +31275,9 @@ var WaveField = class {
|
|
|
29911
31275
|
* only the number should call `heightAt`, which is the same evaluation without either.
|
|
29912
31276
|
*/
|
|
29913
31277
|
sample(x, z, time) {
|
|
29914
|
-
const
|
|
29915
|
-
const height = this.#evaluateCpu(x, z, time,
|
|
29916
|
-
return { height, normal };
|
|
31278
|
+
const normal2 = new Vector3();
|
|
31279
|
+
const height = this.#evaluateCpu(x, z, time, normal2);
|
|
31280
|
+
return { height, normal: normal2 };
|
|
29917
31281
|
}
|
|
29918
31282
|
/**
|
|
29919
31283
|
* Surface height at a point, as a number.
|
|
@@ -29932,7 +31296,7 @@ var WaveField = class {
|
|
|
29932
31296
|
* it, nothing derivative is computed at all. The warp and wave loops run in the same order
|
|
29933
31297
|
* either way, so the height a scalar caller gets is bit-identical to `sample`'s.
|
|
29934
31298
|
*/
|
|
29935
|
-
#evaluateCpu(x, z, time,
|
|
31299
|
+
#evaluateCpu(x, z, time, normal2) {
|
|
29936
31300
|
const sampleX = requireSampleValue("x", x);
|
|
29937
31301
|
const sampleZ = requireSampleValue("z", z);
|
|
29938
31302
|
const sampleTime = requireSampleValue("time", time);
|
|
@@ -29953,7 +31317,7 @@ var WaveField = class {
|
|
|
29953
31317
|
const sine = Math.sin(phase);
|
|
29954
31318
|
warpedX += displacementX * sine;
|
|
29955
31319
|
warpedZ += displacementZ * sine;
|
|
29956
|
-
if (
|
|
31320
|
+
if (normal2 === void 0) continue;
|
|
29957
31321
|
const cosine = Math.cos(phase);
|
|
29958
31322
|
const derivativeX = cosine * kx;
|
|
29959
31323
|
const derivativeZ = cosine * kz;
|
|
@@ -29977,15 +31341,15 @@ var WaveField = class {
|
|
|
29977
31341
|
const phase = waveNumber * (directionX * warpedX + directionZ * warpedZ) - sampleTime * this.parameters[offset + 4] + this.parameters[offset + 5];
|
|
29978
31342
|
const amplitude = this.#amplitude[index];
|
|
29979
31343
|
height += amplitude * Math.sin(phase);
|
|
29980
|
-
if (
|
|
31344
|
+
if (normal2 === void 0) continue;
|
|
29981
31345
|
const slope = amplitude * waveNumber * Math.cos(phase);
|
|
29982
31346
|
gradientX += slope * directionX;
|
|
29983
31347
|
gradientZ += slope * directionZ;
|
|
29984
31348
|
}
|
|
29985
|
-
if (
|
|
31349
|
+
if (normal2 === void 0) return height;
|
|
29986
31350
|
const worldGradientX = gradientX * warpedXX + gradientZ * warpedZX;
|
|
29987
31351
|
const worldGradientZ = gradientX * warpedXZ + gradientZ * warpedZZ;
|
|
29988
|
-
|
|
31352
|
+
normal2.set(
|
|
29989
31353
|
worldGradientX === 0 ? 0 : -worldGradientX,
|
|
29990
31354
|
1,
|
|
29991
31355
|
worldGradientZ === 0 ? 0 : -worldGradientZ
|
|
@@ -30356,7 +31720,7 @@ function softCircleDataTexture(size = 64, hardness = 0.25) {
|
|
|
30356
31720
|
return texture7;
|
|
30357
31721
|
}
|
|
30358
31722
|
var UP2 = new Vector3(0, 1, 0);
|
|
30359
|
-
var
|
|
31723
|
+
var MIN_DISTANCE3 = 0.05;
|
|
30360
31724
|
var MAX_LEAD = 0.16;
|
|
30361
31725
|
function validateSpawnOptions(options) {
|
|
30362
31726
|
const { lifetime, segmentLength, widthScale } = options;
|
|
@@ -30456,7 +31820,7 @@ var TracerPool3D = class {
|
|
|
30456
31820
|
const widthScale = options.widthScale ?? 1;
|
|
30457
31821
|
const slot = this.#slots[this.#cursor % this.#slots.length];
|
|
30458
31822
|
this.#cursor += 1;
|
|
30459
|
-
if (slot === void 0 || distance <
|
|
31823
|
+
if (slot === void 0 || distance < MIN_DISTANCE3) return;
|
|
30460
31824
|
this.#direction.copy(direction2).normalize();
|
|
30461
31825
|
this.#quaternion.setFromUnitVectors(UP2, this.#direction);
|
|
30462
31826
|
const segmentLength = Math.min(shotSegmentLength, distance);
|
|
@@ -30585,9 +31949,9 @@ var PathFollow3D = class {
|
|
|
30585
31949
|
let nearest = Number.POSITIVE_INFINITY;
|
|
30586
31950
|
let nearestIndex = 0;
|
|
30587
31951
|
for (let index = 0; index < this.#samples.length; index += 1) {
|
|
30588
|
-
const
|
|
30589
|
-
if (
|
|
30590
|
-
const distance =
|
|
31952
|
+
const sample2 = this.#samples[index];
|
|
31953
|
+
if (sample2 === void 0) throw new Error("PathFollow3D projection sample is missing.");
|
|
31954
|
+
const distance = sample2.distanceToSquared(position);
|
|
30591
31955
|
if (distance < nearest) {
|
|
30592
31956
|
nearest = distance;
|
|
30593
31957
|
nearestIndex = index;
|
|
@@ -30708,29 +32072,29 @@ var NEUTRAL_FLIGHT_MODIFIERS = Object.freeze({
|
|
|
30708
32072
|
});
|
|
30709
32073
|
var TAU2 = Math.PI * 2;
|
|
30710
32074
|
var SEA_WIND = Object.freeze({ x: 0, y: 0, z: 0 });
|
|
30711
|
-
var
|
|
32075
|
+
var clamp12 = (value, low2, high2) => Math.max(low2, Math.min(high2, value));
|
|
30712
32076
|
var lerp = (a, b, t) => a + (b - a) * t;
|
|
30713
32077
|
var wrap2 = (angle) => (angle % TAU2 + TAU2) % TAU2;
|
|
30714
32078
|
var dot9 = (a, b) => a.x * b.x + a.y * b.y + a.z * b.z;
|
|
30715
32079
|
var unit = (a) => {
|
|
30716
|
-
const
|
|
30717
|
-
return { x: a.x /
|
|
32080
|
+
const length8 = Math.hypot(a.x, a.y, a.z) || 1;
|
|
32081
|
+
return { x: a.x / length8, y: a.y / length8, z: a.z / length8 };
|
|
30718
32082
|
};
|
|
30719
32083
|
var smooth = (a, b, x) => {
|
|
30720
|
-
const t =
|
|
32084
|
+
const t = clamp12((x - a) / (b - a), 0, 1);
|
|
30721
32085
|
return t * t * (3 - 2 * t);
|
|
30722
32086
|
};
|
|
30723
|
-
var move = (a, b, maxStep) => a +
|
|
32087
|
+
var move = (a, b, maxStep) => a + clamp12(b - a, -maxStep, maxStep);
|
|
30724
32088
|
function airDensity(y) {
|
|
30725
32089
|
return 1.225 * Math.max(0.19, 1 - 225577e-10 * Math.max(0, y)) ** 4.25588;
|
|
30726
32090
|
}
|
|
30727
32091
|
function aircraftMass(state, airframe) {
|
|
30728
|
-
return airframe.dryMass + airframe.fuelMass *
|
|
32092
|
+
return airframe.dryMass + airframe.fuelMass * clamp12((state.fuel ?? 100) / 100, 0, 1) + (state.payloadMass ?? 0);
|
|
30729
32093
|
}
|
|
30730
32094
|
function aerodynamicCoefficients(alpha, flaps = 0, gear = 0, brakes = 0) {
|
|
30731
32095
|
const critical = 0.265 + flaps * 0.035;
|
|
30732
32096
|
const stall = smooth(critical - 0.015, critical + 0.15, Math.abs(alpha));
|
|
30733
|
-
const attached =
|
|
32097
|
+
const attached = clamp12(0.22 + flaps * 0.48 + 4.8 * alpha, -1.48, 1.58 + flaps * 0.35);
|
|
30734
32098
|
const separated = 1.1 * Math.sin(2 * alpha);
|
|
30735
32099
|
const cl = lerp(attached, separated, stall);
|
|
30736
32100
|
const cd = 0.027 + 0.075 * cl * cl + 0.9 * Math.sin(alpha) ** 2 * stall + gear * 0.029 + brakes * 0.135 + flaps * flaps * 0.047;
|
|
@@ -30823,7 +32187,7 @@ function flightForces(state, environment) {
|
|
|
30823
32187
|
state.gearPos || 0,
|
|
30824
32188
|
state.brakePos || 0
|
|
30825
32189
|
);
|
|
30826
|
-
const health = 0.72 + 0.28 *
|
|
32190
|
+
const health = 0.72 + 0.28 * clamp12((state.hp ?? 100) / 100, 0, 1);
|
|
30827
32191
|
const mass = aircraftMass(state, airframe);
|
|
30828
32192
|
const lift = qs * coeff.cl * health * modifiers.lift;
|
|
30829
32193
|
const drag = qs * (coeff.cd + modifiers.drag + (state.payloadDrag ?? 0));
|
|
@@ -30877,13 +32241,13 @@ function updateActuators(state, dt, controls = {}) {
|
|
|
30877
32241
|
state.gearPos = move(state.gearPos ?? (state.gear ? 1 : 0), state.gear ? 1 : 0, dt * 0.36);
|
|
30878
32242
|
state.brakePos = move(state.brakePos ?? (state.brakes ? 1 : 0), state.brakes ? 1 : 0, dt * 0.85);
|
|
30879
32243
|
state.flapPos = move(state.flapPos ?? 0, state.flaps ?? 0, dt * 0.23);
|
|
30880
|
-
state.aileron = lerp(state.aileron || 0,
|
|
32244
|
+
state.aileron = lerp(state.aileron || 0, clamp12(controls.turn || 0, -1, 1), 1 - Math.exp(-dt * 7));
|
|
30881
32245
|
state.elevator = lerp(
|
|
30882
32246
|
state.elevator || 0,
|
|
30883
|
-
|
|
32247
|
+
clamp12(controls.pitch || 0, -1, 1),
|
|
30884
32248
|
1 - Math.exp(-dt * 6)
|
|
30885
32249
|
);
|
|
30886
|
-
state.rudder = lerp(state.rudder || 0,
|
|
32250
|
+
state.rudder = lerp(state.rudder || 0, clamp12(controls.rudder || 0, -1, 1), 1 - Math.exp(-dt * 7));
|
|
30887
32251
|
}
|
|
30888
32252
|
function advanceQuaternion(state, dt) {
|
|
30889
32253
|
const q = state.attitude;
|
|
@@ -30909,7 +32273,7 @@ function advanceQuaternion(state, dt) {
|
|
|
30909
32273
|
q.w = w / n;
|
|
30910
32274
|
const axes = attitudeAxes(state);
|
|
30911
32275
|
state.heading = wrap2(Math.atan2(axes.f.x, -axes.f.z));
|
|
30912
|
-
state.pitch = Math.asin(
|
|
32276
|
+
state.pitch = Math.asin(clamp12(axes.f.y, -1, 1));
|
|
30913
32277
|
state.roll = Math.atan2(axes.r.y, axes.u.y);
|
|
30914
32278
|
}
|
|
30915
32279
|
function stepFlight(state, dt, controls, environment) {
|
|
@@ -30929,21 +32293,21 @@ function stepFlight(state, dt, controls, environment) {
|
|
|
30929
32293
|
const speed = Math.max(12, f.airspeed);
|
|
30930
32294
|
const neutralWeight = Math.exp(-Math.abs(state.elevator) * 12);
|
|
30931
32295
|
const upright = f.axes.u.y > 0.35;
|
|
30932
|
-
const assistLoad = state.assist && !controls.autopilot && upright ? neutralWeight * (
|
|
32296
|
+
const assistLoad = state.assist && !controls.autopilot && upright ? neutralWeight * (clamp12(1 / Math.max(0.55, Math.cos(state.roll)), 1, 1.8) - 1 + clamp12(-state.vy * 0.05, -0.45, 0.45)) : 0;
|
|
30933
32297
|
const desiredLoad = 1 + assistLoad + (state.elevator >= 0 ? 4.5 : 2.5) * state.elevator;
|
|
30934
|
-
const trimAlpha = state.assist || controls.autopilot ?
|
|
32298
|
+
const trimAlpha = state.assist || controls.autopilot ? clamp12(
|
|
30935
32299
|
(desiredLoad * f.mass * gravity / Math.max(f.qs, 4e3) - 0.22 - state.flapPos * 0.48) / 4.8,
|
|
30936
32300
|
-0.34,
|
|
30937
32301
|
0.43
|
|
30938
32302
|
) : state.trim + state.elevator * 0.34;
|
|
30939
32303
|
const dampingSpeed = Math.max(25, speed);
|
|
30940
|
-
const controlPower =
|
|
32304
|
+
const controlPower = clamp12(f.qs, 0, 4e5);
|
|
30941
32305
|
const pitchMoment = controlPower * airframe.chord * (0.64 * modifiers.controls * (trimAlpha - f.alpha) - 10 * state.pitchRate * airframe.chord / (2 * dampingSpeed) - 0.045 * f.stall);
|
|
30942
|
-
const bankDemand =
|
|
32306
|
+
const bankDemand = clamp12((state.roll + state.aileron * 1.1) * 1.7 - state.rollRate * 0.65, -1, 1);
|
|
30943
32307
|
const rollInput = state.assist && !controls.autopilot ? bankDemand : state.aileron;
|
|
30944
32308
|
state.controlAileron = rollInput;
|
|
30945
32309
|
const rollMoment = controlPower * airframe.span * (0.023 * rollInput * (0.35 + 0.65 * modifiers.lift) + modifiers.roll - 0.48 * state.rollRate * airframe.span / (2 * dampingSpeed) - 0.012 * f.beta);
|
|
30946
|
-
const yawAssist = state.assist || controls.autopilot ?
|
|
32310
|
+
const yawAssist = state.assist || controls.autopilot ? clamp12(f.beta * 1.3, -0.6, 0.6) : 0;
|
|
30947
32311
|
const yawMoment = controlPower * airframe.span * (0.1 * f.beta + 0.024 * modifiers.controls * (state.rudder + yawAssist) - 0.29 * state.yawRate * airframe.span / (2 * dampingSpeed) - 17e-4 * state.aileron);
|
|
30948
32312
|
state.pitchRate += pitchMoment / airframe.pitchInertia * dt;
|
|
30949
32313
|
state.rollRate += rollMoment / airframe.rollInertia * dt;
|
|
@@ -30976,42 +32340,42 @@ function stepDeck(state, deck, dt, controls, environment) {
|
|
|
30976
32340
|
state.deckSpeed = state.deckSpeed ?? 0;
|
|
30977
32341
|
state.deckLateral = state.deckLateral ?? -2.5;
|
|
30978
32342
|
state.deckOffset = state.deckOffset ?? -105;
|
|
30979
|
-
const
|
|
30980
|
-
const
|
|
30981
|
-
const overDeck = deck.speed + wind.z *
|
|
32343
|
+
const sin3 = Math.sin(deck.heading);
|
|
32344
|
+
const cos3 = Math.cos(deck.heading);
|
|
32345
|
+
const overDeck = deck.speed + wind.z * cos3 - wind.x * sin3;
|
|
30982
32346
|
const speed = state.deckSpeed + overDeck;
|
|
30983
32347
|
const tailRise = smooth(22, 38, speed);
|
|
30984
32348
|
const rotation = smooth(42, 51, speed);
|
|
30985
32349
|
const neutralPitch = lerp(0.22, 0.025, tailRise) + (state.assist ? 0.145 * rotation : 0);
|
|
30986
|
-
const desiredPitch =
|
|
32350
|
+
const desiredPitch = clamp12(neutralPitch + (controls.pitch || 0) * 0.13, -0.025, 0.26);
|
|
30987
32351
|
state.pitch = lerp(state.pitch, desiredPitch, 1 - Math.exp(-dt * 2.8));
|
|
30988
32352
|
state.heading = wrap2(
|
|
30989
|
-
state.heading + (controls.rudder || controls.turn || 0) * dt * 0.22 *
|
|
32353
|
+
state.heading + (controls.rudder || controls.turn || 0) * dt * 0.22 * clamp12(state.deckSpeed / 12, 0, 1)
|
|
30990
32354
|
);
|
|
30991
32355
|
setAttitude(state, state.heading, state.pitch, 0);
|
|
30992
32356
|
const yaw = Math.atan2(
|
|
30993
32357
|
Math.sin(state.heading - deck.heading),
|
|
30994
32358
|
Math.cos(state.heading - deck.heading)
|
|
30995
32359
|
);
|
|
30996
|
-
state.vx = Math.sin(state.heading) * state.deckSpeed +
|
|
32360
|
+
state.vx = Math.sin(state.heading) * state.deckSpeed + sin3 * deck.speed;
|
|
30997
32361
|
state.vy = 0;
|
|
30998
|
-
state.vz = -Math.cos(state.heading) * state.deckSpeed -
|
|
32362
|
+
state.vz = -Math.cos(state.heading) * state.deckSpeed - cos3 * deck.speed;
|
|
30999
32363
|
const f = flightForces(state, environment);
|
|
31000
|
-
const
|
|
32364
|
+
const normal2 = Math.max(0, f.mass * gravity - f.lift * Math.cos(state.pitch));
|
|
31001
32365
|
if (state.chocks !== false && state.throttle < 0.55) {
|
|
31002
32366
|
state.deckSpeed = 0;
|
|
31003
32367
|
} else {
|
|
31004
32368
|
state.chocks = false;
|
|
31005
|
-
const acceleration = (f.thrust - f.drag -
|
|
32369
|
+
const acceleration = (f.thrust - f.drag - normal2 * (controls.wheelBrake ? 0.55 : 0.019)) / f.mass;
|
|
31006
32370
|
state.deckSpeed = Math.max(0, state.deckSpeed + acceleration * dt);
|
|
31007
32371
|
}
|
|
31008
32372
|
state.deckOffset += Math.cos(yaw) * state.deckSpeed * dt;
|
|
31009
32373
|
state.deckLateral += Math.sin(yaw) * state.deckSpeed * dt;
|
|
31010
|
-
state.x = deck.x +
|
|
31011
|
-
state.z = deck.z -
|
|
32374
|
+
state.x = deck.x + sin3 * state.deckOffset + cos3 * state.deckLateral;
|
|
32375
|
+
state.z = deck.z - cos3 * state.deckOffset + sin3 * state.deckLateral;
|
|
31012
32376
|
state.y = deckHeight + gearClearance(state);
|
|
31013
|
-
state.vx = Math.sin(state.heading) * state.deckSpeed +
|
|
31014
|
-
state.vz = -Math.cos(state.heading) * state.deckSpeed -
|
|
32377
|
+
state.vx = Math.sin(state.heading) * state.deckSpeed + sin3 * deck.speed;
|
|
32378
|
+
state.vz = -Math.cos(state.heading) * state.deckSpeed - cos3 * deck.speed;
|
|
31015
32379
|
state.speed = Math.hypot(state.vx - wind.x, state.vz - wind.z);
|
|
31016
32380
|
state.ias = state.speed * Math.sqrt(airDensity(state.y) / 1.225);
|
|
31017
32381
|
state.groundSpeed = state.deckSpeed + deck.speed;
|
|
@@ -31103,13 +32467,13 @@ function parseReplayRecording(value) {
|
|
|
31103
32467
|
fail("runtime fingerprint is invalid");
|
|
31104
32468
|
let previousTick = -1;
|
|
31105
32469
|
for (const rawSample of input) {
|
|
31106
|
-
const
|
|
31107
|
-
const tick =
|
|
32470
|
+
const sample2 = checked(rawSample, ["keys", "pointer", "tick"]);
|
|
32471
|
+
const tick = sample2.tick;
|
|
31108
32472
|
if (!Number.isInteger(tick) || tick <= previousTick || tick >= ticks) fail("bad tick");
|
|
31109
|
-
const keys =
|
|
32473
|
+
const keys = sample2.keys;
|
|
31110
32474
|
if (!Array.isArray(keys) || keys.some((key) => typeof key !== "string")) fail("bad keys");
|
|
31111
32475
|
if (new Set(keys).size !== keys.length) fail("duplicate keys");
|
|
31112
|
-
if (
|
|
32476
|
+
if (sample2.pointer !== void 0) validatePointer(sample2.pointer);
|
|
31113
32477
|
previousTick = tick;
|
|
31114
32478
|
}
|
|
31115
32479
|
return root;
|
|
@@ -31244,7 +32608,7 @@ function restoreRandomState(random, state) {
|
|
|
31244
32608
|
}
|
|
31245
32609
|
function createReplayDriver(recording, target, pointerTarget = target) {
|
|
31246
32610
|
const value = parseReplayRecording(recording);
|
|
31247
|
-
const samples = new Map(value.input.map((
|
|
32611
|
+
const samples = new Map(value.input.map((sample2) => [sample2.tick, sample2]));
|
|
31248
32612
|
let preparedRandom;
|
|
31249
32613
|
const driver = Object.assign(
|
|
31250
32614
|
(runtime) => {
|
|
@@ -31257,11 +32621,11 @@ function createReplayDriver(recording, target, pointerTarget = target) {
|
|
|
31257
32621
|
replayDepth += 1;
|
|
31258
32622
|
try {
|
|
31259
32623
|
for (let tick = 0; tick < value.ticks; tick += 1) {
|
|
31260
|
-
const
|
|
31261
|
-
if (
|
|
31262
|
-
dispatchKeys(target, keys,
|
|
31263
|
-
if (
|
|
31264
|
-
pointer = dispatchPointer(pointer,
|
|
32624
|
+
const sample2 = samples.get(tick);
|
|
32625
|
+
if (sample2 !== void 0) {
|
|
32626
|
+
dispatchKeys(target, keys, sample2.keys);
|
|
32627
|
+
if (sample2.pointer !== void 0)
|
|
32628
|
+
pointer = dispatchPointer(pointer, sample2.pointer, pointerTarget);
|
|
31265
32629
|
}
|
|
31266
32630
|
runtime.fixedStep(1);
|
|
31267
32631
|
}
|
|
@@ -31582,4 +32946,4 @@ var version = CORE_VERSION;
|
|
|
31582
32946
|
* SOFTWARE.
|
|
31583
32947
|
*/
|
|
31584
32948
|
|
|
31585
|
-
export { ATLAS_PADDING, ATMOSPHERE_LUT_RESOLUTIONS, AnimationComposer, AnimationPlayer, Atmosphere, AtmosphereLuts, AutoExposureNode, Billboard3D, BlendSpace1D, BlendSpace2D, BudgetLadder, CanvasLayer, ClusteredBatch, ComputeDrivenRegistry, Daylight, ENVIRONMENT_TOO_SMALL_MARKER, EPIC_SSGI, FRAME_BUDGET_MARKER, FRAME_BUDGET_PHASES, FRAME_HITCH_MARKER, FlightModel, FluidField2D, FluidParticles3D, FrameBudget, GIBudget, GIVisualize, GI_METHODS, GI_VISUALIZE_MODES, GPUSceneBVH, GroundSnap, InputMap, LAMP_SHADOW_MARKER, LUT_RESOLUTIONS, MatrixWorldPass, NEUTRAL_FLIGHT_MODIFIERS, OPACITY_IGNORED_MARKER, PROBE_VOLUME_MARKER, PathFollow3D, PointerEvents3D, ProbeVolume, RENDERLIST_VALIDATE_FLAG, RENDERLIST_VALIDATE_MARKER, RadianceCache, RenderListValidator, RippleField, SCENE_WARNING_MARKER, SHADOW_FILTER_TIERS, SHADOW_STAGES, Scene6 as Scene, ScenePicker, Scheduler, ShadowFilterBudget, SkeletalMesh3D, SkyCapture, SkyCaptureSchedule, SoftBody3D, SpectralOcean, SpriteAnimator3D, SurfaceCache, SurfaceLights, TracedReflections, TracerPool3D, UNLIT_FOLIAGE_FIX, UNLIT_FOLIAGE_MARKER, VIRTUAL_SHADOW_MARKER, VirtualShadowNode, WaterSurface3D, WaveField, WorldEnvironment, aerodynamicCoefficients, afterPhysics, airDensity, aircraftMass, attachToBone, attitudeAxes, boneContact, boneLengthDeviations, boneLengths, bvhIntersectFirstHit, captureMouse, clipBoneCoverage, clipPoseError, clipTrackBindings, createRandom, createReplayDriver, defineGame, describeSceneShape, describeSceneWarning, directionFromSolarPosition, directionalTransmittance, displayPeriodMs, ev100FromCamera, ev100FromExposure, ev100FromLuminance, exposureFromEv100, exposureSettings, formatSceneWarning, formatUnlitFoliageWarning, formatValidationReport, gearClearance, installFilmicToneMapping, installSpanProbes, lampPenumbraTangent, lampShadowMarker, lookDiagnostics, measureThreePose, normaliseToMetres, onLaunchFailure, parseReplayRecording, penumbraUv, posedBounds, prewarm, qualityPreset, qualityTiers, rayStruct, readGIMarker, readLampShadowMarker, readProbeVolumeObservation, readShadowTierMarker, readVirtualShadowMarker, renderListValidationRequested, renderTrapAudit, replay, resolveAtmosphereLutResolutions, resolveAtmosphereParameters, sceneWarning, setAttitude, skeletonBones, softCircleDataTexture, solarPosition, solarPositionAt, sourceAngleShadowFilter, sourceRadiusShadowFilter, stageGpuReading, thinCards, unlitFoliageWarning, updateAtmosphereParameters, useRoughDiffuse, validateWorldMatrices, version, zenithTransmittance };
|
|
32949
|
+
export { ATLAS_PADDING, ATMOSPHERE_LUT_RESOLUTIONS, AnimationComposer, AnimationPlayer, Atmosphere, AtmosphereLuts, AutoExposureNode, Billboard3D, BlendSpace1D, BlendSpace2D, BudgetLadder, CanvasLayer, ClusteredBatch, ComputeDrivenRegistry, Daylight, ENVIRONMENT_TOO_SMALL_MARKER, EPIC_SSGI, FRAME_BUDGET_MARKER, FRAME_BUDGET_PHASES, FRAME_HITCH_MARKER, FlightModel, FluidField2D, FluidParticles3D, FrameBudget, GIBudget, GIVisualize, GI_METHODS, GI_VISUALIZE_MODES, GPUSceneBVH, GRASS_FIELD_ATTRIBUTES, GrassField3D, GroundSnap, InputMap, LAMP_SHADOW_MARKER, LUT_RESOLUTIONS, MatrixWorldPass, NEUTRAL_FLIGHT_MODIFIERS, OPACITY_IGNORED_MARKER, PROBE_VOLUME_MARKER, PathFollow3D, PointerEvents3D, ProbeVolume, RENDERLIST_VALIDATE_FLAG, RENDERLIST_VALIDATE_MARKER, RadianceCache, RenderListValidator, RippleField, SCENE_WARNING_MARKER, SHADOW_FILTER_TIERS, SHADOW_STAGES, ScatterField3D, Scene6 as Scene, ScenePicker, Scheduler, ScreenProbeGather, ShadowFilterBudget, ShortRangeAO, SkeletalMesh3D, SkyCapture, SkyCaptureSchedule, SoftBody3D, SpectralOcean, SpriteAnimator3D, SurfaceCache, SurfaceLights, TracedReflections, TracerPool3D, UNLIT_FOLIAGE_FIX, UNLIT_FOLIAGE_MARKER, VIRTUAL_SHADOW_MARKER, VirtualShadowNode, WaterSurface3D, WaveField, WorldEnvironment, aerodynamicCoefficients, afterPhysics, airDensity, aircraftMass, attachToBone, attitudeAxes, boneContact, boneLengthDeviations, boneLengths, bvhIntersectFirstHit, captureMouse, clipBoneCoverage, clipPoseError, clipTrackBindings, createRandom, createReplayDriver, defineGame, describeSceneShape, describeSceneWarning, directionFromSolarPosition, directionalTransmittance, displayPeriodMs, ev100FromCamera, ev100FromExposure, ev100FromLuminance, exposureFromEv100, exposureSettings, formatSceneWarning, formatUnlitFoliageWarning, formatValidationReport, gearClearance, installFilmicToneMapping, installSpanProbes, lampPenumbraTangent, lampShadowMarker, lookDiagnostics, measureThreePose, normaliseToMetres, onLaunchFailure, parseReplayRecording, penumbraUv, posedBounds, prewarm, qualityPreset, qualityTiers, rayStruct, readGIMarker, readLampShadowMarker, readProbeVolumeObservation, readShadowTierMarker, readVirtualShadowMarker, renderListValidationRequested, renderTrapAudit, replay, resolveAtmosphereLutResolutions, resolveAtmosphereParameters, sceneWarning, setAttitude, skeletonBones, softCircleDataTexture, solarPosition, solarPositionAt, sourceAngleShadowFilter, sourceRadiusShadowFilter, stageGpuReading, thinCards, unlitFoliageWarning, updateAtmosphereParameters, useRoughDiffuse, validateWorldMatrices, version, zenithTransmittance };
|