@galacean/effects-core 2.8.0-alpha.2 → 2.8.0-alpha.3

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/dist/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  * Description: Galacean Effects runtime core for the web
4
4
  * Author: Ant Group CO., Ltd.
5
5
  * Contributors: 燃然,飂兮,十弦,云垣,茂安,意绮
6
- * Version: v2.8.0-alpha.2
6
+ * Version: v2.8.0-alpha.3
7
7
  */
8
8
 
9
9
  'use strict';
@@ -7230,13 +7230,388 @@ __decorate([
7230
7230
  serialize()
7231
7231
  ], RendererComponent.prototype, "_priority", void 0);
7232
7232
 
7233
+ exports.ShaderType = void 0;
7234
+ (function(ShaderType) {
7235
+ ShaderType[ShaderType["vertex"] = 0] = "vertex";
7236
+ ShaderType[ShaderType["fragment"] = 1] = "fragment";
7237
+ })(exports.ShaderType || (exports.ShaderType = {}));
7238
+ exports.MaskMode = void 0;
7239
+ (function(MaskMode) {
7240
+ /**
7241
+ * 无
7242
+ */ MaskMode[MaskMode["NONE"] = 0] = "NONE";
7243
+ /**
7244
+ * 蒙版
7245
+ */ MaskMode[MaskMode["MASK"] = 1] = "MASK";
7246
+ /**
7247
+ * 被遮挡
7248
+ */ MaskMode[MaskMode["OBSCURED"] = 2] = "OBSCURED";
7249
+ /**
7250
+ * 被反向遮挡
7251
+ */ MaskMode[MaskMode["REVERSE_OBSCURED"] = 3] = "REVERSE_OBSCURED";
7252
+ })(exports.MaskMode || (exports.MaskMode = {}));
7253
+
7254
+ exports.TextureLoadAction = void 0;
7255
+ (function(TextureLoadAction) {
7256
+ TextureLoadAction[TextureLoadAction["whatever"] = 0] = "whatever";
7257
+ //preserve previous attachment
7258
+ //load = 1,
7259
+ //clear attachment
7260
+ TextureLoadAction[TextureLoadAction["clear"] = 2] = "clear";
7261
+ })(exports.TextureLoadAction || (exports.TextureLoadAction = {}));
7262
+ exports.TextureSourceType = void 0;
7263
+ (function(TextureSourceType) {
7264
+ TextureSourceType[TextureSourceType["none"] = 0] = "none";
7265
+ TextureSourceType[TextureSourceType["data"] = 1] = "data";
7266
+ TextureSourceType[TextureSourceType["image"] = 2] = "image";
7267
+ TextureSourceType[TextureSourceType["compressed"] = 3] = "compressed";
7268
+ TextureSourceType[TextureSourceType["video"] = 4] = "video";
7269
+ TextureSourceType[TextureSourceType["canvas"] = 5] = "canvas";
7270
+ TextureSourceType[TextureSourceType["framebuffer"] = 6] = "framebuffer";
7271
+ TextureSourceType[TextureSourceType["mipmaps"] = 7] = "mipmaps";
7272
+ })(exports.TextureSourceType || (exports.TextureSourceType = {}));
7273
+
7274
+ var MaskProcessor = /*#__PURE__*/ function() {
7275
+ function MaskProcessor(engine) {
7276
+ this.engine = engine;
7277
+ this.alphaMaskEnabled = false;
7278
+ this.maskMode = exports.MaskMode.NONE;
7279
+ this.maskable = null;
7280
+ this.stencilClearAction = {
7281
+ stencilAction: exports.TextureLoadAction.clear
7282
+ };
7283
+ }
7284
+ var _proto = MaskProcessor.prototype;
7285
+ _proto.getRefValue = function getRefValue() {
7286
+ return 1;
7287
+ };
7288
+ _proto.setMaskOptions = function setMaskOptions(data) {
7289
+ var _data_isMask = data.isMask, isMask = _data_isMask === void 0 ? false : _data_isMask, _data_inverted = data.inverted, inverted = _data_inverted === void 0 ? false : _data_inverted, reference = data.reference, _data_alphaMaskEnabled = data.alphaMaskEnabled, alphaMaskEnabled = _data_alphaMaskEnabled === void 0 ? false : _data_alphaMaskEnabled;
7290
+ this.alphaMaskEnabled = alphaMaskEnabled;
7291
+ if (isMask) {
7292
+ this.maskMode = exports.MaskMode.MASK;
7293
+ } else {
7294
+ this.maskMode = inverted ? exports.MaskMode.REVERSE_OBSCURED : exports.MaskMode.OBSCURED;
7295
+ this.maskable = this.engine.findObject(reference);
7296
+ }
7297
+ };
7298
+ _proto.drawStencilMask = function drawStencilMask(renderer) {
7299
+ if (this.maskable) {
7300
+ renderer.clear(this.stencilClearAction);
7301
+ this.maskable.drawStencilMask(renderer);
7302
+ }
7303
+ };
7304
+ return MaskProcessor;
7305
+ }();
7306
+
7307
+ /**
7308
+ * Helper class to create a WebGL Context
7309
+ *
7310
+ * @param canvas
7311
+ * @param glType
7312
+ * @param options
7313
+ * @returns
7314
+ */ function createGLContext(canvas, glType, options) {
7315
+ if (glType === void 0) glType = "webgl";
7316
+ var context;
7317
+ if (glType === "webgl2") {
7318
+ context = canvas.getContext("webgl2", options);
7319
+ if (!context) {
7320
+ console.debug("WebGL2 context retrieval failed, falling back to WebGL context.");
7321
+ }
7322
+ }
7323
+ if (!context || glType === "webgl") {
7324
+ context = canvas.getContext("webgl", options);
7325
+ }
7326
+ if (!context) {
7327
+ throw new Error("This browser does not support WebGL or the WebGL version is incorrect. Please check your WebGL version.");
7328
+ }
7329
+ return context;
7330
+ }
7331
+
7332
+ function gpuTimer(gl) {
7333
+ var ext = gl.getExtension("EXT_disjoint_timer_query_webgl2");
7334
+ if (ext) {
7335
+ var query = gl.createQuery();
7336
+ var getTime = /*#__PURE__*/ _async_to_generator(function() {
7337
+ return __generator(this, function(_state) {
7338
+ return [
7339
+ 2,
7340
+ new Promise(function(resolve, reject) {
7341
+ if (query) {
7342
+ var available = gl.getQueryParameter(query, gl.QUERY_RESULT_AVAILABLE);
7343
+ var disjoint = gl.getParameter(ext.GPU_DISJOINT_EXT);
7344
+ if (available && !disjoint) {
7345
+ // See how much time the rendering of the object took in nanoseconds.
7346
+ var timeElapsed = gl.getQueryParameter(query, gl.QUERY_RESULT); // Do something useful with the time. Note that care should be
7347
+ // taken to use all significant bits of the result, not just the
7348
+ // least significant 32 bits.
7349
+ resolve(timeElapsed / 1000 / 1000);
7350
+ }
7351
+ if (available || disjoint) {
7352
+ // Clean up the query object.
7353
+ gl.deleteQuery(query); // Don't re-enter this polling loop.
7354
+ query = null;
7355
+ }
7356
+ available !== null && query && window.setTimeout(function() {
7357
+ getTime().then(resolve).catch;
7358
+ }, 1);
7359
+ }
7360
+ })
7361
+ ];
7362
+ });
7363
+ });
7364
+ if (!query) {
7365
+ return;
7366
+ }
7367
+ return {
7368
+ begin: function() {
7369
+ query && gl.beginQuery(ext.TIME_ELAPSED_EXT, query);
7370
+ },
7371
+ end: function() {
7372
+ gl.endQuery(ext.TIME_ELAPSED_EXT);
7373
+ },
7374
+ getTime: getTime
7375
+ };
7376
+ }
7377
+ }
7378
+
7379
+ var initErrors = [];
7380
+ var glContext = {};
7381
+ var IOS16_LOCKDOWN_MODE = "iOS16 lockdown mode, WebGL Constants not in global";
7382
+ var WEBGL_CONSTANTS_NOT_IN_GLOBAL = "WebGL Constants not in global, please check your environment";
7383
+ if (!initErrors.length) {
7384
+ initGLContext();
7385
+ }
7386
+ function initGLContext() {
7387
+ // 重要:iOS 9/10 低版本需要拷贝 gl context 的 prototype,要不然会有属性值的缺失
7388
+ if (typeof WebGL2RenderingContext === "function") {
7389
+ copy(WebGL2RenderingContext);
7390
+ } else if (typeof WebGLRenderingContext !== "undefined") {
7391
+ copy(WebGLRenderingContext);
7392
+ copy(WebGLRenderingContext.prototype);
7393
+ } else {
7394
+ if (canUseBOM) {
7395
+ initErrors.push(// iOS 16 lockdown mode
7396
+ isIOS() ? IOS16_LOCKDOWN_MODE : WEBGL_CONSTANTS_NOT_IN_GLOBAL);
7397
+ } else {
7398
+ initErrors.push(WEBGL_CONSTANTS_NOT_IN_GLOBAL);
7399
+ }
7400
+ }
7401
+ if (!initErrors.length && !("HALF_FLOAT" in glContext)) {
7402
+ // @ts-expect-error set default value
7403
+ glContext["HALF_FLOAT"] = 5131;
7404
+ }
7405
+ }
7406
+ function isWebGL2(gl) {
7407
+ return typeof WebGL2RenderingContext !== "undefined" && gl.constructor.name === "WebGL2RenderingContext";
7408
+ }
7409
+ function copy(target) {
7410
+ for(var name in target){
7411
+ if (/^[A-Z_]/.test(name)) {
7412
+ // @ts-expect-error safe to assign
7413
+ glContext[name] = target[name];
7414
+ }
7415
+ }
7416
+ }
7417
+ function vertexFormatType2GLType(formatType) {
7418
+ switch(formatType){
7419
+ case VertexFormatType.Float32:
7420
+ return WebGLRenderingContext["FLOAT"];
7421
+ case VertexFormatType.Int16:
7422
+ return WebGLRenderingContext["SHORT"];
7423
+ case VertexFormatType.Int8:
7424
+ return WebGLRenderingContext["BYTE"];
7425
+ case VertexFormatType.UInt16:
7426
+ return WebGLRenderingContext["UNSIGNED_SHORT"];
7427
+ case VertexFormatType.UInt8:
7428
+ return WebGLRenderingContext["UNSIGNED_BYTE"];
7429
+ default:
7430
+ return WebGLRenderingContext["FLOAT"];
7431
+ }
7432
+ }
7433
+ function glType2VertexFormatType(webglType) {
7434
+ switch(webglType){
7435
+ case WebGLRenderingContext["FLOAT"]:
7436
+ return VertexFormatType.Float32;
7437
+ case WebGLRenderingContext["SHORT"]:
7438
+ return VertexFormatType.Int16;
7439
+ case WebGLRenderingContext["BYTE"]:
7440
+ return VertexFormatType.Int8;
7441
+ case WebGLRenderingContext["UNSIGNED_SHORT"]:
7442
+ return VertexFormatType.UInt16;
7443
+ case WebGLRenderingContext["UNSIGNED_BYTE"]:
7444
+ return VertexFormatType.UInt8;
7445
+ default:
7446
+ return VertexFormatType.Float32;
7447
+ }
7448
+ }
7449
+
7450
+ function valIfUndefined(val, def) {
7451
+ if (val === undefined || val === null) {
7452
+ return def;
7453
+ }
7454
+ return val;
7455
+ }
7456
+ function getPreMultiAlpha(blending) {
7457
+ switch(blending){
7458
+ case BlendingMode.ALPHA:
7459
+ return 1;
7460
+ case BlendingMode.ADD:
7461
+ return 1;
7462
+ case BlendingMode.SUBTRACTION:
7463
+ return 1;
7464
+ case BlendingMode.STRONG_LIGHT:
7465
+ return 1;
7466
+ case BlendingMode.WEAK_LIGHT:
7467
+ return 1;
7468
+ case BlendingMode.SUPERPOSITION:
7469
+ return 2;
7470
+ case BlendingMode.BRIGHTNESS:
7471
+ return 3;
7472
+ case BlendingMode.MULTIPLY:
7473
+ return 0;
7474
+ default:
7475
+ // 处理undefined
7476
+ return 1;
7477
+ }
7478
+ }
7479
+ function setBlendMode(material, blendMode) {
7480
+ switch(blendMode){
7481
+ case undefined:
7482
+ material.blendFunction = [
7483
+ glContext.ONE,
7484
+ glContext.ONE_MINUS_SRC_ALPHA,
7485
+ glContext.ONE,
7486
+ glContext.ONE_MINUS_SRC_ALPHA
7487
+ ];
7488
+ break;
7489
+ case BlendingMode.ALPHA:
7490
+ material.blendFunction = [
7491
+ glContext.ONE,
7492
+ glContext.ONE_MINUS_SRC_ALPHA,
7493
+ glContext.ONE,
7494
+ glContext.ONE_MINUS_SRC_ALPHA
7495
+ ];
7496
+ break;
7497
+ case BlendingMode.ADD:
7498
+ material.blendFunction = [
7499
+ glContext.ONE,
7500
+ glContext.ONE,
7501
+ glContext.ONE,
7502
+ glContext.ONE
7503
+ ];
7504
+ break;
7505
+ case BlendingMode.SUBTRACTION:
7506
+ material.blendFunction = [
7507
+ glContext.ONE,
7508
+ glContext.ONE,
7509
+ glContext.ZERO,
7510
+ glContext.ONE
7511
+ ];
7512
+ material.blendEquation = [
7513
+ glContext.FUNC_REVERSE_SUBTRACT,
7514
+ glContext.FUNC_REVERSE_SUBTRACT
7515
+ ];
7516
+ break;
7517
+ case BlendingMode.SUPERPOSITION:
7518
+ material.blendFunction = [
7519
+ glContext.ONE,
7520
+ glContext.ONE,
7521
+ glContext.ONE,
7522
+ glContext.ONE
7523
+ ];
7524
+ break;
7525
+ case BlendingMode.MULTIPLY:
7526
+ material.blendFunction = [
7527
+ glContext.DST_COLOR,
7528
+ glContext.ONE_MINUS_SRC_ALPHA,
7529
+ glContext.DST_COLOR,
7530
+ glContext.ONE_MINUS_SRC_ALPHA
7531
+ ];
7532
+ break;
7533
+ case BlendingMode.BRIGHTNESS:
7534
+ material.blendFunction = [
7535
+ glContext.ONE,
7536
+ glContext.ONE_MINUS_SRC_ALPHA,
7537
+ glContext.ONE,
7538
+ glContext.ONE_MINUS_SRC_ALPHA
7539
+ ];
7540
+ break;
7541
+ case BlendingMode.STRONG_LIGHT:
7542
+ material.blendFunction = [
7543
+ glContext.DST_COLOR,
7544
+ glContext.DST_ALPHA,
7545
+ glContext.ZERO,
7546
+ glContext.ONE
7547
+ ];
7548
+ break;
7549
+ case BlendingMode.WEAK_LIGHT:
7550
+ material.blendFunction = [
7551
+ glContext.DST_COLOR,
7552
+ glContext.ZERO,
7553
+ glContext.ZERO,
7554
+ glContext.ONE
7555
+ ];
7556
+ break;
7557
+ default:
7558
+ console.warn("BlendMode " + blendMode + " not in specification, please set blend params separately.");
7559
+ }
7560
+ }
7561
+ function setSideMode(material, side) {
7562
+ if (side === SideMode.DOUBLE) {
7563
+ material.culling = false;
7564
+ } else {
7565
+ material.culling = true;
7566
+ material.frontFace = glContext.CW;
7567
+ material.cullFace = side === SideMode.BACK ? glContext.BACK : glContext.FRONT;
7568
+ }
7569
+ }
7570
+ function setMaskMode(material, maskMode) {
7571
+ switch(maskMode){
7572
+ case undefined:
7573
+ material.stencilTest = false;
7574
+ break;
7575
+ case exports.MaskMode.MASK:
7576
+ material.stencilTest = true;
7577
+ material.stencilFunc = [
7578
+ glContext.ALWAYS,
7579
+ glContext.ALWAYS
7580
+ ];
7581
+ material.stencilOpZPass = [
7582
+ glContext.REPLACE,
7583
+ glContext.REPLACE
7584
+ ];
7585
+ break;
7586
+ case exports.MaskMode.OBSCURED:
7587
+ material.stencilTest = true;
7588
+ material.stencilFunc = [
7589
+ glContext.EQUAL,
7590
+ glContext.EQUAL
7591
+ ];
7592
+ break;
7593
+ case exports.MaskMode.REVERSE_OBSCURED:
7594
+ material.stencilTest = true;
7595
+ material.stencilFunc = [
7596
+ glContext.NOTEQUAL,
7597
+ glContext.NOTEQUAL
7598
+ ];
7599
+ break;
7600
+ case exports.MaskMode.NONE:
7601
+ material.stencilTest = false;
7602
+ break;
7603
+ default:
7604
+ console.warn("MaskMode " + maskMode + " not in specification, please set stencil params seperately.");
7605
+ }
7606
+ }
7607
+
7233
7608
  /**
7234
7609
  * Mesh 组件
7235
7610
  */ var MeshComponent = /*#__PURE__*/ function(RendererComponent) {
7236
7611
  _inherits(MeshComponent, RendererComponent);
7237
- function MeshComponent() {
7612
+ function MeshComponent(engine) {
7238
7613
  var _this;
7239
- _this = RendererComponent.apply(this, arguments) || this;
7614
+ _this = RendererComponent.call(this, engine) || this;
7240
7615
  /**
7241
7616
  * 用于点击测试的碰撞器
7242
7617
  */ _this.meshCollider = new MeshCollider();
@@ -7252,6 +7627,7 @@ __decorate([
7252
7627
  };
7253
7628
  }
7254
7629
  };
7630
+ _this.maskManager = new MaskProcessor(engine);
7255
7631
  return _this;
7256
7632
  }
7257
7633
  var _proto = MeshComponent.prototype;
@@ -7261,12 +7637,42 @@ __decorate([
7261
7637
  renderer.drawGeometry(this.geometry, this.transform.getWorldMatrix(), material, i);
7262
7638
  }
7263
7639
  };
7640
+ _proto.drawStencilMask = function drawStencilMask(renderer) {
7641
+ if (!this.isActiveAndEnabled) {
7642
+ return;
7643
+ }
7644
+ for(var i = 0; i < this.materials.length; i++){
7645
+ var material = this.materials[i];
7646
+ var previousColorMask = material.colorMask;
7647
+ material.colorMask = false;
7648
+ renderer.drawGeometry(this.geometry, this.transform.getWorldMatrix(), material, i);
7649
+ material.colorMask = previousColorMask;
7650
+ }
7651
+ };
7264
7652
  _proto.getBoundingBox = function getBoundingBox() {
7265
7653
  var worldMatrix = this.transform.getWorldMatrix();
7266
7654
  this.meshCollider.setGeometry(this.geometry, worldMatrix);
7267
7655
  var boundingBox = this.meshCollider.getBoundingBox();
7268
7656
  return boundingBox;
7269
7657
  };
7658
+ // TODO: Update data spec
7659
+ _proto.fromData = function fromData(data) {
7660
+ RendererComponent.prototype.fromData.call(this, data);
7661
+ var maskableRendererData = data;
7662
+ var maskOptions = maskableRendererData.mask;
7663
+ if (maskOptions) {
7664
+ this.maskManager.setMaskOptions(maskOptions);
7665
+ }
7666
+ for(var _iterator = _create_for_of_iterator_helper_loose(this.materials), _step; !(_step = _iterator()).done;){
7667
+ var material = _step.value;
7668
+ var stencilRef = this.maskManager.getRefValue();
7669
+ material.stencilRef = [
7670
+ stencilRef,
7671
+ stencilRef
7672
+ ];
7673
+ setMaskMode(material, this.maskManager.maskMode);
7674
+ }
7675
+ };
7270
7676
  return MeshComponent;
7271
7677
  }(RendererComponent);
7272
7678
  __decorate([
@@ -8456,348 +8862,6 @@ Matrix4.tempVec1 = new Vector3();
8456
8862
  Matrix4.tempVec2 = new Vector3();
8457
8863
  Matrix4.tempMat0 = new Matrix4();
8458
8864
 
8459
- /**
8460
- * Helper class to create a WebGL Context
8461
- *
8462
- * @param canvas
8463
- * @param glType
8464
- * @param options
8465
- * @returns
8466
- */ function createGLContext(canvas, glType, options) {
8467
- if (glType === void 0) glType = "webgl";
8468
- var context;
8469
- if (glType === "webgl2") {
8470
- context = canvas.getContext("webgl2", options);
8471
- if (!context) {
8472
- console.debug("WebGL2 context retrieval failed, falling back to WebGL context.");
8473
- }
8474
- }
8475
- if (!context || glType === "webgl") {
8476
- context = canvas.getContext("webgl", options);
8477
- }
8478
- if (!context) {
8479
- throw new Error("This browser does not support WebGL or the WebGL version is incorrect. Please check your WebGL version.");
8480
- }
8481
- return context;
8482
- }
8483
-
8484
- function gpuTimer(gl) {
8485
- var ext = gl.getExtension("EXT_disjoint_timer_query_webgl2");
8486
- if (ext) {
8487
- var query = gl.createQuery();
8488
- var getTime = /*#__PURE__*/ _async_to_generator(function() {
8489
- return __generator(this, function(_state) {
8490
- return [
8491
- 2,
8492
- new Promise(function(resolve, reject) {
8493
- if (query) {
8494
- var available = gl.getQueryParameter(query, gl.QUERY_RESULT_AVAILABLE);
8495
- var disjoint = gl.getParameter(ext.GPU_DISJOINT_EXT);
8496
- if (available && !disjoint) {
8497
- // See how much time the rendering of the object took in nanoseconds.
8498
- var timeElapsed = gl.getQueryParameter(query, gl.QUERY_RESULT); // Do something useful with the time. Note that care should be
8499
- // taken to use all significant bits of the result, not just the
8500
- // least significant 32 bits.
8501
- resolve(timeElapsed / 1000 / 1000);
8502
- }
8503
- if (available || disjoint) {
8504
- // Clean up the query object.
8505
- gl.deleteQuery(query); // Don't re-enter this polling loop.
8506
- query = null;
8507
- }
8508
- available !== null && query && window.setTimeout(function() {
8509
- getTime().then(resolve).catch;
8510
- }, 1);
8511
- }
8512
- })
8513
- ];
8514
- });
8515
- });
8516
- if (!query) {
8517
- return;
8518
- }
8519
- return {
8520
- begin: function() {
8521
- query && gl.beginQuery(ext.TIME_ELAPSED_EXT, query);
8522
- },
8523
- end: function() {
8524
- gl.endQuery(ext.TIME_ELAPSED_EXT);
8525
- },
8526
- getTime: getTime
8527
- };
8528
- }
8529
- }
8530
-
8531
- var initErrors = [];
8532
- var glContext = {};
8533
- var IOS16_LOCKDOWN_MODE = "iOS16 lockdown mode, WebGL Constants not in global";
8534
- var WEBGL_CONSTANTS_NOT_IN_GLOBAL = "WebGL Constants not in global, please check your environment";
8535
- if (!initErrors.length) {
8536
- initGLContext();
8537
- }
8538
- function initGLContext() {
8539
- // 重要:iOS 9/10 低版本需要拷贝 gl context 的 prototype,要不然会有属性值的缺失
8540
- if (typeof WebGL2RenderingContext === "function") {
8541
- copy(WebGL2RenderingContext);
8542
- } else if (typeof WebGLRenderingContext !== "undefined") {
8543
- copy(WebGLRenderingContext);
8544
- copy(WebGLRenderingContext.prototype);
8545
- } else {
8546
- if (canUseBOM) {
8547
- initErrors.push(// iOS 16 lockdown mode
8548
- isIOS() ? IOS16_LOCKDOWN_MODE : WEBGL_CONSTANTS_NOT_IN_GLOBAL);
8549
- } else {
8550
- initErrors.push(WEBGL_CONSTANTS_NOT_IN_GLOBAL);
8551
- }
8552
- }
8553
- if (!initErrors.length && !("HALF_FLOAT" in glContext)) {
8554
- // @ts-expect-error set default value
8555
- glContext["HALF_FLOAT"] = 5131;
8556
- }
8557
- }
8558
- function isWebGL2(gl) {
8559
- return typeof WebGL2RenderingContext !== "undefined" && gl.constructor.name === "WebGL2RenderingContext";
8560
- }
8561
- function copy(target) {
8562
- for(var name in target){
8563
- if (/^[A-Z_]/.test(name)) {
8564
- // @ts-expect-error safe to assign
8565
- glContext[name] = target[name];
8566
- }
8567
- }
8568
- }
8569
- function vertexFormatType2GLType(formatType) {
8570
- switch(formatType){
8571
- case VertexFormatType.Float32:
8572
- return WebGLRenderingContext["FLOAT"];
8573
- case VertexFormatType.Int16:
8574
- return WebGLRenderingContext["SHORT"];
8575
- case VertexFormatType.Int8:
8576
- return WebGLRenderingContext["BYTE"];
8577
- case VertexFormatType.UInt16:
8578
- return WebGLRenderingContext["UNSIGNED_SHORT"];
8579
- case VertexFormatType.UInt8:
8580
- return WebGLRenderingContext["UNSIGNED_BYTE"];
8581
- default:
8582
- return WebGLRenderingContext["FLOAT"];
8583
- }
8584
- }
8585
- function glType2VertexFormatType(webglType) {
8586
- switch(webglType){
8587
- case WebGLRenderingContext["FLOAT"]:
8588
- return VertexFormatType.Float32;
8589
- case WebGLRenderingContext["SHORT"]:
8590
- return VertexFormatType.Int16;
8591
- case WebGLRenderingContext["BYTE"]:
8592
- return VertexFormatType.Int8;
8593
- case WebGLRenderingContext["UNSIGNED_SHORT"]:
8594
- return VertexFormatType.UInt16;
8595
- case WebGLRenderingContext["UNSIGNED_BYTE"]:
8596
- return VertexFormatType.UInt8;
8597
- default:
8598
- return VertexFormatType.Float32;
8599
- }
8600
- }
8601
-
8602
- exports.ShaderType = void 0;
8603
- (function(ShaderType) {
8604
- ShaderType[ShaderType["vertex"] = 0] = "vertex";
8605
- ShaderType[ShaderType["fragment"] = 1] = "fragment";
8606
- })(exports.ShaderType || (exports.ShaderType = {}));
8607
- exports.MaskMode = void 0;
8608
- (function(MaskMode) {
8609
- /**
8610
- * 无
8611
- */ MaskMode[MaskMode["NONE"] = 0] = "NONE";
8612
- /**
8613
- * 蒙版
8614
- */ MaskMode[MaskMode["MASK"] = 1] = "MASK";
8615
- /**
8616
- * 被遮挡
8617
- */ MaskMode[MaskMode["OBSCURED"] = 2] = "OBSCURED";
8618
- /**
8619
- * 被反向遮挡
8620
- */ MaskMode[MaskMode["REVERSE_OBSCURED"] = 3] = "REVERSE_OBSCURED";
8621
- })(exports.MaskMode || (exports.MaskMode = {}));
8622
-
8623
- function valIfUndefined(val, def) {
8624
- if (val === undefined || val === null) {
8625
- return def;
8626
- }
8627
- return val;
8628
- }
8629
- function getPreMultiAlpha(blending) {
8630
- switch(blending){
8631
- case BlendingMode.ALPHA:
8632
- return 1;
8633
- case BlendingMode.ADD:
8634
- return 1;
8635
- case BlendingMode.SUBTRACTION:
8636
- return 1;
8637
- case BlendingMode.STRONG_LIGHT:
8638
- return 1;
8639
- case BlendingMode.WEAK_LIGHT:
8640
- return 1;
8641
- case BlendingMode.SUPERPOSITION:
8642
- return 2;
8643
- case BlendingMode.BRIGHTNESS:
8644
- return 3;
8645
- case BlendingMode.MULTIPLY:
8646
- return 0;
8647
- default:
8648
- // 处理undefined
8649
- return 1;
8650
- }
8651
- }
8652
- function setBlendMode(material, blendMode) {
8653
- switch(blendMode){
8654
- case undefined:
8655
- material.blendFunction = [
8656
- glContext.ONE,
8657
- glContext.ONE_MINUS_SRC_ALPHA,
8658
- glContext.ONE,
8659
- glContext.ONE_MINUS_SRC_ALPHA
8660
- ];
8661
- break;
8662
- case BlendingMode.ALPHA:
8663
- material.blendFunction = [
8664
- glContext.ONE,
8665
- glContext.ONE_MINUS_SRC_ALPHA,
8666
- glContext.ONE,
8667
- glContext.ONE_MINUS_SRC_ALPHA
8668
- ];
8669
- break;
8670
- case BlendingMode.ADD:
8671
- material.blendFunction = [
8672
- glContext.ONE,
8673
- glContext.ONE,
8674
- glContext.ONE,
8675
- glContext.ONE
8676
- ];
8677
- break;
8678
- case BlendingMode.SUBTRACTION:
8679
- material.blendFunction = [
8680
- glContext.ONE,
8681
- glContext.ONE,
8682
- glContext.ZERO,
8683
- glContext.ONE
8684
- ];
8685
- material.blendEquation = [
8686
- glContext.FUNC_REVERSE_SUBTRACT,
8687
- glContext.FUNC_REVERSE_SUBTRACT
8688
- ];
8689
- break;
8690
- case BlendingMode.SUPERPOSITION:
8691
- material.blendFunction = [
8692
- glContext.ONE,
8693
- glContext.ONE,
8694
- glContext.ONE,
8695
- glContext.ONE
8696
- ];
8697
- break;
8698
- case BlendingMode.MULTIPLY:
8699
- material.blendFunction = [
8700
- glContext.DST_COLOR,
8701
- glContext.ONE_MINUS_SRC_ALPHA,
8702
- glContext.DST_COLOR,
8703
- glContext.ONE_MINUS_SRC_ALPHA
8704
- ];
8705
- break;
8706
- case BlendingMode.BRIGHTNESS:
8707
- material.blendFunction = [
8708
- glContext.ONE,
8709
- glContext.ONE_MINUS_SRC_ALPHA,
8710
- glContext.ONE,
8711
- glContext.ONE_MINUS_SRC_ALPHA
8712
- ];
8713
- break;
8714
- case BlendingMode.STRONG_LIGHT:
8715
- material.blendFunction = [
8716
- glContext.DST_COLOR,
8717
- glContext.DST_ALPHA,
8718
- glContext.ZERO,
8719
- glContext.ONE
8720
- ];
8721
- break;
8722
- case BlendingMode.WEAK_LIGHT:
8723
- material.blendFunction = [
8724
- glContext.DST_COLOR,
8725
- glContext.ZERO,
8726
- glContext.ZERO,
8727
- glContext.ONE
8728
- ];
8729
- break;
8730
- default:
8731
- console.warn("BlendMode " + blendMode + " not in specification, please set blend params separately.");
8732
- }
8733
- }
8734
- function setSideMode(material, side) {
8735
- if (side === SideMode.DOUBLE) {
8736
- material.culling = false;
8737
- } else {
8738
- material.culling = true;
8739
- material.frontFace = glContext.CW;
8740
- material.cullFace = side === SideMode.BACK ? glContext.BACK : glContext.FRONT;
8741
- }
8742
- }
8743
- function setMaskMode(material, maskMode) {
8744
- switch(maskMode){
8745
- case undefined:
8746
- material.stencilTest = false;
8747
- break;
8748
- case exports.MaskMode.MASK:
8749
- material.stencilTest = true;
8750
- material.stencilFunc = [
8751
- glContext.ALWAYS,
8752
- glContext.ALWAYS
8753
- ];
8754
- material.stencilOpZPass = [
8755
- glContext.REPLACE,
8756
- glContext.REPLACE
8757
- ];
8758
- break;
8759
- case exports.MaskMode.OBSCURED:
8760
- material.stencilTest = true;
8761
- material.stencilFunc = [
8762
- glContext.EQUAL,
8763
- glContext.EQUAL
8764
- ];
8765
- break;
8766
- case exports.MaskMode.REVERSE_OBSCURED:
8767
- material.stencilTest = true;
8768
- material.stencilFunc = [
8769
- glContext.NOTEQUAL,
8770
- glContext.NOTEQUAL
8771
- ];
8772
- break;
8773
- case exports.MaskMode.NONE:
8774
- material.stencilTest = false;
8775
- break;
8776
- default:
8777
- console.warn("MaskMode " + maskMode + " not in specification, please set stencil params seperately.");
8778
- }
8779
- }
8780
-
8781
- exports.TextureLoadAction = void 0;
8782
- (function(TextureLoadAction) {
8783
- TextureLoadAction[TextureLoadAction["whatever"] = 0] = "whatever";
8784
- //preserve previous attachment
8785
- //load = 1,
8786
- //clear attachment
8787
- TextureLoadAction[TextureLoadAction["clear"] = 2] = "clear";
8788
- })(exports.TextureLoadAction || (exports.TextureLoadAction = {}));
8789
- exports.TextureSourceType = void 0;
8790
- (function(TextureSourceType) {
8791
- TextureSourceType[TextureSourceType["none"] = 0] = "none";
8792
- TextureSourceType[TextureSourceType["data"] = 1] = "data";
8793
- TextureSourceType[TextureSourceType["image"] = 2] = "image";
8794
- TextureSourceType[TextureSourceType["compressed"] = 3] = "compressed";
8795
- TextureSourceType[TextureSourceType["video"] = 4] = "video";
8796
- TextureSourceType[TextureSourceType["canvas"] = 5] = "canvas";
8797
- TextureSourceType[TextureSourceType["framebuffer"] = 6] = "framebuffer";
8798
- TextureSourceType[TextureSourceType["mipmaps"] = 7] = "mipmaps";
8799
- })(exports.TextureSourceType || (exports.TextureSourceType = {}));
8800
-
8801
8865
  /**
8802
8866
  * 负责下载各种资源,并提供了一些异步加载和缓存管理的功能
8803
8867
  */ var Downloader = /*#__PURE__*/ function() {
@@ -10276,39 +10340,6 @@ exports.MaterialRenderType = void 0;
10276
10340
  return Material;
10277
10341
  }(EffectsObject);
10278
10342
 
10279
- var MaskProcessor = /*#__PURE__*/ function() {
10280
- function MaskProcessor(engine) {
10281
- this.engine = engine;
10282
- this.alphaMaskEnabled = false;
10283
- this.maskMode = exports.MaskMode.NONE;
10284
- this.maskable = null;
10285
- this.stencilClearAction = {
10286
- stencilAction: exports.TextureLoadAction.clear
10287
- };
10288
- }
10289
- var _proto = MaskProcessor.prototype;
10290
- _proto.getRefValue = function getRefValue() {
10291
- return 1;
10292
- };
10293
- _proto.setMaskOptions = function setMaskOptions(data) {
10294
- var _data_isMask = data.isMask, isMask = _data_isMask === void 0 ? false : _data_isMask, _data_inverted = data.inverted, inverted = _data_inverted === void 0 ? false : _data_inverted, reference = data.reference, _data_alphaMaskEnabled = data.alphaMaskEnabled, alphaMaskEnabled = _data_alphaMaskEnabled === void 0 ? false : _data_alphaMaskEnabled;
10295
- this.alphaMaskEnabled = alphaMaskEnabled;
10296
- if (isMask) {
10297
- this.maskMode = exports.MaskMode.MASK;
10298
- } else {
10299
- this.maskMode = inverted ? exports.MaskMode.REVERSE_OBSCURED : exports.MaskMode.OBSCURED;
10300
- this.maskable = this.engine.findObject(reference);
10301
- }
10302
- };
10303
- _proto.drawStencilMask = function drawStencilMask(renderer) {
10304
- if (this.maskable) {
10305
- renderer.clear(this.stencilClearAction);
10306
- this.maskable.drawStencilMask(renderer);
10307
- }
10308
- };
10309
- return MaskProcessor;
10310
- }();
10311
-
10312
10343
  var EFFECTS_COPY_MESH_NAME = "effects-internal-copy";
10313
10344
  var COPY_MESH_SHADER_ID = "effects-internal-copy-mesh";
10314
10345
  var COPY_VERTEX_SHADER = "\nprecision highp float;\nattribute vec2 aPos;\nvarying vec2 vTex;\nvoid main(){\n gl_Position = vec4(aPos,0.,1.0);\n vTex = (aPos + vec2(1.0))/2.;\n}";
@@ -12722,244 +12753,131 @@ var ShaderFactory = /*#__PURE__*/ function() {
12722
12753
  return ShaderFactory;
12723
12754
  }();
12724
12755
 
12725
- // Bloom 阈值 Pass
12726
- var BloomThresholdPass = /*#__PURE__*/ function(RenderPass) {
12727
- _inherits(BloomThresholdPass, RenderPass);
12728
- function BloomThresholdPass(renderer) {
12756
+ // Bloom Pass - 包含阈值提取、高斯模糊(Down Sample 和 Up Sample)
12757
+ var BloomPass = /*#__PURE__*/ function(RenderPass) {
12758
+ _inherits(BloomPass, RenderPass);
12759
+ function BloomPass(renderer, iterationCount) {
12760
+ if (iterationCount === void 0) iterationCount = 4;
12729
12761
  var _this;
12730
12762
  _this = RenderPass.call(this, renderer) || this;
12763
+ _this.tempRTs = [];
12764
+ _this.iterationCount = iterationCount;
12731
12765
  var engine = _this.renderer.engine;
12732
- var geometry = Geometry.create(engine, {
12733
- mode: glContext.TRIANGLE_STRIP,
12734
- attributes: {
12735
- aPos: {
12736
- type: glContext.FLOAT,
12737
- size: 2,
12738
- data: new Float32Array([
12739
- -1,
12740
- 1,
12741
- -1,
12742
- -1,
12743
- 1,
12744
- 1,
12745
- 1,
12746
- -1
12747
- ])
12748
- }
12749
- },
12750
- drawCount: 4
12751
- });
12752
- var material = Material.create(engine, {
12766
+ // Threshold material
12767
+ _this.thresholdMaterial = Material.create(engine, {
12753
12768
  shader: {
12754
12769
  vertex: screenMeshVert,
12755
12770
  fragment: thresholdFrag,
12756
12771
  glslVersion: exports.GLSLVersion.GLSL1
12757
12772
  }
12758
12773
  });
12759
- material.blending = false;
12760
- material.depthTest = false;
12761
- material.culling = false;
12762
- _this.screenMesh = Mesh.create(engine, {
12763
- geometry: geometry,
12764
- material: material,
12765
- priority: 0
12774
+ _this.thresholdMaterial.blending = false;
12775
+ _this.thresholdMaterial.depthTest = false;
12776
+ _this.thresholdMaterial.culling = false;
12777
+ // Down sample H material
12778
+ _this.downSampleHMaterial = Material.create(engine, {
12779
+ shader: {
12780
+ vertex: screenMeshVert,
12781
+ fragment: gaussianDownHFrag,
12782
+ glslVersion: exports.GLSLVersion.GLSL1
12783
+ }
12766
12784
  });
12785
+ _this.downSampleHMaterial.blending = false;
12786
+ _this.downSampleHMaterial.depthTest = false;
12787
+ _this.downSampleHMaterial.culling = false;
12788
+ // Down sample V material
12789
+ _this.downSampleVMaterial = Material.create(engine, {
12790
+ shader: {
12791
+ vertex: screenMeshVert,
12792
+ fragment: gaussianDownVFrag,
12793
+ glslVersion: exports.GLSLVersion.GLSL1
12794
+ }
12795
+ });
12796
+ _this.downSampleVMaterial.blending = false;
12797
+ _this.downSampleVMaterial.depthTest = false;
12798
+ _this.downSampleVMaterial.culling = false;
12799
+ // Up sample material
12800
+ _this.upSampleMaterial = Material.create(engine, {
12801
+ shader: {
12802
+ vertex: screenMeshVert,
12803
+ fragment: gaussianUpFrag,
12804
+ glslVersion: exports.GLSLVersion.GLSL1
12805
+ }
12806
+ });
12807
+ _this.upSampleMaterial.blending = false;
12808
+ _this.upSampleMaterial.depthTest = false;
12809
+ _this.upSampleMaterial.culling = false;
12767
12810
  _this.priority = 5000;
12768
- _this.name = "BloomThresholdPass";
12811
+ _this.name = "BloomPass";
12769
12812
  return _this;
12770
12813
  }
12771
- var _proto = BloomThresholdPass.prototype;
12814
+ var _proto = BloomPass.prototype;
12772
12815
  _proto.configure = function configure(renderer) {
12773
- this.framebuffer = renderer.getTemporaryRT(this.name, renderer.getWidth(), renderer.getHeight(), 0, exports.FilterMode.Linear, exports.RenderTextureFormat.RGBAHalf);
12816
+ // 获取场景纹理用于 ToneMappingPass
12774
12817
  this.mainTexture = renderer.getFramebuffer().getColorTextures()[0];
12775
12818
  this.sceneTextureHandle.texture = this.mainTexture;
12776
- renderer.setFramebuffer(this.framebuffer);
12777
12819
  };
12778
12820
  _proto.execute = function execute(renderer) {
12779
12821
  var _renderer_renderingData_currentFrame_globalVolume_bloom, _renderer_renderingData_currentFrame_globalVolume;
12780
- renderer.clear({
12781
- colorAction: exports.TextureLoadAction.clear,
12782
- depthAction: exports.TextureLoadAction.clear,
12783
- stencilAction: exports.TextureLoadAction.clear
12784
- });
12785
- this.screenMesh.material.setTexture("_MainTex", this.mainTexture);
12822
+ var baseWidth = renderer.getWidth();
12823
+ var baseHeight = renderer.getHeight();
12786
12824
  var _renderer_renderingData_currentFrame_globalVolume_bloom_threshold;
12825
+ // 1. Threshold pass - 提取高亮区域
12787
12826
  var threshold = (_renderer_renderingData_currentFrame_globalVolume_bloom_threshold = (_renderer_renderingData_currentFrame_globalVolume = renderer.renderingData.currentFrame.globalVolume) == null ? void 0 : (_renderer_renderingData_currentFrame_globalVolume_bloom = _renderer_renderingData_currentFrame_globalVolume.bloom) == null ? void 0 : _renderer_renderingData_currentFrame_globalVolume_bloom.threshold) != null ? _renderer_renderingData_currentFrame_globalVolume_bloom_threshold : 1.0;
12788
- this.screenMesh.material.setFloat("_Threshold", threshold);
12789
- renderer.renderMeshes([
12790
- this.screenMesh
12791
- ]);
12827
+ this.thresholdRT = renderer.getTemporaryRT("_BloomThreshold", baseWidth, baseHeight, 0, exports.FilterMode.Linear, exports.RenderTextureFormat.RGBAHalf);
12828
+ this.thresholdMaterial.setFloat("_Threshold", threshold);
12829
+ renderer.blit(this.mainTexture, this.thresholdRT, this.thresholdMaterial);
12830
+ var currentTexture = this.thresholdRT.getColorTextures()[0];
12831
+ // 2. Down sample passes
12832
+ for(var i = 0; i < this.iterationCount; i++){
12833
+ var downWidth = Math.floor(baseWidth / Math.pow(2, i + 1));
12834
+ var downHeight = Math.floor(baseHeight / Math.pow(2, i + 1));
12835
+ // Horizontal pass
12836
+ var tempH = renderer.getTemporaryRT("_BloomDownH" + i, downWidth, downHeight, 0, exports.FilterMode.Linear, exports.RenderTextureFormat.RGBAHalf);
12837
+ this.downSampleHMaterial.setVector2("_TextureSize", getTextureSize(currentTexture));
12838
+ renderer.blit(currentTexture, tempH, this.downSampleHMaterial);
12839
+ // Vertical pass
12840
+ var tempV = renderer.getTemporaryRT("_BloomDownV" + i, downWidth, downHeight, 0, exports.FilterMode.Linear, exports.RenderTextureFormat.RGBAHalf);
12841
+ this.downSampleVMaterial.setVector2("_TextureSize", getTextureSize(tempH.getColorTextures()[0]));
12842
+ renderer.blit(tempH.getColorTextures()[0], tempV, this.downSampleVMaterial);
12843
+ // 释放 H pass RT,保留 V pass RT 用于 up sample
12844
+ renderer.releaseTemporaryRT(tempH);
12845
+ this.tempRTs.push(tempV);
12846
+ currentTexture = tempV.getColorTextures()[0];
12847
+ }
12848
+ // 释放 threshold RT
12849
+ renderer.releaseTemporaryRT(this.thresholdRT);
12850
+ // 3. Up sample passes
12851
+ for(var i1 = this.iterationCount - 1; i1 > 0; i1--){
12852
+ var upWidth = Math.floor(baseWidth / Math.pow(2, i1 - 1));
12853
+ var upHeight = Math.floor(baseHeight / Math.pow(2, i1 - 1));
12854
+ var tempUp = renderer.getTemporaryRT("_BloomUp" + i1, upWidth, upHeight, 0, exports.FilterMode.Linear, exports.RenderTextureFormat.RGBAHalf);
12855
+ // 获取下一层的 down sample 结果
12856
+ var downSampleTexture = this.tempRTs[i1 - 1].getColorTextures()[0];
12857
+ this.upSampleMaterial.setTexture("_GaussianDownTex", downSampleTexture);
12858
+ this.upSampleMaterial.setVector2("_GaussianDownTextureSize", getTextureSize(downSampleTexture));
12859
+ renderer.blit(currentTexture, tempUp, this.upSampleMaterial);
12860
+ currentTexture = tempUp.getColorTextures()[0];
12861
+ this.tempRTs.push(tempUp);
12862
+ }
12863
+ // 设置最终输出到当前 framebuffer
12864
+ renderer.setFramebuffer(this.tempRTs[this.tempRTs.length - 1]);
12792
12865
  };
12793
12866
  _proto.onCameraCleanup = function onCameraCleanup(renderer) {
12794
- if (this.framebuffer) {
12795
- renderer.releaseTemporaryRT(this.framebuffer);
12867
+ // 释放所有临时 RT
12868
+ for(var i = 0; i < this.tempRTs.length; i++){
12869
+ renderer.releaseTemporaryRT(this.tempRTs[i]);
12796
12870
  }
12871
+ this.tempRTs = [];
12797
12872
  };
12798
12873
  _proto.dispose = function dispose(options) {
12874
+ this.thresholdMaterial.dispose();
12875
+ this.downSampleHMaterial.dispose();
12876
+ this.downSampleVMaterial.dispose();
12877
+ this.upSampleMaterial.dispose();
12799
12878
  RenderPass.prototype.dispose.call(this, options);
12800
12879
  };
12801
- return BloomThresholdPass;
12802
- }(RenderPass);
12803
- var HQGaussianDownSamplePass = /*#__PURE__*/ function(RenderPass) {
12804
- _inherits(HQGaussianDownSamplePass, RenderPass);
12805
- function HQGaussianDownSamplePass(renderer, type, level) {
12806
- var _this;
12807
- _this = RenderPass.call(this, renderer) || this;
12808
- _this.type = type;
12809
- _this.level = level;
12810
- var engine = _this.renderer.engine;
12811
- var name = "PostProcess";
12812
- var geometry = Geometry.create(engine, {
12813
- name: name,
12814
- mode: glContext.TRIANGLE_STRIP,
12815
- attributes: {
12816
- aPos: {
12817
- type: glContext.FLOAT,
12818
- size: 2,
12819
- data: new Float32Array([
12820
- -1,
12821
- 1,
12822
- -1,
12823
- -1,
12824
- 1,
12825
- 1,
12826
- 1,
12827
- -1
12828
- ])
12829
- }
12830
- },
12831
- drawCount: 4
12832
- });
12833
- var fragment = type === "H" ? gaussianDownHFrag : gaussianDownVFrag;
12834
- var shader = {
12835
- vertex: screenMeshVert,
12836
- fragment: fragment,
12837
- glslVersion: exports.GLSLVersion.GLSL1
12838
- };
12839
- var material = Material.create(engine, {
12840
- name: name,
12841
- shader: shader
12842
- });
12843
- material.blending = false;
12844
- material.depthTest = false;
12845
- material.culling = false;
12846
- _this.screenMesh = Mesh.create(engine, {
12847
- name: name,
12848
- geometry: geometry,
12849
- material: material,
12850
- priority: 0
12851
- });
12852
- _this.priority = 5000;
12853
- _this.name = "GaussianDownPass" + type + level;
12854
- return _this;
12855
- }
12856
- var _proto = HQGaussianDownSamplePass.prototype;
12857
- _proto.configure = function configure(renderer) {
12858
- var width = Math.floor(this.renderer.getWidth() / Math.pow(2, this.level + 1));
12859
- var height = Math.floor(this.renderer.getHeight() / Math.pow(2, this.level + 1));
12860
- this.framebuffer = renderer.getTemporaryRT(this.name, width, height, 0, exports.FilterMode.Linear, exports.RenderTextureFormat.RGBAHalf);
12861
- this.mainTexture = renderer.getFramebuffer().getColorTextures()[0];
12862
- renderer.setFramebuffer(this.framebuffer);
12863
- };
12864
- _proto.execute = function execute(renderer) {
12865
- renderer.clear({
12866
- colorAction: exports.TextureLoadAction.clear,
12867
- depthAction: exports.TextureLoadAction.clear,
12868
- stencilAction: exports.TextureLoadAction.clear
12869
- });
12870
- this.screenMesh.material.setTexture("_MainTex", this.mainTexture);
12871
- this.screenMesh.material.setVector2("_TextureSize", getTextureSize(this.mainTexture));
12872
- renderer.renderMeshes([
12873
- this.screenMesh
12874
- ]);
12875
- if (this.type === "V") {
12876
- this.gaussianResult.texture = renderer.getFramebuffer().getColorTextures()[0];
12877
- }
12878
- };
12879
- _proto.onCameraCleanup = function onCameraCleanup(renderer) {
12880
- if (this.framebuffer) {
12881
- renderer.releaseTemporaryRT(this.framebuffer);
12882
- }
12883
- };
12884
- return HQGaussianDownSamplePass;
12885
- }(RenderPass);
12886
- var HQGaussianUpSamplePass = /*#__PURE__*/ function(RenderPass) {
12887
- _inherits(HQGaussianUpSamplePass, RenderPass);
12888
- function HQGaussianUpSamplePass(renderer, level) {
12889
- var _this;
12890
- _this = RenderPass.call(this, renderer) || this;
12891
- _this.level = level;
12892
- var name = "PostProcess";
12893
- var engine = _this.renderer.engine;
12894
- var geometry = Geometry.create(engine, {
12895
- name: name,
12896
- mode: glContext.TRIANGLE_STRIP,
12897
- attributes: {
12898
- aPos: {
12899
- type: glContext.FLOAT,
12900
- size: 2,
12901
- data: new Float32Array([
12902
- -1,
12903
- 1,
12904
- -1,
12905
- -1,
12906
- 1,
12907
- 1,
12908
- 1,
12909
- -1
12910
- ])
12911
- }
12912
- },
12913
- drawCount: 4
12914
- });
12915
- var shader = {
12916
- vertex: screenMeshVert,
12917
- fragment: gaussianUpFrag
12918
- };
12919
- var material = Material.create(engine, {
12920
- name: name,
12921
- shader: shader
12922
- });
12923
- material.blending = false;
12924
- material.depthTest = false;
12925
- material.culling = false;
12926
- _this.screenMesh = Mesh.create(engine, {
12927
- name: name,
12928
- geometry: geometry,
12929
- material: material,
12930
- priority: 0
12931
- });
12932
- _this.priority = 5000;
12933
- _this.name = "GaussianUpPass" + level;
12934
- return _this;
12935
- }
12936
- var _proto = HQGaussianUpSamplePass.prototype;
12937
- _proto.configure = function configure(renderer) {
12938
- var width = Math.floor(this.renderer.getWidth() / Math.pow(2, this.level - 1));
12939
- var height = Math.floor(this.renderer.getHeight() / Math.pow(2, this.level - 1));
12940
- this.framebuffer = renderer.getTemporaryRT(this.name, width, height, 0, exports.FilterMode.Linear, exports.RenderTextureFormat.RGBAHalf);
12941
- this.mainTexture = renderer.getFramebuffer().getColorTextures()[0];
12942
- renderer.setFramebuffer(this.framebuffer);
12943
- };
12944
- _proto.execute = function execute(renderer) {
12945
- renderer.clear({
12946
- colorAction: exports.TextureLoadAction.clear,
12947
- depthAction: exports.TextureLoadAction.clear,
12948
- stencilAction: exports.TextureLoadAction.clear
12949
- });
12950
- this.screenMesh.material.setTexture("_MainTex", this.mainTexture);
12951
- this.screenMesh.material.setTexture("_GaussianDownTex", this.gaussianDownSampleResult.texture);
12952
- this.screenMesh.material.setVector2("_GaussianDownTextureSize", getTextureSize(this.gaussianDownSampleResult.texture));
12953
- renderer.renderMeshes([
12954
- this.screenMesh
12955
- ]);
12956
- };
12957
- _proto.onCameraCleanup = function onCameraCleanup(renderer) {
12958
- if (this.framebuffer) {
12959
- renderer.releaseTemporaryRT(this.framebuffer);
12960
- }
12961
- };
12962
- return HQGaussianUpSamplePass;
12880
+ return BloomPass;
12963
12881
  }(RenderPass);
12964
12882
  // 合并Bloom的高斯模糊结果,并应用ACES Tonemapping
12965
12883
  var ToneMappingPass = /*#__PURE__*/ function(RenderPass) {
@@ -13103,36 +13021,11 @@ var seed$5 = 1;
13103
13021
  if (postProcessingEnabled) {
13104
13022
  var sceneTextureHandle = new RenderTargetHandle(engine); //保存后处理前的屏幕图像
13105
13023
  var gaussianStep = 7; // 高斯模糊的迭代次数,次数越高模糊范围越大
13106
- var viewport = [
13107
- 0,
13108
- 0,
13109
- this.renderer.getWidth() / 2,
13110
- this.renderer.getHeight() / 2
13111
- ];
13112
- var gaussianDownResults = new Array(gaussianStep); //存放多个高斯Pass的模糊结果,用于Bloom
13113
- var bloomThresholdPass = new BloomThresholdPass(renderer);
13114
- bloomThresholdPass.sceneTextureHandle = sceneTextureHandle;
13115
- this.addRenderPass(bloomThresholdPass);
13116
- for(var i = 0; i < gaussianStep; i++){
13117
- gaussianDownResults[i] = new RenderTargetHandle(engine);
13118
- var gaussianDownHPass = new HQGaussianDownSamplePass(renderer, "H", i);
13119
- var gaussianDownVPass = new HQGaussianDownSamplePass(renderer, "V", i);
13120
- gaussianDownVPass.gaussianResult = gaussianDownResults[i];
13121
- this.addRenderPass(gaussianDownHPass);
13122
- this.addRenderPass(gaussianDownVPass);
13123
- viewport[2] /= 2;
13124
- viewport[3] /= 2;
13125
- // TODO 限制最大迭代
13126
- }
13127
- viewport[2] *= 4;
13128
- viewport[3] *= 4;
13129
- for(var i1 = 0; i1 < gaussianStep - 1; i1++){
13130
- var gaussianUpPass = new HQGaussianUpSamplePass(renderer, gaussianStep - i1);
13131
- gaussianUpPass.gaussianDownSampleResult = gaussianDownResults[gaussianStep - 2 - i1];
13132
- this.addRenderPass(gaussianUpPass);
13133
- viewport[2] *= 2;
13134
- viewport[3] *= 2;
13135
- }
13024
+ // Bloom Pass(包含阈值提取、高斯模糊)
13025
+ var bloomPass = new BloomPass(renderer, gaussianStep);
13026
+ bloomPass.sceneTextureHandle = sceneTextureHandle;
13027
+ this.addRenderPass(bloomPass);
13028
+ // Tone Mapping Pass
13136
13029
  var postProcessPass = new ToneMappingPass(renderer, sceneTextureHandle);
13137
13030
  this.addRenderPass(postProcessPass);
13138
13031
  }
@@ -13626,6 +13519,14 @@ var Renderer = /*#__PURE__*/ function() {
13626
13519
  _proto.releaseTemporaryRT = function releaseTemporaryRT(rt) {
13627
13520
  this.renderTargetPool.release(rt);
13628
13521
  };
13522
+ /**
13523
+ * 将源纹理复制到目标 Framebuffer,可使用自定义材质进行处理
13524
+ * @param source - 源纹理
13525
+ * @param destination - 目标 Framebuffer,如果为 null 则渲染到屏幕
13526
+ * @param material - 可选的自定义材质,不传则使用默认复制材质
13527
+ */ _proto.blit = function blit(source, destination, material) {
13528
+ // OVERRIDE
13529
+ };
13629
13530
  _proto.dispose = function dispose() {
13630
13531
  // OVERRIDE
13631
13532
  };
@@ -31471,7 +31372,7 @@ function getStandardSpriteContent(sprite, transform) {
31471
31372
  return ret;
31472
31373
  }
31473
31374
 
31474
- var version$1 = "2.8.0-alpha.2";
31375
+ var version$1 = "2.8.0-alpha.3";
31475
31376
  var v0 = /^(\d+)\.(\d+)\.(\d+)(-(\w+)\.\d+)?$/;
31476
31377
  var standardVersion = /^(\d+)\.(\d+)$/;
31477
31378
  var reverseParticle = false;
@@ -35172,7 +35073,7 @@ registerPlugin("sprite", SpriteLoader);
35172
35073
  registerPlugin("particle", ParticleLoader);
35173
35074
  registerPlugin("cal", CalculateLoader);
35174
35075
  registerPlugin("interact", InteractLoader);
35175
- var version = "2.8.0-alpha.2";
35076
+ var version = "2.8.0-alpha.3";
35176
35077
  logger.info("Core version: " + version + ".");
35177
35078
 
35178
35079
  exports.AbstractPlugin = AbstractPlugin;