From a604139b5b251c5f2671b2d118576566629234b8 Mon Sep 17 00:00:00 2001 From: 2youyou2 <501251991@qq.com> Date: Wed, 28 Jun 2023 15:35:36 +0800 Subject: [PATCH] refine post process --- cocos/misc/camera-component.ts | 2 ++ .../post-process/components/blit-screen.ts | 15 +++++++++++ .../rendering/post-process/components/fsr.ts | 7 ++--- .../post-process/components/post-process.ts | 5 +++- .../rendering/post-process/components/taa.ts | 27 ++++++++++++++++--- .../rendering/post-process/passes/fsr-pass.ts | 4 +-- editor/i18n/en/localization.js | 14 ++++++++++ editor/i18n/zh/localization.js | 14 ++++++++++ 8 files changed, 79 insertions(+), 9 deletions(-) diff --git a/cocos/misc/camera-component.ts b/cocos/misc/camera-component.ts index 9fb15a769ba..05a22be16e4 100644 --- a/cocos/misc/camera-component.ts +++ b/cocos/misc/camera-component.ts @@ -490,6 +490,7 @@ export class Camera extends Component { this.node.emit(Camera.TARGET_TEXTURE_CHANGE, this); } + @tooltip('i18n:camera.use_postprocess') @property get usePostProcess () { return this._usePostProcess; @@ -501,6 +502,7 @@ export class Camera extends Component { } } + @tooltip('i18n:camera.postprocess') @type(PostProcess) get postProcess () { return this._postProcess; diff --git a/cocos/rendering/post-process/components/blit-screen.ts b/cocos/rendering/post-process/components/blit-screen.ts index d46b2a0ac21..abc7230c4f9 100644 --- a/cocos/rendering/post-process/components/blit-screen.ts +++ b/cocos/rendering/post-process/components/blit-screen.ts @@ -1,3 +1,4 @@ +import { EDITOR } from 'internal:constants'; import { Material } from '../../../asset/assets'; import { property } from '../../../core/data/class-decorator'; import { ccclass, disallowMultiple, executeInEditMode, menu } from '../../../core/data/decorators'; @@ -33,6 +34,15 @@ export class BlitScreen extends PostProcessSetting { } set activeMaterials (v) { this._activeMaterials = v; + for (let i = 0; i < this._materials.length; i++) { + for (let j = 0; j < v.length; j++) { + if (this._materials[i] && v[j]) { + if (this._materials[i].material?.uuid === v[j].uuid) { + this._materials[i].material = v[j]; + } + } + } + } } @property(BlitScreenMaterial) @@ -44,6 +54,11 @@ export class BlitScreen extends PostProcessSetting { } set materials (v) { this._materials = v; + if (EDITOR) { + setTimeout(() => { + globalThis.cce.Engine.repaintInEditMode(); + }, 50); + } this.updateActiveMateirals(); } diff --git a/cocos/rendering/post-process/components/fsr.ts b/cocos/rendering/post-process/components/fsr.ts index d879e73bb58..fe97b54a764 100644 --- a/cocos/rendering/post-process/components/fsr.ts +++ b/cocos/rendering/post-process/components/fsr.ts @@ -1,6 +1,6 @@ import { CCFloat } from '../../../core'; import { type } from '../../../core/data/class-decorator'; -import { ccclass, disallowMultiple, executeInEditMode, menu, range, serializable, slide } from '../../../core/data/decorators'; +import { ccclass, disallowMultiple, executeInEditMode, menu, range, serializable, slide, tooltip } from '../../../core/data/decorators'; import { PostProcessSetting } from './post-process-setting'; @ccclass('cc.FSR') @@ -9,10 +9,11 @@ import { PostProcessSetting } from './post-process-setting'; @executeInEditMode export class FSR extends PostProcessSetting { @serializable - _sharpness = 0.2 + _sharpness = 0.8 + @tooltip('i18n:fsr.sharpness') @slide - @range([0.05, 1, 0.01]) + @range([0.0, 1, 0.01]) @type(CCFloat) get sharpness () { return this._sharpness; diff --git a/cocos/rendering/post-process/components/post-process.ts b/cocos/rendering/post-process/components/post-process.ts index 9c322c165b9..898235cc0b1 100644 --- a/cocos/rendering/post-process/components/post-process.ts +++ b/cocos/rendering/post-process/components/post-process.ts @@ -1,6 +1,6 @@ import { EDITOR } from 'internal:constants'; import { property } from '../../../core/data/class-decorator'; -import { ccclass, disallowMultiple, executeInEditMode, range, slide } from '../../../core/data/decorators'; +import { ccclass, disallowMultiple, executeInEditMode, range, slide, tooltip } from '../../../core/data/decorators'; import { Director, director } from '../../../game'; import { Component } from '../../../scene-graph'; import { PostProcessSetting } from './post-process-setting'; @@ -11,11 +11,13 @@ import { PostProcessSetting } from './post-process-setting'; export class PostProcess extends Component { static all: PostProcess[] = [] + @tooltip('i18n:postprocess.global') @property global = true; @property _shadingScale = 1 + @tooltip('i18n:postprocess.shadingScale') @slide @range([0.01, 1, 0.01]) @property @@ -31,6 +33,7 @@ export class PostProcess extends Component { } } + @tooltip('i18n:postprocess.enableShadingScaleInEditor') @property enableShadingScaleInEditor = false; diff --git a/cocos/rendering/post-process/components/taa.ts b/cocos/rendering/post-process/components/taa.ts index 68e5c135507..6d8d03c4fee 100644 --- a/cocos/rendering/post-process/components/taa.ts +++ b/cocos/rendering/post-process/components/taa.ts @@ -1,5 +1,5 @@ import { property } from '../../../core/data/class-decorator'; -import { ccclass, disallowMultiple, executeInEditMode, menu } from '../../../core/data/decorators'; +import { ccclass, disallowMultiple, executeInEditMode, menu, range, slide, tooltip } from '../../../core/data/decorators'; import { PostProcessSetting } from './post-process-setting'; @ccclass('cc.TAA') @@ -8,8 +8,29 @@ import { PostProcessSetting } from './post-process-setting'; @executeInEditMode export class TAA extends PostProcessSetting { @property - sampleScale = 1 + _sampleScale = 1 + @tooltip('i18n:taa.sampleScale') + @slide + @range([0.01, 5, 0.01]) @property - feedback = 0.95 + get sampleScale () { + return this._sampleScale; + } + set sampleScale (v) { + this._sampleScale = v; + } + + @property + _feedback = 0.95 + @tooltip('i18n:taa.feedback') + @slide + @range([0.0, 1, 0.01]) + @property + get feedback () { + return this._feedback; + } + set feedback (v) { + this._feedback = v; + } } diff --git a/cocos/rendering/post-process/passes/fsr-pass.ts b/cocos/rendering/post-process/passes/fsr-pass.ts index 38ce42f6cc1..1d271d8366a 100644 --- a/cocos/rendering/post-process/passes/fsr-pass.ts +++ b/cocos/rendering/post-process/passes/fsr-pass.ts @@ -1,5 +1,5 @@ import { EDITOR } from 'internal:constants'; -import { Vec4 } from '../../../core'; +import { clamp, Vec4 } from '../../../core'; import { Format } from '../../../gfx'; import { Camera, CameraUsage } from '../../../render-scene/scene'; import { Pipeline } from '../../custom/pipeline'; @@ -39,7 +39,7 @@ export class FSRPass extends SettingPass { const outHeight = Math.floor(game.canvas!.height); const setting = this.setting; - this.material.setProperty('fsrParams', new Vec4(setting.sharpness, 0, 0, 0)); + this.material.setProperty('fsrParams', new Vec4(clamp(1.0 - setting.sharpness, 0.02, 0.98), 0, 0, 0)); this.material.setProperty('texSize', new Vec4( inputWidth, inputHeight, diff --git a/editor/i18n/en/localization.js b/editor/i18n/en/localization.js index 42ccf6de8a3..2e52d65bc4e 100755 --- a/editor/i18n/en/localization.js +++ b/editor/i18n/en/localization.js @@ -251,6 +251,8 @@ module.exports = link(mixin({ ISO: 'Camera ISO, controls the exposure parameter', rect: 'The size of the viewport that this camera will eventually render to the screen.', target_texture: 'Output render texture of the camera. Default to null, which outputs directly to screen', + use_postprocess: 'Whether this camera should use post process.', + postprocess: 'If camera post process is not specified, will use the global post process.', }, lights: { color: 'Color of the light', @@ -1279,6 +1281,18 @@ module.exports = link(mixin({ color_grading: { originalMap: 'Support arbitary LUT for Nx1 blocks or 8x8 blocks automatically. The builtin lut texture path is internal/dependencies/textures/lut/.', }, + taa: { + sampleScale: 'TAA sample range.', + feedback: 'History frame blend value.', + }, + fsr: { + sharpness: 'Sharpness', + }, + postprocess: { + global: 'Whether the post process is enabled for all post process camera.', + shadingScale: 'Rendering resolution.', + enableShadingScaleInEditor: 'Enable Shading Scale In Editor', + }, }, require('./animation'), diff --git a/editor/i18n/zh/localization.js b/editor/i18n/zh/localization.js index b11066b5c5e..23581d1a5ab 100755 --- a/editor/i18n/zh/localization.js +++ b/editor/i18n/zh/localization.js @@ -248,6 +248,8 @@ module.exports = link(mixin({ ISO: '相机感光度,影响相机的曝光参数', rect: '此相机最终渲染到屏幕上的视口位置和大小', target_texture: '指定此相机的渲染输出目标贴图,默认为空,直接渲染到屏幕', + use_postprocess: '此相机是否需要使用后效。', + postprocess: '如果后效没有被指定,将使用全局后效。', }, lights: { color: '光源颜色', @@ -1260,6 +1262,18 @@ module.exports = link(mixin({ color_grading: { originalMap: '支持任意Nx1的长条图和8x8的方块图,系统自动适配。内置lut贴图路径internal/dependencies/textures/lut/', }, + taa: { + sampleScale: 'TAA 采样范围。', + feedback: '历史帧混合值。', + }, + fsr: { + sharpness: '画面锐化度', + }, + postprocess: { + global: '是否对所有后效摄像机开启此后效流程', + shadingScale: '渲染分辨率', + enableShadingScaleInEditor: '是否在编辑器中缩放渲染分辨率', + }, }, require('./animation'),