-
Notifications
You must be signed in to change notification settings - Fork 1
/
BloomShader.js
38 lines (32 loc) · 1002 Bytes
/
BloomShader.js
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
var BloomShader = {
uniforms: {
'sceneDiffuse': { value: null },
'sceneDepth': { value: null },
'bloomDiffuse': { value: null },
'bloomDepth': { value: null }
},
vertexShader: /* glsl */ `
varying vec2 vUv;
void main() {
vUv = uv;
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
}`,
fragmentShader: /* glsl */ `
uniform float opacity;
uniform sampler2D sceneDiffuse;
uniform sampler2D bloomDiffuse;
uniform sampler2D sceneDepth;
uniform sampler2D bloomDepth;
varying vec2 vUv;
void main() {
vec4 texel = texture2D( bloomDiffuse, vUv );
float bloomDepthAmt = texture2D( bloomDepth, vUv ).x;
float sceneDepthAmt = texture2D( sceneDepth, vUv ).x;
if (bloomDepthAmt <= sceneDepthAmt) {
gl_FragColor = texel;
} else {
gl_FragColor = vec4(vec3(0.0), 1.0);
}
}`
};
export { BloomShader };