@galacean/engine-core 1.5.0-alpha.0 → 1.5.0-alpha.1

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/module.js CHANGED
@@ -4265,75 +4265,6 @@ function dependentComponents(componentOrComponents, dependentMode) {
4265
4265
  return Layer;
4266
4266
  }({});
4267
4267
 
4268
- /**
4269
- * @internal
4270
- */ var PipelineUtils = /*#__PURE__*/ function() {
4271
- function PipelineUtils() {}
4272
- /**
4273
- * Recreate texture if needed.
4274
- * @param engine - Engine
4275
- * @param currentTexture - Current texture
4276
- * @param width - Need texture width
4277
- * @param height - Need texture height
4278
- * @param format - Need texture format
4279
- * @param mipmap - Need texture mipmap
4280
- * @param isSRGBColorSpace - Whether to use sRGB color space
4281
- * @param textureWrapMode - Texture wrap mode
4282
- * @param textureFilterMode - Texture filter mode
4283
- * @returns Texture
4284
- */ PipelineUtils.recreateTextureIfNeeded = function recreateTextureIfNeeded(engine, currentTexture, width, height, format, mipmap, isSRGBColorSpace, textureWrapMode, textureFilterMode) {
4285
- if (currentTexture) {
4286
- if (currentTexture.width !== width || currentTexture.height !== height || currentTexture.format !== format || currentTexture.isSRGBColorSpace !== isSRGBColorSpace || currentTexture.mipmapCount > 1 !== mipmap) {
4287
- currentTexture.destroy(true);
4288
- currentTexture = new Texture2D(engine, width, height, format, mipmap, isSRGBColorSpace);
4289
- currentTexture.isGCIgnored = true;
4290
- }
4291
- } else {
4292
- currentTexture = new Texture2D(engine, width, height, format, mipmap, isSRGBColorSpace);
4293
- currentTexture.isGCIgnored = true;
4294
- }
4295
- currentTexture.wrapModeU = currentTexture.wrapModeV = textureWrapMode;
4296
- currentTexture.filterMode = textureFilterMode;
4297
- return currentTexture;
4298
- };
4299
- /**
4300
- * Recreate render target if needed.
4301
- * @param engine - Engine
4302
- * @param currentRenderTarget - Current render target
4303
- * @param width - Need render target width
4304
- * @param height - Need render target height
4305
- * @param colorFormat - Need render target color format
4306
- * @param depthFormat - Need render target depth format
4307
- * @param mipmap - Need render target mipmap
4308
- * @param isSRGBColorSpace - Whether to use sRGB color space
4309
- * @param antiAliasing - Need render target anti aliasing
4310
- * @param textureWrapMode - Texture wrap mode
4311
- * @param textureFilterMode - Texture filter mode
4312
- * @returns Render target
4313
- */ PipelineUtils.recreateRenderTargetIfNeeded = function recreateRenderTargetIfNeeded(engine, currentRenderTarget, width, height, colorFormat, depthFormat, needDepthTexture, mipmap, isSRGBColorSpace, antiAliasing, textureWrapMode, textureFilterMode) {
4314
- var currentColorTexture = currentRenderTarget == null ? void 0 : currentRenderTarget.getColorTexture(0);
4315
- var colorTexture = colorFormat ? PipelineUtils.recreateTextureIfNeeded(engine, currentColorTexture, width, height, colorFormat, mipmap, isSRGBColorSpace, textureWrapMode, textureFilterMode) : null;
4316
- if (needDepthTexture) {
4317
- var currentDepthTexture = currentRenderTarget == null ? void 0 : currentRenderTarget.depthTexture;
4318
- var _$needDepthTexture = depthFormat ? PipelineUtils.recreateTextureIfNeeded(engine, currentDepthTexture, width, height, depthFormat, mipmap, isSRGBColorSpace, textureWrapMode, textureFilterMode) : null;
4319
- if (currentColorTexture !== colorTexture || currentDepthTexture !== _$needDepthTexture) {
4320
- currentRenderTarget == null ? void 0 : currentRenderTarget.destroy(true);
4321
- currentRenderTarget = new RenderTarget(engine, width, height, colorTexture, _$needDepthTexture, antiAliasing);
4322
- currentRenderTarget.isGCIgnored = true;
4323
- }
4324
- } else {
4325
- if (currentColorTexture !== colorTexture || (currentRenderTarget == null ? void 0 : currentRenderTarget._depthFormat) !== depthFormat || currentRenderTarget.antiAliasing !== antiAliasing) {
4326
- currentRenderTarget == null ? void 0 : currentRenderTarget.destroy(true);
4327
- currentRenderTarget = new RenderTarget(engine, width, height, colorTexture, depthFormat, antiAliasing);
4328
- currentRenderTarget.isGCIgnored = true;
4329
- }
4330
- }
4331
- return currentRenderTarget;
4332
- };
4333
- return PipelineUtils;
4334
- }();
4335
- PipelineUtils.defaultViewport = new Vector4(0, 0, 1, 1);
4336
-
4337
4268
  /**
4338
4269
  * Used to update tags.
4339
4270
  */ var UpdateFlag = /*#__PURE__*/ function() {
@@ -5227,7 +5158,7 @@ __decorate([
5227
5158
  * The anti-aliasing mode.
5228
5159
  */ var AntiAliasing = /*#__PURE__*/ function(AntiAliasing) {
5229
5160
  /* Disable anti-aliasing. */ AntiAliasing[AntiAliasing["None"] = 0] = "None";
5230
- /* Fast approximate anti-aliasing. */ AntiAliasing[AntiAliasing["FXAA"] = 1] = "FXAA";
5161
+ /* Fast approximate anti-aliasing, it detects and smooths jagged edges based on luminance contrast in the final rendered image. */ AntiAliasing[AntiAliasing["FXAA"] = 1] = "FXAA";
5231
5162
  return AntiAliasing;
5232
5163
  }({});
5233
5164
 
@@ -5846,11 +5777,14 @@ var Camera = /*#__PURE__*/ function(Component) {
5846
5777
  *
5847
5778
  * @defaultValue `Downsampling.TwoX`
5848
5779
  */ _this.opaqueTextureDownsampling = Downsampling.TwoX, /**
5849
- * Multi-sample anti-aliasing samples when use independent canvas mode.
5780
+ * The number of samples used for hardware multisample anti-aliasing (MSAA) to smooth geometry edges during rasterization.
5781
+ * Higher sample counts (e.g., 2x, 4x, 8x) produce smoother edges.
5782
+ *
5783
+ * @defaultValue `MSAASamples.FourX`
5784
+ */ _this.msaaSamples = MSAASamples.FourX, /**
5785
+ * The screen-space anti-aliasing mode applied after the camera renders the final image.
5786
+ * Unlike MSAA, it can smooth all pixels, including by shader-generated specular, alpha-cutoff edge, low resolution texture.
5850
5787
  *
5851
- * @remarks It will take effect when `independentCanvasEnabled` property is `true`, otherwise it will be invalid.
5852
- */ _this.msaaSamples = MSAASamples.None, /**
5853
- * Anti-aliasing mode.
5854
5788
  * @defaultValue `AntiAliasing.None`
5855
5789
  */ _this.antiAliasing = AntiAliasing.None, /** @internal */ _this._cameraType = CameraType.Normal, /** @internal */ _this._globalShaderMacro = new ShaderMacroCollection(), /** @internal */ _this._frustum = new BoundingFrustum(), /** @internal */ _this._virtualCamera = new VirtualCamera(), /** @internal */ _this._replacementShader = null, /** @internal */ _this._replacementSubShaderTag = null, /** @internal */ _this._replacementFailureStrategy = null, /** @internal */ _this._cameraIndex = -1, _this._priority = 0, _this._shaderData = new ShaderData(ShaderDataGroup.Camera), _this._isCustomViewMatrix = false, _this._isCustomProjectionMatrix = false, _this._fieldOfView = 45, _this._orthographicSize = 10, _this._isProjectionDirty = true, _this._isInvProjMatDirty = true, _this._customAspectRatio = undefined, _this._renderTarget = null, _this._depthBufferParams = new Vector4(), _this._opaqueTextureEnabled = false, _this._enableHDR = false, _this._enablePostProcess = false, _this._viewport = new Vector4(0, 0, 1, 1), _this._pixelViewport = new Rect(0, 0, 0, 0), _this._inverseProjectionMatrix = new Matrix(), _this._invViewProjMat = new Matrix();
5856
5790
  _this._isViewMatrixDirty = entity.registerWorldChangeFlag();
@@ -6027,7 +5961,7 @@ var Camera = /*#__PURE__*/ function(Component) {
6027
5961
  Logger.error("mipLevel only take effect in WebGL2.0");
6028
5962
  }
6029
5963
  var ignoreClearFlags;
6030
- if (this._cameraType !== CameraType.Normal && !this._renderTarget && !this.independentCanvasEnabled) {
5964
+ if (this._cameraType !== CameraType.Normal && !this._renderTarget && !this._isIndependentCanvasEnabled()) {
6031
5965
  ignoreClearFlags = engine.xrManager._getCameraIgnoreClearFlags(this._cameraType);
6032
5966
  }
6033
5967
  this._renderPipeline.render(context, cubeFace, mipLevel, ignoreClearFlags);
@@ -6061,6 +5995,31 @@ var Camera = /*#__PURE__*/ function(Component) {
6061
5995
  };
6062
5996
  /**
6063
5997
  * @internal
5998
+ * Whether independent canvas is enabled.
5999
+ */ _proto._isIndependentCanvasEnabled = function _isIndependentCanvasEnabled() {
6000
+ // Uber pass need internal RT
6001
+ if (this.enablePostProcess && this.scene.postProcessManager._isValid()) {
6002
+ return true;
6003
+ }
6004
+ // Final pass should sRGB conversion and FXAA
6005
+ if (this._needFinalPass()) {
6006
+ return true;
6007
+ }
6008
+ var renderTarget = this._renderTarget;
6009
+ // Need HDR and opaque texture
6010
+ if (this.enableHDR || this.opaqueTextureEnabled) {
6011
+ if (renderTarget) {
6012
+ // If camera is HDR and format is same with renderTarget can reuse renderTarget if renderTarget is same HDR format
6013
+ // If camera is LDR and opaqueTextureEnabled is true, can reuse renderTarget if renderTarget is LDR format(Only R8G8B8A8)
6014
+ return this._getInternalColorTextureFormat() !== renderTarget.getColorTexture(0).format;
6015
+ } else {
6016
+ return true;
6017
+ }
6018
+ }
6019
+ return false;
6020
+ };
6021
+ /**
6022
+ * @internal
6064
6023
  */ _proto._getInternalColorTextureFormat = function _getInternalColorTextureFormat() {
6065
6024
  return this._enableHDR ? this.engine._hardwareRenderer.isWebGL2 ? TextureFormat.R11G11B10_UFloat : TextureFormat.R16G16B16A16 : TextureFormat.R8G8B8A8;
6066
6025
  };
@@ -6186,12 +6145,6 @@ var Camera = /*#__PURE__*/ function(Component) {
6186
6145
  this._updatePixelViewport();
6187
6146
  var _this__customAspectRatio;
6188
6147
  (_this__customAspectRatio = this._customAspectRatio) != null ? _this__customAspectRatio : this._projectionMatrixChange();
6189
- this._checkMainCanvasAntialiasWaste();
6190
- };
6191
- _proto._checkMainCanvasAntialiasWaste = function _checkMainCanvasAntialiasWaste() {
6192
- if (this._phasedActiveInScene && this.independentCanvasEnabled && Vector4.equals(this._viewport, PipelineUtils.defaultViewport)) {
6193
- Logger.warn("Camera use independent canvas and viewport cover the whole screen, it is recommended to disable antialias, depth and stencil to save memory when create engine.");
6194
- }
6195
6148
  };
6196
6149
  _proto._dispatchModify = function _dispatchModify(flag) {
6197
6150
  var _this__updateFlagManager;
@@ -6205,43 +6158,11 @@ var Camera = /*#__PURE__*/ function(Component) {
6205
6158
  * If enabled, the opaque texture can be accessed in the shader using `camera_OpaqueTexture`.
6206
6159
  *
6207
6160
  * @defaultValue `false`
6208
- * @remarks If enabled, the `independentCanvasEnabled` property will be forced to be true.
6209
6161
  */ function get() {
6210
6162
  return this._opaqueTextureEnabled;
6211
6163
  },
6212
6164
  set: function set(value) {
6213
- if (this._opaqueTextureEnabled !== value) {
6214
- this._opaqueTextureEnabled = value;
6215
- this._checkMainCanvasAntialiasWaste();
6216
- }
6217
- }
6218
- },
6219
- {
6220
- key: "independentCanvasEnabled",
6221
- get: /**
6222
- * Whether independent canvas is enabled.
6223
- * @remarks If true, the msaa in viewport can turn or off independently by `msaaSamples` property.
6224
- */ function get() {
6225
- // Uber pass need internal RT
6226
- if (this.enablePostProcess && this.scene.postProcessManager._isValid()) {
6227
- return true;
6228
- }
6229
- // Final pass should sRGB conversion and FXAA
6230
- if (this._needFinalPass()) {
6231
- return true;
6232
- }
6233
- var renderTarget = this._renderTarget;
6234
- // Need HDR and opaque texture
6235
- if (this.enableHDR || this.opaqueTextureEnabled) {
6236
- if (renderTarget) {
6237
- // If camera is HDR and format is same with renderTarget can reuse renderTarget if renderTarget is same HDR format
6238
- // If camera is LDR and opaqueTextureEnabled is true, can reuse renderTarget if renderTarget is LDR format(Only R8G8B8A8)
6239
- return this._getInternalColorTextureFormat() !== renderTarget.getColorTexture(0).format;
6240
- } else {
6241
- return true;
6242
- }
6243
- }
6244
- return false;
6165
+ this._opaqueTextureEnabled = value;
6245
6166
  }
6246
6167
  },
6247
6168
  {
@@ -6438,7 +6359,6 @@ var Camera = /*#__PURE__*/ function(Component) {
6438
6359
  get: /**
6439
6360
  * Whether to enable HDR.
6440
6361
  * @defaultValue `false`
6441
- * @remarks If enabled, the `independentCanvasEnabled` property will be forced to be true.
6442
6362
  */ function get() {
6443
6363
  return this._enableHDR;
6444
6364
  },
@@ -6451,7 +6371,6 @@ var Camera = /*#__PURE__*/ function(Component) {
6451
6371
  return;
6452
6372
  }
6453
6373
  this._enableHDR = value;
6454
- this._checkMainCanvasAntialiasWaste();
6455
6374
  }
6456
6375
  }
6457
6376
  },
@@ -6460,14 +6379,12 @@ var Camera = /*#__PURE__*/ function(Component) {
6460
6379
  get: /**
6461
6380
  * Whether to enable post process.
6462
6381
  * @defaultValue `false`
6463
- * @remarks If enabled, the `independentCanvasEnabled` property will be forced to be true.
6464
6382
  */ function get() {
6465
6383
  return this._enablePostProcess;
6466
6384
  },
6467
6385
  set: function set(value) {
6468
6386
  if (this._enablePostProcess !== value) {
6469
6387
  this._enablePostProcess = value;
6470
- this._checkMainCanvasAntialiasWaste();
6471
6388
  }
6472
6389
  }
6473
6390
  },
@@ -9251,6 +9168,75 @@ __decorate([
9251
9168
  deepClone
9252
9169
  ], PostProcess.prototype, "_effects", void 0);
9253
9170
 
9171
+ /**
9172
+ * @internal
9173
+ */ var PipelineUtils = /*#__PURE__*/ function() {
9174
+ function PipelineUtils() {}
9175
+ /**
9176
+ * Recreate texture if needed.
9177
+ * @param engine - Engine
9178
+ * @param currentTexture - Current texture
9179
+ * @param width - Need texture width
9180
+ * @param height - Need texture height
9181
+ * @param format - Need texture format
9182
+ * @param mipmap - Need texture mipmap
9183
+ * @param isSRGBColorSpace - Whether to use sRGB color space
9184
+ * @param textureWrapMode - Texture wrap mode
9185
+ * @param textureFilterMode - Texture filter mode
9186
+ * @returns Texture
9187
+ */ PipelineUtils.recreateTextureIfNeeded = function recreateTextureIfNeeded(engine, currentTexture, width, height, format, mipmap, isSRGBColorSpace, textureWrapMode, textureFilterMode) {
9188
+ if (currentTexture) {
9189
+ if (currentTexture.width !== width || currentTexture.height !== height || currentTexture.format !== format || currentTexture.isSRGBColorSpace !== isSRGBColorSpace || currentTexture.mipmapCount > 1 !== mipmap) {
9190
+ currentTexture.destroy(true);
9191
+ currentTexture = new Texture2D(engine, width, height, format, mipmap, isSRGBColorSpace);
9192
+ currentTexture.isGCIgnored = true;
9193
+ }
9194
+ } else {
9195
+ currentTexture = new Texture2D(engine, width, height, format, mipmap, isSRGBColorSpace);
9196
+ currentTexture.isGCIgnored = true;
9197
+ }
9198
+ currentTexture.wrapModeU = currentTexture.wrapModeV = textureWrapMode;
9199
+ currentTexture.filterMode = textureFilterMode;
9200
+ return currentTexture;
9201
+ };
9202
+ /**
9203
+ * Recreate render target if needed.
9204
+ * @param engine - Engine
9205
+ * @param currentRenderTarget - Current render target
9206
+ * @param width - Need render target width
9207
+ * @param height - Need render target height
9208
+ * @param colorFormat - Need render target color format
9209
+ * @param depthFormat - Need render target depth format
9210
+ * @param mipmap - Need render target mipmap
9211
+ * @param isSRGBColorSpace - Whether to use sRGB color space
9212
+ * @param antiAliasing - Need render target anti aliasing
9213
+ * @param textureWrapMode - Texture wrap mode
9214
+ * @param textureFilterMode - Texture filter mode
9215
+ * @returns Render target
9216
+ */ PipelineUtils.recreateRenderTargetIfNeeded = function recreateRenderTargetIfNeeded(engine, currentRenderTarget, width, height, colorFormat, depthFormat, needDepthTexture, mipmap, isSRGBColorSpace, antiAliasing, textureWrapMode, textureFilterMode) {
9217
+ var currentColorTexture = currentRenderTarget == null ? void 0 : currentRenderTarget.getColorTexture(0);
9218
+ var colorTexture = colorFormat ? PipelineUtils.recreateTextureIfNeeded(engine, currentColorTexture, width, height, colorFormat, mipmap, isSRGBColorSpace, textureWrapMode, textureFilterMode) : null;
9219
+ if (needDepthTexture) {
9220
+ var currentDepthTexture = currentRenderTarget == null ? void 0 : currentRenderTarget.depthTexture;
9221
+ var _$needDepthTexture = depthFormat ? PipelineUtils.recreateTextureIfNeeded(engine, currentDepthTexture, width, height, depthFormat, mipmap, isSRGBColorSpace, textureWrapMode, textureFilterMode) : null;
9222
+ if (currentColorTexture !== colorTexture || currentDepthTexture !== _$needDepthTexture) {
9223
+ currentRenderTarget == null ? void 0 : currentRenderTarget.destroy(true);
9224
+ currentRenderTarget = new RenderTarget(engine, width, height, colorTexture, _$needDepthTexture, antiAliasing);
9225
+ currentRenderTarget.isGCIgnored = true;
9226
+ }
9227
+ } else {
9228
+ if (currentColorTexture !== colorTexture || (currentRenderTarget == null ? void 0 : currentRenderTarget._depthFormat) !== depthFormat || currentRenderTarget.antiAliasing !== antiAliasing) {
9229
+ currentRenderTarget == null ? void 0 : currentRenderTarget.destroy(true);
9230
+ currentRenderTarget = new RenderTarget(engine, width, height, colorTexture, depthFormat, antiAliasing);
9231
+ currentRenderTarget.isGCIgnored = true;
9232
+ }
9233
+ }
9234
+ return currentRenderTarget;
9235
+ };
9236
+ return PipelineUtils;
9237
+ }();
9238
+ PipelineUtils.defaultViewport = new Vector4(0, 0, 1, 1);
9239
+
9254
9240
  var Collider = /*#__PURE__*/ function(Component) {
9255
9241
  _inherits(Collider, Component);
9256
9242
  function Collider(entity) {
@@ -14885,7 +14871,8 @@ CascadedShadowCasterPass._tempMatrix0 = new Matrix();
14885
14871
  */ _proto.render = function render(context, cubeFace, mipLevel, ignoreClear) {
14886
14872
  context.rendererUpdateFlag = ContextRendererUpdateFlag.All;
14887
14873
  var camera = this._camera;
14888
- var scene = camera.scene, engine = camera.engine, renderTarget = camera.renderTarget, independentCanvasEnabled = camera.independentCanvasEnabled;
14874
+ var scene = camera.scene, engine = camera.engine, renderTarget = camera.renderTarget;
14875
+ var independentCanvasEnabled = camera._isIndependentCanvasEnabled();
14889
14876
  var rhi = engine._hardwareRenderer;
14890
14877
  var cullingResults = this._cullingResults;
14891
14878
  var sunlight = scene._lightManager._sunlight;
@@ -14893,10 +14880,12 @@ CascadedShadowCasterPass._tempMatrix0 = new Matrix();
14893
14880
  var depthPassEnabled = camera.depthTextureMode === DepthTextureMode.PrePass && depthOnlyPass._supportDepthTexture;
14894
14881
  var finalClearFlags = camera.clearFlags & ~(ignoreClear != null ? ignoreClear : CameraClearFlags.None);
14895
14882
  var msaaSamples = renderTarget ? renderTarget.antiAliasing : camera.msaaSamples;
14883
+ // Check whether can use `blitFramebuffer` to blit internal render target, source maybe screen canvas or camera's render target
14884
+ // Our screen canvas's anti-aliasing is always disable, so blit source and dest is always same by below rules:
14896
14885
  // 1. Only support blitFramebuffer in webgl2 context
14897
14886
  // 2. Can't blit normal FBO to MSAA FBO
14898
14887
  // 3. Can't blit screen MSAA FBO to normal FBO in mac safari platform and mobile, but mac chrome and firfox is OK
14899
- this._canUseBlitFrameBuffer = rhi.isWebGL2 && msaaSamples === 1 && (!!renderTarget || !rhi.context.antialias);
14888
+ this._canUseBlitFrameBuffer = rhi.isWebGL2 && msaaSamples === 1;
14900
14889
  // Because internal render target is linear color space, so we should convert srgb background color to linear color space
14901
14890
  var isSRGBBackground = !renderTarget || renderTarget.getColorTexture(0).isSRGBColorSpace;
14902
14891
  this._shouldCopyBackgroundColor = independentCanvasEnabled && !(finalClearFlags & CameraClearFlags.Color) && (!this._canUseBlitFrameBuffer || isSRGBBackground);
@@ -14924,11 +14913,11 @@ CascadedShadowCasterPass._tempMatrix0 = new Matrix();
14924
14913
  var depthFormat;
14925
14914
  if (camera.renderTarget) {
14926
14915
  depthFormat = camera.renderTarget._depthFormat;
14927
- } else if (rhi.context.depth && rhi.context.stencil) {
14916
+ } else if (rhi._options.depth && rhi._options.stencil) {
14928
14917
  depthFormat = TextureFormat.Depth24Stencil8;
14929
- } else if (rhi.context.depth) {
14918
+ } else if (rhi._options.depth) {
14930
14919
  depthFormat = TextureFormat.Depth24;
14931
- } else if (rhi.context.stencil) {
14920
+ } else if (rhi._options.stencil) {
14932
14921
  depthFormat = TextureFormat.Stencil;
14933
14922
  } else {
14934
14923
  depthFormat = null;
@@ -14978,23 +14967,24 @@ CascadedShadowCasterPass._tempMatrix0 = new Matrix();
14978
14967
  // If color target is null, hardware will not convert linear color space to sRGB
14979
14968
  var color = colorTarget ? background._linearSolidColor : background.solidColor;
14980
14969
  finalClearFlags !== CameraClearFlags.None && rhi.clearRenderTarget(engine, finalClearFlags, color);
14981
- if (internalColorTarget && finalClearFlags !== CameraClearFlags.All) {
14982
- // Can use `blitFramebuffer` API to copy color/depth/stencil buffer from back buffer to internal RT
14983
- if (this._canUseBlitFrameBuffer) {
14984
- var blitIgnoreFlags = finalClearFlags | (this._shouldCopyBackgroundColor ? CameraClearFlags.Color : CameraClearFlags.None);
14985
- rhi.blitInternalRTByBlitFrameBuffer(camera.renderTarget, internalColorTarget, blitIgnoreFlags, camera.viewport);
14986
- } else {
14987
- if (!(finalClearFlags & CameraClearFlags.DepthStencil)) {
14988
- Logger.warn("We clear all depth/stencil state cause of the internalRT can't copy depth/stencil buffer from back buffer when use copy plan");
14970
+ if (internalColorTarget) {
14971
+ // Force clear internal color target depth and stencil buffer, because it already missed due to post process, HDR, sRGB covert, etc.
14972
+ var keepDSFlags = ~finalClearFlags & CameraClearFlags.DepthStencil;
14973
+ if (keepDSFlags) {
14974
+ rhi.clearRenderTarget(engine, keepDSFlags);
14975
+ }
14976
+ var keepColorFlag = ~finalClearFlags & CameraClearFlags.Color;
14977
+ if (keepColorFlag) {
14978
+ if (this._shouldCopyBackgroundColor) {
14979
+ // Copy RT's color buffer to grab texture
14980
+ rhi.copyRenderTargetToSubTexture(camera.renderTarget, this._copyBackgroundTexture, camera.viewport);
14981
+ // Then blit grab texture to internal RT's color buffer
14982
+ Blitter.blitTexture(engine, this._copyBackgroundTexture, internalColorTarget, 0, undefined, camera.renderTarget ? undefined : engine._basicResources.blitScreenMaterial);
14983
+ } else {
14984
+ // Only blit color buffer from back buffer
14985
+ var ignoreFlags = CameraClearFlags.DepthStencil;
14986
+ rhi.blitInternalRTByBlitFrameBuffer(camera.renderTarget, internalColorTarget, ignoreFlags, camera.viewport);
14989
14987
  }
14990
- // We must clear depth/stencil buffer manually if current context don't support `blitFramebuffer` API
14991
- rhi.clearRenderTarget(engine, CameraClearFlags.DepthStencil);
14992
- }
14993
- if (this._shouldCopyBackgroundColor) {
14994
- // Copy RT's color buffer to grab texture
14995
- rhi.copyRenderTargetToSubTexture(camera.renderTarget, this._copyBackgroundTexture, camera.viewport);
14996
- // Then blit grab texture to internal RT's color buffer
14997
- Blitter.blitTexture(engine, this._copyBackgroundTexture, internalColorTarget, 0, undefined, camera.renderTarget ? undefined : engine._basicResources.blitScreenMaterial);
14998
14988
  }
14999
14989
  context.setRenderTarget(colorTarget, colorViewport, mipLevel, cubeFace);
15000
14990
  }