Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix clear flag of internal render target #2444

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/core/src/BasicResources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { MeshTopology } from "./graphic/enums/MeshTopology";
import { VertexElementFormat } from "./graphic/enums/VertexElementFormat";
import { Material } from "./material";
import { ModelMesh } from "./mesh";
import { BlendFactor, BlendOperation } from "./shader";
import { Shader } from "./shader/Shader";
import { Texture, Texture2D, TextureCube, TextureCubeFace } from "./texture";
import { Texture2DArray } from "./texture/Texture2DArray";
Expand Down Expand Up @@ -46,6 +47,14 @@ export class BasicResources {
blitMaterial._addReferCount(1);
blitMaterial.renderState.depthState.enabled = false;
blitMaterial.renderState.depthState.writeEnabled = false;
const blendState = blitMaterial.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;

this.blitMesh = this._createBlitMesh(engine, vertices);
this.flipYBlitMesh = this._createBlitMesh(engine, flipYVertices);
Expand Down
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 @@
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
6 changes: 6 additions & 0 deletions packages/core/src/RenderPipeline/PipelineUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Vector4 } from "@galacean/engine-math";
import { Engine } from "../Engine";
import { CameraClearFlags } from "../enums/CameraClearFlags";
import { Material } from "../material";
import { ShaderProperty } from "../shader";
import { Shader } from "../shader/Shader";
Expand Down Expand Up @@ -194,6 +195,11 @@
program.uploadAll(program.materialUniformBlock, blitMaterial.shaderData);
program.uploadUnGroupTextures();

if (!material) {
blitMaterial.renderState.blendState.targetBlendState.enabled = !(

Check warning on line 199 in packages/core/src/RenderPipeline/PipelineUtils.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/RenderPipeline/PipelineUtils.ts#L199

Added line #L199 was not covered by tests
context.camera.clearFlags & CameraClearFlags.Color
);
}
(pass._renderState || blitMaterial.renderState)._applyStates(
engine,
false,
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 @@
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 @@
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
Loading