@shapediver/viewer.rendering-engine.rendering-engine-threejs 3.18.2 → 3.19.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +73 -73
- package/README.md +3 -3
- package/dist/RenderingEngine.d.ts +5 -5
- package/dist/RenderingEngine.d.ts.map +1 -1
- package/dist/RenderingEngine.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/injectors/TextureUnifierInjector.js +57 -57
- package/dist/interfaces/IRenderingEngine.d.ts +2 -2
- package/dist/interfaces/IRenderingEngine.d.ts.map +1 -1
- package/dist/loaders/EnvironmentMapLoader.d.ts +1 -1
- package/dist/loaders/EnvironmentMapLoader.d.ts.map +1 -1
- package/dist/loaders/EnvironmentMapLoader.js.map +1 -1
- package/dist/loaders/GeometryLoader.d.ts +2 -2
- package/dist/loaders/GeometryLoader.d.ts.map +1 -1
- package/dist/loaders/GeometryLoader.js +43 -43
- package/dist/loaders/GeometryLoader.js.map +1 -1
- package/dist/loaders/HTMLElementAnchorLoader.d.ts +2 -2
- package/dist/loaders/HTMLElementAnchorLoader.d.ts.map +1 -1
- package/dist/loaders/HTMLElementAnchorLoader.js.map +1 -1
- package/dist/loaders/LightLoader.d.ts +2 -2
- package/dist/loaders/LightLoader.d.ts.map +1 -1
- package/dist/loaders/LightLoader.js.map +1 -1
- package/dist/loaders/MaterialLoader.d.ts +7 -7
- package/dist/loaders/MaterialLoader.d.ts.map +1 -1
- package/dist/loaders/MaterialLoader.js +42 -42
- package/dist/loaders/MaterialLoader.js.map +1 -1
- package/dist/managers/ARManager.d.ts +1 -1
- package/dist/managers/ARManager.d.ts.map +1 -1
- package/dist/managers/ARManager.js.map +1 -1
- package/dist/managers/CameraManager.d.ts +1 -1
- package/dist/managers/CameraManager.d.ts.map +1 -1
- package/dist/managers/CameraManager.js.map +1 -1
- package/dist/managers/EnvironmentGeometryManager.d.ts +2 -2
- package/dist/managers/EnvironmentGeometryManager.d.ts.map +1 -1
- package/dist/managers/EnvironmentGeometryManager.js.map +1 -1
- package/dist/managers/FlagManager.d.ts +1 -1
- package/dist/managers/FlagManager.d.ts.map +1 -1
- package/dist/managers/FlagManager.js.map +1 -1
- package/dist/managers/PostProcessingManager.d.ts +2 -2
- package/dist/managers/PostProcessingManager.d.ts.map +1 -1
- package/dist/managers/PostProcessingManager.js.map +1 -1
- package/dist/managers/RenderingManager.d.ts +2 -1
- package/dist/managers/RenderingManager.d.ts.map +1 -1
- package/dist/managers/RenderingManager.js +12 -0
- package/dist/managers/RenderingManager.js.map +1 -1
- package/dist/managers/SceneTracingManager.d.ts +3 -3
- package/dist/managers/SceneTracingManager.d.ts.map +1 -1
- package/dist/managers/SceneTracingManager.js.map +1 -1
- package/dist/managers/SceneTreeManager.d.ts +3 -3
- package/dist/managers/SceneTreeManager.d.ts.map +1 -1
- package/dist/managers/SceneTreeManager.js.map +1 -1
- package/dist/managers/SettingsManager.d.ts +2 -2
- package/dist/managers/SettingsManager.d.ts.map +1 -1
- package/dist/managers/SettingsManager.js.map +1 -1
- package/dist/managers/environmentGeometry/ContactShadow.d.ts +1 -1
- package/dist/managers/environmentGeometry/ContactShadow.d.ts.map +1 -1
- package/dist/managers/environmentGeometry/ContactShadow.js +3 -3
- package/dist/managers/environmentGeometry/Grid.d.ts +2 -2
- package/dist/managers/environmentGeometry/Grid.d.ts.map +1 -1
- package/dist/managers/environmentGeometry/GroundPlane.d.ts +2 -2
- package/dist/managers/environmentGeometry/GroundPlane.d.ts.map +1 -1
- package/dist/managers/environmentGeometry/GroundPlane.js.map +1 -1
- package/dist/managers/environmentGeometry/GroundPlaneShadow.d.ts +2 -2
- package/dist/managers/environmentGeometry/GroundPlaneShadow.d.ts.map +1 -1
- package/dist/managers/environmentGeometry/IEnvironmentGeometry.d.ts +1 -1
- package/dist/managers/environmentGeometry/IEnvironmentGeometry.d.ts.map +1 -1
- package/dist/managers/postprocessing/GodRaysManager.d.ts +1 -1
- package/dist/managers/postprocessing/GodRaysManager.d.ts.map +1 -1
- package/dist/managers/postprocessing/OutlineManager.d.ts +1 -1
- package/dist/managers/postprocessing/OutlineManager.d.ts.map +1 -1
- package/dist/managers/postprocessing/SelectiveBloomManager.d.ts +1 -1
- package/dist/managers/postprocessing/SelectiveBloomManager.d.ts.map +1 -1
- package/dist/managers/postprocessing/ao/ao/shader/ao_compose.js +18 -18
- package/dist/managers/postprocessing/ao/ao/shader/ao_utils.js +81 -81
- package/dist/managers/postprocessing/ao/hbao/shader/hbao.js +154 -154
- package/dist/managers/postprocessing/ao/poissionDenoise/shader/poissionDenoise.js +152 -152
- package/dist/managers/postprocessing/ao/ssao/shader/ssao.js +115 -115
- package/dist/managers/postprocessing/ao/utils/shader/basic.js +10 -10
- package/dist/managers/postprocessing/ao/utils/shader/sampleBlueNoise.js +37 -37
- package/dist/managers/postprocessing/effects/tone-mapping/tone-mapping.js +92 -92
- package/dist/managers/postprocessing/utils/CopyMaterial.js +36 -36
- package/dist/managers/postprocessing/utils/CopyShader.js +23 -23
- package/dist/managers/sceneTree/SDTFUtils.d.ts +2 -2
- package/dist/managers/sceneTree/SDTFUtils.d.ts.map +1 -1
- package/dist/managers/sceneTree/SDTFUtils.js.map +1 -1
- package/dist/managers/sceneTree/SceenTreeManagerUtils.d.ts +1 -1
- package/dist/managers/sceneTree/SceenTreeManagerUtils.d.ts.map +1 -1
- package/dist/managers/sceneTree/SceenTreeManagerUtils.js.map +1 -1
- package/dist/objects/SDColor.d.ts +1 -1
- package/dist/objects/SDColor.d.ts.map +1 -1
- package/dist/objects/SDObject.d.ts +1 -1
- package/dist/objects/SDObject.d.ts.map +1 -1
- package/dist/shaders/PCSS.js +121 -121
- package/dist/shaders/gem.js +576 -576
- package/dist/shaders/multi_points.js +288 -288
- package/dist/styling/viewport-css.js +112 -112
- package/dist/types/IThreejsData.d.ts +1 -1
- package/dist/types/IThreejsData.d.ts.map +1 -1
- package/dist/types/ThreejsData.d.ts +1 -1
- package/dist/types/ThreejsData.d.ts.map +1 -1
- package/package.json +17 -17
|
@@ -1,159 +1,159 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.hbao = void 0;
|
|
4
|
-
exports.hbao = `
|
|
5
|
-
#define PI 3.14159265358979323846264338327950288
|
|
6
|
-
|
|
7
|
-
varying vec2 vUv;
|
|
8
|
-
|
|
9
|
-
uniform highp sampler2D depthTexture;
|
|
10
|
-
|
|
11
|
-
uniform mat4 projectionViewMatrix;
|
|
12
|
-
uniform int frame;
|
|
13
|
-
|
|
14
|
-
uniform sampler2D blueNoiseTexture;
|
|
15
|
-
uniform vec2 blueNoiseRepeat;
|
|
16
|
-
uniform vec2 texSize;
|
|
17
|
-
|
|
18
|
-
uniform float aoDistance;
|
|
19
|
-
uniform float distancePower;
|
|
20
|
-
uniform float bias;
|
|
21
|
-
uniform float thickness;
|
|
22
|
-
|
|
23
|
-
#include <packing>
|
|
24
|
-
#include <sampleBlueNoise>
|
|
25
|
-
|
|
26
|
-
uniform float cameraNear;
|
|
27
|
-
uniform float cameraFar;
|
|
28
|
-
uniform mat4 cameraMatrixWorld;
|
|
29
|
-
|
|
30
|
-
#include <ao_utils>
|
|
31
|
-
|
|
32
|
-
// source: https://github.com/mrdoob/three.js/blob/342946c8392639028da439b6dc0597e58209c696/examples/js/shaders/SAOShader.js#L123
|
|
33
|
-
float getViewZ(const float depth) {
|
|
34
|
-
#ifdef PERSPECTIVE_CAMERA
|
|
35
|
-
return perspectiveDepthToViewZ(depth, cameraNear, cameraFar);
|
|
36
|
-
#else
|
|
37
|
-
return orthographicDepthToViewZ(depth, cameraNear, cameraFar);
|
|
38
|
-
#endif
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
vec3 slerp(const vec3 a, const vec3 b, const float t) {
|
|
42
|
-
float cosAngle = dot(a, b);
|
|
43
|
-
float angle = acos(cosAngle);
|
|
44
|
-
|
|
45
|
-
if (abs(angle) < 0.001) {
|
|
46
|
-
return mix(a, b, t);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
float sinAngle = sin(angle);
|
|
50
|
-
float t1 = sin((1.0 - t) * angle) / sinAngle;
|
|
51
|
-
float t2 = sin(t * angle) / sinAngle;
|
|
52
|
-
|
|
53
|
-
return (a * t1) + (b * t2);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// source: https://www.shadertoy.com/view/cll3R4
|
|
57
|
-
vec3 cosineSampleHemisphere(const vec3 n, const vec2 u) {
|
|
58
|
-
float r = sqrt(u.x);
|
|
59
|
-
float theta = 2.0 * PI * u.y;
|
|
60
|
-
|
|
61
|
-
vec3 b = normalize(cross(n, vec3(0.0, 1.0, 1.0)));
|
|
62
|
-
vec3 t = cross(b, n);
|
|
63
|
-
|
|
64
|
-
return normalize(r * sin(theta) * b + sqrt(1.0 - u.x) * n + r * cos(theta) * t);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
void main() {
|
|
68
|
-
float depth = textureLod(depthTexture, vUv, 0.0).r;
|
|
69
|
-
vec3 normal = computeNormal(vUv);
|
|
70
|
-
|
|
71
|
-
// filter out background
|
|
72
|
-
if (depth == 1.0) {
|
|
73
|
-
gl_FragColor = vec4(normal, 1.0);
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
vec4 cameraPosition = cameraMatrixWorld * vec4(0.0, 0.0, 0.0, 1.0);
|
|
78
|
-
|
|
79
|
-
vec3 worldPos = computeWorldPosition(depth, vUv);
|
|
80
|
-
vec3 screenSpaceNormal = getUnpackedNormal(vUv);
|
|
81
|
-
|
|
82
|
-
float ao = 0.0, totalWeight = 0.0;
|
|
83
|
-
|
|
84
|
-
for (int i = 0; i < spp; i++) {
|
|
85
|
-
int seed = i;
|
|
86
|
-
#ifdef animatedNoise
|
|
87
|
-
seed += frame;
|
|
88
|
-
#endif
|
|
89
|
-
|
|
90
|
-
vec4 blueNoise = sampleBlueNoise(blueNoiseTexture, seed, blueNoiseRepeat, texSize);
|
|
91
|
-
|
|
92
|
-
vec3 sampleWorldDir = cosineSampleHemisphere(normal, blueNoise.rg);
|
|
93
|
-
|
|
94
|
-
vec3 sampleWorldPos = worldPos + aoDistance * pow(blueNoise.b, distancePower + 1.0) * sampleWorldDir;
|
|
95
|
-
|
|
96
|
-
// Project the sample position to screen space
|
|
97
|
-
vec4 sampleUv = projectionViewMatrix * vec4(sampleWorldPos, 1.);
|
|
98
|
-
sampleUv.xy /= sampleUv.w;
|
|
99
|
-
sampleUv.xy = sampleUv.xy * 0.5 + 0.5;
|
|
100
|
-
|
|
101
|
-
// Get the depth of the sample position
|
|
102
|
-
float sampleDepth = textureLod(depthTexture, sampleUv.xy, 0.0).r;
|
|
103
|
-
|
|
104
|
-
if(sampleDepth < 1.0) {
|
|
105
|
-
vec3 sampleNormal = getUnpackedNormal(sampleUv.xy);
|
|
106
|
-
|
|
107
|
-
// Compute the horizon line
|
|
108
|
-
float deltaDepth = depth - sampleDepth;
|
|
109
|
-
|
|
110
|
-
// distance based bias
|
|
111
|
-
float d = distance(sampleWorldPos, cameraPosition.xyz) / aoDistance;
|
|
112
|
-
deltaDepth *= 0.001 * d * d;
|
|
113
|
-
|
|
114
|
-
float th = thickness * 0.01;
|
|
115
|
-
|
|
116
|
-
float theta = dot(normal, sampleWorldDir);
|
|
117
|
-
totalWeight += theta;
|
|
118
|
-
|
|
119
|
-
if (deltaDepth < th) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
float horizon = sampleDepth + deltaDepth * bias * 1000.;
|
|
123
|
-
|
|
124
|
-
float occlusion = max(0.0, horizon - depth) * theta;
|
|
125
|
-
|
|
126
|
-
float m = max(0., 1. - deltaDepth / th);
|
|
127
|
-
occlusion = 10. * occlusion * m / d;
|
|
128
|
-
|
|
129
|
-
occlusion = max(0.0, occlusion);
|
|
130
|
-
|
|
131
|
-
// check if the normals are in the same direction
|
|
132
|
-
float dotProduct = dot(screenSpaceNormal, sampleNormal);
|
|
133
|
-
if (dotProduct < 0.9999) {
|
|
134
|
-
|
|
135
|
-
occlusion = sqrt(occlusion);
|
|
136
|
-
ao += occlusion;
|
|
137
|
-
} else {
|
|
138
|
-
if(areDepthsOnSamePlane(depth, sampleDepth, vUv, sampleUv.xy, screenSpaceNormal, 0.1)) {
|
|
139
|
-
// occluded += 0.0;
|
|
140
|
-
// totalWeight += 1.0;
|
|
141
|
-
} else {
|
|
142
|
-
|
|
143
|
-
occlusion = sqrt(occlusion);
|
|
144
|
-
ao += occlusion;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
if (totalWeight > 0.) ao /= totalWeight;
|
|
152
|
-
|
|
153
|
-
// clamp ao to [0, 1]
|
|
154
|
-
ao = clamp(1. - ao, 0., 1.);
|
|
155
|
-
|
|
156
|
-
gl_FragColor = vec4(normal, ao);
|
|
157
|
-
}
|
|
4
|
+
exports.hbao = `
|
|
5
|
+
#define PI 3.14159265358979323846264338327950288
|
|
6
|
+
|
|
7
|
+
varying vec2 vUv;
|
|
8
|
+
|
|
9
|
+
uniform highp sampler2D depthTexture;
|
|
10
|
+
|
|
11
|
+
uniform mat4 projectionViewMatrix;
|
|
12
|
+
uniform int frame;
|
|
13
|
+
|
|
14
|
+
uniform sampler2D blueNoiseTexture;
|
|
15
|
+
uniform vec2 blueNoiseRepeat;
|
|
16
|
+
uniform vec2 texSize;
|
|
17
|
+
|
|
18
|
+
uniform float aoDistance;
|
|
19
|
+
uniform float distancePower;
|
|
20
|
+
uniform float bias;
|
|
21
|
+
uniform float thickness;
|
|
22
|
+
|
|
23
|
+
#include <packing>
|
|
24
|
+
#include <sampleBlueNoise>
|
|
25
|
+
|
|
26
|
+
uniform float cameraNear;
|
|
27
|
+
uniform float cameraFar;
|
|
28
|
+
uniform mat4 cameraMatrixWorld;
|
|
29
|
+
|
|
30
|
+
#include <ao_utils>
|
|
31
|
+
|
|
32
|
+
// source: https://github.com/mrdoob/three.js/blob/342946c8392639028da439b6dc0597e58209c696/examples/js/shaders/SAOShader.js#L123
|
|
33
|
+
float getViewZ(const float depth) {
|
|
34
|
+
#ifdef PERSPECTIVE_CAMERA
|
|
35
|
+
return perspectiveDepthToViewZ(depth, cameraNear, cameraFar);
|
|
36
|
+
#else
|
|
37
|
+
return orthographicDepthToViewZ(depth, cameraNear, cameraFar);
|
|
38
|
+
#endif
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
vec3 slerp(const vec3 a, const vec3 b, const float t) {
|
|
42
|
+
float cosAngle = dot(a, b);
|
|
43
|
+
float angle = acos(cosAngle);
|
|
44
|
+
|
|
45
|
+
if (abs(angle) < 0.001) {
|
|
46
|
+
return mix(a, b, t);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
float sinAngle = sin(angle);
|
|
50
|
+
float t1 = sin((1.0 - t) * angle) / sinAngle;
|
|
51
|
+
float t2 = sin(t * angle) / sinAngle;
|
|
52
|
+
|
|
53
|
+
return (a * t1) + (b * t2);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// source: https://www.shadertoy.com/view/cll3R4
|
|
57
|
+
vec3 cosineSampleHemisphere(const vec3 n, const vec2 u) {
|
|
58
|
+
float r = sqrt(u.x);
|
|
59
|
+
float theta = 2.0 * PI * u.y;
|
|
60
|
+
|
|
61
|
+
vec3 b = normalize(cross(n, vec3(0.0, 1.0, 1.0)));
|
|
62
|
+
vec3 t = cross(b, n);
|
|
63
|
+
|
|
64
|
+
return normalize(r * sin(theta) * b + sqrt(1.0 - u.x) * n + r * cos(theta) * t);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
void main() {
|
|
68
|
+
float depth = textureLod(depthTexture, vUv, 0.0).r;
|
|
69
|
+
vec3 normal = computeNormal(vUv);
|
|
70
|
+
|
|
71
|
+
// filter out background
|
|
72
|
+
if (depth == 1.0) {
|
|
73
|
+
gl_FragColor = vec4(normal, 1.0);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
vec4 cameraPosition = cameraMatrixWorld * vec4(0.0, 0.0, 0.0, 1.0);
|
|
78
|
+
|
|
79
|
+
vec3 worldPos = computeWorldPosition(depth, vUv);
|
|
80
|
+
vec3 screenSpaceNormal = getUnpackedNormal(vUv);
|
|
81
|
+
|
|
82
|
+
float ao = 0.0, totalWeight = 0.0;
|
|
83
|
+
|
|
84
|
+
for (int i = 0; i < spp; i++) {
|
|
85
|
+
int seed = i;
|
|
86
|
+
#ifdef animatedNoise
|
|
87
|
+
seed += frame;
|
|
88
|
+
#endif
|
|
89
|
+
|
|
90
|
+
vec4 blueNoise = sampleBlueNoise(blueNoiseTexture, seed, blueNoiseRepeat, texSize);
|
|
91
|
+
|
|
92
|
+
vec3 sampleWorldDir = cosineSampleHemisphere(normal, blueNoise.rg);
|
|
93
|
+
|
|
94
|
+
vec3 sampleWorldPos = worldPos + aoDistance * pow(blueNoise.b, distancePower + 1.0) * sampleWorldDir;
|
|
95
|
+
|
|
96
|
+
// Project the sample position to screen space
|
|
97
|
+
vec4 sampleUv = projectionViewMatrix * vec4(sampleWorldPos, 1.);
|
|
98
|
+
sampleUv.xy /= sampleUv.w;
|
|
99
|
+
sampleUv.xy = sampleUv.xy * 0.5 + 0.5;
|
|
100
|
+
|
|
101
|
+
// Get the depth of the sample position
|
|
102
|
+
float sampleDepth = textureLod(depthTexture, sampleUv.xy, 0.0).r;
|
|
103
|
+
|
|
104
|
+
if(sampleDepth < 1.0) {
|
|
105
|
+
vec3 sampleNormal = getUnpackedNormal(sampleUv.xy);
|
|
106
|
+
|
|
107
|
+
// Compute the horizon line
|
|
108
|
+
float deltaDepth = depth - sampleDepth;
|
|
109
|
+
|
|
110
|
+
// distance based bias
|
|
111
|
+
float d = distance(sampleWorldPos, cameraPosition.xyz) / aoDistance;
|
|
112
|
+
deltaDepth *= 0.001 * d * d;
|
|
113
|
+
|
|
114
|
+
float th = thickness * 0.01;
|
|
115
|
+
|
|
116
|
+
float theta = dot(normal, sampleWorldDir);
|
|
117
|
+
totalWeight += theta;
|
|
118
|
+
|
|
119
|
+
if (deltaDepth < th) {
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
float horizon = sampleDepth + deltaDepth * bias * 1000.;
|
|
123
|
+
|
|
124
|
+
float occlusion = max(0.0, horizon - depth) * theta;
|
|
125
|
+
|
|
126
|
+
float m = max(0., 1. - deltaDepth / th);
|
|
127
|
+
occlusion = 10. * occlusion * m / d;
|
|
128
|
+
|
|
129
|
+
occlusion = max(0.0, occlusion);
|
|
130
|
+
|
|
131
|
+
// check if the normals are in the same direction
|
|
132
|
+
float dotProduct = dot(screenSpaceNormal, sampleNormal);
|
|
133
|
+
if (dotProduct < 0.9999) {
|
|
134
|
+
|
|
135
|
+
occlusion = sqrt(occlusion);
|
|
136
|
+
ao += occlusion;
|
|
137
|
+
} else {
|
|
138
|
+
if(areDepthsOnSamePlane(depth, sampleDepth, vUv, sampleUv.xy, screenSpaceNormal, 0.1)) {
|
|
139
|
+
// occluded += 0.0;
|
|
140
|
+
// totalWeight += 1.0;
|
|
141
|
+
} else {
|
|
142
|
+
|
|
143
|
+
occlusion = sqrt(occlusion);
|
|
144
|
+
ao += occlusion;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (totalWeight > 0.) ao /= totalWeight;
|
|
152
|
+
|
|
153
|
+
// clamp ao to [0, 1]
|
|
154
|
+
ao = clamp(1. - ao, 0., 1.);
|
|
155
|
+
|
|
156
|
+
gl_FragColor = vec4(normal, ao);
|
|
157
|
+
}
|
|
158
158
|
`;
|
|
159
159
|
//# sourceMappingURL=hbao.js.map
|
|
@@ -1,157 +1,157 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.poissionDenoise = void 0;
|
|
4
|
-
exports.poissionDenoise = `
|
|
5
|
-
varying vec2 vUv;
|
|
6
|
-
|
|
7
|
-
uniform sampler2D inputTexture;
|
|
8
|
-
uniform highp sampler2D depthTexture;
|
|
9
|
-
uniform highp sampler2D normalTexture;
|
|
10
|
-
uniform mat4 projectionMatrixInverse;
|
|
11
|
-
uniform mat4 viewMatrixInverse;
|
|
12
|
-
uniform mat4 cameraMatrixWorld;
|
|
13
|
-
uniform float lumaPhi;
|
|
14
|
-
uniform float depthPhi;
|
|
15
|
-
uniform float normalPhi;
|
|
16
|
-
uniform float distance;
|
|
17
|
-
uniform sampler2D blueNoiseTexture;
|
|
18
|
-
uniform vec2 blueNoiseRepeat;
|
|
19
|
-
uniform int index;
|
|
20
|
-
uniform vec2 resolution;
|
|
21
|
-
|
|
22
|
-
#include <common>
|
|
23
|
-
#include <sampleBlueNoise>
|
|
24
|
-
|
|
25
|
-
vec3 computeWorldPosition(float depth, vec2 coord, bool useCameraMatrixWorld) {
|
|
26
|
-
// Convert depth to normalized device coordinates (NDC)
|
|
27
|
-
float z = depth * 2.0 - 1.0;
|
|
28
|
-
vec4 clipSpacePosition = vec4(coord * 2.0 - 1.0, z, 1.0);
|
|
29
|
-
|
|
30
|
-
// Transform to view space
|
|
31
|
-
vec4 viewSpacePosition = projectionMatrixInverse * clipSpacePosition;
|
|
32
|
-
|
|
33
|
-
// Perspective division
|
|
34
|
-
viewSpacePosition /= viewSpacePosition.w;
|
|
35
|
-
|
|
36
|
-
// Transform to world space using the selected method
|
|
37
|
-
vec4 worldSpacePosition;
|
|
38
|
-
if (useCameraMatrixWorld) {
|
|
39
|
-
// Use cameraMatrixWorld directly
|
|
40
|
-
worldSpacePosition = cameraMatrixWorld * viewSpacePosition;
|
|
41
|
-
} else {
|
|
42
|
-
// Use viewMatrixInverse
|
|
43
|
-
worldSpacePosition = viewMatrixInverse * viewSpacePosition;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return worldSpacePosition.xyz;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
#define luminance(a) dot(vec3(0.2125, 0.7154, 0.0721), a)
|
|
50
|
-
|
|
51
|
-
vec3 getNormal(vec2 uv, vec4 texel) {
|
|
52
|
-
#ifdef NORMAL_IN_RGB
|
|
53
|
-
// in case the normal is stored in the RGB channels of the texture
|
|
54
|
-
return texel.rgb;
|
|
55
|
-
#else
|
|
56
|
-
return normalize(textureLod(normalTexture, uv, 0.).xyz * 2.0 - 1.0);
|
|
57
|
-
#endif
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
float distToPlane(const vec3 worldPos, const vec3 neighborWorldPos, const vec3 worldNormal) {
|
|
61
|
-
vec3 toCurrent = worldPos - neighborWorldPos;
|
|
62
|
-
float distToPlane = abs(dot(toCurrent, worldNormal));
|
|
63
|
-
|
|
64
|
-
return distToPlane;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
void main() {
|
|
68
|
-
vec4 depthTexel = textureLod(depthTexture, vUv, 0.);
|
|
69
|
-
vec4 texel = textureLod(inputTexture, vUv, 0.0);
|
|
70
|
-
vec3 normal = getNormal(vUv, texel);
|
|
71
|
-
|
|
72
|
-
if (depthTexel.r == 1.0 || dot(depthTexel.rgb, depthTexel.rgb) == 0.) {
|
|
73
|
-
#ifdef NORMAL_IN_RGB
|
|
74
|
-
gl_FragColor = vec4(normal, 1.0);
|
|
75
|
-
#else
|
|
76
|
-
gl_FragColor = vec4(1.0);
|
|
77
|
-
#endif
|
|
78
|
-
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
#ifdef NORMAL_IN_RGB
|
|
83
|
-
float inputTexel = texel.a;
|
|
84
|
-
float center = texel.a;
|
|
85
|
-
#else
|
|
86
|
-
vec3 inputTexel = texel.rgb;
|
|
87
|
-
vec3 center = texel.rgb;
|
|
88
|
-
#endif
|
|
89
|
-
|
|
90
|
-
float depth = depthTexel.x;
|
|
91
|
-
vec3 worldPos = computeWorldPosition(depth, vUv, true);
|
|
92
|
-
|
|
93
|
-
float totalWeight = 1.0;
|
|
94
|
-
|
|
95
|
-
vec4 blueNoise = sampleBlueNoise(blueNoiseTexture, 0, blueNoiseRepeat, resolution);
|
|
96
|
-
float angle = blueNoise[index];
|
|
97
|
-
|
|
98
|
-
float s = sin(angle), c = cos(angle);
|
|
99
|
-
|
|
100
|
-
mat2 rotationMatrix = mat2(c, -s, s, c);
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
#ifdef NORMAL_IN_RGB
|
|
104
|
-
float denoised = inputTexel;
|
|
105
|
-
#else
|
|
106
|
-
vec3 denoised = inputTexel;
|
|
107
|
-
#endif
|
|
108
|
-
|
|
109
|
-
for (int i = 0; i < samples; i++) {
|
|
110
|
-
vec2 offset = rotationMatrix * poissonDisk[i];
|
|
111
|
-
vec2 neighborUv = vUv + offset;
|
|
112
|
-
|
|
113
|
-
vec4 neighborTexel = textureLod(inputTexture, neighborUv, 0.0);
|
|
114
|
-
|
|
115
|
-
vec3 neighborNormal = getNormal(neighborUv, neighborTexel);
|
|
116
|
-
#ifdef NORMAL_IN_RGB
|
|
117
|
-
float neighborColor = neighborTexel.a;
|
|
118
|
-
#else
|
|
119
|
-
vec3 neighborColor = neighborTexel.rgb;
|
|
120
|
-
#endif
|
|
121
|
-
|
|
122
|
-
float sampleDepth = textureLod(depthTexture, neighborUv, 0.0).x;
|
|
123
|
-
|
|
124
|
-
vec3 worldPosSample = computeWorldPosition(sampleDepth, neighborUv, true);
|
|
125
|
-
float tangentPlaneDist = abs(dot(worldPos - worldPosSample, normal));
|
|
126
|
-
|
|
127
|
-
if (sampleDepth < 1.0) {
|
|
128
|
-
float normalDiff = dot(normal, neighborNormal);
|
|
129
|
-
float normalSimilarity = pow(max(normalDiff, 0.), normalPhi);
|
|
130
|
-
|
|
131
|
-
#ifdef NORMAL_IN_RGB
|
|
132
|
-
float lumaDiff = abs(neighborColor - center);
|
|
133
|
-
#else
|
|
134
|
-
float lumaDiff = abs(luminance(neighborColor) - luminance(center));
|
|
135
|
-
#endif
|
|
136
|
-
float lumaSimilarity = max(1.0 - lumaDiff / lumaPhi, 0.0);
|
|
137
|
-
|
|
138
|
-
float depthDiff = 1. - (distToPlane(worldPos, worldPosSample, normal) / distance);
|
|
139
|
-
float depthSimilarity = max(depthDiff / depthPhi, 0.);
|
|
140
|
-
|
|
141
|
-
float w = lumaSimilarity * depthSimilarity * normalSimilarity;
|
|
142
|
-
|
|
143
|
-
denoised += w * neighborColor;
|
|
144
|
-
totalWeight += w;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
if (totalWeight > 0.) denoised /= totalWeight;
|
|
149
|
-
|
|
150
|
-
#ifdef NORMAL_IN_RGB
|
|
151
|
-
gl_FragColor = vec4(normal, denoised);
|
|
152
|
-
#else
|
|
153
|
-
gl_FragColor = vec4(denoised, 1.);
|
|
154
|
-
#endif
|
|
155
|
-
}
|
|
4
|
+
exports.poissionDenoise = `
|
|
5
|
+
varying vec2 vUv;
|
|
6
|
+
|
|
7
|
+
uniform sampler2D inputTexture;
|
|
8
|
+
uniform highp sampler2D depthTexture;
|
|
9
|
+
uniform highp sampler2D normalTexture;
|
|
10
|
+
uniform mat4 projectionMatrixInverse;
|
|
11
|
+
uniform mat4 viewMatrixInverse;
|
|
12
|
+
uniform mat4 cameraMatrixWorld;
|
|
13
|
+
uniform float lumaPhi;
|
|
14
|
+
uniform float depthPhi;
|
|
15
|
+
uniform float normalPhi;
|
|
16
|
+
uniform float distance;
|
|
17
|
+
uniform sampler2D blueNoiseTexture;
|
|
18
|
+
uniform vec2 blueNoiseRepeat;
|
|
19
|
+
uniform int index;
|
|
20
|
+
uniform vec2 resolution;
|
|
21
|
+
|
|
22
|
+
#include <common>
|
|
23
|
+
#include <sampleBlueNoise>
|
|
24
|
+
|
|
25
|
+
vec3 computeWorldPosition(float depth, vec2 coord, bool useCameraMatrixWorld) {
|
|
26
|
+
// Convert depth to normalized device coordinates (NDC)
|
|
27
|
+
float z = depth * 2.0 - 1.0;
|
|
28
|
+
vec4 clipSpacePosition = vec4(coord * 2.0 - 1.0, z, 1.0);
|
|
29
|
+
|
|
30
|
+
// Transform to view space
|
|
31
|
+
vec4 viewSpacePosition = projectionMatrixInverse * clipSpacePosition;
|
|
32
|
+
|
|
33
|
+
// Perspective division
|
|
34
|
+
viewSpacePosition /= viewSpacePosition.w;
|
|
35
|
+
|
|
36
|
+
// Transform to world space using the selected method
|
|
37
|
+
vec4 worldSpacePosition;
|
|
38
|
+
if (useCameraMatrixWorld) {
|
|
39
|
+
// Use cameraMatrixWorld directly
|
|
40
|
+
worldSpacePosition = cameraMatrixWorld * viewSpacePosition;
|
|
41
|
+
} else {
|
|
42
|
+
// Use viewMatrixInverse
|
|
43
|
+
worldSpacePosition = viewMatrixInverse * viewSpacePosition;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return worldSpacePosition.xyz;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
#define luminance(a) dot(vec3(0.2125, 0.7154, 0.0721), a)
|
|
50
|
+
|
|
51
|
+
vec3 getNormal(vec2 uv, vec4 texel) {
|
|
52
|
+
#ifdef NORMAL_IN_RGB
|
|
53
|
+
// in case the normal is stored in the RGB channels of the texture
|
|
54
|
+
return texel.rgb;
|
|
55
|
+
#else
|
|
56
|
+
return normalize(textureLod(normalTexture, uv, 0.).xyz * 2.0 - 1.0);
|
|
57
|
+
#endif
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
float distToPlane(const vec3 worldPos, const vec3 neighborWorldPos, const vec3 worldNormal) {
|
|
61
|
+
vec3 toCurrent = worldPos - neighborWorldPos;
|
|
62
|
+
float distToPlane = abs(dot(toCurrent, worldNormal));
|
|
63
|
+
|
|
64
|
+
return distToPlane;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
void main() {
|
|
68
|
+
vec4 depthTexel = textureLod(depthTexture, vUv, 0.);
|
|
69
|
+
vec4 texel = textureLod(inputTexture, vUv, 0.0);
|
|
70
|
+
vec3 normal = getNormal(vUv, texel);
|
|
71
|
+
|
|
72
|
+
if (depthTexel.r == 1.0 || dot(depthTexel.rgb, depthTexel.rgb) == 0.) {
|
|
73
|
+
#ifdef NORMAL_IN_RGB
|
|
74
|
+
gl_FragColor = vec4(normal, 1.0);
|
|
75
|
+
#else
|
|
76
|
+
gl_FragColor = vec4(1.0);
|
|
77
|
+
#endif
|
|
78
|
+
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
#ifdef NORMAL_IN_RGB
|
|
83
|
+
float inputTexel = texel.a;
|
|
84
|
+
float center = texel.a;
|
|
85
|
+
#else
|
|
86
|
+
vec3 inputTexel = texel.rgb;
|
|
87
|
+
vec3 center = texel.rgb;
|
|
88
|
+
#endif
|
|
89
|
+
|
|
90
|
+
float depth = depthTexel.x;
|
|
91
|
+
vec3 worldPos = computeWorldPosition(depth, vUv, true);
|
|
92
|
+
|
|
93
|
+
float totalWeight = 1.0;
|
|
94
|
+
|
|
95
|
+
vec4 blueNoise = sampleBlueNoise(blueNoiseTexture, 0, blueNoiseRepeat, resolution);
|
|
96
|
+
float angle = blueNoise[index];
|
|
97
|
+
|
|
98
|
+
float s = sin(angle), c = cos(angle);
|
|
99
|
+
|
|
100
|
+
mat2 rotationMatrix = mat2(c, -s, s, c);
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
#ifdef NORMAL_IN_RGB
|
|
104
|
+
float denoised = inputTexel;
|
|
105
|
+
#else
|
|
106
|
+
vec3 denoised = inputTexel;
|
|
107
|
+
#endif
|
|
108
|
+
|
|
109
|
+
for (int i = 0; i < samples; i++) {
|
|
110
|
+
vec2 offset = rotationMatrix * poissonDisk[i];
|
|
111
|
+
vec2 neighborUv = vUv + offset;
|
|
112
|
+
|
|
113
|
+
vec4 neighborTexel = textureLod(inputTexture, neighborUv, 0.0);
|
|
114
|
+
|
|
115
|
+
vec3 neighborNormal = getNormal(neighborUv, neighborTexel);
|
|
116
|
+
#ifdef NORMAL_IN_RGB
|
|
117
|
+
float neighborColor = neighborTexel.a;
|
|
118
|
+
#else
|
|
119
|
+
vec3 neighborColor = neighborTexel.rgb;
|
|
120
|
+
#endif
|
|
121
|
+
|
|
122
|
+
float sampleDepth = textureLod(depthTexture, neighborUv, 0.0).x;
|
|
123
|
+
|
|
124
|
+
vec3 worldPosSample = computeWorldPosition(sampleDepth, neighborUv, true);
|
|
125
|
+
float tangentPlaneDist = abs(dot(worldPos - worldPosSample, normal));
|
|
126
|
+
|
|
127
|
+
if (sampleDepth < 1.0) {
|
|
128
|
+
float normalDiff = dot(normal, neighborNormal);
|
|
129
|
+
float normalSimilarity = pow(max(normalDiff, 0.), normalPhi);
|
|
130
|
+
|
|
131
|
+
#ifdef NORMAL_IN_RGB
|
|
132
|
+
float lumaDiff = abs(neighborColor - center);
|
|
133
|
+
#else
|
|
134
|
+
float lumaDiff = abs(luminance(neighborColor) - luminance(center));
|
|
135
|
+
#endif
|
|
136
|
+
float lumaSimilarity = max(1.0 - lumaDiff / lumaPhi, 0.0);
|
|
137
|
+
|
|
138
|
+
float depthDiff = 1. - (distToPlane(worldPos, worldPosSample, normal) / distance);
|
|
139
|
+
float depthSimilarity = max(depthDiff / depthPhi, 0.);
|
|
140
|
+
|
|
141
|
+
float w = lumaSimilarity * depthSimilarity * normalSimilarity;
|
|
142
|
+
|
|
143
|
+
denoised += w * neighborColor;
|
|
144
|
+
totalWeight += w;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (totalWeight > 0.) denoised /= totalWeight;
|
|
149
|
+
|
|
150
|
+
#ifdef NORMAL_IN_RGB
|
|
151
|
+
gl_FragColor = vec4(normal, denoised);
|
|
152
|
+
#else
|
|
153
|
+
gl_FragColor = vec4(denoised, 1.);
|
|
154
|
+
#endif
|
|
155
|
+
}
|
|
156
156
|
`;
|
|
157
157
|
//# sourceMappingURL=poissionDenoise.js.map
|