@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.
- package/core/bvh2/aabb3/AABB3.js +4 -1
- package/core/collection/array/copyArray.js +2 -2
- package/core/collection/table/RowFirstTableSpec.js +8 -0
- package/core/geom/3d/aabb/aabb3_compute_projected_area.js +1 -0
- package/core/geom/3d/aabb/aabb3_estimate_projected_area2.js +59 -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/engine/graphics/GraphicsEngine.js +9 -116
- 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/format/MicronGeometryBufferAttributeSpec.js +1 -1
- package/engine/graphics/micron/prototypeVirtualGeometry.js +1 -1
- package/engine/graphics/micron/render/VirtualGeometryBuilder.js +5 -17
- package/engine/graphics/micron/render/instanced/AttributeDataTexture.js +2 -4
- package/engine/graphics/micron/render/refinement/ActivePatchList.js +33 -25
- package/engine/graphics/micron/render/refinement/ActivePatchRecord.js +4 -2
- 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/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 +435 -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/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 +137 -0
- package/engine/graphics/texture/sampler/convertTexture2Sampler2D.js +3 -2
- package/engine/graphics/texture/virtual/v2/ShaderUsage.js +6 -5
- package/engine/graphics/texture/virtual/v2/prototype.js +16 -6
- package/package.json +1 -1
|
@@ -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
|
+
}
|