@woosh/meep-engine 2.34.40 → 2.34.44

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 (55) hide show
  1. package/core/bvh2/BinaryNode.js +10 -8
  2. package/core/bvh2/BinaryNode.spec.js +1 -0
  3. package/core/bvh2/LeafNode.js +2 -1
  4. package/core/bvh2/aabb3/AABB3.js +879 -1059
  5. package/core/bvh2/aabb3/AABB3.spec.js +5 -7
  6. package/core/bvh2/aabb3/aabb3_array_intersects_ray.js +2 -2
  7. package/core/bvh2/aabb3/aabb3_box_surface_area_2.js +10 -0
  8. package/core/bvh2/aabb3/aabb3_compute_half_surface_area.js +16 -0
  9. package/core/bvh2/aabb3/aabb3_compute_surface_area.js +18 -0
  10. package/core/bvh2/aabb3/aabb3_expand_array.js +15 -0
  11. package/core/bvh2/aabb3/aabb3_intersect_aabb3.js +28 -0
  12. package/core/bvh2/aabb3/aabb3_intersect_ray_slab.js +73 -0
  13. package/core/bvh2/aabb3/{aabb3_intersects_frustum.js → aabb3_intersects_frustum_array.js} +16 -1
  14. package/core/bvh2/aabb3/aabb3_intersects_line_segment.js +79 -0
  15. package/core/bvh2/aabb3/aabb3_intersects_ray.js +92 -0
  16. package/core/bvh2/aabb3/{AABB3Math.spec.js → aabb3_intersects_ray.spec.js} +3 -3
  17. package/core/bvh2/aabb3/aabb3_intersects_ray_fast.js +176 -0
  18. package/core/bvh2/aabb3/aabb3_score_boxes_SAH.js +43 -0
  19. package/core/bvh2/aabb3/aabb_score_boxes_SAH_delta.js +37 -0
  20. package/core/bvh2/aabb3/deserializeAABB3.js +17 -0
  21. package/core/bvh2/aabb3/deserializeAABB3Encoded_v0.js +73 -0
  22. package/core/bvh2/aabb3/deserializeAABB3Quantized16Uint.js +36 -0
  23. package/core/bvh2/aabb3/serializeAABB3.js +13 -0
  24. package/core/bvh2/aabb3/serializeAABB3Quantized16Uint.js +33 -0
  25. package/core/bvh2/binary/2/BinaryUint32BVH.js +3 -3
  26. package/core/bvh2/binary/BinaryBVH.js +2 -2
  27. package/core/bvh2/binary/RayLeafIntersectionVisitor.js +2 -2
  28. package/core/bvh2/serialization/deserializeBinaryNode.js +1 -1
  29. package/core/bvh2/serialization/deserializeBinaryNodeFromBinaryBuffer.js +2 -1
  30. package/core/bvh2/serialization/serializeBinaryNode.js +1 -1
  31. package/core/bvh2/serialization/serializeBinaryNodeToBinaryBuffer.js +2 -1
  32. package/core/bvh2/transform/BottomUpOptimizingRebuilder.js +6 -5
  33. package/core/bvh2/transform/tryRotateSingleNode.js +2 -1
  34. package/core/geom/3d/frustum/{array_setFromProjectionMatrix.js → frustum_from_projection_matrix_array.js} +1 -1
  35. package/core/math/fabsf.js +8 -0
  36. package/engine/development/performance/MetricCollection.js +6 -0
  37. package/engine/graphics/composit/CompositLayer.js +15 -1
  38. package/engine/graphics/ecs/highlight/plugin/OutlineRenderPlugin.js +7 -0
  39. package/engine/graphics/ecs/light/binding/three/ThreeLightBinding.js +1 -1
  40. package/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +2 -2
  41. package/engine/graphics/ecs/mesh-v2/sample/prototypeShadedGeometry.js +23 -8
  42. package/engine/graphics/geometry/buffered/query/RaycastNearestHitComputingVisitor.js +2 -2
  43. package/engine/graphics/micron/format/MicronGeometryPatchOccurance.js +3 -2
  44. package/engine/graphics/micron/prototypeVirtualGeometry.js +4 -2
  45. package/engine/graphics/micron/render/PatchCacheKey.js +1 -1
  46. package/engine/graphics/micron/render/VirtualGeometryBuilder.js +15 -41
  47. package/engine/graphics/micron/render/instanced/ThreeInstancedAdapter.js +5 -1
  48. package/engine/graphics/micron/render/refinement/ActivePatchList.js +2 -2
  49. package/engine/graphics/micron/render/refinement/RefinementSpec.js +16 -20
  50. package/engine/graphics/render/buffer/simple-fx/DepthLimitedBlur.js +27 -4
  51. package/engine/graphics/render/buffer/simple-fx/ao/AmbientOcclusionPostProcessEffect.js +7 -2
  52. package/engine/graphics/render/buffer/simple-fx/ao/SAOShader.js +186 -187
  53. package/engine/graphics/render/visibility/hiz/buildCanvasViewFromTexture.js +3 -3
  54. package/package.json +1 -1
  55. package/core/bvh2/aabb3/AABB3Math.js +0 -579
@@ -1,187 +1,186 @@
1
- import { Matrix4, Vector2 } from 'three';
2
-
3
- /**
4
- * TODO
5
- */
6
-
7
- const SAOShader = {
8
- defines: {
9
- 'NUM_SAMPLES': 7,
10
- 'NUM_RINGS': 4,
11
- 'NORMAL_TEXTURE': 0,
12
- 'DIFFUSE_TEXTURE': 0,
13
- 'DEPTH_PACKING': 1,
14
- 'PERSPECTIVE_CAMERA': 1
15
- },
16
- uniforms: {
17
-
18
- 'tDepth': { value: null },
19
- 'tNormal': { value: null },
20
- 'size': { value: new Vector2(512, 512) },
21
-
22
- 'cameraNear': { value: 1 },
23
- 'cameraFar': { value: 100 },
24
- 'cameraProjectionMatrix': { value: new Matrix4() },
25
- 'cameraInverseProjectionMatrix': { value: new Matrix4() },
26
-
27
- 'intensity': { value: 0.1 },
28
- 'bias': { value: 0.5 },
29
-
30
- 'minResolution': { value: 0.0 },
31
- 'kernelRadius': { value: 100.0 },
32
- 'randomSeed': { value: 0.0 }
33
- },
34
- vertexShader: /* glsl */`
35
-
36
- varying vec2 vUv;
37
-
38
- void main() {
39
- vUv = uv;
40
- gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
41
- }`,
42
-
43
- fragmentShader: /* glsl */`
44
-
45
- #include <common>
46
-
47
- varying vec2 vUv;
48
-
49
- uniform sampler2D tDepth;
50
-
51
- #if NORMAL_TEXTURE == 1
52
- uniform sampler2D tNormal;
53
- #endif
54
-
55
- uniform float cameraNear;
56
- uniform float cameraFar;
57
- uniform mat4 cameraProjectionMatrix;
58
- uniform mat4 cameraInverseProjectionMatrix;
59
-
60
- uniform float intensity;
61
- uniform float bias;
62
- uniform float kernelRadius;
63
- uniform float minResolution;
64
- uniform vec2 size;
65
- uniform float randomSeed;
66
-
67
- // RGBA depth
68
-
69
- #include <packing>
70
-
71
- out float out_occlusion;
72
-
73
- float getDepth( const in vec2 screenPosition ) {
74
- #if DEPTH_PACKING == 1
75
- return unpackRGBAToDepth( texture2D( tDepth, screenPosition ) );
76
- #else
77
- return texture2D( tDepth, screenPosition ).x;
78
- #endif
79
- }
80
-
81
- float getViewZ( const in float depth ) {
82
- #if PERSPECTIVE_CAMERA == 1
83
- return perspectiveDepthToViewZ( depth, cameraNear, cameraFar );
84
- #else
85
- return orthographicDepthToViewZ( depth, cameraNear, cameraFar );
86
- #endif
87
- }
88
-
89
- vec3 getViewPosition( const in vec2 screenPosition, const in float depth, const in float viewZ ) {
90
- float clipW = cameraProjectionMatrix[2][3] * viewZ + cameraProjectionMatrix[3][3];
91
- vec4 clipPosition = vec4( ( vec3( screenPosition, depth ) - 0.5 ) * 2.0, 1.0 );
92
- clipPosition *= clipW; // unprojection.
93
-
94
- return ( cameraInverseProjectionMatrix * clipPosition ).xyz;
95
- }
96
-
97
- vec3 getViewNormal( const in vec3 viewPosition, const in vec2 screenPosition ) {
98
- #if NORMAL_TEXTURE == 1
99
- return unpackRGBToNormal( texture2D( tNormal, screenPosition ).xyz );
100
- #else
101
- return normalize( cross( dFdx( viewPosition ), dFdy( viewPosition ) ) );
102
- #endif
103
- }
104
-
105
- // Non-sin based hash function, fast and has good randomness
106
- float hash12(vec2 p){
107
- vec3 p3 = fract(vec3(p.xyx) * .1031);
108
- p3 += dot(p3, p3.yzx + 33.33);
109
- return fract((p3.x + p3.y) * p3.z);
110
- }
111
-
112
- float minResolutionMultipliedByCameraFar;
113
-
114
- float getOcclusion( const in vec3 centerViewPosition, const in vec3 centerViewNormal, const in vec3 sampleViewPosition ) {
115
- vec3 viewDelta = sampleViewPosition - centerViewPosition;
116
-
117
- float viewDistance = length( viewDelta );
118
-
119
- float vn = dot( centerViewNormal, viewDelta );
120
- float a2 = (vn - minResolutionMultipliedByCameraFar) / viewDistance - bias;
121
- float a1 = (1.0 + pow2( viewDistance ) );
122
-
123
- return max(0.0, a2) / a1;
124
- }
125
-
126
- // moving costly divides into consts
127
- const float ANGLE_STEP = PI2 * float( NUM_RINGS ) / float( NUM_SAMPLES );
128
- const float INV_NUM_SAMPLES = 1.0 / float( NUM_SAMPLES );
129
-
130
- float getAmbientOcclusion( const in vec3 centerViewPosition ) {
131
- // precompute some variables require in getOcclusion.
132
- minResolutionMultipliedByCameraFar = minResolution * cameraFar;
133
- vec3 centerViewNormal = getViewNormal( centerViewPosition, vUv );
134
-
135
- // jsfiddle that shows sample pattern: https://jsfiddle.net/a16ff1p7/
136
- float angle = hash12( vUv + randomSeed ) * PI2;
137
- vec2 radius = vec2( kernelRadius * INV_NUM_SAMPLES ) / size;
138
-
139
- float occlusionSum = 0.0;
140
- float weightSum = 0.0;
141
-
142
- for( int i = 0; i < NUM_SAMPLES; i ++ ) {
143
- vec2 sampleUv = vUv + vec2( cos( angle ), sin( angle ) ) * radius * float(i+1);
144
-
145
- angle += ANGLE_STEP;
146
-
147
- float sampleDepth = getDepth( sampleUv );
148
-
149
- if( sampleDepth >= ( 1.0 - EPSILON ) ) {
150
- // skip, too far
151
- continue;
152
- }
153
-
154
- float sampleViewZ = getViewZ( sampleDepth );
155
-
156
- vec3 sampleViewPosition = getViewPosition( sampleUv, sampleDepth, sampleViewZ );
157
-
158
- occlusionSum += getOcclusion( centerViewPosition, centerViewNormal, sampleViewPosition );
159
-
160
- weightSum += 1.0;
161
- }
162
-
163
- if( weightSum == 0.0 ) discard;
164
-
165
- return occlusionSum * ( intensity / weightSum );
166
- }
167
-
168
- void main() {
169
- float centerDepth = getDepth( vUv );
170
- if( centerDepth >= ( 1.0 - EPSILON ) ) {
171
- out_occlusion = 1.0;
172
- return;
173
- }
174
-
175
- float centerViewZ = getViewZ( centerDepth );
176
- vec3 viewPosition = getViewPosition( vUv, centerDepth, centerViewZ );
177
-
178
- float ambientOcclusion = getAmbientOcclusion( viewPosition );
179
-
180
- float invOcclusion = 1.0 - ambientOcclusion;
181
-
182
- out_occlusion = invOcclusion;
183
- }`
184
-
185
- };
186
-
187
- export { SAOShader };
1
+ import { Matrix4, Vector2 } from 'three';
2
+
3
+ /**
4
+ * TODO
5
+ */
6
+
7
+ const SAOShader = {
8
+ defines: {
9
+ 'NUM_SAMPLES': 7,
10
+ 'NUM_RINGS': 4,
11
+ 'NORMAL_TEXTURE': 0,
12
+ 'DIFFUSE_TEXTURE': 0,
13
+ 'DEPTH_PACKING': 1,
14
+ 'PERSPECTIVE_CAMERA': 1
15
+ },
16
+ uniforms: {
17
+
18
+ 'tDepth': { value: null },
19
+ 'tNormal': { value: null },
20
+ 'size': { value: new Vector2(512, 512) },
21
+
22
+ 'cameraNear': { value: 1 },
23
+ 'cameraFar': { value: 100 },
24
+ 'cameraProjectionMatrix': { value: new Matrix4() },
25
+ 'cameraInverseProjectionMatrix': { value: new Matrix4() },
26
+
27
+ 'intensity': { value: 0.1 },
28
+ 'bias': { value: 0.5 },
29
+
30
+ 'minResolution': { value: 0.0 },
31
+ 'kernelRadius': { value: 100.0 },
32
+ 'randomSeed': { value: 0.0 }
33
+ },
34
+ vertexShader: /* glsl */`
35
+
36
+ varying vec2 vUv;
37
+
38
+ void main() {
39
+ vUv = uv;
40
+ gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
41
+ }`,
42
+
43
+ fragmentShader: /* glsl */`
44
+
45
+ #include <common>
46
+
47
+ varying vec2 vUv;
48
+
49
+ uniform sampler2D tDepth;
50
+
51
+ #if NORMAL_TEXTURE == 1
52
+ uniform sampler2D tNormal;
53
+ #endif
54
+
55
+ uniform float cameraNear;
56
+ uniform float cameraFar;
57
+ uniform mat4 cameraProjectionMatrix;
58
+ uniform mat4 cameraInverseProjectionMatrix;
59
+
60
+ uniform float intensity;
61
+ uniform float bias;
62
+ uniform float kernelRadius;
63
+ uniform float minResolution;
64
+ uniform vec2 size;
65
+ uniform float randomSeed;
66
+
67
+ // RGBA depth
68
+
69
+ #include <packing>
70
+
71
+ out float out_occlusion;
72
+
73
+ float getDepth( const in vec2 screenPosition ) {
74
+ #if DEPTH_PACKING == 1
75
+ return unpackRGBAToDepth( texture2D( tDepth, screenPosition ) );
76
+ #else
77
+ return texture2D( tDepth, screenPosition ).x;
78
+ #endif
79
+ }
80
+
81
+ float getViewZ( const in float depth ) {
82
+ #if PERSPECTIVE_CAMERA == 1
83
+ return perspectiveDepthToViewZ( depth, cameraNear, cameraFar );
84
+ #else
85
+ return orthographicDepthToViewZ( depth, cameraNear, cameraFar );
86
+ #endif
87
+ }
88
+
89
+ vec3 getViewPosition( const in vec2 screenPosition, const in float depth, const in float viewZ ) {
90
+ float clipW = cameraProjectionMatrix[2][3] * viewZ + cameraProjectionMatrix[3][3];
91
+ vec4 clipPosition = vec4( ( vec3( screenPosition, depth ) - 0.5 ) * 2.0, 1.0 );
92
+ clipPosition *= clipW; // unprojection.
93
+
94
+ return ( cameraInverseProjectionMatrix * clipPosition ).xyz;
95
+ }
96
+
97
+ vec3 getViewNormal( const in vec3 viewPosition, const in vec2 screenPosition ) {
98
+ #if NORMAL_TEXTURE == 1
99
+ return unpackRGBToNormal( texture2D( tNormal, screenPosition ).xyz );
100
+ #else
101
+ return normalize( cross( dFdx( viewPosition ), dFdy( viewPosition ) ) );
102
+ #endif
103
+ }
104
+
105
+ // Non-sin based hash function, fast and has good randomness
106
+ float hash12(vec2 p){
107
+ vec3 p3 = fract(vec3(p.xyx) * .1031);
108
+ p3 += dot(p3, p3.yzx + 33.33);
109
+ return fract((p3.x + p3.y) * p3.z);
110
+ }
111
+
112
+ float minResolutionMultipliedByCameraFar;
113
+
114
+ float getOcclusion( const in vec3 centerViewPosition, const in vec3 centerViewNormal, const in vec3 sampleViewPosition ) {
115
+ vec3 viewDelta = sampleViewPosition - centerViewPosition;
116
+
117
+ float viewDistance = length( viewDelta );
118
+
119
+ float vn = dot( centerViewNormal, viewDelta );
120
+ float a2 = (vn - minResolutionMultipliedByCameraFar) / viewDistance - bias;
121
+ float a1 = (1.0 + pow2( viewDistance ) );
122
+
123
+ return max(0.0, a2) / a1;
124
+ }
125
+
126
+ // moving costly divides into consts
127
+ const float ANGLE_STEP = PI2 * float( NUM_RINGS ) / float( NUM_SAMPLES );
128
+ const float INV_NUM_SAMPLES = 1.0 / float( NUM_SAMPLES );
129
+
130
+ float getAmbientOcclusion( const in vec3 centerViewPosition ) {
131
+ // precompute some variables require in getOcclusion.
132
+ minResolutionMultipliedByCameraFar = minResolution * cameraFar;
133
+ vec3 centerViewNormal = getViewNormal( centerViewPosition, vUv );
134
+
135
+ // jsfiddle that shows sample pattern: https://jsfiddle.net/a16ff1p7/
136
+ float angle = hash12( vUv + randomSeed ) * PI2;
137
+ vec2 radius = vec2( kernelRadius * INV_NUM_SAMPLES ) / size;
138
+
139
+ float occlusionSum = 0.0;
140
+ float weightSum = 0.0;
141
+
142
+ for( int i = 0; i < NUM_SAMPLES; i ++ ) {
143
+ vec2 sampleUv = vUv + vec2( cos( angle ), sin( angle ) ) * radius * float(i+1);
144
+
145
+ angle += ANGLE_STEP;
146
+
147
+ float sampleDepth = getDepth( sampleUv );
148
+
149
+ if( sampleDepth >= ( 1.0 - EPSILON ) ) {
150
+ // skip, too far
151
+ continue;
152
+ }
153
+
154
+ float sampleViewZ = getViewZ( sampleDepth );
155
+
156
+ vec3 sampleViewPosition = getViewPosition( sampleUv, sampleDepth, sampleViewZ );
157
+
158
+ occlusionSum += getOcclusion( centerViewPosition, centerViewNormal, sampleViewPosition );
159
+
160
+ weightSum += 1.0;
161
+ }
162
+
163
+ if( weightSum == 0.0 ) discard;
164
+
165
+ return occlusionSum * ( intensity / weightSum );
166
+ }
167
+
168
+ void main() {
169
+ float centerDepth = getDepth( vUv );
170
+ if( centerDepth >= ( 1.0 - EPSILON ) ) {
171
+ discard;
172
+ }
173
+
174
+ float centerViewZ = getViewZ( centerDepth );
175
+ vec3 viewPosition = getViewPosition( vUv, centerDepth, centerViewZ );
176
+
177
+ float ambientOcclusion = getAmbientOcclusion( viewPosition );
178
+
179
+ float invOcclusion = 1.0 - ambientOcclusion;
180
+
181
+ out_occlusion = invOcclusion;
182
+ }`
183
+
184
+ };
185
+
186
+ export { SAOShader };
@@ -89,12 +89,12 @@ function makeShader(texture) {
89
89
  * @param {THREE.Texture} texture
90
90
  * @param {THREE.WebGLRenderer} renderer
91
91
  * @param flipY
92
- * @return {{view: View, render: render}}
92
+ * @return {{view: View, render: function}}
93
93
  */
94
94
  export function buildCanvasViewFromTexture({
95
- height,
96
- width,
97
95
  texture = CheckersTexture.create(),
96
+ width = texture.image.width,
97
+ height = texture.image.height,
98
98
  renderer,
99
99
  flipY = true
100
100
  }) {
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "productName": "Meep",
6
6
  "description": "production-ready JavaScript game engine based on Entity Component System Architecture",
7
7
  "author": "Alexander Goldring",
8
- "version": "2.34.40",
8
+ "version": "2.34.44",
9
9
  "dependencies": {
10
10
  "gl-matrix": "3.4.3",
11
11
  "fast-levenshtein": "2.0.6",