question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Depth buffer issue when using DepthOfFieldEffect

See original GitHub issue

Description of the bug

Follow-up to #420. By using dofEffect.circleOfConfusionMaterial.adoptCameraSettings and worldFocusDistance, I was able to get a dynamic target to change the focus. I got it to match up / work in @vanruesc’s sandbox.

However, I still don’t get it to work elsewhere…

For me it looks like the depth buffer is in a wrong format, and that the calculation to go from linearized near/far values to world distances and vice versa doesn’t match some setting here. I checked that we’re not using logarithmic depth.

Maybe these images of expected and not expected cases help: In the below images,

  • the textured plane is cut off by near and far clip planes of 1 and 10
  • the white cube is the focus target - placed at 1, 10, ~5.5 and ~2.5

✔️ Target at near clip plane - as expected: near clip plane is in focus 20221116-232215_chrome

✔️ Target at far clip plane - as expected: far clip plane is in focus 20221116-232224_chrome

Target at center between near and far - not expected: focus is too close 20221116-232232_chrome

Target at 1/4 between near and far - not expected: focus is too close 20221116-232236_chrome

So there seems to be some nonlinearity going on, but I have no idea why.

To Reproduce

I’m unfortunately unsure how to reproduce / what’s wrong in this setup so far. Happy to answer any questions to hopefully figure out what I’m doing wrong.

Expected behavior

Ability to set the worldFocusDistance and get that distance in focus.

Screenshots

see above

Library versions used

  • Three: 0.145.4
  • Post Processing: 6.29.1

Desktop

  • OS: Windows 10 and 11
  • Browser Chrome
  • Graphics hardware: RTX 2070 Max-Q and RTX 3070

Issue Analytics

  • State:open
  • Created 10 months ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
vanruesccommented, Dec 5, 2022

@optimus007 Thanks for the sandbox! The unexpected behaviour that can be observed when the target is off-center has to do with perspective projection. The object would probably remain in focus at all times with an orthographic camera. The effect translates the world distance to a linear, orthographic depth value which basically counters the perspective projection. I wonder if we could use perspective depth instead 🤔

Right now, I’m busy with work and the v7 redesign. I’ll eventually get to the DepthOfFieldEffect.

@hybridherbst Does your project use logarithmic depth? That would explain why you’re only able to focus objects close to the near and far planes.

1reaction
hybridherbstcommented, Nov 30, 2022

Played around a bit with it, hard to say, but could be related! I get it to break in interesting ways for sure. Sorry that I didn’t get to make a simple repro scene yet…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issues with flickering/pop-in depth of field effect ... - Unity Forum
I'm using the depth of field effect to achieve a "tilt-shift" look, and it does mostly work, but it often has issues with...
Read more >
Does anyone use Depth of field effect in reshade? : r/starcitizen
I tried to use it but it didn't do anything, obviously I don't know ... Reshade blocks access to the depth buffer when...
Read more >
Just Cause 2's Depth Buffer is Flipped - Forum - ReShade
It's completely possible to use manual focus for a far depth of field effect, but auto focus is completely broken due to this...
Read more >
SsaoPass: artifacts with depth buffer - mrdoob/three.js - GitHub
I solved the depth issue by rendering the depth data to a separate render target, using unpackRGBAToDepth and packDepthToRGBA from packing.glsl.
Read more >
World space UI gets blured with Depth Of Field effect when ...
This is reasonable, common transparent shaders don't write the depth buffer, ... To solve this problem, enable write depth feature for these ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found