Skip to content

Commit ae29c4a

Browse files
committed
Use world distance for CoC
1 parent dbf8947 commit ae29c4a

File tree

2 files changed

+6
-43
lines changed

2 files changed

+6
-43
lines changed

src/materials/CircleOfConfusionMaterial.ts

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Texture, Uniform } from "three";
2-
import { orthographicDepthToViewZ, viewZToOrthographicDepth } from "../utils/functions/camera.js";
32
import { FullscreenMaterial } from "./FullscreenMaterial.js";
43

54
import fragmentShader from "./shaders/circle-of-confusion.frag";
@@ -43,7 +42,7 @@ export class CircleOfConfusionMaterial extends FullscreenMaterial {
4342
}
4443

4544
/**
46-
* The focus distance. Range: [0.0, 1.0].
45+
* The focus distance in world units.
4746
*/
4847

4948
get focusDistance(): number {
@@ -59,23 +58,7 @@ export class CircleOfConfusionMaterial extends FullscreenMaterial {
5958
}
6059

6160
/**
62-
* The focus distance in world units.
63-
*/
64-
65-
get worldFocusDistance(): number {
66-
67-
return -orthographicDepthToViewZ(this.focusDistance, this.near, this.far);
68-
69-
}
70-
71-
set worldFocusDistance(value: number) {
72-
73-
this.focusDistance = viewZToOrthographicDepth(-value, this.near, this.far);
74-
75-
}
76-
77-
/**
78-
* The focus range. Range: [0.0, 1.0].
61+
* The focus range in world units.
7962
*/
8063

8164
get focusRange(): number {
@@ -90,20 +73,4 @@ export class CircleOfConfusionMaterial extends FullscreenMaterial {
9073

9174
}
9275

93-
/**
94-
* The focus range in world units.
95-
*/
96-
97-
get worldFocusRange(): number {
98-
99-
return -orthographicDepthToViewZ(this.focusRange, this.near, this.far);
100-
101-
}
102-
103-
set worldFocusRange(value: number) {
104-
105-
this.focusRange = viewZToOrthographicDepth(-value, this.near, this.far);
106-
107-
}
108-
10976
}

src/materials/shaders/circle-of-confusion.frag

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <pp_default_output_pars_fragment>
44
#include <pp_depth_buffer_pars_fragment>
55
#include <pp_depth_utils_pars_fragment>
6+
#include <pp_world_utils_pars_fragment>
67

78
uniform float focusDistance;
89
uniform float focusRange;
@@ -12,15 +13,10 @@ in vec2 vUv;
1213
void main() {
1314

1415
float depth = readDepth(vUv);
16+
vec3 viewPosition = getViewPosition(vUv, depth);
17+
float distance = getDistance(viewPosition);
1518

16-
#ifdef PERSPECTIVE_CAMERA
17-
18-
float viewZ = perspectiveDepthToViewZ(depth, cameraParams.x, cameraParams.y);
19-
depth = viewZToOrthographicDepth(viewZ, cameraParams.x, cameraParams.y);
20-
21-
#endif
22-
23-
float signedDistance = depth - focusDistance;
19+
float signedDistance = distance - focusDistance;
2420
float magnitude = smoothstep(0.0, focusRange, abs(signedDistance));
2521

2622
out_Color.rg = magnitude * vec2(

0 commit comments

Comments
 (0)