Skip to content

#8833 fix: ensure dof effect is resolution independent#8834

Merged
mvaligursky merged 5 commits into
playcanvas:mainfrom
MAG-AdrianMeredith:fix/dof-resolution-dependent
Jun 8, 2026
Merged

#8833 fix: ensure dof effect is resolution independent#8834
mvaligursky merged 5 commits into
playcanvas:mainfrom
MAG-AdrianMeredith:fix/dof-resolution-dependent

Conversation

@MAG-AdrianMeredith

@MAG-AdrianMeredith MAG-AdrianMeredith commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes #8833

  • Change the blur radius to be resolution independent against a reference resolution of 540.

High resolution
Screenshot 2026-06-03 at 15 16 12

Low resolution
Screenshot 2026-06-03 at 15 16 04

Checklist

  • I have read the contributing guidelines
  • My code follows the project's coding standards
  • This PR focuses on a single change

@MAG-AdrianMeredith

Copy link
Copy Markdown
Contributor Author

@mvaligursky What do you suggest we do with "high quality" switch. From what I can tell it was a workaround for this issue and as such no longer makes sense. Remove it? Deprecate it?

@willeastcott willeastcott requested review from Copilot and mvaligursky and removed request for Copilot June 3, 2026 19:54
@willeastcott willeastcott added the area: graphics Graphics related issue label Jun 3, 2026
@mvaligursky mvaligursky requested a review from Copilot June 8, 2026 09:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes the Depth of Field (DoF) blur varying with render resolution / pixel ratio by redefining blur radius in the DoF blur shader as a normalized value (calibrated against a reference height) and adding aspect correction so the blur kernel remains circular in screen pixels.

Changes:

  • Update GLSL/WGSL DoF blur shaders to use an aspect-corrected, resolution-independent blur step.
  • Normalize blurRadiusNear/Far against a new referenceHeight (default 540) when uploading uniforms.
  • Remove the previous per-quality compensation for far blur radius since scaling is now handled consistently.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
src/scene/shader-lib/wgsl/chunks/render-pass/frag/dofBlur.js Makes WGSL DoF blur step resolution-independent and aspect-corrected.
src/scene/shader-lib/glsl/chunks/render-pass/frag/dofBlur.js Makes GLSL DoF blur step resolution-independent and aspect-corrected.
src/extras/render-passes/render-pass-dof-blur.js Adds reference-height normalization when setting blur radius uniforms.
src/extras/render-passes/frame-pass-dof.js Removes quality-based far blur compensation and updates blur radius wiring.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/extras/render-passes/frame-pass-dof.js Outdated
Comment thread src/extras/render-passes/render-pass-dof-blur.js
Comment thread src/scene/shader-lib/glsl/chunks/render-pass/frag/dofBlur.js
Comment thread src/scene/shader-lib/glsl/chunks/render-pass/frag/dofBlur.js
Comment thread src/scene/shader-lib/wgsl/chunks/render-pass/frag/dofBlur.js

@mvaligursky mvaligursky left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good — the approach is correct. Expressing the blur as a fraction of a reference height (rather than in source-texture texels) is the right way to make this resolution- and pixel-ratio-independent, and the height/width factor on the X step correctly keeps the kernel circular in screen pixels. The math checks out: in pixels both axes resolve to kernel * blurRadius/540 * height. Picking referenceHeight = 540 to reproduce the old high-quality blur at 1080p is a sensible calibration that preserves previously authored blurRadius values. Perf impact is effectively nil (one scalar divide swapped for a vec2 divide; no change to tap count or texture sizes).

On the high quality flag question: I'd keep it. It's not the workaround for this issue — it controls the internal resolution of the DoF textures (half-of-full-res far texture + full-res composite vs. quarter-res), which is a genuine quality/perf trade-off independent of the resolution-dependence bug. The actual workaround was the * (highQuality ? 1 : 0.5) factor on blurRadiusFar, and you've already correctly removed that — now that blur is reference-height-relative, the far-texture resolution no longer changes blur strength, so the compensation is obsolete. So nothing further to deprecate.

Two small suggestions inline (both optional, ready to accept).

Comment thread src/extras/render-passes/frame-pass-dof.js Outdated
Comment thread src/extras/render-passes/render-pass-dof-blur.js Outdated
@mvaligursky mvaligursky marked this pull request as ready for review June 8, 2026 09:54
A suggestion was applied one line off, leaving the original
invReferenceHeight declaration in place alongside the guarded one,
breaking the build. Remove the duplicate and keep the reference-height
guard.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@mvaligursky mvaligursky merged commit e703d65 into playcanvas:main Jun 8, 2026
7 of 9 checks passed
mvaligursky added a commit that referenced this pull request Jun 8, 2026
* #8833 fix: ensure dof effect is resolution independent

* Update src/extras/render-passes/frame-pass-dof.js

* Update src/extras/render-passes/render-pass-dof-blur.js

* fix: remove duplicate invReferenceHeight declaration

A suggestion was applied one line off, leaving the original
invReferenceHeight declaration in place alongside the guarded one,
breaking the build. Remove the duplicate and keep the reference-height
guard.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

---------

Co-authored-by: Martin Valigursky <59932779+mvaligursky@users.noreply.github.com>
Co-authored-by: Martin Valigursky <mvaligursky@snapchat.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: graphics Graphics related issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Depth of Field effect not resolution independent

4 participants