Commit 2930d9f
authored
Prevent DoF effect disappearing at small
# Objective
- In the `depth_of_field` example, setting `focal_distance` to a small
value (<= 0.02) causes the DoF effect to disappear unexpectedly.
<img width="1936" height="1129" alt="before"
src="https://github.com/user-attachments/assets/ea12016e-b9d5-4232-b8e0-b354efdecaae"
/>
- I believe that a small focal_distance makes `(focus - f)` zero or
negative. This leads to a non-positive candidate_coc, which is then
clamped to 0.0, effectively disabling the DoF effect.
- Although the formula is physically accurate, we cannot assume users
have a deep understanding of the depth of field effect. This will make
them confused.
## Solution
- Use `max(focus - f, EPSILON)` to ensure the denominator is always
positive.
- Now, the effect looks correct.
<img width="1938" height="1135" alt="later"
src="https://github.com/user-attachments/assets/4462bc78-e5d1-4d74-a9c7-d69ed111b4c6"
/>
## Testing
- CI
---focus_distances (bevyengine#21816)1 parent 0c90f04 commit 2930d9f
File tree
2 files changed
+4
-2
lines changed- crates/bevy_post_process/src/dof
- examples/3d
2 files changed
+4
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
| 101 | + | |
| 102 | + | |
101 | 103 | | |
102 | 104 | | |
103 | 105 | | |
| |||
128 | 130 | | |
129 | 131 | | |
130 | 132 | | |
131 | | - | |
| 133 | + | |
132 | 134 | | |
133 | 135 | | |
134 | 136 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
243 | 243 | | |
244 | 244 | | |
245 | 245 | | |
246 | | - | |
| 246 | + | |
247 | 247 | | |
248 | 248 | | |
249 | 249 | | |
| |||
0 commit comments