@woosh/meep-engine 2.33.23 → 2.33.24
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/core/bvh2/BinaryNode.js +1 -1
- package/core/bvh2/aabb3/AABB3.js +18 -0
- package/core/bvh2/aabb3/AABB3Math.js +1 -1
- package/core/bvh2/binary/2/BinaryUint32BVH.js +498 -0
- package/core/bvh2/binary/2/BinaryUint32BVH.spec.js +54 -0
- package/core/bvh2/binary/IndexedBinaryBVH.js +22 -26
- package/core/collection/ArrayUtils.js +1 -1
- package/core/collection/array/arrayQuickSort.js +9 -6
- package/core/collection/array/array_swap.js +22 -0
- package/core/collection/array/computeHashArray.js +22 -0
- package/core/collection/array/computeHashIntegerArray.js +15 -0
- package/core/collection/table/DataType2TypedArrayConstructorMapping.js +15 -0
- package/core/color/Color.js +2 -1
- package/core/function/FunctionCompiler.js +2 -1
- package/core/geom/3d/aabb/aabb3_computeDistanceAbovePlane.js +9 -33
- package/core/geom/3d/frustum/frustum3_computeNearestPointToPoint.js +1 -1
- package/core/geom/3d/line/line3_computeSegmentPointDistance_sqr.js +41 -0
- package/core/geom/3d/morton/mortonEncode_magicbits.js +2 -1
- package/core/geom/3d/morton/reinterpret_float32_as_int32.js +13 -0
- package/core/geom/3d/morton/v3_morton_encode_transformed.js +33 -0
- package/core/geom/3d/ray/ray_computeNearestPointToPoint.js +37 -0
- package/core/geom/3d/shape/AbstractShape3D.js +29 -0
- package/core/geom/3d/shape/CompositeShape.js +60 -0
- package/core/geom/3d/shape/TransformedShape3D.js +70 -0
- package/core/geom/3d/shape/UnitCubeShape3D.js +13 -0
- package/core/geom/3d/shape/UnitSphereShape3D.js +16 -0
- package/core/geom/AABB2.js +1 -1
- package/core/geom/ConicRay.js +3 -1
- package/core/geom/LineSegment.js +0 -78
- package/core/geom/Matrix4.js +7 -8
- package/core/geom/Rectangle.js +2 -1
- package/core/geom/Vector1.js +1 -1
- package/core/geom/Vector3.js +2 -1
- package/core/geom/Vector4.js +2 -1
- package/core/geom/random/randomPointInBox.js +7 -3
- package/core/geom/random/randomPointInPoint.js +6 -3
- package/core/geom/random/randomPointInSphere.js +6 -3
- package/core/geom/random/randomPointOnBox.js +7 -3
- package/core/geom/random/randomPointOnSphere.js +6 -3
- package/core/geom/v3_length.js +8 -3
- package/core/graph/graph_k_means_cluster.js +1 -1
- package/core/math/MathUtils.js +0 -354
- package/core/math/MathUtils.spec.js +7 -1
- package/core/math/gaussian.js +9 -0
- package/core/math/hash/computeHashFloat.js +17 -0
- package/core/math/hash/computeHashFloatArray.js +34 -0
- package/core/math/hash/computeObjectHash.js +54 -0
- package/core/math/intersects1D.js +19 -0
- package/core/math/interval/NumericInterval.js +2 -2
- package/core/math/isValueBetween.js +10 -0
- package/core/math/isValueBetweenInclusive.js +10 -0
- package/core/math/noise/curl_noise_3dt.js +1 -1
- package/core/math/noise/sdnoise.js +10 -10
- package/core/math/overlap1D.js +19 -0
- package/core/math/pingpong.js +17 -0
- package/core/math/random/makeRangedRandom.js +19 -0
- package/core/math/random/randomFloatBetween.js +14 -0
- package/core/math/random/randomFromArray.js +19 -0
- package/core/math/random/randomGaussian.js +15 -0
- package/core/math/random/randomIntegerBetween.js +14 -0
- package/core/math/random/roundFair.js +15 -0
- package/core/math/separation1D.js +21 -0
- package/core/math/solveQuadratic.js +25 -0
- package/core/model/BoundedValue.js +1 -1
- package/core/model/node-graph/node/NodeInstancePortReference.js +1 -1
- package/core/model/node-graph/node/Port.js +1 -1
- package/core/model/reactive/evaluation/MultiPredicateEvaluator.spec.js +3 -1
- package/core/model/reactive/model/ReactiveBinaryExpression.js +1 -1
- package/core/model/reactive/model/terminal/ReactiveLiteralNumber.js +1 -1
- package/core/model/reactive/model/terminal/ReactiveReference.js +1 -1
- package/core/model/reactive/model/util/createRandomReactiveExpression.js +1 -1
- package/core/model/stat/LinearModifier.js +1 -1
- package/engine/animation/curve/AnimationCurve.js +72 -0
- package/engine/animation/curve/Keyframe.js +27 -0
- package/engine/animation/keyed2/AnimationTrack.js +27 -3
- package/engine/asset/Asset.js +1 -1
- package/engine/asset/loaders/GLTFAssetLoader.d.ts +1 -1
- package/engine/asset/loaders/GLTFAssetLoader.js +10 -0
- package/engine/asset/loaders/image/ImageRGBADataAsset.js +8 -1
- package/engine/asset/loaders/material/computeMaterialHash.js +3 -1
- package/engine/asset/loaders/material/computeTextureHash.js +2 -1
- package/engine/ecs/animation/Animation.js +2 -1
- package/engine/ecs/animation/InverseKinematics.js +2 -1
- package/engine/ecs/dynamic_actions/DynamicActorSystem.js +2 -1
- package/engine/ecs/dynamic_actions/DynamicRuleDescriptionTable.spec.js +3 -5
- package/engine/ecs/dynamic_actions/actions/definition/WeightedRandomActionDescription.js +1 -1
- package/engine/ecs/evaluation/complex/PointFitnessGaussianBlur.js +1 -1
- package/engine/ecs/foliage/ecs/Foliage2.js +1 -1
- package/engine/ecs/fow/shader/FogOfWarRenderer.js +1 -1
- package/engine/ecs/gui/GUIElement.js +1 -1
- package/engine/ecs/gui/hud/HeadsUpDisplay.js +1 -1
- package/engine/ecs/gui/position/ViewportPosition.js +2 -1
- package/engine/ecs/systems/RangedAttackSystem.js +1 -1
- package/engine/ecs/systems/SteeringSystem.js +1 -1
- package/engine/ecs/terrain/tiles/TerrainTileManager.js +1 -1
- package/engine/ecs/tooltip/TooltipComponent.js +15 -0
- package/engine/graphics/ecs/animation/animator/AnimationClip.js +2 -1
- package/engine/graphics/ecs/animation/animator/AnimationClipDefinition.js +2 -1
- package/engine/graphics/ecs/animation/animator/AnimationNotification.js +2 -1
- package/engine/graphics/ecs/animation/animator/AnimationNotificationDefinition.js +2 -1
- package/engine/graphics/ecs/animation/animator/graph/AnimationGraph.js +2 -1
- package/engine/graphics/ecs/animation/animator/graph/definition/AnimationGraphDefinition.js +2 -1
- package/engine/graphics/ecs/animation/animator/graph/definition/AnimationStateDefinition.js +1 -1
- package/engine/graphics/ecs/animation/animator/graph/definition/AnimationTransitionDefinition.js +2 -1
- package/engine/graphics/ecs/camera/CameraClippingPlaneComputer.js +1 -1
- package/engine/graphics/ecs/highlight/HighlightDefinition.js +2 -1
- package/engine/graphics/ecs/light/Light.d.ts +1 -1
- package/engine/graphics/ecs/light/Light.js +3 -0
- package/engine/graphics/ecs/mesh/Mesh.js +2 -1
- package/engine/graphics/ecs/mesh-v2/ShadedGeometry.d.ts +13 -0
- package/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.d.ts +6 -0
- package/engine/graphics/geometry/AttributeSpec.js +105 -0
- package/engine/graphics/{micron/format/MicronVertexDataSpec.js → geometry/VertexDataSpec.js} +56 -25
- package/engine/graphics/micron/build/buildMicronGeometryFromBufferGeometry.js +7 -7
- package/engine/graphics/micron/build/fill_patch_geometry_data.js +1 -1
- package/engine/graphics/micron/buildPatchwork.js +1 -1
- package/engine/graphics/micron/format/MicronGeometry.js +3 -3
- package/engine/graphics/micron/format/serialization/MicronGeometryBinarySerializationAdapter.js +2 -2
- package/engine/graphics/micron/format/serialization/deserialize_attribute_spec.js +1 -1
- package/engine/graphics/micron/format/serialization/serialize_attribute_spec.js +1 -1
- package/engine/graphics/micron/render/PatchCacheKey.js +1 -1
- package/engine/graphics/micron/render/instanced/AttributeDataTexture.js +5 -5
- package/engine/graphics/micron/render/v1/ThreeVirtualGeometryAdapter.js +1 -1
- package/engine/graphics/particles/particular/engine/emitter/PARTICULAR_PARTICLE_SPECIFICATION.js +80 -16
- package/engine/graphics/particles/particular/engine/emitter/ParticleEmitter.js +57 -52
- package/engine/graphics/particles/particular/engine/emitter/ParticleLayer.js +2 -1
- package/engine/graphics/particles/particular/engine/emitter/ParticlePool.js +51 -12
- package/engine/graphics/particles/particular/engine/emitter/ParticlePool.spec.js +3 -2
- package/engine/graphics/particles/particular/engine/emitter/computeEmissionFunction.js +1 -1
- package/engine/graphics/particles/particular/engine/emitter/serde/ParameterLookupTableSerializationAdapter.js +8 -2
- package/engine/graphics/particles/particular/engine/parameter/ParameterLookupTable.js +2 -1
- package/engine/graphics/particles/particular/engine/parameter/ParameterTrack.js +1 -1
- package/engine/graphics/particles/particular/engine/parameter/ParticleParameter.js +1 -1
- package/engine/graphics/particles/particular/engine/renderers/billboard/BILLBOARD_PARTICLE_SPECIFICATION.js +21 -0
- package/engine/graphics/particles/particular/engine/renderers/billboard/ParticleBillboardMaterial.js +0 -20
- package/engine/graphics/particles/particular/engine/renderers/billboard/prototypeBillboardRenderer.js +9 -9
- package/engine/graphics/particles/particular/engine/simulator/SimulationStepApplyForce.js +2 -5
- package/engine/graphics/particles/particular/engine/simulator/SimulationStepCurlNoiseAcceleration.js +2 -6
- package/engine/graphics/particles/particular/engine/simulator/SimulationStepCurlNoiseVelocity.js +2 -7
- package/engine/graphics/particles/particular/engine/simulator/SimulationStepFixedPhysics.js +2 -5
- package/engine/graphics/particles/particular/engine/simulator/update_parameters.js +1 -1
- package/engine/graphics/particles/particular/engine/utils/distributeParticlesOnObject3D.js +1 -1
- package/engine/graphics/particles/particular/engine/utils/distrubuteParticlesOnMesh.js +1 -1
- package/engine/graphics/particles/particular/engine/utils/volume/ParticleVolume.js +384 -0
- package/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +558 -0
- package/engine/graphics/particles/particular/group/Operation.js +18 -0
- package/engine/graphics/particles/particular/group/OperationType.js +9 -0
- package/engine/graphics/particles/particular/group/ParticleAttribute.js +2 -1
- package/engine/graphics/particles/particular/group/ParticleAttributeType.js +11 -0
- package/engine/graphics/particles/particular/group/ParticleDataType.js +10 -0
- package/engine/graphics/particles/particular/group/ParticleGroup.js +7 -245
- package/engine/graphics/particles/particular/group/ParticleGroup.spec.js +3 -1
- package/engine/graphics/particles/particular/group/ParticleSpecification.js +21 -14
- package/engine/graphics/particles/particular/group/itemSizeFromAttributeType.js +20 -0
- package/engine/graphics/particles/particular/group/optimizeCommandQueue.js +162 -0
- package/engine/graphics/particles/particular/group/typedArrayConstructorFromDataType.js +19 -0
- package/engine/graphics/render/buffer/simple-fx/ao/AmbientOcclusionPostProcessEffect.js +1 -1
- package/engine/graphics/render/buffer/slot/parameter/ProgramValueSlotParameter.js +2 -1
- package/engine/graphics/render/buffer/slot/parameter/ProgramValueSlotParameterSet.js +1 -1
- package/engine/graphics/render/forward_plus/LightManager.js +117 -94
- package/engine/graphics/render/forward_plus/PointLight.js +9 -0
- package/engine/graphics/render/forward_plus/PointLightData.js +1 -1
- package/engine/graphics/render/forward_plus/SpotLight.js +9 -0
- package/engine/graphics/render/forward_plus/cluster/compute_light_data_hash_0.js +2 -2
- package/engine/graphics/render/forward_plus/plugin/ForwardPlusRenderingPlugin.js +1 -1
- package/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +5 -5
- package/engine/graphics/render/forward_plus/prototypeLightManager.js +180 -86
- package/engine/graphics/render/forward_plus/query/analytical_triplanar_corner_mapping.js +8 -0
- package/engine/graphics/render/forward_plus/query/cube_mapping.js +38 -0
- package/engine/graphics/render/forward_plus/query/detailed_sphere_frustum_intersection_test.js +86 -0
- package/engine/graphics/render/forward_plus/query/point_light_inside_volume.js +73 -0
- package/engine/graphics/render/forward_plus/query/query_bvh_frustum_from_objects.js +131 -0
- package/engine/graphics/render/forward_plus/query/query_bvh_frustum_from_texture.js +129 -0
- package/engine/graphics/render/forward_plus/query/spot_light_inside_volume.js +33 -0
- package/engine/graphics/render/forward_plus/read_frustum_corner.js +14 -0
- package/engine/graphics/render/forward_plus/testClusterEquality.js +22 -0
- package/engine/graphics/render/visibility/IncrementalDeltaSet.js +11 -0
- package/engine/graphics/render/visibility/hiz/prototypeHiZ.js +1 -1
- package/engine/graphics/texture/sampler/HarmonicDiffusionGrid.spec.js +1 -1
- package/engine/graphics/texture/sampler/SampleTraverser.js +1 -1
- package/engine/graphics/texture/sampler/distanceField.spec.js +1 -1
- package/engine/grid/components/GridObstacle.js +1 -1
- package/engine/intelligence/behavior/selector/WeightedElement.js +2 -1
- package/engine/intelligence/optimization/RandomOptimizer.js +1 -1
- package/engine/navigation/ecs/components/Path.js +1 -1
- package/engine/navigation/grid/FastBinaryHeap.spec.js +1 -1
- package/engine/sound/ecs/emitter/SoundEmitter.js +2 -1
- package/engine/sound/ecs/emitter/SoundTrack.js +2 -1
- package/engine/sound/material/concrete/RandomSoundMaterial.js +1 -1
- package/engine/ui/notification/notificationGenerator.js +1 -1
- package/generation/filtering/numeric/complex/CellFilterGaussianBlur.js +1 -1
- package/generation/grid/generation/GridTaskExecuteRuleTimes.js +2 -1
- package/generation/markers/actions/MarkerNodeActionSelectRandom.js +1 -1
- package/generation/markers/transform/MarkerNodeTransformerRecordUniqueRandomEnum.js +1 -1
- package/generation/placement/action/random/CellActionSelectRandom.js +1 -1
- package/generation/theme/ThemeEngine.js +1 -1
- package/misc/makeMaterialIconCached.js +2 -2
- package/package.json +1 -1
- package/view/elements/image/HTMLElementCacheKey.js +2 -1
- package/view/elements/radial/RadialText.js +2 -1
- package/view/minimap/gl/MinimapMarkersGL.js +6 -100
- package/view/minimap/gl/buildMaterial.js +94 -0
- package/engine/graphics/micron/format/MicronGeometryBufferAttributeSpec.js +0 -71
- package/engine/graphics/render/forward_plus/queryBVH_Frustum.js +0 -357
|
@@ -3,7 +3,7 @@ import { PointLightData } from "./PointLightData.js";
|
|
|
3
3
|
import { DataTexture, DataTexture3D, Frustum, NearestFilter, RGBIntegerFormat, UnsignedShortType } from "three";
|
|
4
4
|
import { frustumFromCamera } from "../../ecs/camera/CameraSystem.js";
|
|
5
5
|
import Vector3 from "../../../../core/geom/Vector3.js";
|
|
6
|
-
import {
|
|
6
|
+
import { query_bvh_frustum_from_objects } from "./query/query_bvh_frustum_from_objects.js";
|
|
7
7
|
import { IncrementalDeltaSet } from "../visibility/IncrementalDeltaSet.js";
|
|
8
8
|
import { computeFrustumCorners } from "./computeFrustumCorners.js";
|
|
9
9
|
import { arraySwapElements } from "../../../../core/collection/ArrayUtils.js";
|
|
@@ -18,69 +18,25 @@ import { NumericType } from "./data/NumericType.js";
|
|
|
18
18
|
import { computeDataType } from "./data/computeDataType.js";
|
|
19
19
|
import { computeThreeTextureTypeFromDataType } from "./data/computeThreeTextureTypeFromDataType.js";
|
|
20
20
|
import { computeThreeTextureInternalFormatFromDataType } from "./data/computeThreeTextureInternalFormatFromDataType.js";
|
|
21
|
+
import { testClusterEquality } from "./testClusterEquality.js";
|
|
22
|
+
import { read_frustum_corner } from "./read_frustum_corner.js";
|
|
23
|
+
import { BinaryUint32BVH } from "../../../../core/bvh2/binary/2/BinaryUint32BVH.js";
|
|
24
|
+
import { query_bvh_frustum_from_texture } from "./query/query_bvh_frustum_from_texture.js";
|
|
25
|
+
import { mat4 } from "gl-matrix";
|
|
26
|
+
import { mortonEncode_magicbits } from "../../../../core/geom/3d/morton/mortonEncode_magicbits.js";
|
|
21
27
|
|
|
22
28
|
const LOOKUP_CACHE_SIZE = 16384; // must be power of two
|
|
23
|
-
/**
|
|
24
|
-
* Cache used to identify duplicate cells. Helps reduce memory usage and just point to equivalent existing cells instead of allocating new ones.
|
|
25
|
-
* @type {Uint16Array|Uint32Array}
|
|
26
|
-
*/
|
|
27
|
-
const LOOKUP_CACHE = new Uint32Array(LOOKUP_CACHE_SIZE);
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
*
|
|
31
|
-
* @param {PointLightData[]} lights
|
|
32
|
-
* @param {number} count
|
|
33
|
-
* @param {number[]|Uint32Array|Uint16Array|Uint8Array|Uint8ClampedArray} light_lookup_texture_data
|
|
34
|
-
* @param {number} address
|
|
35
|
-
* @returns {boolean}
|
|
36
|
-
*/
|
|
37
|
-
function testClusterEquality(lights, count, light_lookup_texture_data, address) {
|
|
38
|
-
for (let i = 0; i < count; i++) {
|
|
39
|
-
|
|
40
|
-
const actual_visible_index = light_lookup_texture_data[address + i];
|
|
41
|
-
|
|
42
|
-
const datum = scratch_light_nodes[i];
|
|
43
|
-
|
|
44
|
-
const expected_visible_index = datum.visible_index;
|
|
45
|
-
|
|
46
|
-
if (expected_visible_index !== actual_visible_index) {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return true;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
*
|
|
56
|
-
* @param {PointLightData} datum
|
|
57
|
-
* @returns {number}
|
|
58
|
-
*/
|
|
59
|
-
function get_light_visible_index(datum) {
|
|
60
|
-
return datum.visible_index;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
*
|
|
65
|
-
* @param {number[]|Float32Array|Float64Array} source
|
|
66
|
-
* @param {number} source_index
|
|
67
|
-
* @param {number[]|Float32Array|Float64Array} destination
|
|
68
|
-
* @param {number} destination_offset
|
|
69
|
-
*/
|
|
70
|
-
function read_frustum_corner(source, source_index, destination, destination_offset) {
|
|
71
|
-
const address = source_index * 3;
|
|
72
|
-
|
|
73
|
-
destination[destination_offset] = source[address];
|
|
74
|
-
destination[destination_offset + 1] = source[address + 1];
|
|
75
|
-
destination[destination_offset + 2] = source[address + 2];
|
|
76
|
-
}
|
|
77
29
|
|
|
78
30
|
/**
|
|
79
31
|
* Using continuous buffer for related attributes to get better cache utilization
|
|
80
32
|
* @type {ArrayBuffer}
|
|
81
33
|
* @private
|
|
82
34
|
*/
|
|
83
|
-
const _scratch_array_buffer = new ArrayBuffer(
|
|
35
|
+
const _scratch_array_buffer = new ArrayBuffer(
|
|
36
|
+
24 * 4
|
|
37
|
+
+ 24 * 4
|
|
38
|
+
+ LOOKUP_CACHE_SIZE * 4
|
|
39
|
+
);
|
|
84
40
|
|
|
85
41
|
/**
|
|
86
42
|
*
|
|
@@ -88,11 +44,6 @@ const _scratch_array_buffer = new ArrayBuffer((24 + 24) * 4);
|
|
|
88
44
|
*/
|
|
89
45
|
const scratch_corners = new Float32Array(_scratch_array_buffer, 0, 24);
|
|
90
46
|
|
|
91
|
-
/**
|
|
92
|
-
*
|
|
93
|
-
* @type {PointLightData[]}
|
|
94
|
-
*/
|
|
95
|
-
const scratch_light_nodes = [];
|
|
96
47
|
|
|
97
48
|
/**
|
|
98
49
|
* Linear access data structure with parameters of each plane of the frustum
|
|
@@ -102,6 +53,18 @@ const scratch_light_nodes = [];
|
|
|
102
53
|
*/
|
|
103
54
|
const scratch_frustum_planes = new Float32Array(_scratch_array_buffer, 24 * 4, 24);
|
|
104
55
|
|
|
56
|
+
/**
|
|
57
|
+
* Cache used to identify duplicate cells. Helps reduce memory usage and just point to equivalent existing cells instead of allocating new ones.
|
|
58
|
+
* @type {Uint16Array|Uint32Array}
|
|
59
|
+
*/
|
|
60
|
+
const LOOKUP_CACHE = new Uint32Array(_scratch_array_buffer, (24 + 24) * 4, LOOKUP_CACHE_SIZE);
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
*
|
|
64
|
+
* @type {number[]}
|
|
65
|
+
*/
|
|
66
|
+
const scratch_light_nodes = [];
|
|
67
|
+
|
|
105
68
|
export class LightManager {
|
|
106
69
|
|
|
107
70
|
constructor() {
|
|
@@ -170,10 +133,10 @@ export class LightManager {
|
|
|
170
133
|
|
|
171
134
|
/**
|
|
172
135
|
*
|
|
173
|
-
* @type {
|
|
136
|
+
* @type {BinaryUint32BVH}
|
|
174
137
|
* @private
|
|
175
138
|
*/
|
|
176
|
-
this.__visible_bvh = new
|
|
139
|
+
this.__visible_bvh = new BinaryUint32BVH();
|
|
177
140
|
|
|
178
141
|
/**
|
|
179
142
|
*
|
|
@@ -189,6 +152,13 @@ export class LightManager {
|
|
|
189
152
|
*/
|
|
190
153
|
this.__view_frustum_points = new Float32Array(24);
|
|
191
154
|
|
|
155
|
+
/**
|
|
156
|
+
*
|
|
157
|
+
* @type {Float32Array|mat4|number[]}
|
|
158
|
+
* @private
|
|
159
|
+
*/
|
|
160
|
+
this.__projection_matrix = new Float32Array(16);
|
|
161
|
+
|
|
192
162
|
|
|
193
163
|
/**
|
|
194
164
|
* Accelerated data structure with pre-computed plane normals for clusters in each dimensions. Order: X, Y, Z
|
|
@@ -313,6 +283,14 @@ export class LightManager {
|
|
|
313
283
|
return this.__tiles_resolution;
|
|
314
284
|
}
|
|
315
285
|
|
|
286
|
+
/**
|
|
287
|
+
*
|
|
288
|
+
* @private
|
|
289
|
+
*/
|
|
290
|
+
__request_update_visible_bvh() {
|
|
291
|
+
this.__visible_bvh_needs_update = true;
|
|
292
|
+
}
|
|
293
|
+
|
|
316
294
|
/**
|
|
317
295
|
*
|
|
318
296
|
* @param {PointLightData} data
|
|
@@ -320,6 +298,8 @@ export class LightManager {
|
|
|
320
298
|
*/
|
|
321
299
|
__handle_visible_added(data) {
|
|
322
300
|
this.__visible_bvh_needs_update = true;
|
|
301
|
+
|
|
302
|
+
data.light.onDimensionChanged(this.__request_update_visible_bvh, this);
|
|
323
303
|
}
|
|
324
304
|
|
|
325
305
|
/**
|
|
@@ -331,40 +311,70 @@ export class LightManager {
|
|
|
331
311
|
this.__visible_bvh_needs_update = true;
|
|
332
312
|
|
|
333
313
|
data.bvh_leaf_visible.disconnect();
|
|
314
|
+
|
|
315
|
+
data.light.offDimensionChanged(this.__request_update_visible_bvh, this);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
*
|
|
320
|
+
* @param {PointLightData} light
|
|
321
|
+
* @returns {number}
|
|
322
|
+
* @private
|
|
323
|
+
*/
|
|
324
|
+
__sort_visible_light_score(light) {
|
|
325
|
+
const p = light.light.position;
|
|
326
|
+
|
|
327
|
+
// return v3_morton_encode_transformed(p.x, p.y, p.z, this.__projection_matrix);
|
|
328
|
+
return mortonEncode_magicbits(p.x, p.y, p.z);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Sort lights for better data locality
|
|
333
|
+
* @private
|
|
334
|
+
*/
|
|
335
|
+
__sort_visible_light() {
|
|
336
|
+
this.__visible_lights.sort(this.__sort_visible_light_score, this);
|
|
334
337
|
}
|
|
335
338
|
|
|
336
339
|
__update_visible_bvh() {
|
|
337
340
|
this.__visible_bvh_needs_update = false;
|
|
338
341
|
|
|
339
|
-
this.__visible_bvh.reset();
|
|
340
|
-
|
|
341
342
|
const lights = this.__visible_lights.elements;
|
|
342
343
|
const light_count = lights.length;
|
|
343
344
|
|
|
344
|
-
|
|
345
|
+
// sort light for better search and query locality
|
|
346
|
+
this.__sort_visible_light();
|
|
347
|
+
|
|
348
|
+
const vbvh = this.__visible_bvh;
|
|
349
|
+
|
|
350
|
+
vbvh.setLeafCount(light_count);
|
|
351
|
+
vbvh.initialize_structure();
|
|
352
|
+
|
|
353
|
+
for (let i = 0; i < light_count; i++) {
|
|
354
|
+
|
|
345
355
|
/**
|
|
346
356
|
*
|
|
347
357
|
* @type {PointLightData}
|
|
348
358
|
*/
|
|
349
359
|
const datum = lights[i];
|
|
350
360
|
|
|
351
|
-
|
|
361
|
+
const bb = datum.bvh_leaf_main;
|
|
352
362
|
|
|
353
|
-
|
|
363
|
+
vbvh.setLeafData(
|
|
364
|
+
i, i,
|
|
365
|
+
bb.x0, bb.y0, bb.z0,
|
|
366
|
+
bb.x1, bb.y1, bb.z1
|
|
367
|
+
);
|
|
354
368
|
}
|
|
355
369
|
|
|
356
|
-
this.
|
|
370
|
+
// vbvh.sort_morton(this.__projection_matrix);
|
|
371
|
+
// vbvh.sort_bubble_sah();
|
|
357
372
|
|
|
358
|
-
|
|
373
|
+
vbvh.build();
|
|
359
374
|
|
|
360
|
-
/**
|
|
361
|
-
*
|
|
362
|
-
* @returns {BinaryNode<PointLightData>}
|
|
363
|
-
*/
|
|
364
|
-
getBVH() {
|
|
365
|
-
return this.__light_points_bvh;
|
|
366
375
|
}
|
|
367
376
|
|
|
377
|
+
|
|
368
378
|
/**
|
|
369
379
|
*
|
|
370
380
|
* @param {Camera} camera
|
|
@@ -388,13 +398,11 @@ export class LightManager {
|
|
|
388
398
|
|
|
389
399
|
visible_lights.initializeUpdate();
|
|
390
400
|
|
|
391
|
-
let index_counter = 0;
|
|
392
|
-
|
|
393
401
|
const nodes = [];
|
|
394
402
|
|
|
395
403
|
read_frustum_planes_to_array(this.__view_frustum.planes, scratch_frustum_planes)
|
|
396
404
|
|
|
397
|
-
const match_count =
|
|
405
|
+
const match_count = query_bvh_frustum_from_objects(nodes, 0, this.__light_points_bvh, scratch_frustum_planes, this.__view_frustum_points);
|
|
398
406
|
|
|
399
407
|
for (let i = 0; i < match_count; i++) {
|
|
400
408
|
|
|
@@ -404,10 +412,6 @@ export class LightManager {
|
|
|
404
412
|
*/
|
|
405
413
|
const light_data = nodes[i];
|
|
406
414
|
|
|
407
|
-
const index = index_counter++;
|
|
408
|
-
|
|
409
|
-
light_data.visible_index = index;
|
|
410
|
-
|
|
411
415
|
visible_lights.push(light_data);
|
|
412
416
|
}
|
|
413
417
|
|
|
@@ -433,7 +437,7 @@ export class LightManager {
|
|
|
433
437
|
|
|
434
438
|
this.__light_data.update();
|
|
435
439
|
|
|
436
|
-
// update lookup precision
|
|
440
|
+
// update required lookup precision
|
|
437
441
|
this.__lookup_data.precision = Math.max(0, Math.ceil(Math.log2(this.__light_data.size)));
|
|
438
442
|
|
|
439
443
|
const tx_light = this.__light_data.getTexture();
|
|
@@ -448,7 +452,7 @@ export class LightManager {
|
|
|
448
452
|
const datum = visible_lights[i];
|
|
449
453
|
|
|
450
454
|
|
|
451
|
-
const address =
|
|
455
|
+
const address = i * 8;
|
|
452
456
|
|
|
453
457
|
assert.lessThan(address, tx_light_data.length, "overflow")
|
|
454
458
|
|
|
@@ -490,6 +494,12 @@ export class LightManager {
|
|
|
490
494
|
const cluster_planes_y_offset = tr_x_1 * 4;
|
|
491
495
|
const cluster_planes_z_offset = cluster_planes_y_offset + tr_y_1 * 4;
|
|
492
496
|
|
|
497
|
+
/**
|
|
498
|
+
*
|
|
499
|
+
* @type {number[]|Uint8ClampedArray}
|
|
500
|
+
*/
|
|
501
|
+
const light_source_data = this.__light_data.getTexture().image.data;
|
|
502
|
+
|
|
493
503
|
const tile_slice_size = tr_x * tr_y;
|
|
494
504
|
|
|
495
505
|
const light_cluster_texture = this.__cluster_texture;
|
|
@@ -507,6 +517,7 @@ export class LightManager {
|
|
|
507
517
|
|
|
508
518
|
let lookup_address_offset = 0;
|
|
509
519
|
let i_x_0, i_y_0, i_z_0;
|
|
520
|
+
let i;
|
|
510
521
|
|
|
511
522
|
// clear cache
|
|
512
523
|
LOOKUP_CACHE.fill(0xFFFFFFFF);
|
|
@@ -567,10 +578,11 @@ export class LightManager {
|
|
|
567
578
|
|
|
568
579
|
|
|
569
580
|
// at this point we have a fully constructed cluster, we can query lights within the cluster
|
|
570
|
-
const match_count =
|
|
581
|
+
const match_count = query_bvh_frustum_from_texture(
|
|
571
582
|
scratch_light_nodes,
|
|
572
583
|
0,
|
|
573
584
|
bvh,
|
|
585
|
+
light_source_data,
|
|
574
586
|
scratch_frustum_planes,
|
|
575
587
|
scratch_corners
|
|
576
588
|
);
|
|
@@ -626,15 +638,15 @@ export class LightManager {
|
|
|
626
638
|
// write address of the lookup table
|
|
627
639
|
tile_texture_data[tile_address] = lookup_address_offset;
|
|
628
640
|
|
|
629
|
-
for (
|
|
641
|
+
for (i = 0; i < match_count; i++) {
|
|
630
642
|
/**
|
|
631
643
|
*
|
|
632
|
-
* @type {
|
|
644
|
+
* @type {number[]}
|
|
633
645
|
*/
|
|
634
|
-
const
|
|
646
|
+
const light_index = scratch_light_nodes[i];
|
|
635
647
|
|
|
636
648
|
// construct lookup table
|
|
637
|
-
light_lookup_texture_data[lookup_address_offset] =
|
|
649
|
+
light_lookup_texture_data[lookup_address_offset] = light_index * 2;
|
|
638
650
|
|
|
639
651
|
lookup_address_offset++;
|
|
640
652
|
}
|
|
@@ -732,6 +744,7 @@ export class LightManager {
|
|
|
732
744
|
const y_plane_count = tr_y + 1;
|
|
733
745
|
const z_plane_count = tr_z + 1;
|
|
734
746
|
|
|
747
|
+
// TODO compute slices to minimize world-space volume difference between clusters
|
|
735
748
|
const z_slice_stride = x_plane_count * y_plane_count;
|
|
736
749
|
|
|
737
750
|
const points_data = this.__cluster_frustum_points;
|
|
@@ -782,16 +795,20 @@ export class LightManager {
|
|
|
782
795
|
|
|
783
796
|
/**
|
|
784
797
|
* Build light tile texture
|
|
785
|
-
* @param {Camera} camera
|
|
798
|
+
* @param {Camera|THREE.PerspectiveCamera} camera
|
|
786
799
|
*/
|
|
787
800
|
buildTiles(camera) {
|
|
788
801
|
camera.updateProjectionMatrix();
|
|
802
|
+
camera.updateMatrix();
|
|
789
803
|
camera.updateMatrixWorld(true);
|
|
790
804
|
|
|
791
805
|
//update world inverse matrix
|
|
792
806
|
camera.matrixWorldInverse.copy(camera.matrixWorld);
|
|
793
807
|
camera.matrixWorldInverse.invert();
|
|
794
808
|
|
|
809
|
+
// this.__projection_matrix.set(camera.matrixWorldInverse.elements);
|
|
810
|
+
mat4.multiply(this.__projection_matrix, camera.projectionMatrix.elements, camera.matrixWorldInverse.elements);
|
|
811
|
+
|
|
795
812
|
// console.time('__build_view_frustum');
|
|
796
813
|
this.__build_view_frustum(camera);
|
|
797
814
|
// console.timeEnd('__build_view_frustum');
|
|
@@ -836,12 +853,18 @@ export class LightManager {
|
|
|
836
853
|
this.__cluster_texture_needs_rebuild = true;
|
|
837
854
|
this.__update_cluster_texture();
|
|
838
855
|
|
|
856
|
+
const cluster_planes_size = ((x + 1) + (y + 1) + (z + 1)) * 4;
|
|
857
|
+
const cluster_frustum_points_size = (x + 1) * (y + 1) * (z + 1) * 3;
|
|
858
|
+
|
|
859
|
+
const buffer = new ArrayBuffer((cluster_planes_size + cluster_frustum_points_size) * 4);
|
|
860
|
+
|
|
839
861
|
this.__cluster_planes = new Float32Array(
|
|
840
|
-
|
|
862
|
+
buffer, 0,
|
|
863
|
+
cluster_planes_size
|
|
841
864
|
);
|
|
842
|
-
|
|
843
865
|
this.__cluster_frustum_points = new Float32Array(
|
|
844
|
-
|
|
866
|
+
buffer, cluster_planes_size * 4,
|
|
867
|
+
cluster_frustum_points_size
|
|
845
868
|
);
|
|
846
869
|
}
|
|
847
870
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import Vector3 from "../../../../core/geom/Vector3.js";
|
|
2
2
|
import { Color } from "../../../../core/color/Color.js";
|
|
3
3
|
import Vector1 from "../../../../core/geom/Vector1.js";
|
|
4
|
+
import { mortonEncode_magicbits } from "../../../../core/geom/3d/morton/mortonEncode_magicbits.js";
|
|
4
5
|
|
|
5
6
|
export class PointLight {
|
|
6
7
|
constructor() {
|
|
@@ -21,6 +22,14 @@ export class PointLight {
|
|
|
21
22
|
this.intensity = new Vector1(1);
|
|
22
23
|
}
|
|
23
24
|
|
|
25
|
+
/**
|
|
26
|
+
*
|
|
27
|
+
* @returns {number}
|
|
28
|
+
*/
|
|
29
|
+
computeMortonCode() {
|
|
30
|
+
return mortonEncode_magicbits(this.position.x, this.position.y, this.position.z);
|
|
31
|
+
}
|
|
32
|
+
|
|
24
33
|
/**
|
|
25
34
|
*
|
|
26
35
|
* @param {AABB3} result
|
|
@@ -2,6 +2,7 @@ import Vector3 from "../../../../core/geom/Vector3.js";
|
|
|
2
2
|
import Vector1 from "../../../../core/geom/Vector1.js";
|
|
3
3
|
import { Color } from "../../../../core/color/Color.js";
|
|
4
4
|
import { computeConeBoundingBox } from "../../../../core/geom/3d/cone/computeConeBoundingBox.js";
|
|
5
|
+
import { mortonEncode_magicbits } from "../../../../core/geom/3d/morton/mortonEncode_magicbits.js";
|
|
5
6
|
|
|
6
7
|
export class SpotLight {
|
|
7
8
|
constructor() {
|
|
@@ -48,6 +49,14 @@ export class SpotLight {
|
|
|
48
49
|
this.penumbra = new Vector1(0.4);
|
|
49
50
|
}
|
|
50
51
|
|
|
52
|
+
/**
|
|
53
|
+
*
|
|
54
|
+
* @returns {number}
|
|
55
|
+
*/
|
|
56
|
+
computeMortonCode() {
|
|
57
|
+
return mortonEncode_magicbits(this.position.x, this.position.y, this.position.z);
|
|
58
|
+
}
|
|
59
|
+
|
|
51
60
|
/**
|
|
52
61
|
*
|
|
53
62
|
* @param {AABB3} result
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Hash function using prime shift
|
|
3
|
-
* @param {
|
|
3
|
+
* @param {number[]} nodes
|
|
4
4
|
* @param {number} count
|
|
5
5
|
*/
|
|
6
6
|
export function compute_light_data_hash_0(nodes, count) {
|
|
@@ -10,7 +10,7 @@ export function compute_light_data_hash_0(nodes, count) {
|
|
|
10
10
|
for (let i = 0; i < count; i++) {
|
|
11
11
|
const datum = nodes[i];
|
|
12
12
|
|
|
13
|
-
hash =
|
|
13
|
+
hash = hash * 31 + datum;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
return hash & 0x7fffffff;
|
|
@@ -59,7 +59,6 @@ import { BehaviorComponent } from "../../../../intelligence/behavior/ecs/Behavio
|
|
|
59
59
|
import { Light } from "../../../ecs/light/Light.js";
|
|
60
60
|
import { LightType } from "../../../ecs/light/LightType.js";
|
|
61
61
|
import { parseColor } from "../../../../../core/color/ColorUtils.js";
|
|
62
|
-
import { randomFloatBetween } from "../../../../../core/math/MathUtils.js";
|
|
63
62
|
import Renderable from "../../../../ecs/components/Renderable.js";
|
|
64
63
|
import { makeHelperSphereGeometry } from "../../../../../editor/process/symbolic/makeHelperSphereGeometry.js";
|
|
65
64
|
import GUIElement from "../../../../ecs/gui/GUIElement.js";
|
|
@@ -75,8 +74,8 @@ import { TextureAssetLoader } from "../../../../asset/loaders/texture/TextureAss
|
|
|
75
74
|
import { GameAssetType } from "../../../../asset/GameAssetType.js";
|
|
76
75
|
import { GLTFAssetLoader } from "../../../../asset/loaders/GLTFAssetLoader.js";
|
|
77
76
|
import { ImageRGBADataLoader } from "../../../../asset/loaders/image/ImageRGBADataLoader.js";
|
|
78
|
-
import { MicronRenderPlugin } from "../../../micron/plugin/MicronRenderPlugin.js";
|
|
79
77
|
import { buildCubeURLs } from "../../../texture/cubemap/buildCubeURLs.js";
|
|
78
|
+
import { randomFloatBetween } from "../../../../../core/math/random/randomFloatBetween.js";
|
|
80
79
|
|
|
81
80
|
const engineHarness = new EngineHarness();
|
|
82
81
|
|
|
@@ -152,7 +151,7 @@ function makeConfig(engine) {
|
|
|
152
151
|
|
|
153
152
|
// Plugins
|
|
154
153
|
config.addPlugin(ForwardPlusRenderingPlugin);
|
|
155
|
-
config.addPlugin(MicronRenderPlugin);
|
|
154
|
+
// config.addPlugin(MicronRenderPlugin);
|
|
156
155
|
|
|
157
156
|
// Knowledge
|
|
158
157
|
|
|
@@ -286,7 +285,7 @@ function setup_scene_0(engine, ecd) {
|
|
|
286
285
|
"y": 1,
|
|
287
286
|
"z": -0.3141130871587056
|
|
288
287
|
},
|
|
289
|
-
"pitch":
|
|
288
|
+
"pitch": 0.47999999999999965,
|
|
290
289
|
"yaw": 4.279999999999975,
|
|
291
290
|
"roll": 0,
|
|
292
291
|
"distance": 28,
|
|
@@ -586,7 +585,7 @@ function main(engine) {
|
|
|
586
585
|
// pitch: -0.5,
|
|
587
586
|
// yaw: 2.2,
|
|
588
587
|
// distance: 3
|
|
589
|
-
pitch: 0.9,
|
|
588
|
+
pitch: -0.9,
|
|
590
589
|
yaw: 3.1,
|
|
591
590
|
distance: 20,
|
|
592
591
|
enableLights: false
|
|
@@ -609,6 +608,7 @@ function main(engine) {
|
|
|
609
608
|
lm.setTileMapResolution(24, 14, 14);
|
|
610
609
|
|
|
611
610
|
console.log(lm);
|
|
611
|
+
window.lm = lm;
|
|
612
612
|
|
|
613
613
|
const v = new View();
|
|
614
614
|
const clusterWidget = buildLightClusterWidget(lm, engine.graphics.camera);
|