forked from pmndrs/postprocessing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDepthComparisonMaterial.js
More file actions
127 lines (90 loc) · 2.31 KB
/
DepthComparisonMaterial.js
File metadata and controls
127 lines (90 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import { NoBlending, PerspectiveCamera, RGBADepthPacking, ShaderMaterial, Uniform } from "three";
import fragmentShader from "./glsl/depth-comparison.frag";
import vertexShader from "./glsl/depth-comparison.vert";
/**
* A depth comparison shader material.
*/
export class DepthComparisonMaterial extends ShaderMaterial {
/**
* Constructs a new depth comparison material.
*
* @param {Texture} [depthTexture=null] - A depth texture.
* @param {PerspectiveCamera} [camera] - A camera.
*/
constructor(depthTexture = null, camera) {
super({
name: "DepthComparisonMaterial",
defines: {
DEPTH_PACKING: "0"
},
uniforms: {
depthBuffer: new Uniform(null),
cameraNear: new Uniform(0.3),
cameraFar: new Uniform(1000)
},
blending: NoBlending,
toneMapped: false,
depthWrite: false,
depthTest: false,
fragmentShader,
vertexShader
});
this.depthBuffer = depthTexture;
this.depthPacking = RGBADepthPacking;
this.copyCameraSettings(camera);
}
/**
* The depth buffer.
*
* @type {Texture}
*/
set depthBuffer(value) {
this.uniforms.depthBuffer.value = value;
}
/**
* The depth packing strategy.
*
* @type {DepthPackingStrategies}
*/
set depthPacking(value) {
this.defines.DEPTH_PACKING = value.toFixed(0);
this.needsUpdate = true;
}
/**
* Sets the depth buffer.
*
* @deprecated Use depthBuffer and depthPacking instead.
* @param {Texture} buffer - The depth texture.
* @param {DepthPackingStrategies} [depthPacking=RGBADepthPacking] - The depth packing strategy.
*/
setDepthBuffer(buffer, depthPacking = RGBADepthPacking) {
this.depthBuffer = buffer;
this.depthPacking = depthPacking;
}
/**
* Copies the settings of the given camera.
*
* @deprecated Use copyCameraSettings instead.
* @param {Camera} camera - A camera.
*/
adoptCameraSettings(camera) {
this.copyCameraSettings(camera);
}
/**
* Copies the settings of the given camera.
*
* @param {Camera} camera - A camera.
*/
copyCameraSettings(camera) {
if(camera) {
this.uniforms.cameraNear.value = camera.near;
this.uniforms.cameraFar.value = camera.far;
if(camera instanceof PerspectiveCamera) {
this.defines.PERSPECTIVE_CAMERA = "1";
} else {
delete this.defines.PERSPECTIVE_CAMERA;
}
this.needsUpdate = true;
}
}
}