Depth buffer issue when using DepthOfFieldEffect
See original GitHub issueDescription 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
✔️ Target at far clip plane - as expected: far clip plane is in focus
❌ Target at center between near and far - not expected: focus is too close
❌ Target at 1/4 between near and far - not expected: focus is too close
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:
- Created 10 months ago
- Comments:10 (4 by maintainers)
Top GitHub Comments
@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.
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…