mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-06 19:42:39 +08:00
fix web-pipeline ui in post-processing (#14145)
This commit is contained in:
@@ -23,9 +23,11 @@
|
||||
*/
|
||||
|
||||
import { EDITOR } from 'internal:constants';
|
||||
import { Camera } from '../../render-scene/scene';
|
||||
import { Camera, CameraUsage } from '../../render-scene/scene';
|
||||
import { Pipeline, PipelineBuilder } from './pipeline';
|
||||
import { buildForwardPass, buildGBufferPass, buildLightingPass, buildPostprocessPass, buildReflectionProbePasss } from './define';
|
||||
import { buildForwardPass, buildGBufferPass, buildLightingPass, buildPostprocessPass, buildProfilerPass,
|
||||
buildReflectionProbePasss, buildUIAndProfilerPass } from './define';
|
||||
import { isUICamera } from './utils';
|
||||
|
||||
export class ForwardPipelineBuilder implements PipelineBuilder {
|
||||
public setup (cameras: Camera[], ppl: Pipeline): void {
|
||||
@@ -50,16 +52,25 @@ export class DeferredPipelineBuilder implements PipelineBuilder {
|
||||
if (!camera.scene) {
|
||||
continue;
|
||||
}
|
||||
if (EDITOR) {
|
||||
const isGameView = camera.cameraUsage === CameraUsage.GAME
|
||||
|| camera.cameraUsage === CameraUsage.GAME_VIEW;
|
||||
if (!isGameView) {
|
||||
buildForwardPass(camera, ppl, false);
|
||||
continue;
|
||||
}
|
||||
if (!isUICamera(camera)) {
|
||||
// GBuffer Pass
|
||||
const gBufferInfo = buildGBufferPass(camera, ppl);
|
||||
// Lighting Pass
|
||||
const lightInfo = buildLightingPass(camera, ppl, gBufferInfo);
|
||||
// Postprocess
|
||||
buildPostprocessPass(camera, ppl, lightInfo.rtName);
|
||||
const gBufferInfo = buildGBufferPass(camera, ppl);
|
||||
// Lighting Pass
|
||||
const lightInfo = buildLightingPass(camera, ppl, gBufferInfo);
|
||||
// Postprocess
|
||||
buildPostprocessPass(camera, ppl, lightInfo.rtName);
|
||||
// Profiler
|
||||
buildProfilerPass(camera, ppl);
|
||||
continue;
|
||||
}
|
||||
// render ui and profiler
|
||||
buildUIAndProfilerPass(camera, ppl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,8 +24,10 @@
|
||||
|
||||
import { Camera, CameraUsage } from '../../render-scene/scene';
|
||||
import { buildFxaaPass, buildBloomPass as buildBloomPasses, buildForwardPass,
|
||||
buildNativeDeferredPipeline, buildNativeForwardPass, buildPostprocessPass, AntiAliasing } from './define';
|
||||
buildNativeDeferredPipeline, buildNativeForwardPass, buildPostprocessPass,
|
||||
AntiAliasing, buildUIAndProfilerPass, buildProfilerPass } from './define';
|
||||
import { Pipeline, PipelineBuilder } from './pipeline';
|
||||
import { isUICamera } from './utils';
|
||||
|
||||
export class CustomPipelineBuilder implements PipelineBuilder {
|
||||
public setup (cameras: Camera[], ppl: Pipeline): void {
|
||||
@@ -36,17 +38,27 @@ export class CustomPipelineBuilder implements PipelineBuilder {
|
||||
}
|
||||
const isGameView = camera.cameraUsage === CameraUsage.GAME
|
||||
|| camera.cameraUsage === CameraUsage.GAME_VIEW;
|
||||
// forward pass
|
||||
const forwardInfo = buildForwardPass(camera, ppl, isGameView);
|
||||
if (!isGameView) {
|
||||
// forward pass
|
||||
buildForwardPass(camera, ppl, isGameView);
|
||||
continue;
|
||||
}
|
||||
// fxaa pass
|
||||
const fxaaInfo = buildFxaaPass(camera, ppl, forwardInfo.rtName);
|
||||
// bloom passes
|
||||
const bloomInfo = buildBloomPasses(camera, ppl, fxaaInfo.rtName);
|
||||
// Present Pass
|
||||
buildPostprocessPass(camera, ppl, bloomInfo.rtName, AntiAliasing.NONE);
|
||||
// TODO: There is currently no effective way to judge the ui camera. Let’s do this first.
|
||||
if (!isUICamera(camera)) {
|
||||
// forward pass
|
||||
const forwardInfo = buildForwardPass(camera, ppl, isGameView);
|
||||
// fxaa pass
|
||||
const fxaaInfo = buildFxaaPass(camera, ppl, forwardInfo.rtName);
|
||||
// bloom passes
|
||||
const bloomInfo = buildBloomPasses(camera, ppl, fxaaInfo.rtName);
|
||||
// Present Pass
|
||||
buildPostprocessPass(camera, ppl, bloomInfo.rtName, AntiAliasing.NONE);
|
||||
// Profiler
|
||||
buildProfilerPass(camera, ppl);
|
||||
continue;
|
||||
}
|
||||
// render ui and profiler
|
||||
buildUIAndProfilerPass(camera, ppl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -519,7 +519,7 @@ export function buildPostprocessPass (camera: Camera,
|
||||
postInfo.postMaterial, 0, SceneFlags.NONE,
|
||||
);
|
||||
postprocessPass.addQueue(QueueHint.RENDER_TRANSPARENT).addSceneOfCamera(camera, new LightInfo(),
|
||||
SceneFlags.UI | SceneFlags.PROFILER);
|
||||
SceneFlags.UI);
|
||||
return { rtName: postprocessPassRTName, dsName: postprocessPassDS };
|
||||
}
|
||||
|
||||
@@ -917,8 +917,8 @@ export function buildLightingPass (camera: Camera, ppl: Pipeline, gBuffer: GBuff
|
||||
camera, lightingInfo.deferredLightingMaterial, 0,
|
||||
SceneFlags.VOLUMETRIC_LIGHTING,
|
||||
);
|
||||
// lightingPass.addQueue(QueueHint.RENDER_TRANSPARENT).addSceneOfCamera(camera, new LightInfo(),
|
||||
// SceneFlags.TRANSPARENT_OBJECT | SceneFlags.PLANAR_SHADOW | SceneFlags.GEOMETRY);
|
||||
lightingPass.addQueue(QueueHint.RENDER_TRANSPARENT).addSceneOfCamera(camera, new LightInfo(),
|
||||
SceneFlags.TRANSPARENT_OBJECT | SceneFlags.PLANAR_SHADOW | SceneFlags.GEOMETRY);
|
||||
return { rtName: deferredLightingPassRTName, dsName: deferredLightingPassDS };
|
||||
}
|
||||
|
||||
@@ -944,6 +944,84 @@ function getClearFlags (attachment: AttachmentType, clearFlag: ClearFlagBit, loa
|
||||
}
|
||||
}
|
||||
|
||||
export function buildProfilerPass (camera: Camera,
|
||||
ppl: Pipeline) {
|
||||
const cameraID = getCameraUniqueID(camera);
|
||||
const cameraName = `Camera${cameraID}`;
|
||||
const area = getRenderArea(camera, camera.window.width, camera.window.height);
|
||||
const width = area.width;
|
||||
const height = area.height;
|
||||
|
||||
const dsProfilerPassRTName = `dsProfilerPassColor${cameraName}`;
|
||||
const dsProfilerPassDSName = `dsProfilerPassDS${cameraName}`;
|
||||
if (!ppl.containsResource(dsProfilerPassRTName)) {
|
||||
ppl.addRenderTexture(dsProfilerPassRTName, Format.BGRA8, width, height, camera.window);
|
||||
ppl.addDepthStencil(dsProfilerPassDSName, Format.DEPTH_STENCIL, width, height, ResourceResidency.MANAGED);
|
||||
}
|
||||
ppl.updateRenderWindow(dsProfilerPassRTName, camera.window);
|
||||
ppl.updateDepthStencil(dsProfilerPassDSName, width, height);
|
||||
const ProfilerPass = ppl.addRasterPass(width, height, 'default');
|
||||
ProfilerPass.name = `CameraProfilerPass${cameraID}`;
|
||||
ProfilerPass.setViewport(new Viewport(area.x, area.y, width, height));
|
||||
const passView = new RasterView('_',
|
||||
AccessType.WRITE, AttachmentType.RENDER_TARGET,
|
||||
getLoadOpOfClearFlag(ClearFlagBit.DEPTH_STENCIL, AttachmentType.RENDER_TARGET),
|
||||
StoreOp.STORE,
|
||||
ClearFlagBit.DEPTH_STENCIL,
|
||||
new Color(camera.clearColor.x, camera.clearColor.y, camera.clearColor.z, camera.clearColor.w));
|
||||
const passDSView = new RasterView('_',
|
||||
AccessType.WRITE, AttachmentType.DEPTH_STENCIL,
|
||||
getLoadOpOfClearFlag(ClearFlagBit.DEPTH_STENCIL, AttachmentType.DEPTH_STENCIL),
|
||||
StoreOp.STORE,
|
||||
ClearFlagBit.DEPTH_STENCIL,
|
||||
new Color(camera.clearDepth, camera.clearStencil, 0, 0));
|
||||
ProfilerPass.addRasterView(dsProfilerPassRTName, passView);
|
||||
ProfilerPass.addRasterView(dsProfilerPassDSName, passDSView);
|
||||
const sceneFlags = SceneFlags.PROFILER;
|
||||
ProfilerPass
|
||||
.addQueue(QueueHint.RENDER_TRANSPARENT)
|
||||
.addSceneOfCamera(camera, new LightInfo(), sceneFlags);
|
||||
}
|
||||
|
||||
export function buildUIAndProfilerPass (camera: Camera,
|
||||
ppl: Pipeline) {
|
||||
const cameraID = getCameraUniqueID(camera);
|
||||
const cameraName = `Camera${cameraID}`;
|
||||
const area = getRenderArea(camera, camera.window.width, camera.window.height);
|
||||
const width = area.width;
|
||||
const height = area.height;
|
||||
|
||||
const dsUIAndProfilerPassRTName = `dsUIAndProfilerPassColor${cameraName}`;
|
||||
const dsUIAndProfilerPassDSName = `dsUIAndProfilerPassDS${cameraName}`;
|
||||
if (!ppl.containsResource(dsUIAndProfilerPassRTName)) {
|
||||
ppl.addRenderTexture(dsUIAndProfilerPassRTName, Format.BGRA8, width, height, camera.window);
|
||||
ppl.addDepthStencil(dsUIAndProfilerPassDSName, Format.DEPTH_STENCIL, width, height, ResourceResidency.MANAGED);
|
||||
}
|
||||
ppl.updateRenderWindow(dsUIAndProfilerPassRTName, camera.window);
|
||||
ppl.updateDepthStencil(dsUIAndProfilerPassDSName, width, height);
|
||||
const uIAndProfilerPass = ppl.addRasterPass(width, height, 'default');
|
||||
uIAndProfilerPass.name = `CameraUIAndProfilerPass${cameraID}`;
|
||||
uIAndProfilerPass.setViewport(new Viewport(area.x, area.y, width, height));
|
||||
const passView = new RasterView('_',
|
||||
AccessType.WRITE, AttachmentType.RENDER_TARGET,
|
||||
getLoadOpOfClearFlag(camera.clearFlag, AttachmentType.RENDER_TARGET),
|
||||
StoreOp.STORE,
|
||||
camera.clearFlag,
|
||||
new Color(camera.clearColor.x, camera.clearColor.y, camera.clearColor.z, camera.clearColor.w));
|
||||
const passDSView = new RasterView('_',
|
||||
AccessType.WRITE, AttachmentType.DEPTH_STENCIL,
|
||||
getLoadOpOfClearFlag(camera.clearFlag, AttachmentType.DEPTH_STENCIL),
|
||||
StoreOp.STORE,
|
||||
camera.clearFlag,
|
||||
new Color(camera.clearDepth, camera.clearStencil, 0, 0));
|
||||
uIAndProfilerPass.addRasterView(dsUIAndProfilerPassRTName, passView);
|
||||
uIAndProfilerPass.addRasterView(dsUIAndProfilerPassDSName, passDSView);
|
||||
const sceneFlags = SceneFlags.UI | SceneFlags.PROFILER;
|
||||
uIAndProfilerPass
|
||||
.addQueue(QueueHint.RENDER_TRANSPARENT)
|
||||
.addSceneOfCamera(camera, new LightInfo(), sceneFlags);
|
||||
}
|
||||
|
||||
export function buildNativeForwardPass (camera: Camera, ppl: Pipeline) {
|
||||
const cameraID = getCameraUniqueID(camera);
|
||||
const cameraName = `Camera${cameraID}`;
|
||||
|
||||
@@ -104,6 +104,7 @@ export interface RasterPassBuilder extends Setter {
|
||||
addQueue (/*QueueHint.NONE*/): RasterQueueBuilder;
|
||||
setViewport (viewport: Viewport): void;
|
||||
setVersion (name: string, version: number): void;
|
||||
showStatistics: boolean;
|
||||
}
|
||||
|
||||
export interface ComputeQueueBuilder extends Setter {
|
||||
|
||||
@@ -1026,6 +1026,7 @@ export class RasterPass {
|
||||
readonly viewport: Viewport = new Viewport();
|
||||
versionName = '';
|
||||
version = 0;
|
||||
showStatistics = false;
|
||||
}
|
||||
|
||||
export class ComputePass {
|
||||
|
||||
@@ -25,6 +25,19 @@
|
||||
// https://stackoverflow.com/questions/56714318/how-to-disable-multiple-rules-for-eslint-nextline?msclkid=5d4c2298ba7911eca34d0ab30591752e
|
||||
|
||||
import { Type } from '../../gfx';
|
||||
import { Camera } from '../../render-scene/scene/camera';
|
||||
|
||||
export function isUICamera (camera: Camera): boolean {
|
||||
const scene = camera.scene!;
|
||||
const batches = scene.batches;
|
||||
for (let i = 0; i < batches.length; i++) {
|
||||
const batch = batches[i];
|
||||
if (camera.visibility & batch.visFlags) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export function replacer (key: unknown, value: unknown) {
|
||||
|
||||
@@ -721,6 +721,12 @@ export class WebRasterPassBuilder extends WebSetter implements RasterPassBuilder
|
||||
setViewport (viewport: Viewport): void {
|
||||
this._pass.viewport.copy(viewport);
|
||||
}
|
||||
get showStatistics (): boolean {
|
||||
return this._pass.showStatistics;
|
||||
}
|
||||
set showStatistics (enable: boolean) {
|
||||
this._pass.showStatistics = enable;
|
||||
}
|
||||
private readonly _renderGraph: RenderGraph;
|
||||
private readonly _vertID: number;
|
||||
private readonly _layoutID: number;
|
||||
|
||||
@@ -77,9 +77,6 @@ export function decideProfilerCamera (cameras: Camera[]) {
|
||||
}
|
||||
|
||||
export function renderProfiler (device: Device, renderPass: RenderPass, cmdBuff: CommandBuffer, profiler: Model | null, camera: Camera) {
|
||||
if (isEnableEffect()) {
|
||||
return;
|
||||
}
|
||||
if (!profiler || !profiler.enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user