@woosh/meep-engine 2.33.4 → 2.33.9
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/binary/BinaryBuffer.js +26 -2
- package/core/bvh2/LeafNode.js +6 -1
- package/core/bvh2/aabb3/AABB3.js +21 -1
- package/core/collection/RingBuffer.js +40 -10
- package/core/collection/array/copyArray.js +2 -2
- package/core/collection/array/typed/typed_array_copy.js +2 -2
- package/core/collection/set/compute_set_difference.js +32 -0
- package/core/collection/set/compute_set_intersection.js +22 -0
- package/core/collection/set/set_remove.js +15 -0
- package/core/collection/table/DataType2TypedArrayConstructorMapping.js +2 -0
- package/core/collection/table/DataTypeByteSizes.js +21 -0
- package/core/collection/table/RowFirstTable.js +1 -88
- package/core/collection/table/RowFirstTable.spec.js +3 -1
- package/core/collection/table/RowFirstTableSpec.js +9 -19
- package/core/collection/table/computeDataTypeByIndex.js +21 -0
- package/core/collection/table/deserializeRowFirstTable.js +48 -0
- package/core/collection/table/serializeRowFirstTable.js +27 -0
- package/core/color/Color.js +1 -0
- package/core/color/ColorUtils.js +12 -3
- package/core/geom/3d/aabb/aabb3_compute_projected_area.js +6 -4
- package/core/geom/3d/aabb/aabb3_estimate_projected_area2.js +59 -0
- package/core/geom/3d/aabb/aabb3_from_min_max.js +15 -0
- package/core/geom/3d/aabb/aabb3_matrix4_project.js +33 -0
- package/core/geom/3d/aabb/aabb3_matrix4_project.spec.js +41 -0
- package/core/geom/3d/aabb/aabb3_matrix4_project_by_corners.js +96 -0
- package/{engine/graphics/micron/render/v1 → core/geom/3d}/apply_mat4_transform_to_v3_array.js +0 -0
- package/{engine/graphics/micron/build/bounds → core/geom/3d}/compute_bounding_cone_of_2_cones.js +3 -3
- package/{engine/graphics/micron/build/bounds → core/geom/3d}/compute_bounding_cone_of_2_cones.spec.js +1 -1
- package/{engine/graphics/micron/build/bounds → core/geom/3d}/compute_bounding_sphere_of_2_spheres.js +3 -3
- package/{engine/graphics/micron/util → core/geom/3d}/encode_unit3_hemioct.js +0 -0
- package/core/geom/3d/frustum/array_normalize_plane.js +25 -0
- package/core/geom/3d/frustum/array_setFromProjectionMatrix.js +60 -0
- package/{engine/graphics/micron/util → core/geom/3d}/unit_hemioct.spec.js +1 -1
- package/{engine/graphics/micron/build → core}/graph/MultiNode.js +0 -0
- package/{engine/graphics/micron/build → core}/graph/SquareMatrix.js +2 -2
- package/{engine/graphics/micron/build → core}/graph/SquareMatrix.spec.js +1 -1
- package/{engine/graphics/micron/build → core}/graph/WeightedEdge.js +1 -1
- package/{engine/graphics/micron/build → core}/graph/build_face_graph_from_mesh.js +2 -2
- package/{engine/graphics/micron/build/clustering → core/graph}/cluster_mesh_metis.js +2 -6
- package/{engine/graphics/micron/build → core}/graph/coarsen_graph.js +1 -1
- package/{engine/graphics/micron/build → core}/graph/coarsen_graph.spec.js +1 -1
- package/{engine/graphics/micron/build → core}/graph/eigen/eigen.js +0 -0
- package/{engine/graphics/micron/build → core}/graph/eigen/eigen.spec.js +1 -1
- package/{engine/graphics/micron/build/hierarchy → core/graph/eigen}/eigen_values_find_spectral_gap.js +0 -0
- package/{engine/graphics/micron/build → core}/graph/graph_adjacency_matrix.js +0 -0
- package/{engine/graphics/micron/build → core}/graph/graph_compute_disconnected_clusters.js +0 -0
- package/{engine/graphics/micron/build → core}/graph/graph_degree_matrix.js +0 -0
- package/{engine/graphics/micron/build → core}/graph/graph_k_means_cluster.js +5 -5
- package/{engine/graphics/micron/build → core}/graph/graph_laplacian_matrix.js +1 -1
- package/{engine/graphics/micron/build → core}/graph/metis/metis.js +2 -2
- package/{engine/graphics/micron/build → core}/graph/metis/metis_options.js +0 -0
- package/{engine/graphics/micron/build → core}/graph/mn_graph_collapse_weighted_edge.js +0 -0
- package/core/process/undo/ActionProcessor.d.ts +2 -0
- package/core/process/undo/ActionProcessor.js +59 -1
- package/core/process/undo/ActionProcessor.spec.js +59 -0
- package/core/process/undo/Mark.js +2 -1
- package/engine/Engine.d.ts +2 -0
- package/engine/EngineHarness.js +4 -4
- package/engine/asset/loaders/material/bitmap2sampler_gl.js +19 -0
- package/engine/asset/loaders/material/computeImageBitmapEquality.js +7 -19
- package/engine/ecs/foliage/InstancedFoliage.js +3 -5
- package/engine/ecs/fow/serialization/FogOfWarSerializationAdapter.js +2 -1
- package/engine/ecs/transform/Transform.js +2 -1
- package/engine/graphics/GraphicsEngine.js +9 -116
- package/engine/graphics/ecs/mesh/updateNodeByTransformAndBBB.js +22 -37
- package/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +155 -0
- package/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +68 -0
- package/engine/graphics/ecs/mesh-v2/prototypeShadedGeometry.js +31 -0
- package/engine/graphics/filter/FlipArrayInPlace.js +25 -0
- package/engine/graphics/filter/FlipArrayViaCanvas.js +13 -0
- package/engine/graphics/filter/ImageFilter.js +20 -51
- package/engine/graphics/{micron → geometry}/aabb3_to_buffer_geometry.js +0 -0
- package/engine/graphics/{micron/build → geometry/buffered}/compute_buffer_geometry_byte_size.js +0 -0
- package/engine/graphics/geometry/instancing/InstancedMeshGroup.js +25 -16
- package/engine/graphics/material/SplatMaterial.js +4 -97
- package/engine/graphics/micron/build/buildMicronGeometryFromBufferGeometry.js +2 -6
- package/engine/graphics/micron/build/clustering/build_clustering_2.js +2 -2
- package/engine/graphics/micron/build/clustering/build_leaf_patches_metis.js +1 -1
- package/engine/graphics/micron/build/fill_patch_geometry_data.js +2 -0
- package/engine/graphics/micron/build/hierarchy/buildAbstractPatchHierarchy.js +3 -3
- package/engine/graphics/micron/build/hierarchy/build_intermediate_patch_topology.js +0 -72
- package/engine/graphics/micron/build/hierarchy/build_merge_graph.js +2 -2
- package/engine/graphics/micron/build/hierarchy/computePatchMergeScore.js +3 -3
- package/engine/graphics/micron/build/hierarchy/merge_patches.js +6 -3
- package/engine/graphics/micron/build/hierarchy/metis_cluster_clusters.js +1 -1
- package/engine/graphics/micron/build/hierarchy/optimize_graph_partitioning_balance.js +1 -1
- package/engine/graphics/micron/build/hierarchy/patch_combine.js +2 -2
- package/engine/graphics/micron/build/hierarchy/qvdr_build_simplified_clusters.js +2 -1
- package/engine/graphics/micron/format/MicronGeometry.js +12 -0
- package/engine/graphics/micron/format/MicronGeometryBufferAttributeSpec.js +2 -2
- package/engine/graphics/micron/format/MicronGeometryPatch.js +17 -9
- package/engine/graphics/micron/format/MicronVertexDataSpec.js +25 -3
- package/engine/graphics/micron/format/serialization/MicronGeometryBinarySerializationAdapter.js +101 -0
- package/engine/graphics/micron/format/serialization/deserialize_attribute_spec.js +25 -0
- package/engine/graphics/micron/format/serialization/deserialize_patch.js +104 -0
- package/engine/graphics/micron/format/serialization/serialize_attribute_spec.js +18 -0
- package/engine/graphics/micron/format/serialization/serialize_patch.js +84 -0
- package/engine/graphics/micron/prototypeVirtualGeometry.js +1 -1
- package/engine/graphics/micron/render/VirtualGeometryBuilder.js +27 -23
- package/engine/graphics/micron/render/culling/{PathCullingSystem.js → PatchCullingSystem.js} +1 -1
- package/engine/graphics/micron/render/instanced/AttributeDataTexture.js +3 -5
- package/engine/graphics/micron/render/refinement/ActivePatchList.js +38 -49
- package/engine/graphics/micron/render/refinement/ActivePatchRecord.js +4 -2
- package/engine/graphics/micron/render/refinement/RefinementSpec.js +98 -0
- package/engine/graphics/micron/render/v1/MaterialVertexSpec.js +21 -0
- package/engine/graphics/micron/render/v1/VGThreeRenderer.js +12 -9
- package/engine/graphics/micron/render/v1/getTransformedPositionsCached.js +1 -1
- package/engine/graphics/render/buffer/buffers/ColorAndDepthFrameBuffer.js +5 -3
- package/engine/graphics/render/buffer/buffers/prototypeNormalFrameBuffer.js +8 -10
- package/engine/graphics/render/forward_plus/LightManager.js +5 -7
- package/engine/graphics/render/forward_plus/data/NumericType.js +9 -0
- package/engine/graphics/render/forward_plus/{TextureBackedMemoryRegion.js → data/TextureBackedMemoryRegion.js} +11 -190
- package/engine/graphics/render/forward_plus/data/channelCountToThreIntegerTextureType.js +16 -0
- package/engine/graphics/render/forward_plus/data/computeDataType.js +36 -0
- package/engine/graphics/render/forward_plus/data/computeThreeTextureFormat.js +18 -0
- package/engine/graphics/render/forward_plus/data/computeThreeTextureInternalFormatFromDataType.js +63 -0
- package/engine/graphics/render/forward_plus/data/computeThreeTextureTypeFromDataType.js +41 -0
- package/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +1 -1
- package/engine/graphics/render/forward_plus/prototypeLightManager.js +1 -1
- package/engine/graphics/render/visibility/hiz/buffer/HierarchicalZBuffer.js +198 -0
- package/engine/graphics/render/visibility/hiz/buffer/ReductionShader.js +51 -0
- package/engine/graphics/render/visibility/hiz/buildCanvasViewFromTexture.js +179 -0
- package/engine/graphics/render/visibility/hiz/prototypeHiZ.js +440 -0
- package/engine/graphics/render/visibility/hiz/query/BatchOcclusionQuery.js +174 -0
- package/engine/graphics/render/visibility/hiz/query/QueryShader.js +173 -0
- package/engine/graphics/shadows/ShadowMapRenderer.js +12 -2
- package/engine/graphics/texture/cubemap/buildCubeURLs.js +13 -0
- package/engine/graphics/texture/cubemap/load_environment_map.d.ts +8 -0
- package/engine/graphics/texture/cubemap/load_environment_map.js +163 -0
- package/engine/graphics/texture/sampler/Sampler2D.js +18 -62
- package/engine/graphics/texture/sampler/TextureBinaryBufferSerializer.js +1 -1
- package/engine/graphics/texture/sampler/convertTexture2Sampler2D.js +3 -2
- package/engine/graphics/texture/sampler/debug/paintSamplerOnHTML.js +3 -2
- package/engine/graphics/texture/sampler/differenceSampler.js +31 -0
- package/engine/graphics/texture/sampler/typedArrayConstructorByInstance.js +25 -0
- package/engine/graphics/texture/sampler/util/drawSamplerHTML.js +3 -2
- package/engine/graphics/texture/virtual/v2/ShaderUsage.js +6 -5
- package/engine/graphics/texture/virtual/v2/prototype.js +16 -6
- package/engine/network/convertPathToURL.js +6 -0
- package/engine/plugin/EnginePluginManager.d.ts +9 -0
- package/engine/reference/v2/Reference.d.ts +7 -0
- package/package.json +1 -1
- package/view/minimap/gl/MinimapMarkersGL.js +2 -2
- package/engine/graphics/micron/build/clustering/cluster_mesh_vertices.js +0 -3
- package/engine/graphics/micron/render/RefinementSpec.js +0 -181
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { RedIntegerFormat, RGBAIntegerFormat, RGBIntegerFormat, RGIntegerFormat } from "three";
|
|
2
|
+
|
|
3
|
+
export function channelCountToThreIntegerTextureType(channel_count) {
|
|
4
|
+
switch (channel_count) {
|
|
5
|
+
case 1:
|
|
6
|
+
return RedIntegerFormat;
|
|
7
|
+
case 2:
|
|
8
|
+
return RGIntegerFormat;
|
|
9
|
+
case 3:
|
|
10
|
+
return RGBIntegerFormat;
|
|
11
|
+
case 4:
|
|
12
|
+
return RGBAIntegerFormat;
|
|
13
|
+
default:
|
|
14
|
+
throw new Error(`Unsupported channel count '${channel_count}'`);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { NumericType } from "./NumericType.js";
|
|
2
|
+
import { DataType } from "../../../../../core/collection/table/DataType.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @param {NumericType} type
|
|
7
|
+
* @param {number} precision
|
|
8
|
+
* @returns {DataType}
|
|
9
|
+
*/
|
|
10
|
+
export function computeDataType(type, precision) {
|
|
11
|
+
if (type === NumericType.Uint) {
|
|
12
|
+
if (precision <= 8) {
|
|
13
|
+
return DataType.Uint8;
|
|
14
|
+
} else if (precision <= 16) {
|
|
15
|
+
return DataType.Uint16;
|
|
16
|
+
} else if (precision <= 32) {
|
|
17
|
+
return DataType.Uint32;
|
|
18
|
+
}
|
|
19
|
+
} else if (type === NumericType.Int) {
|
|
20
|
+
if (precision <= 8) {
|
|
21
|
+
return DataType.Int8;
|
|
22
|
+
} else if (precision <= 16) {
|
|
23
|
+
return DataType.Int16;
|
|
24
|
+
} else if (precision <= 32) {
|
|
25
|
+
return DataType.Int32;
|
|
26
|
+
}
|
|
27
|
+
} else if (type === NumericType.Float) {
|
|
28
|
+
if (precision <= 32) {
|
|
29
|
+
return DataType.Float32;
|
|
30
|
+
} else if (precision <= 64) {
|
|
31
|
+
return DataType.Float64;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
throw new Error(`Unsupported numeric type(=${type}) and precision(=${precision}) combination`);
|
|
36
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { NumericType } from "./NumericType.js";
|
|
2
|
+
import { channelCountToThreIntegerTextureType } from "./channelCountToThreIntegerTextureType.js";
|
|
3
|
+
import { channelCountToThreeTextureFormat } from "../../../texture/channelCountToThreeTextureFormat.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @param {NumericType} type
|
|
8
|
+
* @param {number} channel_count
|
|
9
|
+
*/
|
|
10
|
+
export function computeThreeTextureFormat(type, channel_count) {
|
|
11
|
+
if (type === NumericType.Uint || type === NumericType.Int) {
|
|
12
|
+
return channelCountToThreIntegerTextureType(channel_count);
|
|
13
|
+
} else if (type === NumericType.Float) {
|
|
14
|
+
return channelCountToThreeTextureFormat(channel_count);
|
|
15
|
+
} else {
|
|
16
|
+
throw new Error(`Unsupported numeric type '${type}'`);
|
|
17
|
+
}
|
|
18
|
+
}
|
package/engine/graphics/render/forward_plus/data/computeThreeTextureInternalFormatFromDataType.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { DataType } from "../../../../../core/collection/table/DataType.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param {DataType} dt
|
|
6
|
+
* @param {number} channel_count
|
|
7
|
+
* @returns {string|THREE.PixelFormatGPU}
|
|
8
|
+
*/
|
|
9
|
+
export function computeThreeTextureInternalFormatFromDataType(dt, channel_count) {
|
|
10
|
+
let suffix = '';
|
|
11
|
+
switch (dt) {
|
|
12
|
+
case DataType.Uint8:
|
|
13
|
+
suffix = '8UI';
|
|
14
|
+
break;
|
|
15
|
+
case DataType.Uint16:
|
|
16
|
+
suffix = '16UI';
|
|
17
|
+
break;
|
|
18
|
+
case DataType.Uint32:
|
|
19
|
+
suffix = '32UI';
|
|
20
|
+
break;
|
|
21
|
+
case DataType.Int8:
|
|
22
|
+
suffix = '8I';
|
|
23
|
+
break;
|
|
24
|
+
case DataType.Int16:
|
|
25
|
+
suffix = '16I';
|
|
26
|
+
break;
|
|
27
|
+
case DataType.Int32:
|
|
28
|
+
suffix = '32I';
|
|
29
|
+
break;
|
|
30
|
+
case DataType.Float16:
|
|
31
|
+
suffix = '16F';
|
|
32
|
+
break;
|
|
33
|
+
case DataType.Float32:
|
|
34
|
+
suffix = '32F';
|
|
35
|
+
break;
|
|
36
|
+
case DataType.Float64:
|
|
37
|
+
suffix = '64F';
|
|
38
|
+
break;
|
|
39
|
+
default:
|
|
40
|
+
throw new Error(`Unsupported data type '${dt}'`);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
let prefix = '';
|
|
44
|
+
|
|
45
|
+
switch (channel_count) {
|
|
46
|
+
case 1:
|
|
47
|
+
prefix = 'R';
|
|
48
|
+
break;
|
|
49
|
+
case 2:
|
|
50
|
+
prefix = 'RG';
|
|
51
|
+
break;
|
|
52
|
+
case 3:
|
|
53
|
+
prefix = 'RGB';
|
|
54
|
+
break;
|
|
55
|
+
case 4:
|
|
56
|
+
prefix = 'RGBA';
|
|
57
|
+
break;
|
|
58
|
+
default:
|
|
59
|
+
throw new Error(`Unsupported channel count '${channel_count}'`);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return prefix + suffix;
|
|
63
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { DataType } from "../../../../../core/collection/table/DataType.js";
|
|
2
|
+
import {
|
|
3
|
+
ByteType,
|
|
4
|
+
FloatType,
|
|
5
|
+
HalfFloatType,
|
|
6
|
+
IntType,
|
|
7
|
+
ShortType,
|
|
8
|
+
UnsignedByteType,
|
|
9
|
+
UnsignedIntType,
|
|
10
|
+
UnsignedShortType
|
|
11
|
+
} from "three";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
* @param {DataType} dt
|
|
16
|
+
* @returns {number}
|
|
17
|
+
*/
|
|
18
|
+
export function computeThreeTextureTypeFromDataType(dt) {
|
|
19
|
+
switch (dt) {
|
|
20
|
+
case DataType.Uint8:
|
|
21
|
+
return UnsignedByteType;
|
|
22
|
+
case DataType.Uint16:
|
|
23
|
+
return UnsignedShortType;
|
|
24
|
+
case DataType.Uint32:
|
|
25
|
+
return UnsignedIntType;
|
|
26
|
+
case DataType.Int8:
|
|
27
|
+
return ByteType;
|
|
28
|
+
case DataType.Int16:
|
|
29
|
+
return ShortType;
|
|
30
|
+
case DataType.Int32:
|
|
31
|
+
return IntType;
|
|
32
|
+
case DataType.Float16:
|
|
33
|
+
return HalfFloatType;
|
|
34
|
+
case DataType.Float32:
|
|
35
|
+
return FloatType;
|
|
36
|
+
case DataType.Float64:
|
|
37
|
+
return FloatType;
|
|
38
|
+
default:
|
|
39
|
+
throw new Error(`Unsupported data type '${dt}'`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -45,7 +45,6 @@ import { SerializationMetadataSystem } from "../../../../ecs/systems/Serializati
|
|
|
45
45
|
import { InverseKinematicsSystem } from "../../../../ecs/animation/InverseKinematicsSystem.js";
|
|
46
46
|
import { PathDisplaySystem } from "../../../ecs/path/PathDisplaySystem.js";
|
|
47
47
|
import { Line, LineBasicMaterial, MeshStandardMaterial, TorusKnotBufferGeometry } from "three";
|
|
48
|
-
import { buildCubeURLs } from "../../../GraphicsEngine.js";
|
|
49
48
|
import RenderSystem from "../../../../ecs/systems/RenderSystem.js";
|
|
50
49
|
import { makeEngineOptionsModel } from "../../../../../../model/game/options/makeEngineOptionsModel.js";
|
|
51
50
|
import { enableEditor } from "../../../../../editor/enableEditor.js";
|
|
@@ -77,6 +76,7 @@ import { GameAssetType } from "../../../../asset/GameAssetType.js";
|
|
|
77
76
|
import { GLTFAssetLoader } from "../../../../asset/loaders/GLTFAssetLoader.js";
|
|
78
77
|
import { ImageRGBADataLoader } from "../../../../asset/loaders/image/ImageRGBADataLoader.js";
|
|
79
78
|
import { MicronRenderPlugin } from "../../../micron/plugin/MicronRenderPlugin.js";
|
|
79
|
+
import { buildCubeURLs } from "../../../texture/cubemap/buildCubeURLs.js";
|
|
80
80
|
|
|
81
81
|
const engineHarness = new EngineHarness();
|
|
82
82
|
|
|
@@ -233,7 +233,7 @@ function prepare_scene_0() {
|
|
|
233
233
|
|
|
234
234
|
controls.minDistance = 2;
|
|
235
235
|
|
|
236
|
-
for (let i = 0; i <
|
|
236
|
+
for (let i = 0; i < 500; i++) {
|
|
237
237
|
const radius = randomFloatBetween(random, 4, 4);
|
|
238
238
|
const intensity = randomFloatBetween(random, 2, 2);
|
|
239
239
|
addPointLight([
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { max2 } from "../../../../../../core/math/max2.js";
|
|
2
|
+
import { ceilPowerOfTwo } from "../../../../../../core/binary/operations/ceilPowerOfTwo.js";
|
|
3
|
+
import { ClampToEdgeWrapping, FloatType, NearestFilter, RedFormat, WebGLRenderTarget } from "three";
|
|
4
|
+
import { renderScreenSpace } from "../../../utils/renderScreenSpace.js";
|
|
5
|
+
import { makeReductionShader } from "./ReductionShader.js";
|
|
6
|
+
import Vector2 from "../../../../../../core/geom/Vector2.js";
|
|
7
|
+
|
|
8
|
+
export class HierarchicalZBuffer {
|
|
9
|
+
constructor() {
|
|
10
|
+
/**
|
|
11
|
+
*
|
|
12
|
+
* @type {THREE.Texture|null}
|
|
13
|
+
* @private
|
|
14
|
+
*/
|
|
15
|
+
this.__input_buffer = null;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
* @type {THREE.WebGLRenderer|null}
|
|
20
|
+
* @private
|
|
21
|
+
*/
|
|
22
|
+
this.__renderer = null;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
*
|
|
26
|
+
* @type {THREE.WebGLRenderTarget[]}
|
|
27
|
+
*/
|
|
28
|
+
this.mips = [];
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
*
|
|
32
|
+
* @type {ShaderMaterial}
|
|
33
|
+
* @private
|
|
34
|
+
*/
|
|
35
|
+
this.__material = makeReductionShader();
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
*
|
|
40
|
+
* @type {Vector2}
|
|
41
|
+
* @private
|
|
42
|
+
*/
|
|
43
|
+
this.__resolution = new Vector2(0, 0);
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
*
|
|
47
|
+
* @type {Vector2}
|
|
48
|
+
* @private
|
|
49
|
+
*/
|
|
50
|
+
this.__limits = new Vector2(1, 1);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
*
|
|
55
|
+
* @return {Vector2}
|
|
56
|
+
*/
|
|
57
|
+
get mip_limits() {
|
|
58
|
+
return this.__limits;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @param {THREE.WebGLRenderer} v
|
|
63
|
+
*/
|
|
64
|
+
set renderer(v) {
|
|
65
|
+
this.__renderer = v;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @param {THREE.Texture} v
|
|
70
|
+
*/
|
|
71
|
+
set input(v) {
|
|
72
|
+
this.__input_buffer = v;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
build_mip_chain() {
|
|
76
|
+
const size_max = ceilPowerOfTwo(max2(this.__resolution.x, this.__resolution.y));
|
|
77
|
+
const mip_depth = Math.log2(size_max);
|
|
78
|
+
|
|
79
|
+
const mips = this.mips;
|
|
80
|
+
const existing_mip_depth = mips.length;
|
|
81
|
+
|
|
82
|
+
if (existing_mip_depth > mip_depth) {
|
|
83
|
+
|
|
84
|
+
for (let i = mip_depth; i < existing_mip_depth; i++) {
|
|
85
|
+
mips[i].dispose();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
mips.splice(mip_depth, existing_mip_depth - mip_depth);
|
|
89
|
+
|
|
90
|
+
} else {
|
|
91
|
+
|
|
92
|
+
for (let i = existing_mip_depth; i < mip_depth; i++) {
|
|
93
|
+
|
|
94
|
+
mips[i] = new WebGLRenderTarget(1, 1, {
|
|
95
|
+
minFilter: NearestFilter,
|
|
96
|
+
magFilter: NearestFilter,
|
|
97
|
+
format: RedFormat,
|
|
98
|
+
type: FloatType,
|
|
99
|
+
internalFormat: 'R32F',
|
|
100
|
+
depthBuffer: false,
|
|
101
|
+
stencilBuffer: false,
|
|
102
|
+
wrapS: ClampToEdgeWrapping,
|
|
103
|
+
wrapT: ClampToEdgeWrapping,
|
|
104
|
+
generateMipmaps: false
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
*
|
|
114
|
+
* @param {number} x
|
|
115
|
+
* @param {number} y
|
|
116
|
+
*/
|
|
117
|
+
set_resolution(x, y) {
|
|
118
|
+
this.__resolution.set(x, y);
|
|
119
|
+
|
|
120
|
+
const mips = this.mips;
|
|
121
|
+
const mip_count = mips.length;
|
|
122
|
+
|
|
123
|
+
let _x = ceilPowerOfTwo(x);
|
|
124
|
+
let _y = ceilPowerOfTwo(y);
|
|
125
|
+
|
|
126
|
+
for (let i = 0; i < mip_count; i++) {
|
|
127
|
+
const mip = mips[i];
|
|
128
|
+
|
|
129
|
+
const _nx = max2(1, _x >> 1);
|
|
130
|
+
const _ny = max2(1, _y >> 1);
|
|
131
|
+
|
|
132
|
+
if (mip.width !== _nx || mip.height !== _ny) {
|
|
133
|
+
mip.setSize(_nx, _ny);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (_nx === 1 && _x !== _nx) {
|
|
137
|
+
this.__limits.x = i;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (_ny === 1 && _y !== _ny) {
|
|
141
|
+
this.__limits.y = i;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
_x = _nx;
|
|
145
|
+
_y = _ny;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
build_mips() {
|
|
150
|
+
const mips = this.mips;
|
|
151
|
+
|
|
152
|
+
let t0 = null;
|
|
153
|
+
let t1 = {
|
|
154
|
+
texture: this.__input_buffer
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
for (let i = 0; i < mips.length; i++) {
|
|
158
|
+
t0 = t1;
|
|
159
|
+
t1 = mips[i];
|
|
160
|
+
|
|
161
|
+
this.reduce_mip(t0.texture, t1);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
this.__input_buffer.generateMipmaps = false;
|
|
165
|
+
this.__input_buffer.mips = mips.map(m => m.texture);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* @private
|
|
170
|
+
* @param {THREE.Texture} input
|
|
171
|
+
* @param {THREE.WebGLRenderTarget} output
|
|
172
|
+
*/
|
|
173
|
+
reduce_mip(input, output) {
|
|
174
|
+
|
|
175
|
+
const material = this.__material;
|
|
176
|
+
material.uniforms.source_texture.value = input;
|
|
177
|
+
material.uniforms.destination_resolution.value.set(output.width, output.height);
|
|
178
|
+
material.uniforms.source_resolution.value.set(input.image.width, input.image.height);
|
|
179
|
+
|
|
180
|
+
const renderer = this.__renderer;
|
|
181
|
+
|
|
182
|
+
const __rt = renderer.getRenderTarget();
|
|
183
|
+
|
|
184
|
+
renderer.setRenderTarget(output);
|
|
185
|
+
|
|
186
|
+
renderScreenSpace(renderer, material);
|
|
187
|
+
|
|
188
|
+
renderer.setRenderTarget(__rt);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Depth texture with mips
|
|
193
|
+
* @returns {THREE.Texture}
|
|
194
|
+
*/
|
|
195
|
+
getTexture() {
|
|
196
|
+
return this.__input_buffer;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { GLSL3, ShaderMaterial, Vector2 } from "three";
|
|
2
|
+
|
|
3
|
+
export function makeReductionShader() {
|
|
4
|
+
return new ShaderMaterial({
|
|
5
|
+
vertexShader: `
|
|
6
|
+
void main() {
|
|
7
|
+
gl_Position = vec4( position, 1.0 );
|
|
8
|
+
}
|
|
9
|
+
`,
|
|
10
|
+
fragmentShader: `
|
|
11
|
+
uniform sampler2D source_texture;
|
|
12
|
+
|
|
13
|
+
uniform vec2 source_resolution;
|
|
14
|
+
uniform vec2 destination_resolution;
|
|
15
|
+
|
|
16
|
+
out highp float out_value;
|
|
17
|
+
|
|
18
|
+
float reduce(float a, float b, float c, float d){
|
|
19
|
+
return max( a, max( b, max( c, d ) ) );
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
void main() {
|
|
23
|
+
vec2 source_uv = gl_FragCoord.xy / destination_resolution;
|
|
24
|
+
vec2 uv_mapping = source_resolution/destination_resolution;
|
|
25
|
+
|
|
26
|
+
ivec2 source_texel_uv_0 = ivec2( source_uv * source_resolution);
|
|
27
|
+
|
|
28
|
+
float d0 = texelFetch(source_texture, source_texel_uv_0, 0).x;
|
|
29
|
+
float d1 = texelFetch(source_texture, source_texel_uv_0 + ivec2( uv_mapping.x, 0 ), 0).x;
|
|
30
|
+
float d2 = texelFetch(source_texture, source_texel_uv_0 + ivec2( 0, uv_mapping.y ), 0).x;
|
|
31
|
+
float d3 = texelFetch(source_texture, source_texel_uv_0 + ivec2( uv_mapping.x, uv_mapping.y ), 0).x;
|
|
32
|
+
|
|
33
|
+
out_value = reduce(d0, d1, d2, d3);
|
|
34
|
+
}
|
|
35
|
+
`,
|
|
36
|
+
depthTest: false,
|
|
37
|
+
depthWrite: false,
|
|
38
|
+
uniforms: {
|
|
39
|
+
source_texture: {
|
|
40
|
+
value: null
|
|
41
|
+
},
|
|
42
|
+
destination_resolution: {
|
|
43
|
+
value: new Vector2()
|
|
44
|
+
},
|
|
45
|
+
source_resolution: {
|
|
46
|
+
value: new Vector2()
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
glslVersion: GLSL3
|
|
50
|
+
});
|
|
51
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { CanvasView } from "../../../../../view/elements/CanvasView.js";
|
|
2
|
+
import {
|
|
3
|
+
DoubleSide,
|
|
4
|
+
LinearFilter,
|
|
5
|
+
Mesh as ThreeMesh,
|
|
6
|
+
OrthographicCamera,
|
|
7
|
+
Scene,
|
|
8
|
+
ShaderMaterial,
|
|
9
|
+
UnsignedByteType,
|
|
10
|
+
WebGLRenderTarget
|
|
11
|
+
} from "three";
|
|
12
|
+
import CheckersTexture from "../../../texture/CheckersTexture.js";
|
|
13
|
+
import { FULL_SCREEN_TRIANGLE_GEOMETRY } from "../../../geometry/FULL_SCREEN_TRIANGLE_GEOMETRY.js";
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
*
|
|
18
|
+
* @param {THREE.Texture} texture
|
|
19
|
+
* @returns {string}
|
|
20
|
+
*/
|
|
21
|
+
function defineSamplerType(texture) {
|
|
22
|
+
switch (texture.format) {
|
|
23
|
+
case UnsignedByteType:
|
|
24
|
+
return 'usampler2D';
|
|
25
|
+
default:
|
|
26
|
+
return 'sampler2D'
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
*
|
|
32
|
+
* @param {THREE.Texture} texture
|
|
33
|
+
* @param {string} name
|
|
34
|
+
* @param {string} uv
|
|
35
|
+
* @returns {string}
|
|
36
|
+
*/
|
|
37
|
+
function sampleTexel(texture, name, uv) {
|
|
38
|
+
switch (texture.format) {
|
|
39
|
+
default:
|
|
40
|
+
return `texture2D(${name}, ${uv})`;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
*
|
|
46
|
+
* @param {THREE.Texture} texture
|
|
47
|
+
*/
|
|
48
|
+
function makeShader(texture) {
|
|
49
|
+
return new ShaderMaterial({
|
|
50
|
+
|
|
51
|
+
vertexShader: /* glsl */`
|
|
52
|
+
|
|
53
|
+
varying vec2 vUv;
|
|
54
|
+
|
|
55
|
+
void main() {
|
|
56
|
+
|
|
57
|
+
vUv = uv;
|
|
58
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
|
59
|
+
|
|
60
|
+
}`,
|
|
61
|
+
|
|
62
|
+
fragmentShader: /* glsl */`
|
|
63
|
+
|
|
64
|
+
uniform ${defineSamplerType(texture)} tDiffuse;
|
|
65
|
+
|
|
66
|
+
varying vec2 vUv;
|
|
67
|
+
|
|
68
|
+
void main() {
|
|
69
|
+
|
|
70
|
+
vec4 texel = ${sampleTexel(texture, 'tDiffuse', 'vUv')};
|
|
71
|
+
gl_FragColor = texel;
|
|
72
|
+
|
|
73
|
+
gl_FragColor.a = 1.0;
|
|
74
|
+
// gl_FragColor.r *= 255.0;
|
|
75
|
+
|
|
76
|
+
}`,
|
|
77
|
+
uniforms: {
|
|
78
|
+
|
|
79
|
+
'tDiffuse': { value: null }
|
|
80
|
+
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
*
|
|
87
|
+
* @param {number} height
|
|
88
|
+
* @param {number} width
|
|
89
|
+
* @param {THREE.Texture} texture
|
|
90
|
+
* @param {THREE.WebGLRenderer} renderer
|
|
91
|
+
* @param flipY
|
|
92
|
+
* @return {{view: View, render: render}}
|
|
93
|
+
*/
|
|
94
|
+
export function buildCanvasViewFromTexture({
|
|
95
|
+
height,
|
|
96
|
+
width,
|
|
97
|
+
texture = CheckersTexture.create(),
|
|
98
|
+
renderer,
|
|
99
|
+
flipY = true
|
|
100
|
+
}) {
|
|
101
|
+
const canvasView = new CanvasView();
|
|
102
|
+
canvasView.size.set(width, height);
|
|
103
|
+
|
|
104
|
+
const ctx = canvasView.context2d;
|
|
105
|
+
|
|
106
|
+
let copyShader = null;
|
|
107
|
+
|
|
108
|
+
const camera = new OrthographicCamera(-1, 1, 1, -1, 0, 1);
|
|
109
|
+
const scene = new Scene();
|
|
110
|
+
scene.add(camera);
|
|
111
|
+
|
|
112
|
+
const quad = new ThreeMesh(FULL_SCREEN_TRIANGLE_GEOMETRY, null);
|
|
113
|
+
|
|
114
|
+
if (flipY) {
|
|
115
|
+
quad.scale.y = -1;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
scene.add(quad);
|
|
119
|
+
|
|
120
|
+
const gl = renderer.getContext();
|
|
121
|
+
|
|
122
|
+
const renderTargetOptions = {
|
|
123
|
+
generateMipmaps: false,
|
|
124
|
+
minFilter: LinearFilter,
|
|
125
|
+
stencilBuffer: false,
|
|
126
|
+
depthBuffer: false
|
|
127
|
+
};
|
|
128
|
+
const renderTarget = new WebGLRenderTarget(width, height, renderTargetOptions);
|
|
129
|
+
|
|
130
|
+
const imageData = ctx.createImageData(width, height);
|
|
131
|
+
|
|
132
|
+
let __texture_cached = texture;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
*
|
|
136
|
+
* @return {ShaderMaterial}
|
|
137
|
+
*/
|
|
138
|
+
function getShader() {
|
|
139
|
+
if (__texture_cached !== texture || copyShader === null) {
|
|
140
|
+
copyShader = makeShader(texture);
|
|
141
|
+
|
|
142
|
+
copyShader.side = DoubleSide;
|
|
143
|
+
copyShader.uniforms.tDiffuse.value = texture;
|
|
144
|
+
|
|
145
|
+
quad.material = copyShader;
|
|
146
|
+
|
|
147
|
+
__texture_cached = texture;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return copyShader;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const render = () => {
|
|
154
|
+
|
|
155
|
+
getShader().uniforms.tDiffuse.value = texture;
|
|
156
|
+
|
|
157
|
+
renderer.setRenderTarget(renderTarget);
|
|
158
|
+
|
|
159
|
+
renderer.render(scene, camera);
|
|
160
|
+
|
|
161
|
+
gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, imageData.data);
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
ctx.putImageData(imageData, 0, 0)
|
|
165
|
+
|
|
166
|
+
renderer.setRenderTarget(null);
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
return {
|
|
170
|
+
view: canvasView,
|
|
171
|
+
render,
|
|
172
|
+
set texture(v) {
|
|
173
|
+
|
|
174
|
+
texture = v;
|
|
175
|
+
|
|
176
|
+
getShader().uniforms.tDiffuse.value = v;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|