@woosh/meep-engine 2.33.55 → 2.33.56
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/geom/3d/shape/json/type_adapters.js +1 -1
- package/core/math/MathUtils.spec.js +0 -1
- package/engine/ecs/transform/Transform.d.ts +4 -0
- package/engine/graphics/composit/CompositLayer.js +22 -2
- package/engine/graphics/particles/particular/engine/renderers/billboard/ParticleBillboardMaterial.js +38 -66
- package/engine/graphics/particles/particular/engine/utils/volume/AttributeValue.js +1 -1
- package/engine/graphics/particles/particular/engine/utils/volume/ParticleVolume.js +23 -8
- package/engine/graphics/render/buffer/simple-fx/DepthLimitedBlur.js +7 -3
- package/engine/graphics/render/buffer/simple-fx/ao/AmbientOcclusionPostProcessEffect.js +24 -17
- package/engine/graphics/render/buffer/simple-fx/ao/SAOShader.js +18 -16
- package/engine/graphics/shaders/ScreenSpaceQuadShader.js +23 -3
- package/package.json +1 -1
|
@@ -2,7 +2,7 @@ import { UnitCubeShape3D } from "../UnitCubeShape3D.js";
|
|
|
2
2
|
import { UnitSphereShape3D } from "../UnitSphereShape3D.js";
|
|
3
3
|
import { TransformedShape3D } from "../TransformedShape3D.js";
|
|
4
4
|
import { UnionShape3D } from "../UnionShape3D.js";
|
|
5
|
-
import { shape_from_json} from "./shape_from_json.js";
|
|
5
|
+
import { shape_from_json } from "./shape_from_json.js";
|
|
6
6
|
import { shape_to_json } from "./shape_to_json.js";
|
|
7
7
|
|
|
8
8
|
export const type_adapters = {
|
|
@@ -13,7 +13,6 @@ import { isValueBetweenInclusive } from "./isValueBetweenInclusive.js";
|
|
|
13
13
|
import { solveQuadratic } from "./solveQuadratic.js";
|
|
14
14
|
import { overlap1D } from "./overlap1D.js";
|
|
15
15
|
import { computeHashFloat } from "./hash/computeHashFloat.js";
|
|
16
|
-
import { computeHashFloatArray } from "./hash/computeHashFloatArray.js";
|
|
17
16
|
|
|
18
17
|
test('min2', () => {
|
|
19
18
|
expect(min2(0, 0)).toBe(0);
|
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
AddEquation,
|
|
3
|
+
CustomBlending,
|
|
4
|
+
Mesh,
|
|
5
|
+
OneFactor,
|
|
6
|
+
OneMinusSrcAlphaFactor,
|
|
7
|
+
RedFormat,
|
|
8
|
+
RGBAFormat,
|
|
9
|
+
ShaderMaterial
|
|
10
|
+
} from "three";
|
|
2
11
|
import Vector2 from "../../../core/geom/Vector2.js";
|
|
3
12
|
import { assert } from "../../../core/assert.js";
|
|
4
13
|
import { blendingType2three } from "../texture/sampler/blendingType2Three.js";
|
|
@@ -201,10 +210,21 @@ export class CompositLayer {
|
|
|
201
210
|
}
|
|
202
211
|
};
|
|
203
212
|
|
|
213
|
+
// determine swizzle for the material
|
|
214
|
+
let swizzle;
|
|
215
|
+
const texture_format = this.renderTarget.texture.format;
|
|
216
|
+
if (texture_format === RedFormat) {
|
|
217
|
+
swizzle = ['r', 'r', 'r', 1];
|
|
218
|
+
} else if (texture_format === RGBAFormat) {
|
|
219
|
+
swizzle = ['r', 'g', 'b', 'a'];
|
|
220
|
+
} else {
|
|
221
|
+
throw new Error('Unsupported format');
|
|
222
|
+
}
|
|
223
|
+
|
|
204
224
|
const material = new ShaderMaterial({
|
|
205
225
|
uniforms,
|
|
206
226
|
vertexShader: ScreenSpaceQuadShader.vertexShader(),
|
|
207
|
-
fragmentShader: ScreenSpaceQuadShader.fragmentShader(),
|
|
227
|
+
fragmentShader: ScreenSpaceQuadShader.fragmentShader(swizzle),
|
|
208
228
|
lights: false,
|
|
209
229
|
fog: false,
|
|
210
230
|
depthTest: false,
|
package/engine/graphics/particles/particular/engine/renderers/billboard/ParticleBillboardMaterial.js
CHANGED
|
@@ -28,27 +28,11 @@ backGeometry.viewDir = geometry.viewDir;
|
|
|
28
28
|
|
|
29
29
|
vLightFront = vec3( 0.0 );
|
|
30
30
|
vIndirectFront = vec3( 0.0 );
|
|
31
|
-
#ifdef DOUBLE_SIDED
|
|
32
|
-
vLightBack = vec3( 0.0 );
|
|
33
|
-
vIndirectBack = vec3( 0.0 );
|
|
34
|
-
#endif
|
|
35
31
|
|
|
36
32
|
IncidentLight directLight;
|
|
37
33
|
float dotNL;
|
|
38
34
|
vec3 directLightColor_Diffuse;
|
|
39
35
|
|
|
40
|
-
vIndirectFront += getAmbientLightIrradiance( ambientLightColor );
|
|
41
|
-
|
|
42
|
-
vIndirectFront += getLightProbeIrradiance( lightProbe, geometry.normal );
|
|
43
|
-
|
|
44
|
-
#ifdef DOUBLE_SIDED
|
|
45
|
-
|
|
46
|
-
vIndirectBack += getAmbientLightIrradiance( ambientLightColor );
|
|
47
|
-
|
|
48
|
-
vIndirectBack += getLightProbeIrradiance( lightProbe, backGeometry.normal );
|
|
49
|
-
|
|
50
|
-
#endif
|
|
51
|
-
|
|
52
36
|
#if NUM_POINT_LIGHTS > 0
|
|
53
37
|
|
|
54
38
|
#pragma unroll_loop_start
|
|
@@ -56,17 +40,8 @@ vIndirectFront += getLightProbeIrradiance( lightProbe, geometry.normal );
|
|
|
56
40
|
|
|
57
41
|
getPointLightInfo( pointLights[ i ], geometry, directLight );
|
|
58
42
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
vLightFront += saturate( dotNL ) * directLightColor_Diffuse;
|
|
63
|
-
|
|
64
|
-
#ifdef DOUBLE_SIDED
|
|
65
|
-
|
|
66
|
-
vLightBack += saturate( - dotNL ) * directLightColor_Diffuse;
|
|
67
|
-
|
|
68
|
-
#endif
|
|
69
|
-
|
|
43
|
+
RE_Direct( directLight, geometry, material, reflectedLight );
|
|
44
|
+
|
|
70
45
|
}
|
|
71
46
|
#pragma unroll_loop_end
|
|
72
47
|
|
|
@@ -79,16 +54,7 @@ vIndirectFront += getLightProbeIrradiance( lightProbe, geometry.normal );
|
|
|
79
54
|
|
|
80
55
|
getSpotLightInfo( spotLights[ i ], geometry, directLight );
|
|
81
56
|
|
|
82
|
-
|
|
83
|
-
directLightColor_Diffuse = directLight.color;
|
|
84
|
-
|
|
85
|
-
vLightFront += saturate( dotNL ) * directLightColor_Diffuse;
|
|
86
|
-
|
|
87
|
-
#ifdef DOUBLE_SIDED
|
|
88
|
-
|
|
89
|
-
vLightBack += saturate( - dotNL ) * directLightColor_Diffuse;
|
|
90
|
-
|
|
91
|
-
#endif
|
|
57
|
+
RE_Direct( directLight, geometry, material, reflectedLight );
|
|
92
58
|
}
|
|
93
59
|
#pragma unroll_loop_end
|
|
94
60
|
|
|
@@ -101,38 +67,50 @@ vIndirectFront += getLightProbeIrradiance( lightProbe, geometry.normal );
|
|
|
101
67
|
|
|
102
68
|
getDirectionalLightInfo( directionalLights[ i ], geometry, directLight );
|
|
103
69
|
|
|
104
|
-
|
|
105
|
-
directLightColor_Diffuse = directLight.color;
|
|
106
|
-
|
|
107
|
-
vLightFront += saturate( dotNL ) * directLightColor_Diffuse;
|
|
108
|
-
|
|
109
|
-
#ifdef DOUBLE_SIDED
|
|
110
|
-
|
|
111
|
-
vLightBack += saturate( - dotNL ) * directLightColor_Diffuse;
|
|
112
|
-
|
|
113
|
-
#endif
|
|
70
|
+
RE_Direct( directLight, geometry, material, reflectedLight );
|
|
114
71
|
|
|
115
72
|
}
|
|
116
73
|
#pragma unroll_loop_end
|
|
117
74
|
|
|
118
75
|
#endif
|
|
119
76
|
|
|
120
|
-
#if NUM_HEMI_LIGHTS > 0
|
|
121
77
|
|
|
122
|
-
#pragma unroll_loop_start
|
|
123
|
-
for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {
|
|
124
78
|
|
|
125
|
-
|
|
79
|
+
#if defined( RE_IndirectDiffuse )
|
|
80
|
+
vec3 iblIrradiance = vec3( 0.0 );
|
|
81
|
+
vec3 irradiance = getAmbientLightIrradiance( ambientLightColor );
|
|
82
|
+
irradiance += getLightProbeIrradiance( lightProbe, geometry.normal );
|
|
83
|
+
#if NUM_HEMI_LIGHTS > 0
|
|
126
84
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
85
|
+
#pragma unroll_loop_start
|
|
86
|
+
for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {
|
|
87
|
+
|
|
88
|
+
vIndirectFront += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry.normal );
|
|
89
|
+
|
|
90
|
+
}
|
|
91
|
+
#pragma unroll_loop_end
|
|
92
|
+
|
|
93
|
+
#endif
|
|
94
|
+
|
|
95
|
+
#if defined( USE_ENVMAP ) && defined( ENVMAP_TYPE_CUBE_UV )
|
|
96
|
+
iblIrradiance += getIBLIrradiance( geometry.normal );
|
|
97
|
+
#endif
|
|
98
|
+
#endif
|
|
130
99
|
|
|
131
|
-
|
|
100
|
+
#if defined( RE_IndirectSpecular )
|
|
101
|
+
vec3 radiance = vec3( 0.0 );
|
|
102
|
+
vec3 clearcoatRadiance = vec3( 0.0 );
|
|
103
|
+
#endif
|
|
132
104
|
|
|
133
|
-
|
|
134
|
-
|
|
105
|
+
#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )
|
|
106
|
+
radiance += getIBLRadiance( geometry.viewDir, geometry.normal, material.roughness );
|
|
107
|
+
#endif
|
|
135
108
|
|
|
109
|
+
#if defined( RE_IndirectDiffuse )
|
|
110
|
+
RE_IndirectDiffuse( irradiance, geometry, material, reflectedLight );
|
|
111
|
+
#endif
|
|
112
|
+
#if defined( RE_IndirectSpecular )
|
|
113
|
+
RE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, geometry, material, reflectedLight );
|
|
136
114
|
#endif
|
|
137
115
|
`;
|
|
138
116
|
|
|
@@ -389,18 +367,12 @@ function make_fragment_shader() {
|
|
|
389
367
|
|
|
390
368
|
vec3 transformedNormal = construct_spherical_normal_from_point_coord(gl_PointCoord.xy);
|
|
391
369
|
|
|
392
|
-
${CHUNK_LAMBERT_LIGHTING}
|
|
393
|
-
|
|
394
370
|
LambertMaterial material = LambertMaterial(texel.rgb);
|
|
395
|
-
|
|
396
371
|
ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
|
|
397
|
-
vec3 totalEmissiveRadiance = vec3(0.0);
|
|
398
|
-
|
|
399
|
-
reflectedLight.indirectDiffuse += vIndirectFront;
|
|
400
|
-
reflectedLight.indirectDiffuse *= BRDF_Lambert( texel.rgb );
|
|
401
372
|
|
|
402
|
-
|
|
403
|
-
|
|
373
|
+
${CHUNK_LAMBERT_LIGHTING}
|
|
374
|
+
|
|
375
|
+
vec3 totalEmissiveRadiance = vec3(0.0);
|
|
404
376
|
|
|
405
377
|
//@injection_point FORWARD_PLUS:accumulation
|
|
406
378
|
|
|
@@ -257,8 +257,10 @@ export class ParticleVolume {
|
|
|
257
257
|
init_attributes() {
|
|
258
258
|
const spec = PARTICULAR_PARTICLE_SPECIFICATION;
|
|
259
259
|
|
|
260
|
-
|
|
261
|
-
|
|
260
|
+
const attributeSpecs = spec.attributes;
|
|
261
|
+
const attribute_count = attributeSpecs.length;
|
|
262
|
+
for (let i = 0; i < attribute_count; i++) {
|
|
263
|
+
const attributeSpec = attributeSpecs[i];
|
|
262
264
|
|
|
263
265
|
const av = new AttributeValue();
|
|
264
266
|
av.spec = attributeSpec;
|
|
@@ -300,6 +302,7 @@ export class ParticleVolume {
|
|
|
300
302
|
* @param {number} [particle_size]
|
|
301
303
|
* @param {AbstractShape3D} [shape]
|
|
302
304
|
* @param {boolean} sort
|
|
305
|
+
* @param {boolean} lighting
|
|
303
306
|
* @param {string} [sprite]
|
|
304
307
|
*/
|
|
305
308
|
from({
|
|
@@ -307,14 +310,19 @@ export class ParticleVolume {
|
|
|
307
310
|
particle_size = 1,
|
|
308
311
|
shape = new UnitCubeShape3D(),
|
|
309
312
|
sort = false,
|
|
313
|
+
lighting = true,
|
|
310
314
|
sprite = "data/textures/particle/smokeparticle.png"
|
|
311
315
|
} = {}) {
|
|
312
316
|
|
|
313
317
|
this.__density = density;
|
|
314
318
|
this.__shape = shape;
|
|
315
319
|
|
|
316
|
-
this.__emitter
|
|
317
|
-
|
|
320
|
+
const emitter = this.__emitter;
|
|
321
|
+
|
|
322
|
+
emitter.writeFlag(ParticleEmitterFlag.DepthSorting, sort);
|
|
323
|
+
emitter.writeFlag(ParticleEmitterFlag.Lit, lighting);
|
|
324
|
+
|
|
325
|
+
emitter.layers.get(0).imageURL = sprite;
|
|
318
326
|
|
|
319
327
|
const attributes = this.attributes;
|
|
320
328
|
|
|
@@ -328,6 +336,7 @@ export class ParticleVolume {
|
|
|
328
336
|
* @param {number} [particle_size]
|
|
329
337
|
* @param {Object} shape
|
|
330
338
|
* @param {boolean} [is_sorted]
|
|
339
|
+
* @param {boolean} [is_lit]
|
|
331
340
|
* @param {string} sprite
|
|
332
341
|
* @param {Object<Object>} [attributes]
|
|
333
342
|
*/
|
|
@@ -337,6 +346,7 @@ export class ParticleVolume {
|
|
|
337
346
|
particle_size = 1,
|
|
338
347
|
shape,
|
|
339
348
|
is_sorted = true,
|
|
349
|
+
is_lit = true,
|
|
340
350
|
sprite,
|
|
341
351
|
attributes = {}
|
|
342
352
|
}) {
|
|
@@ -350,9 +360,11 @@ export class ParticleVolume {
|
|
|
350
360
|
shape: shape_object,
|
|
351
361
|
particle_size,
|
|
352
362
|
sort: is_sorted,
|
|
363
|
+
lighting: is_lit,
|
|
353
364
|
sprite
|
|
354
365
|
});
|
|
355
366
|
|
|
367
|
+
// parse attributes
|
|
356
368
|
for (const attributesKey in attributes) {
|
|
357
369
|
const attribute_object = this.attributes[attributesKey];
|
|
358
370
|
|
|
@@ -397,13 +409,13 @@ export class ParticleVolume {
|
|
|
397
409
|
|
|
398
410
|
const layer = emitter.layers.get(0);
|
|
399
411
|
|
|
412
|
+
// build transform matrix
|
|
400
413
|
const m4_transform = new Matrix4();
|
|
401
414
|
|
|
402
415
|
const t = this.__transform;
|
|
403
416
|
|
|
404
417
|
composeMatrix4(m4_transform, t.position, t.rotation, t.scale);
|
|
405
418
|
|
|
406
|
-
|
|
407
419
|
const m4_layer = new Matrix4();
|
|
408
420
|
|
|
409
421
|
composeMatrix4(m4_layer, layer.position, new Quaternion(), layer.scale);
|
|
@@ -414,11 +426,14 @@ export class ParticleVolume {
|
|
|
414
426
|
|
|
415
427
|
m4_final.multiplyMatrices(m4_transform, m4_layer);
|
|
416
428
|
|
|
417
|
-
|
|
429
|
+
// cache variables to save a bit on de-referencing
|
|
430
|
+
const matrix_elements = m4_final.elements;
|
|
431
|
+
const shape = this.__shape;
|
|
418
432
|
|
|
419
|
-
|
|
433
|
+
for (let i = 0; i < particle_count; i++) {
|
|
434
|
+
shape.sample_random_point_in_volume(v3_position, 0, random);
|
|
420
435
|
|
|
421
|
-
vec3.transformMat4(v3_position, v3_position,
|
|
436
|
+
vec3.transformMat4(v3_position, v3_position, matrix_elements);
|
|
422
437
|
|
|
423
438
|
particles.writeAttributeVector3(i, PARTICLE_ATTRIBUTE_POSITION, v3_position[0], v3_position[1], v3_position[2]);
|
|
424
439
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { NoBlending, ShaderMaterial, UniformsUtils, Vector2, WebGLMultisampleRenderTarget } from "three";
|
|
1
|
+
import { NoBlending, RGBAFormat, ShaderMaterial, UniformsUtils, Vector2, WebGLMultisampleRenderTarget } from "three";
|
|
2
2
|
import { BlurShaderUtils, DepthLimitedBlurShader } from "three/examples/jsm/shaders/DepthLimitedBlurShader.js";
|
|
3
3
|
import { renderScreenSpace } from "../../utils/renderScreenSpace.js";
|
|
4
4
|
|
|
5
5
|
export class DepthLimitedBlur {
|
|
6
|
-
constructor() {
|
|
6
|
+
constructor({ format = RGBAFormat }) {
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
*
|
|
@@ -19,7 +19,7 @@ export class DepthLimitedBlur {
|
|
|
19
19
|
*/
|
|
20
20
|
this.__rt_output = null;
|
|
21
21
|
|
|
22
|
-
this.__intermediate = new WebGLMultisampleRenderTarget({});
|
|
22
|
+
this.__intermediate = new WebGLMultisampleRenderTarget({ format });
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
this.__material_blur_x = new ShaderMaterial({
|
|
@@ -161,4 +161,8 @@ export class DepthLimitedBlur {
|
|
|
161
161
|
this.__rt_output = render_target;
|
|
162
162
|
|
|
163
163
|
}
|
|
164
|
+
|
|
165
|
+
dispose() {
|
|
166
|
+
this.__intermediate.dispose();
|
|
167
|
+
}
|
|
164
168
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { EnginePlugin } from "../../../../../plugin/EnginePlugin.js";
|
|
2
2
|
import {
|
|
3
|
+
GLSL3,
|
|
3
4
|
LinearFilter,
|
|
4
5
|
NoBlending,
|
|
5
|
-
|
|
6
|
+
RedFormat,
|
|
6
7
|
ShaderMaterial,
|
|
7
8
|
UniformsUtils,
|
|
8
9
|
WebGLMultisampleRenderTarget
|
|
@@ -25,9 +26,18 @@ export class AmbientOcclusionPostProcessEffect extends EnginePlugin {
|
|
|
25
26
|
defines: defines,
|
|
26
27
|
fragmentShader: SAOShader.fragmentShader,
|
|
27
28
|
vertexShader: SAOShader.vertexShader,
|
|
28
|
-
uniforms: UniformsUtils.clone(SAOShader.uniforms)
|
|
29
|
+
uniforms: UniformsUtils.clone(SAOShader.uniforms),
|
|
30
|
+
glslVersion: GLSL3
|
|
29
31
|
});
|
|
30
32
|
|
|
33
|
+
// AO parameters
|
|
34
|
+
const uniforms = this.__material.uniforms;
|
|
35
|
+
uniforms.bias.value = 0.5;
|
|
36
|
+
uniforms.intensity.value = 1;
|
|
37
|
+
|
|
38
|
+
uniforms.kernelRadius.value = 30;
|
|
39
|
+
uniforms.minResolution.value = 0;
|
|
40
|
+
|
|
31
41
|
this.__material.blending = NoBlending;
|
|
32
42
|
|
|
33
43
|
this.__material.extensions.derivatives = true;
|
|
@@ -43,7 +53,7 @@ export class AmbientOcclusionPostProcessEffect extends EnginePlugin {
|
|
|
43
53
|
defines.NUM_SAMPLES = 13;
|
|
44
54
|
|
|
45
55
|
// More rings = better quality
|
|
46
|
-
defines.NUM_RINGS =
|
|
56
|
+
defines.NUM_RINGS = 5;
|
|
47
57
|
|
|
48
58
|
/**
|
|
49
59
|
* Should normal buffer be used or not? Using normal buffer might be significantly more expensive, as this would require normal buffer to be built every frame. If there are other users of the buffer - this is not an issue
|
|
@@ -78,10 +88,10 @@ export class AmbientOcclusionPostProcessEffect extends EnginePlugin {
|
|
|
78
88
|
minFilter: LinearFilter,
|
|
79
89
|
magFilter: LinearFilter,
|
|
80
90
|
|
|
81
|
-
format:
|
|
91
|
+
format: RedFormat,
|
|
82
92
|
depthBuffer: false,
|
|
83
93
|
stencilBuffer: false,
|
|
84
|
-
generateMipmaps: false
|
|
94
|
+
generateMipmaps: false,
|
|
85
95
|
});
|
|
86
96
|
|
|
87
97
|
/**
|
|
@@ -96,7 +106,7 @@ export class AmbientOcclusionPostProcessEffect extends EnginePlugin {
|
|
|
96
106
|
* @type {DepthLimitedBlur}
|
|
97
107
|
* @private
|
|
98
108
|
*/
|
|
99
|
-
this.__blur = new DepthLimitedBlur();
|
|
109
|
+
this.__blur = new DepthLimitedBlur({ format: RedFormat });
|
|
100
110
|
}
|
|
101
111
|
|
|
102
112
|
/**
|
|
@@ -156,16 +166,6 @@ export class AmbientOcclusionPostProcessEffect extends EnginePlugin {
|
|
|
156
166
|
uniforms.cameraInverseProjectionMatrix.value.copy(camera.projectionMatrixInverse);
|
|
157
167
|
uniforms.cameraProjectionMatrix.value.copy(camera.projectionMatrix);
|
|
158
168
|
|
|
159
|
-
// AO parameters
|
|
160
|
-
uniforms.bias.value = 0.5;
|
|
161
|
-
uniforms.intensity.value = 0.18;
|
|
162
|
-
|
|
163
|
-
// scale is divided by camera far in the shader, we unbias it here
|
|
164
|
-
// TODO remove this term from the shader
|
|
165
|
-
uniforms.scale.value = far * 0.25;
|
|
166
|
-
|
|
167
|
-
uniforms.kernelRadius.value = 30;
|
|
168
|
-
uniforms.minResolution.value = 0;
|
|
169
169
|
|
|
170
170
|
// trigger uniform update
|
|
171
171
|
material.uniformsNeedUpdate = true;
|
|
@@ -300,7 +300,12 @@ export class AmbientOcclusionPostProcessEffect extends EnginePlugin {
|
|
|
300
300
|
const graphics = engine.graphics;
|
|
301
301
|
|
|
302
302
|
// bind compositing layer
|
|
303
|
-
this.__composit_layer = graphics.layerComposer.createLayer(
|
|
303
|
+
this.__composit_layer = graphics.layerComposer.createLayer(
|
|
304
|
+
{
|
|
305
|
+
format: RedFormat
|
|
306
|
+
},
|
|
307
|
+
BlendingType.Multiply
|
|
308
|
+
);
|
|
304
309
|
this.__composit_layer.name = 'Ambient Occlusion';
|
|
305
310
|
|
|
306
311
|
// apply ambient occlusion on opaque pass, otherwise it would occlude transparent geometry
|
|
@@ -344,6 +349,8 @@ export class AmbientOcclusionPostProcessEffect extends EnginePlugin {
|
|
|
344
349
|
this.__composit_layer.on.preRender.remove(this.__render, this);
|
|
345
350
|
graphics.viewport.size.onChanged.add(this.__update_render_target_size, this);
|
|
346
351
|
|
|
352
|
+
this.__blur.dispose();
|
|
353
|
+
|
|
347
354
|
return super.shutdown();
|
|
348
355
|
}
|
|
349
356
|
|
|
@@ -25,7 +25,6 @@ const SAOShader = {
|
|
|
25
25
|
'cameraProjectionMatrix': { value: new Matrix4() },
|
|
26
26
|
'cameraInverseProjectionMatrix': { value: new Matrix4() },
|
|
27
27
|
|
|
28
|
-
'scale': { value: 1.0 },
|
|
29
28
|
'intensity': { value: 0.1 },
|
|
30
29
|
'bias': { value: 0.5 },
|
|
31
30
|
|
|
@@ -63,7 +62,6 @@ const SAOShader = {
|
|
|
63
62
|
uniform mat4 cameraProjectionMatrix;
|
|
64
63
|
uniform mat4 cameraInverseProjectionMatrix;
|
|
65
64
|
|
|
66
|
-
uniform float scale;
|
|
67
65
|
uniform float intensity;
|
|
68
66
|
uniform float bias;
|
|
69
67
|
uniform float kernelRadius;
|
|
@@ -74,6 +72,8 @@ const SAOShader = {
|
|
|
74
72
|
// RGBA depth
|
|
75
73
|
|
|
76
74
|
#include <packing>
|
|
75
|
+
|
|
76
|
+
out float out_occlusion;
|
|
77
77
|
|
|
78
78
|
vec4 getDefaultColor( const in vec2 screenPosition ) {
|
|
79
79
|
#if DIFFUSE_TEXTURE == 1
|
|
@@ -115,15 +115,18 @@ const SAOShader = {
|
|
|
115
115
|
#endif
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
float scaleDividedByCameraFar;
|
|
119
118
|
float minResolutionMultipliedByCameraFar;
|
|
120
119
|
|
|
121
120
|
float getOcclusion( const in vec3 centerViewPosition, const in vec3 centerViewNormal, const in vec3 sampleViewPosition ) {
|
|
122
121
|
vec3 viewDelta = sampleViewPosition - centerViewPosition;
|
|
122
|
+
|
|
123
123
|
float viewDistance = length( viewDelta );
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
124
|
+
|
|
125
|
+
float vn = dot( centerViewNormal, viewDelta );
|
|
126
|
+
float a2 = (vn - minResolutionMultipliedByCameraFar) / viewDistance - bias;
|
|
127
|
+
float a1 = (1.0 + pow2( viewDistance ) );
|
|
128
|
+
|
|
129
|
+
return max(0.0, a2) / a1;
|
|
127
130
|
}
|
|
128
131
|
|
|
129
132
|
// moving costly divides into consts
|
|
@@ -132,31 +135,34 @@ const SAOShader = {
|
|
|
132
135
|
|
|
133
136
|
float getAmbientOcclusion( const in vec3 centerViewPosition ) {
|
|
134
137
|
// precompute some variables require in getOcclusion.
|
|
135
|
-
scaleDividedByCameraFar = scale / cameraFar;
|
|
136
138
|
minResolutionMultipliedByCameraFar = minResolution * cameraFar;
|
|
137
139
|
vec3 centerViewNormal = getViewNormal( centerViewPosition, vUv );
|
|
138
140
|
|
|
139
141
|
// jsfiddle that shows sample pattern: https://jsfiddle.net/a16ff1p7/
|
|
140
142
|
float angle = rand( vUv + randomSeed ) * PI2;
|
|
141
143
|
vec2 radius = vec2( kernelRadius * INV_NUM_SAMPLES ) / size;
|
|
142
|
-
vec2 radiusStep = radius;
|
|
143
144
|
|
|
144
145
|
float occlusionSum = 0.0;
|
|
145
146
|
float weightSum = 0.0;
|
|
146
147
|
|
|
147
148
|
for( int i = 0; i < NUM_SAMPLES; i ++ ) {
|
|
148
|
-
vec2 sampleUv = vUv + vec2( cos( angle ), sin( angle ) ) * radius;
|
|
149
|
-
|
|
149
|
+
vec2 sampleUv = vUv + vec2( cos( angle ), sin( angle ) ) * radius * float(i+1);
|
|
150
|
+
|
|
150
151
|
angle += ANGLE_STEP;
|
|
151
152
|
|
|
152
153
|
float sampleDepth = getDepth( sampleUv );
|
|
154
|
+
|
|
153
155
|
if( sampleDepth >= ( 1.0 - EPSILON ) ) {
|
|
156
|
+
// skip, too far
|
|
154
157
|
continue;
|
|
155
158
|
}
|
|
156
159
|
|
|
157
160
|
float sampleViewZ = getViewZ( sampleDepth );
|
|
161
|
+
|
|
158
162
|
vec3 sampleViewPosition = getViewPosition( sampleUv, sampleDepth, sampleViewZ );
|
|
163
|
+
|
|
159
164
|
occlusionSum += getOcclusion( centerViewPosition, centerViewNormal, sampleViewPosition );
|
|
165
|
+
|
|
160
166
|
weightSum += 1.0;
|
|
161
167
|
}
|
|
162
168
|
|
|
@@ -177,12 +183,8 @@ const SAOShader = {
|
|
|
177
183
|
float ambientOcclusion = getAmbientOcclusion( viewPosition );
|
|
178
184
|
|
|
179
185
|
float invOcclusion = 1.0 - ambientOcclusion;
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
gl_FragColor.xyz *= invOcclusion;
|
|
183
|
-
#else
|
|
184
|
-
gl_FragColor = vec4(invOcclusion,invOcclusion,invOcclusion,1.0);
|
|
185
|
-
#endif
|
|
186
|
+
|
|
187
|
+
out_occlusion = invOcclusion;
|
|
186
188
|
}`
|
|
187
189
|
|
|
188
190
|
};
|
|
@@ -11,13 +11,33 @@ function vertexShader() {
|
|
|
11
11
|
`;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
* @param {string[]} [swizzle] what to read from the texture
|
|
17
|
+
* @returns {string}
|
|
18
|
+
*/
|
|
19
|
+
function fragmentShader(swizzle = ['r', 'g', 'b', 'a']) {
|
|
20
|
+
const swizzle_read = [];
|
|
21
|
+
const n = swizzle.length;
|
|
22
|
+
for (let i = 0; i < n; i++) {
|
|
23
|
+
const token = swizzle[i];
|
|
24
|
+
|
|
25
|
+
if (typeof token === "string") {
|
|
26
|
+
swizzle_read[i] = `texel.${token}`;
|
|
27
|
+
} else if (typeof token === "number") {
|
|
28
|
+
swizzle_read[i] = Number(token).toFixed(4);
|
|
29
|
+
} else {
|
|
30
|
+
throw new Error(`Unsupported swizzle token '${token}'`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
15
34
|
return `
|
|
16
35
|
uniform sampler2D tTexture;
|
|
17
36
|
varying vec2 vUv;
|
|
18
37
|
|
|
19
38
|
void main(){
|
|
20
|
-
|
|
39
|
+
vec4 texel = texture2D( tTexture, vUv );
|
|
40
|
+
gl_FragColor = vec4(${swizzle_read.join(',')});
|
|
21
41
|
}
|
|
22
42
|
`;
|
|
23
43
|
}
|
|
@@ -25,4 +45,4 @@ function fragmentShader() {
|
|
|
25
45
|
export const ScreenSpaceQuadShader = {
|
|
26
46
|
vertexShader,
|
|
27
47
|
fragmentShader
|
|
28
|
-
};
|
|
48
|
+
};
|
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.33.
|
|
8
|
+
"version": "2.33.56",
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"gl-matrix": "3.4.3",
|
|
11
11
|
"fast-levenshtein": "2.0.6",
|