Skip to content

Commit

Permalink
fix: adjust clear flag of internal render target
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuxudong committed Nov 21, 2024
1 parent f9fc2c6 commit e252e1b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
5 changes: 4 additions & 1 deletion packages/core/src/RenderPipeline/BasicRenderPipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@ export class BasicRenderPipeline {
rhi.activeRenderTarget(colorTarget, colorViewport, context.flipProjection, mipLevel, cubeFace);
const clearFlags = camera.clearFlags & ~(ignoreClear ?? CameraClearFlags.None);
const color = background.solidColor;
if (clearFlags !== CameraClearFlags.None) {

if (internalColorTarget) {
rhi.clearRenderTarget(camera.engine, CameraClearFlags.All, color);

Check warning on line 169 in packages/core/src/RenderPipeline/BasicRenderPipeline.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/RenderPipeline/BasicRenderPipeline.ts#L169

Added line #L169 was not covered by tests
} else if (clearFlags !== CameraClearFlags.None) {
rhi.clearRenderTarget(camera.engine, clearFlags, color);
}

Expand Down
15 changes: 14 additions & 1 deletion packages/core/src/postProcess/PostProcessManager.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { PipelineUtils } from "../RenderPipeline/PipelineUtils";
import { RenderContext } from "../RenderPipeline/RenderContext";
import { Scene } from "../Scene";
import { CameraClearFlags } from "../enums/CameraClearFlags";
import { Material } from "../material";
import { Shader } from "../shader";
import { BlendFactor, BlendOperation, Shader } from "../shader";
import { RenderTarget, Texture2D } from "../texture";
import { BloomEffect, TonemappingEffect } from "./effects";

Expand Down Expand Up @@ -39,6 +40,14 @@ export class _PostProcessManager {
const uberShader = Shader.find(_PostProcessManager.UBER_SHADER_NAME);
const uberMaterial = new Material(scene.engine, uberShader);
const depthState = uberMaterial.renderState.depthState;
const blendState = uberMaterial.renderState.blendState.targetBlendState;

blendState.enabled = true;
blendState.sourceColorBlendFactor = BlendFactor.SourceAlpha;
blendState.destinationColorBlendFactor = BlendFactor.OneMinusSourceAlpha;
blendState.sourceAlphaBlendFactor = BlendFactor.One;
blendState.destinationAlphaBlendFactor = BlendFactor.OneMinusSourceAlpha;
blendState.colorBlendOperation = blendState.alphaBlendOperation = BlendOperation.Add;

depthState.enabled = false;
depthState.writeEnabled = false;
Expand Down Expand Up @@ -67,6 +76,10 @@ export class _PostProcessManager {
bloomEffect.onRender(context, srcTexture);
}

this._uberMaterial.renderState.blendState.targetBlendState.enabled = !(

Check warning on line 79 in packages/core/src/postProcess/PostProcessManager.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/postProcess/PostProcessManager.ts#L79

Added line #L79 was not covered by tests
context.camera.clearFlags & CameraClearFlags.Color
);

// Done with Uber, blit it
PipelineUtils.blitTexture(engine, srcTexture, destTarget, 0, camera.viewport, this._uberMaterial);
}
Expand Down

0 comments on commit e252e1b

Please sign in to comment.