Files
cocos4/cocos/rendering/post-process/passes/base-pass.ts
T
PP 509d73b27d merge branch v3.8.0-aot (#15421)
* PR1: add explicit function return type (#15311)

* PR4: add explicit function return type (#15314)

* [ci skip][AUTO]: Automated code generating update: 8843bfe54cd3f8e6f84432948716c8d130ecb233  (#15314) (#15357)

Co-authored-by: cocos-robot <cocos-robot@cocos.com>

* add function return type

* fix version checking

* fix return type

---------

Co-authored-by: Cocos Robot <48829427+cocos-robot@users.noreply.github.com>
Co-authored-by: cocos-robot <cocos-robot@cocos.com>
2023-06-13 18:08:45 +08:00

103 lines
3.4 KiB
TypeScript

import { EDITOR } from 'internal:constants';
import { Material } from '../../../asset/assets';
import { Camera } from '../../../render-scene/scene';
import { getCameraUniqueID } from '../../custom/define';
import { BasicPipeline, Pipeline, PipelineRuntime } from '../../custom/pipeline';
import { passContext } from '../utils/pass-context';
import { Format } from '../../../gfx';
import { supportsRGBA16HalfFloatTexture } from '../../define';
import { cclegacy, macro } from '../../../core';
let _BasePassID = 0;
export function getRTFormatBeforeToneMapping (ppl: BasicPipeline): Format {
const useFloatOutput = ppl.getMacroBool('CC_USE_FLOAT_OUTPUT');
return ppl.pipelineSceneData.isHDR && useFloatOutput && supportsRGBA16HalfFloatTexture(ppl.device) ? Format.RGBA16F : Format.RGBA8;
}
export function forceEnableFloatOutput (ppl: PipelineRuntime): boolean {
let enabled = ppl.getMacroBool('CC_USE_FLOAT_OUTPUT');
if (ppl.pipelineSceneData.isHDR && !enabled) {
const supportFloatOutput = supportsRGBA16HalfFloatTexture(ppl.device);
ppl.setMacroBool('CC_USE_FLOAT_OUTPUT', supportFloatOutput);
macro.ENABLE_FLOAT_OUTPUT = supportFloatOutput;
enabled = supportFloatOutput;
}
return enabled;
}
export function disablePostProcessForDebugView (): boolean {
const debugView = cclegacy.director.root.debugView;
return debugView.singleMode as number > 0;
}
export abstract class BasePass {
abstract name: string;
effectName = 'pipeline/post-process/blit-screen';
_id = 0
constructor () {
this._id = _BasePassID++;
}
context = passContext;
getCameraUniqueID = getCameraUniqueID;
// private _materialMap: Map<Camera, Material> = new Map()
_material: Material | undefined
get material (): Material {
const effectReloaded = false;
// if (EDITOR && this._material) {
// const effect = builtinResMgr.get(this.effectName);
// effectReloaded = effect && this._material.effectAsset !== effect;
// }
if (!this._material || effectReloaded) {
const mat = new Material();
mat._uuid = `${this.name}-${this.effectName}-material`;
mat.initialize({ effectName: this.effectName });
this._material = mat;
}
let material: Material | undefined;
// if (EDITOR) {
// if (passUtils.camera) {
// material = this._materialMap.get(passUtils.camera);
// if (!material || material.parent !== this._material) {
// material = new MaterialInstance({
// parent: this._material,
// });
// this._materialMap.set(passUtils.camera, material);
// }
// }
// }
return material || this._material;
}
enable = true;
outputNames: string[] = []
lastPass: BasePass | undefined;
slotName (camera: Camera, index = 0): string {
const name = this.outputNames[index] + this.name;
return `${name}_${this._id}_${getCameraUniqueID(camera)}`;
}
enableInAllEditorCamera = false;
checkEnable (camera: Camera): boolean {
return this.enable;
}
renderProfiler (camera): void {
if (passContext.isFinalCamera && !EDITOR) {
passContext.pass!.showStatistics = true;
}
}
abstract render (camera: Camera, ppl: Pipeline): any;
}