-
Notifications
You must be signed in to change notification settings - Fork 4
/
EffectCompositer.js
40 lines (37 loc) · 1.35 KB
/
EffectCompositer.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
39
40
import * as THREE from 'https://cdn.skypack.dev/pin/[email protected]/mode=imports/optimized/three.js';
const EffectCompositer = {
uniforms: {
'sceneDiffuse': { value: null },
'sceneDepth': { value: null },
'tDiffuse': { value: null },
'projMat': { value: new THREE.Matrix4() },
'viewMat': { value: new THREE.Matrix4() },
'projectionMatrixInv': { value: new THREE.Matrix4() },
'viewMatrixInv': { value: new THREE.Matrix4() },
'cameraPos': { value: new THREE.Vector3() },
'resolution': { value: new THREE.Vector2() },
'time': { value: 0.0 },
},
vertexShader: /* glsl */ `
varying vec2 vUv;
void main() {
vUv = uv;
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
}`,
fragmentShader: /* glsl */ `
uniform sampler2D sceneDiffuse;
uniform sampler2D sceneDepth;
uniform sampler2D tDiffuse;
uniform vec2 resolution;
varying vec2 vUv;
highp float linearize_depth(highp float d, highp float zNear,highp float zFar)
{
highp float z_n = 2.0 * d - 1.0;
return 2.0 * zNear * zFar / (zFar + zNear - z_n * (zFar - zNear));
}
void main() {
gl_FragColor = vec4(texture2D(sceneDiffuse, vUv).rgb * vec3(pow(texture2D(tDiffuse, vUv).r, 2.0)), 1.0);
}
`
}
export { EffectCompositer };