Skip to content

Commit

Permalink
Fixed a bug with dof under vulkan back end (#17847)
Browse files Browse the repository at this point in the history
  • Loading branch information
GengineJS authored Nov 13, 2024
1 parent c8c1c31 commit 459f0d3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
10 changes: 0 additions & 10 deletions cocos/render-scene/scene/camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 相机的投影矩阵
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion editor/assets/default_renderpipeline/builtin-pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion editor/assets/effects/pipeline/post-process/dof1.effect
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 459f0d3

Please sign in to comment.