From d97f2085f1549a27ea60377581958d54c7273f0e Mon Sep 17 00:00:00 2001 From: GengineJS <476393671@qq.com> Date: Wed, 13 Nov 2024 15:15:52 +0800 Subject: [PATCH] Fixed a bug with dof under vulkan back end --- cocos/render-scene/scene/camera.ts | 10 ---------- .../assets/default_renderpipeline/builtin-pipeline.ts | 2 +- .../assets/effects/pipeline/post-process/dof1.effect | 5 ++++- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/cocos/render-scene/scene/camera.ts b/cocos/render-scene/scene/camera.ts index 8a29b406809..eff16e74171 100644 --- a/cocos/render-scene/scene/camera.ts +++ b/cocos/render-scene/scene/camera.ts @@ -767,14 +767,6 @@ export class Camera { return this._matView$; } - /** - * @en The inverse of the view matrix of the camera - * @zh 相机的逆视图矩阵 - */ - get matViewInv (): Mat4 { - return this._matViewInv$; - } - /** * @en The projection matrix of the camera * @zh 相机的投影矩阵 @@ -843,7 +835,6 @@ export class Camera { private _curTransform$ = SurfaceTransform.IDENTITY; private _isProjDirty$ = true; private _matView$: Mat4 = mat4(); - private _matViewInv$: Mat4 = mat4(); private _matProj$: Mat4 = mat4(); private _matProjInv$: Mat4 = mat4(); private _matViewProj$: Mat4 = mat4(); @@ -1030,7 +1021,6 @@ export class Camera { this._forward$.z = -this._matView$.m10; // Remove scale Mat4.multiply(this._matView$, new Mat4().scale(this._node$.worldScale), this._matView$); - Mat4.invert(this._matViewInv$, this._matView$); this._node$.getWorldPosition(this._position$); viewProjDirty = true; } diff --git a/editor/assets/default_renderpipeline/builtin-pipeline.ts b/editor/assets/default_renderpipeline/builtin-pipeline.ts index f08ee3e228e..d0b92895f49 100644 --- a/editor/assets/default_renderpipeline/builtin-pipeline.ts +++ b/editor/assets/default_renderpipeline/builtin-pipeline.ts @@ -1064,7 +1064,7 @@ if (rendering) { cocPass.setVec4('g_platform', this._configs.platform); cocPass.setMat4('proj', camera.matProj); cocPass.setMat4('invProj', camera.matProjInv); - cocPass.setMat4('viewMatInv', camera.matViewInv); + cocPass.setMat4('viewMatInv', camera.node.worldMatrix); cocPass.setVec4('cocParams', this._cocParams); cocPass.setVec4('focus', this._focusPos); cocPass diff --git a/editor/assets/effects/pipeline/post-process/dof1.effect b/editor/assets/effects/pipeline/post-process/dof1.effect index f69b89b5e89..33bbcfc4b0f 100644 --- a/editor/assets/effects/pipeline/post-process/dof1.effect +++ b/editor/assets/effects/pipeline/post-process/dof1.effect @@ -86,7 +86,10 @@ uniform DofCocUBO { void main() { vec4 blurPixel = texture(colorTex, v_uv); vec4 screenPixel = texture(screenTex, v_uv); - float depth = GetDepthFromTex(v_uv) * 2.0 - 1.0; + float depth = GetDepthFromTex(v_uv); + #if __VERSION__ < 450 + depth = 2.0 * depth - 1.0; + #endif vec4 screenPos = vec4(v_uv.x * 2.0 - 1.0, v_uv.y * 2.0 - 1.0, depth, 1.0); vec4 viewPos = invProj * screenPos; viewPos /= viewPos.w;