@woosh/meep-engine 2.33.4 → 2.33.5

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.
Files changed (40) hide show
  1. package/core/bvh2/aabb3/AABB3.js +4 -1
  2. package/core/collection/array/copyArray.js +2 -2
  3. package/core/collection/table/RowFirstTableSpec.js +8 -0
  4. package/core/geom/3d/aabb/aabb3_compute_projected_area.js +1 -0
  5. package/core/geom/3d/aabb/aabb3_estimate_projected_area2.js +59 -0
  6. package/core/geom/3d/aabb/aabb3_matrix4_project.js +33 -0
  7. package/core/geom/3d/aabb/aabb3_matrix4_project.spec.js +41 -0
  8. package/engine/graphics/GraphicsEngine.js +9 -116
  9. package/engine/graphics/filter/FlipArrayInPlace.js +25 -0
  10. package/engine/graphics/filter/FlipArrayViaCanvas.js +13 -0
  11. package/engine/graphics/filter/ImageFilter.js +20 -51
  12. package/engine/graphics/micron/format/MicronGeometryBufferAttributeSpec.js +1 -1
  13. package/engine/graphics/micron/prototypeVirtualGeometry.js +1 -1
  14. package/engine/graphics/micron/render/VirtualGeometryBuilder.js +5 -17
  15. package/engine/graphics/micron/render/instanced/AttributeDataTexture.js +2 -4
  16. package/engine/graphics/micron/render/refinement/ActivePatchList.js +33 -25
  17. package/engine/graphics/micron/render/refinement/ActivePatchRecord.js +4 -2
  18. package/engine/graphics/render/buffer/buffers/prototypeNormalFrameBuffer.js +8 -10
  19. package/engine/graphics/render/forward_plus/LightManager.js +5 -7
  20. package/engine/graphics/render/forward_plus/data/NumericType.js +9 -0
  21. package/engine/graphics/render/forward_plus/{TextureBackedMemoryRegion.js → data/TextureBackedMemoryRegion.js} +11 -190
  22. package/engine/graphics/render/forward_plus/data/channelCountToThreIntegerTextureType.js +16 -0
  23. package/engine/graphics/render/forward_plus/data/computeDataType.js +36 -0
  24. package/engine/graphics/render/forward_plus/data/computeThreeTextureFormat.js +18 -0
  25. package/engine/graphics/render/forward_plus/data/computeThreeTextureInternalFormatFromDataType.js +63 -0
  26. package/engine/graphics/render/forward_plus/data/computeThreeTextureTypeFromDataType.js +41 -0
  27. package/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +1 -1
  28. package/engine/graphics/render/visibility/hiz/buffer/HierarchicalZBuffer.js +198 -0
  29. package/engine/graphics/render/visibility/hiz/buffer/ReductionShader.js +51 -0
  30. package/engine/graphics/render/visibility/hiz/buildCanvasViewFromTexture.js +179 -0
  31. package/engine/graphics/render/visibility/hiz/prototypeHiZ.js +435 -0
  32. package/engine/graphics/render/visibility/hiz/query/BatchOcclusionQuery.js +174 -0
  33. package/engine/graphics/render/visibility/hiz/query/QueryShader.js +173 -0
  34. package/engine/graphics/texture/cubemap/buildCubeURLs.js +13 -0
  35. package/engine/graphics/texture/cubemap/load_environment_map.d.ts +8 -0
  36. package/engine/graphics/texture/cubemap/load_environment_map.js +137 -0
  37. package/engine/graphics/texture/sampler/convertTexture2Sampler2D.js +3 -2
  38. package/engine/graphics/texture/virtual/v2/ShaderUsage.js +6 -5
  39. package/engine/graphics/texture/virtual/v2/prototype.js +16 -6
  40. package/package.json +1 -1
@@ -0,0 +1,173 @@
1
+ import { GLSL3, ShaderMaterial, Vector2 } from "three";
2
+
3
+ export function makeQueryShader() {
4
+ return new ShaderMaterial({
5
+ vertexShader: `
6
+ void main() {
7
+ gl_Position = vec4( position, 1.0 );
8
+ }
9
+ `,
10
+ fragmentShader: `
11
+ uniform sampler2D utDepth;
12
+ uniform sampler2D utInput;
13
+
14
+ uniform vec2 uDepthMipLimits;
15
+
16
+ out highp vec4 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
+ vec3 read_input_v3(ivec2 start){
23
+ float x = texelFetch(utInput, start, 0).x;
24
+ float y = texelFetch(utInput, start + ivec2(1,0), 0).x;
25
+ float z = texelFetch(utInput, start + ivec2(2,0), 0).x;
26
+
27
+ return vec3(x,y,z);
28
+ }
29
+
30
+ vec4 read_input_v4(ivec2 start){
31
+ return vec4(
32
+ read_input_v3(start),
33
+ texelFetch(utInput, start + ivec2(3,0) , 0).x
34
+ );
35
+ }
36
+
37
+ mat4 read_input_m4(ivec2 start){
38
+ return mat4(
39
+ read_input_v4(start),
40
+ read_input_v4(start + ivec2(4,0)),
41
+ read_input_v4(start + ivec2(8,0)),
42
+ read_input_v4(start + ivec2(12,0))
43
+ );
44
+ }
45
+
46
+ vec3 project_vec3(vec3 value, mat4 transform){
47
+ vec4 v1 = transform * vec4( value, 1.0 );
48
+ v1.xyz /= abs(v1.w);
49
+
50
+ return v1.xyz;
51
+ }
52
+
53
+ void project_aabb(out vec3 pb_min, out vec3 pb_max, in vec3 bb_min, in vec3 bb_max, in mat4 transform){
54
+ vec3 p0 = project_vec3( bb_min, transform );
55
+ vec3 p1 = project_vec3( vec3(bb_min.xy, bb_max.z), transform );
56
+
57
+ pb_min = min( p0, p1 );
58
+ pb_max = max( p0, p1 );
59
+
60
+ vec3 p2 = project_vec3( vec3(bb_min.x, bb_max.y, bb_min.z), transform );
61
+
62
+ pb_min = min( pb_min, p2 );
63
+ pb_max = max( pb_max, p2 );
64
+
65
+ vec3 p3 = project_vec3( vec3( bb_min.x, bb_max.y, bb_max.z ), transform );
66
+
67
+ pb_min = min( pb_min, p3 );
68
+ pb_max = max( pb_max, p3 );
69
+
70
+ vec3 p4 = project_vec3( vec3( bb_max.x, bb_min.y, bb_min.z), transform );
71
+
72
+ pb_min = min( pb_min, p4 );
73
+ pb_max = max( pb_max, p4 );
74
+
75
+ vec3 p5 = project_vec3( vec3( bb_max.x, bb_min.y, bb_max.z ), transform );
76
+
77
+ pb_min = min( pb_min, p5 );
78
+ pb_max = max( pb_max, p5 );
79
+
80
+ vec3 p6 = project_vec3( vec3( bb_max.x, bb_max.y, bb_min.z ), transform );
81
+
82
+ pb_min = min( pb_min, p6 );
83
+ pb_max = max( pb_max, p6 );
84
+
85
+ vec3 p7 = project_vec3( vec3( bb_max.x, bb_max.y, bb_max.z ), transform );
86
+
87
+ pb_min = min( pb_min, p7 );
88
+ pb_max = max( pb_max, p7 );
89
+ }
90
+
91
+ int compute_mip_level_for_dimension(float mip_limit, float ndc_extents){
92
+ return max(0, int( floor( mip_limit - log2( 1.0 / ndc_extents) ) ) );
93
+ }
94
+
95
+ float query_depth_from_screen_space_bb(in vec3 pb_min, in vec3 pb_max){
96
+ vec3 n_min = clamp( (pb_min+1.0)*0.5, 0.0, 1.0);
97
+ vec3 n_max = clamp( (pb_max+1.0)*0.5, 0.0, 1.0);
98
+
99
+ float bb_width = ( n_max.x - n_min.x ) * 0.5;
100
+ float bb_height = ( n_max.y - n_min.y ) * 0.5 ;
101
+
102
+ // pick coarsest z-buffer mip to test 4x4 pixels of the bounding box against
103
+ int mip_level_x = compute_mip_level_for_dimension( uDepthMipLimits.x, bb_width );
104
+ int mip_level_y = compute_mip_level_for_dimension( uDepthMipLimits.y, bb_height );
105
+
106
+ // figure out which mip level to use
107
+ int mip_to_use = max(mip_level_x, mip_level_y);
108
+
109
+ // sample 4 pixels that cover AABB
110
+ float n0 = textureLod(utDepth, n_min.xy, float(mip_to_use)).x;
111
+ float n1 = textureLod(utDepth, vec2(n_min.x, n_max.y), float(mip_to_use)).x;
112
+ float n2 = textureLod(utDepth, vec2(n_max.y, n_min.y), float(mip_to_use)).x;
113
+ float n3 = textureLod(utDepth, n_max.xy, float(mip_to_use)).x;
114
+
115
+ float n = max(n0, max(n1, max(n2,n3)));
116
+
117
+ float depth_delta = n - n_min.z;
118
+
119
+ return depth_delta;
120
+ // return float( uDepthMipLimits.x );
121
+ // return float( depth_delta*255.0 );
122
+ }
123
+
124
+ uint query_bounds(vec3 bb_min, vec3 bb_max, mat4 transform){
125
+ vec3 pb_min;
126
+ vec3 pb_max;
127
+
128
+ // project bounds to screen space
129
+ project_aabb(pb_min, pb_max, bb_min, bb_max, transform);
130
+
131
+ if(
132
+ pb_max.x < -1.0 || pb_max.y < -1.0 || pb_max.z < -1.0
133
+ || pb_min.x > 1.0 || pb_min.y > 1.0 || pb_min.z > 1.0
134
+ ){
135
+ // outside of view frustum
136
+ return 0u;
137
+ }
138
+
139
+ float n = query_depth_from_screen_space_bb( pb_min, pb_max );
140
+
141
+ if(n < 0.0){
142
+ return 0u;
143
+ }else{
144
+ return 255u;
145
+ }
146
+ }
147
+
148
+ void main() {
149
+ ivec2 input_offset = ivec2( int(gl_FragCoord.x) * ITEM_SIZE, int(gl_FragCoord.y) );
150
+
151
+ vec3 bb_min = read_input_v3(input_offset);
152
+ vec3 bb_max = read_input_v3(input_offset + ivec2(3,0));
153
+ mat4 transform = read_input_m4(input_offset + ivec2(6,0));
154
+
155
+ out_value = vec4( float( query_bounds(bb_min, bb_max, transform) ) / 255.0, 0.0, 0.0, 1.0 );
156
+ }
157
+ `,
158
+ depthTest: false,
159
+ depthWrite: false,
160
+ uniforms: {
161
+ utDepth: {
162
+ value: null
163
+ },
164
+ utInput: {
165
+ value: null
166
+ },
167
+ uDepthMipLimits: {
168
+ value: new Vector2(1, 1)
169
+ }
170
+ },
171
+ glslVersion: GLSL3
172
+ });
173
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ *
3
+ * @param {String} path
4
+ * @param {String} format
5
+ * @returns {String[]}
6
+ */
7
+ export function buildCubeURLs(path, format) {
8
+ return [
9
+ path + "posx" + format, path + "negx" + format,
10
+ path + "posy" + format, path + "negy" + format,
11
+ path + "posz" + format, path + "negz" + format
12
+ ];
13
+ }
@@ -0,0 +1,8 @@
1
+ import {CubeTexture, WebGLRenderer} from "three";
2
+
3
+ export function load_environment_map(args: {
4
+ path: (string | string[]),
5
+ renderer?: WebGLRenderer,
6
+ original?: boolean,
7
+ filtered?: boolean
8
+ }): Promise<{ original?: CubeTexture, filtered?: CubeTexture }>
@@ -0,0 +1,137 @@
1
+ import { EXRLoader } from "three/examples/jsm/loaders/EXRLoader.js";
2
+ import { CubeTextureLoader, LinearFilter, PMREMGenerator, sRGBEncoding, TextureLoader, UnsignedByteType } from "three";
3
+ import { noop } from "../../../../core/function/Functions.js";
4
+ import { computeFileExtension } from "../../../../core/FilePath.js";
5
+
6
+ /**
7
+ *
8
+ * @param {string[]|string} paths
9
+ * @return {Promise<THREE.CubeTexture>}
10
+ */
11
+ function load_cube_texture(paths) {
12
+ // piece-wise cubemap, a collection of images for each face
13
+ const cubeTextureLoader = new CubeTextureLoader();
14
+ return new Promise((resolve, reject) => {
15
+ cubeTextureLoader.load(
16
+ paths,
17
+ texture => {
18
+ resolve(texture);
19
+ },
20
+ noop,
21
+ reject
22
+ );
23
+ });
24
+ }
25
+
26
+ /**
27
+ *
28
+ * @param {string} path
29
+ * @return {Promise<THREE.Texture>}
30
+ */
31
+ function load_exr_texture(path) {
32
+ return new Promise((resolve, reject) => {
33
+ new EXRLoader()
34
+ .setDataType(UnsignedByteType)
35
+ .load(path, texture => {
36
+ resolve(texture);
37
+ }, noop, reject);
38
+ })
39
+ }
40
+
41
+ /**
42
+ *
43
+ * @param {string} path
44
+ * @return {Promise<THREE.Texture>}
45
+ */
46
+ function load_standard_texture(path) {
47
+ return new Promise((resolve, reject) => {
48
+ new TextureLoader()
49
+ .load(path, texture => {
50
+ texture.encoding = sRGBEncoding;
51
+ resolve(texture);
52
+ }, noop, reject);
53
+ })
54
+ }
55
+
56
+ /**
57
+ *
58
+ * @param {string|string[]} path
59
+ * @param {THREE.WebGLRenderer} [renderer]
60
+ * @param {boolean} [original]
61
+ * @param {boolean} [filtered]
62
+ * @returns {{original?:THREE.CubeTexture, filtered?: THREE.CubeTexture}}
63
+ */
64
+ export async function load_environment_map({ path, renderer, original = false, filtered = true }) {
65
+ /**
66
+ * @type {string} 'e' or 'c'
67
+ */
68
+ let type;
69
+
70
+ /**
71
+ * @type {THREE.WebGLCubeRenderTarget}
72
+ */
73
+ let cube_rt;
74
+
75
+ /**
76
+ * @type {THREE.Texture|THREE.CubeTexture}
77
+ */
78
+ let texture;
79
+
80
+ if (Array.isArray(path)) {
81
+ texture = await load_cube_texture(path);
82
+
83
+ texture.magFilter = LinearFilter;
84
+ texture.encoding = sRGBEncoding;
85
+
86
+ type = 'c';
87
+
88
+ } else if (typeof path === 'string') {
89
+ // single cubemap
90
+ const extension = computeFileExtension(path).toLowerCase();
91
+ if (extension === 'exr') {
92
+ texture = await load_exr_texture(path);
93
+ } else if (extension === 'jpg') {
94
+ texture = await load_standard_texture(path);
95
+ } else {
96
+ // unsupported extension
97
+ throw new Error(`Unsupported cube map texture extension '${extension}'`);
98
+ }
99
+
100
+ type = 'e';
101
+
102
+ } else {
103
+ throw new Error(`Unsupported parameter format: '${path}'`);
104
+ }
105
+
106
+ const result = {};
107
+
108
+ if (filtered) {
109
+
110
+ if (renderer === undefined) {
111
+ throw new Error('renderer argument not supplied, expected a WebGLRenderer');
112
+ }
113
+
114
+ const pmremGenerator = new PMREMGenerator(renderer);
115
+
116
+ if (type === 'c') {
117
+ cube_rt = pmremGenerator.fromCubemap(texture);
118
+ } else if (type === 'e') {
119
+ cube_rt = pmremGenerator.fromEquirectangular(texture);
120
+ } else {
121
+ throw new Error(`Unsupported cubemap type '${type}'`);
122
+ }
123
+
124
+ pmremGenerator.dispose();
125
+
126
+ result.filtered = cube_rt.texture;
127
+ }
128
+
129
+ if (original) {
130
+ result.original = texture;
131
+ } else {
132
+ // cleanup
133
+ texture.dispose();
134
+ }
135
+
136
+ return result;
137
+ }
@@ -1,7 +1,8 @@
1
1
  import { WebGLRendererPool } from "../../render/RendererPool.js";
2
- import ImageFilter, { flipArrayInPlace } from "../../filter/ImageFilter.js";
2
+ import ImageFilter from "../../filter/ImageFilter.js";
3
3
  import { Sampler2D } from "./Sampler2D.js";
4
4
  import CopyShader from "../../postprocess/threejs/shaders/CopyShader.js";
5
+ import { flipArrayInPlace } from "../../filter/FlipArrayInPlace.js";
5
6
 
6
7
 
7
8
  const DEFAULT_TEXTURE_WIDTH = 512;
@@ -65,7 +66,7 @@ export function convertTexture2Sampler2D(texture, width, height, flipY = true) {
65
66
  value: texture,
66
67
  type: 't'
67
68
  },
68
- "opacity": { value: 1.0 }
69
+ opacity: { value: 1.0 }
69
70
  }
70
71
  });
71
72
 
@@ -14,27 +14,28 @@ function vertex() {
14
14
  function fragment() {
15
15
  return `
16
16
  uniform vec4 u_mt_tex; // [ width, height, tileSize, id ]
17
+ uniform vec2 u_mt_params; // [ bias, maxLevel, xx, xx ]
18
+ varying vec2 vUv;
19
+
17
20
  float MTCalculateMipLevel( const in vec2 uv, const in float bias ) {
18
21
  vec2 dx = dFdx( uv * u_mt_tex.x );
19
22
  vec2 dy = dFdy( uv * u_mt_tex.y );
20
23
  return log2( max( dot( dx, dx ), dot( dy, dy ) ) ) / 2.0 + bias;
21
24
  }
22
25
 
23
- uniform vec2 u_mt_params; // [ bias, maxLevel, xx, xx ]
24
26
  vec4 MTCalculateTileKeyRGBA( const in vec2 uv ) {
25
27
  float level = clamp( floor( MTCalculateMipLevel( uv, u_mt_params.x ) ), 0.0, u_mt_params.y );
26
28
  vec2 texIS = uv.xy * u_mt_tex.xy; // [0-1]x[0-1] -> [0-texwidth]x[0-texheight]
27
29
  vec2 texLS = texIS / exp2( level ); // -> [0-levelwidth]x[0-levelheight]
28
30
  vec2 texTS = floor( texLS / u_mt_tex.z ); // -> [0->tileswide]x[0-tileshigh]
29
- return vec4( u_mt_params.y - level, texTS.xy, u_mt_tex.w ) / 255.0; // [ texId, level, tileX, tileY ] -> RGBA
31
+ return vec4( u_mt_params.y - level, texTS.xy, u_mt_tex.w ) / 255.0; // [ level, tileX, tileY, texId ] -> RGBA
30
32
  }
31
33
 
32
- varying vec2 vUv;
33
34
 
34
35
  void main(){
35
36
  vec4 tile = MTCalculateTileKeyRGBA(vUv);
36
37
  // gl_FragColor = tile;
37
- gl_FragColor = vec4(mix(0.1,1.0,tile.x*255.0), tile.yz*64.0, 1.0);
38
+ gl_FragColor = vec4(mix(0.1,1.0,tile.x*255.0/u_mt_params.y), tile.yz*64.0, 1.0);
38
39
  // gl_FragColor = MTCalculateTileKeyRGBA(vUv);
39
40
  // gl_FragColor = vec4(1.0);
40
41
  }
@@ -44,4 +45,4 @@ void main(){
44
45
  export {
45
46
  vertex,
46
47
  fragment
47
- };
48
+ };
@@ -1,5 +1,6 @@
1
1
  import * as THREE from "three";
2
2
  import { fragment, vertex } from "./ShaderUsage.js";
3
+ import { OrbitControls } from "three/examples/jsm/controls/OrbitControls.js";
3
4
 
4
5
  let camera, renderer, clock, scene;
5
6
 
@@ -22,7 +23,14 @@ function init() {
22
23
  const textureLoader = new THREE.TextureLoader();
23
24
 
24
25
  uniforms = {
25
- "u_mt_params": { value: new THREE.Vector2(0.1, 5) },
26
+ "u_mt_params": { value: new THREE.Vector2(0.1, 6) },
27
+ /**
28
+ * Format: VT_WIDTH, VT_HEIGHT, VT_TILE_SIZE, VT_ID
29
+ * - VT_WIDTH : width of the virtual texture
30
+ * - VT_HEIGHT : height of the virtual texture
31
+ * - VT_TILE_SIZE : resolution of a single tile
32
+ * - VT_ID : multiple different virtual textures may be used, this identifies current texture
33
+ */
26
34
  "u_mt_tex": { value: new THREE.Vector4(16384, 16384, 256, 1) }
27
35
  };
28
36
 
@@ -30,11 +38,11 @@ function init() {
30
38
 
31
39
  const material = new THREE.ShaderMaterial({
32
40
 
33
- uniforms: uniforms,
34
- vertexShader: vertex(),
35
- fragmentShader: fragment()
41
+ uniforms: uniforms,
42
+ vertexShader: vertex(),
43
+ fragmentShader: fragment()
36
44
 
37
- });
45
+ });
38
46
 
39
47
  mesh = new THREE.Mesh(new THREE.TorusGeometry(size, 0.3, 30, 30), material);
40
48
  mesh.rotation.x = 0.3;
@@ -57,6 +65,8 @@ function init() {
57
65
 
58
66
  window.addEventListener("resize", onWindowResize);
59
67
 
68
+ new OrbitControls(camera, renderer.domElement);
69
+
60
70
  }
61
71
 
62
72
  function onWindowResize() {
@@ -88,4 +98,4 @@ function render() {
88
98
  renderer.clear();
89
99
  renderer.render(scene, camera)
90
100
 
91
- }
101
+ }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "productName": "Meep",
5
5
  "description": "production-ready JavaScript game engine based on Entity Component System Architecture",
6
6
  "author": "Alexander Goldring",
7
- "version": "2.33.4",
7
+ "version": "2.33.5",
8
8
  "dependencies": {
9
9
  "fast-levenshtein": "2.0.6",
10
10
  "opentype.js": "1.3.3",