-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathEffectCompositer.js
More file actions
77 lines (75 loc) · 2.84 KB
/
Copy pathEffectCompositer.js
File metadata and controls
77 lines (75 loc) · 2.84 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
import * as THREE from 'https://cdn.skypack.dev/three@0.142.0';
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() },
'blueNoise': { value: null },
'time': { value: 0.0 },
'intensity': { value: 10.0 },
'renderMode': { 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 sampler2D blueNoise;
uniform vec2 resolution;
uniform float intensity;
uniform float renderMode;
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));
}
#include <common>
#include <dithering_pars_fragment>
void main() {
const float directions = 16.0;
const float quality = 6.0;
const float pi = 3.14159;
float size = 0.0;//1000.0 * (1.0 - texture2D(sceneDepth, vUv).x);
vec2 radius = vec2(size) / resolution;
vec4 texel = texture2D(tDiffuse, vUv);//vec3(0.0);
float finalAo = pow(texel.a, intensity);
if (renderMode == 0.0) {
gl_FragColor = vec4( texture2D(sceneDiffuse, vUv).rgb *finalAo, 1.0);
} else if (renderMode == 1.0) {
gl_FragColor = vec4( vec3(finalAo), 1.0);
} else if (renderMode == 2.0) {
gl_FragColor = vec4( texture2D(sceneDiffuse, vUv).rgb, 1.0);
} else if (renderMode == 3.0) {
if (vUv.x < 0.5) {
gl_FragColor = vec4( texture2D(sceneDiffuse, vUv).rgb, 1.0);
} else if (abs(vUv.x - 0.5) < 1.0 / resolution.x) {
gl_FragColor = vec4(1.0);
} else {
gl_FragColor = vec4( texture2D(sceneDiffuse, vUv).rgb *finalAo, 1.0);
}
} else if (renderMode == 4.0) {
if (vUv.x < 0.5) {
gl_FragColor = vec4( texture2D(sceneDiffuse, vUv).rgb, 1.0);
} else if (abs(vUv.x - 0.5) < 1.0 / resolution.x) {
gl_FragColor = vec4(1.0);
} else {
gl_FragColor = vec4( vec3(finalAo), 1.0);
}
}
#include <dithering_fragment>
}
`
}
export { EffectCompositer };