three-stdlib 2.9.1 → 2.10.0
Sign up to get free protection for your applications and to get access to all the features.
- package/index.cjs.js +1 -1
- package/objects/MarchingCubes.cjs.js +1 -1
- package/objects/MarchingCubes.js +49 -109
- package/package.json +1 -1
- package/postprocessing/BloomPass.cjs.js +1 -1
- package/postprocessing/BloomPass.d.ts +12 -10
- package/postprocessing/BloomPass.js +93 -58
- package/postprocessing/BokehPass.cjs.js +1 -1
- package/postprocessing/BokehPass.d.ts +12 -14
- package/postprocessing/BokehPass.js +70 -55
- package/postprocessing/ClearPass.cjs.js +1 -1
- package/postprocessing/ClearPass.d.ts +6 -5
- package/postprocessing/ClearPass.js +21 -12
- package/postprocessing/DotScreenPass.cjs.js +1 -1
- package/postprocessing/DotScreenPass.d.ts +8 -8
- package/postprocessing/DotScreenPass.js +29 -20
- package/postprocessing/FilmPass.cjs.js +1 -1
- package/postprocessing/FilmPass.d.ts +8 -8
- package/postprocessing/FilmPass.js +30 -23
- package/postprocessing/GlitchPass.cjs.js +1 -1
- package/postprocessing/GlitchPass.d.ts +8 -9
- package/postprocessing/GlitchPass.js +15 -1
- package/postprocessing/HalftonePass.cjs.js +1 -1
- package/postprocessing/HalftonePass.d.ts +13 -13
- package/postprocessing/HalftonePass.js +35 -26
- package/postprocessing/OutlinePass.cjs.js +1 -1
- package/postprocessing/OutlinePass.d.ts +15 -26
- package/postprocessing/OutlinePass.js +317 -220
@@ -1,103 +1,170 @@
|
|
1
|
-
import
|
2
|
-
import {
|
1
|
+
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
2
|
+
import { Pass, FullScreenQuad } from './Pass.js';
|
3
|
+
import { Vector2, Color, WebGLRenderTarget, MeshDepthMaterial, DoubleSide, RGBADepthPacking, NoBlending, UniformsUtils, ShaderMaterial, Matrix4, Vector3, AdditiveBlending } from 'three';
|
3
4
|
import { CopyShader } from '../shaders/CopyShader.js';
|
4
5
|
|
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
|
-
|
6
|
+
class OutlinePass extends Pass {
|
7
|
+
constructor(resolution, scene, camera, selectedObjects) {
|
8
|
+
super();
|
9
|
+
|
10
|
+
_defineProperty(this, "renderScene", void 0);
|
11
|
+
|
12
|
+
_defineProperty(this, "renderCamera", void 0);
|
13
|
+
|
14
|
+
_defineProperty(this, "selectedObjects", void 0);
|
15
|
+
|
16
|
+
_defineProperty(this, "visibleEdgeColor", void 0);
|
17
|
+
|
18
|
+
_defineProperty(this, "hiddenEdgeColor", void 0);
|
19
|
+
|
20
|
+
_defineProperty(this, "edgeGlow", void 0);
|
21
|
+
|
22
|
+
_defineProperty(this, "usePatternTexture", void 0);
|
23
|
+
|
24
|
+
_defineProperty(this, "edgeThickness", void 0);
|
25
|
+
|
26
|
+
_defineProperty(this, "edgeStrength", void 0);
|
27
|
+
|
28
|
+
_defineProperty(this, "downSampleRatio", void 0);
|
29
|
+
|
30
|
+
_defineProperty(this, "pulsePeriod", void 0);
|
31
|
+
|
32
|
+
_defineProperty(this, "resolution", void 0);
|
33
|
+
|
34
|
+
_defineProperty(this, "renderTargetMaskBuffer", void 0);
|
35
|
+
|
36
|
+
_defineProperty(this, "depthMaterial", void 0);
|
37
|
+
|
38
|
+
_defineProperty(this, "prepareMaskMaterial", void 0);
|
39
|
+
|
40
|
+
_defineProperty(this, "renderTargetDepthBuffer", void 0);
|
41
|
+
|
42
|
+
_defineProperty(this, "renderTargetMaskDownSampleBuffer", void 0);
|
43
|
+
|
44
|
+
_defineProperty(this, "renderTargetBlurBuffer1", void 0);
|
45
|
+
|
46
|
+
_defineProperty(this, "renderTargetBlurBuffer2", void 0);
|
47
|
+
|
48
|
+
_defineProperty(this, "edgeDetectionMaterial", void 0);
|
49
|
+
|
50
|
+
_defineProperty(this, "renderTargetEdgeBuffer1", void 0);
|
51
|
+
|
52
|
+
_defineProperty(this, "renderTargetEdgeBuffer2", void 0);
|
53
|
+
|
54
|
+
_defineProperty(this, "separableBlurMaterial1", void 0);
|
55
|
+
|
56
|
+
_defineProperty(this, "separableBlurMaterial2", void 0);
|
57
|
+
|
58
|
+
_defineProperty(this, "overlayMaterial", void 0);
|
59
|
+
|
60
|
+
_defineProperty(this, "materialCopy", void 0);
|
61
|
+
|
62
|
+
_defineProperty(this, "oldClearAlpha", void 0);
|
63
|
+
|
64
|
+
_defineProperty(this, "fsQuad", void 0);
|
65
|
+
|
66
|
+
_defineProperty(this, "tempPulseColor1", void 0);
|
67
|
+
|
68
|
+
_defineProperty(this, "tempPulseColor2", void 0);
|
69
|
+
|
70
|
+
_defineProperty(this, "textureMatrix", void 0);
|
71
|
+
|
72
|
+
_defineProperty(this, "patternTexture", void 0);
|
73
|
+
|
74
|
+
_defineProperty(this, "_visibilityCache", void 0);
|
75
|
+
|
76
|
+
_defineProperty(this, "_oldClearColor", void 0);
|
77
|
+
|
78
|
+
_defineProperty(this, "copyUniforms", void 0);
|
79
|
+
|
80
|
+
_defineProperty(this, "BlurDirectionX", new Vector2(1.0, 0.0));
|
81
|
+
|
82
|
+
_defineProperty(this, "BlurDirectionY", new Vector2(0.0, 1.0));
|
83
|
+
|
84
|
+
this.renderScene = scene;
|
85
|
+
this.renderCamera = camera;
|
86
|
+
this.selectedObjects = selectedObjects !== undefined ? selectedObjects : [];
|
87
|
+
this.visibleEdgeColor = new Color(1, 1, 1);
|
88
|
+
this.hiddenEdgeColor = new Color(0.1, 0.04, 0.02);
|
89
|
+
this.edgeGlow = 0.0;
|
90
|
+
this.usePatternTexture = false;
|
91
|
+
this.edgeThickness = 1.0;
|
92
|
+
this.edgeStrength = 3.0;
|
93
|
+
this.downSampleRatio = 2;
|
94
|
+
this.pulsePeriod = 0;
|
95
|
+
this._visibilityCache = new Map();
|
96
|
+
this.resolution = resolution !== undefined ? new Vector2(resolution.x, resolution.y) : new Vector2(256, 256);
|
97
|
+
const resx = Math.round(this.resolution.x / this.downSampleRatio);
|
98
|
+
const resy = Math.round(this.resolution.y / this.downSampleRatio);
|
99
|
+
this.renderTargetMaskBuffer = new WebGLRenderTarget(this.resolution.x, this.resolution.y);
|
100
|
+
this.renderTargetMaskBuffer.texture.name = 'OutlinePass.mask';
|
101
|
+
this.renderTargetMaskBuffer.texture.generateMipmaps = false;
|
102
|
+
this.depthMaterial = new MeshDepthMaterial();
|
103
|
+
this.depthMaterial.side = DoubleSide;
|
104
|
+
this.depthMaterial.depthPacking = RGBADepthPacking;
|
105
|
+
this.depthMaterial.blending = NoBlending;
|
106
|
+
this.prepareMaskMaterial = this.getPrepareMaskMaterial();
|
107
|
+
this.prepareMaskMaterial.side = DoubleSide;
|
108
|
+
this.prepareMaskMaterial.fragmentShader = replaceDepthToViewZ(this.prepareMaskMaterial.fragmentShader, this.renderCamera);
|
109
|
+
this.renderTargetDepthBuffer = new WebGLRenderTarget(this.resolution.x, this.resolution.y);
|
110
|
+
this.renderTargetDepthBuffer.texture.name = 'OutlinePass.depth';
|
111
|
+
this.renderTargetDepthBuffer.texture.generateMipmaps = false;
|
112
|
+
this.renderTargetMaskDownSampleBuffer = new WebGLRenderTarget(resx, resy);
|
113
|
+
this.renderTargetMaskDownSampleBuffer.texture.name = 'OutlinePass.depthDownSample';
|
114
|
+
this.renderTargetMaskDownSampleBuffer.texture.generateMipmaps = false;
|
115
|
+
this.renderTargetBlurBuffer1 = new WebGLRenderTarget(resx, resy);
|
116
|
+
this.renderTargetBlurBuffer1.texture.name = 'OutlinePass.blur1';
|
117
|
+
this.renderTargetBlurBuffer1.texture.generateMipmaps = false;
|
118
|
+
this.renderTargetBlurBuffer2 = new WebGLRenderTarget(Math.round(resx / 2), Math.round(resy / 2));
|
119
|
+
this.renderTargetBlurBuffer2.texture.name = 'OutlinePass.blur2';
|
120
|
+
this.renderTargetBlurBuffer2.texture.generateMipmaps = false;
|
121
|
+
this.edgeDetectionMaterial = this.getEdgeDetectionMaterial();
|
122
|
+
this.renderTargetEdgeBuffer1 = new WebGLRenderTarget(resx, resy);
|
123
|
+
this.renderTargetEdgeBuffer1.texture.name = 'OutlinePass.edge1';
|
124
|
+
this.renderTargetEdgeBuffer1.texture.generateMipmaps = false;
|
125
|
+
this.renderTargetEdgeBuffer2 = new WebGLRenderTarget(Math.round(resx / 2), Math.round(resy / 2));
|
126
|
+
this.renderTargetEdgeBuffer2.texture.name = 'OutlinePass.edge2';
|
127
|
+
this.renderTargetEdgeBuffer2.texture.generateMipmaps = false;
|
128
|
+
const MAX_EDGE_THICKNESS = 4;
|
129
|
+
const MAX_EDGE_GLOW = 4;
|
130
|
+
this.separableBlurMaterial1 = this.getSeperableBlurMaterial(MAX_EDGE_THICKNESS);
|
131
|
+
this.separableBlurMaterial1.uniforms['texSize'].value.set(resx, resy);
|
132
|
+
this.separableBlurMaterial1.uniforms['kernelRadius'].value = 1;
|
133
|
+
this.separableBlurMaterial2 = this.getSeperableBlurMaterial(MAX_EDGE_GLOW);
|
134
|
+
this.separableBlurMaterial2.uniforms['texSize'].value.set(Math.round(resx / 2), Math.round(resy / 2));
|
135
|
+
this.separableBlurMaterial2.uniforms['kernelRadius'].value = MAX_EDGE_GLOW; // Overlay material
|
136
|
+
|
137
|
+
this.overlayMaterial = this.getOverlayMaterial(); // copy material
|
138
|
+
|
139
|
+
if (CopyShader === undefined) console.error('THREE.OutlinePass relies on CopyShader');
|
140
|
+
const copyShader = CopyShader;
|
141
|
+
this.copyUniforms = UniformsUtils.clone(copyShader.uniforms);
|
142
|
+
this.copyUniforms['opacity'].value = 1.0;
|
143
|
+
this.materialCopy = new ShaderMaterial({
|
144
|
+
uniforms: this.copyUniforms,
|
145
|
+
vertexShader: copyShader.vertexShader,
|
146
|
+
fragmentShader: copyShader.fragmentShader,
|
147
|
+
blending: NoBlending,
|
148
|
+
depthTest: false,
|
149
|
+
depthWrite: false,
|
150
|
+
transparent: true
|
151
|
+
});
|
152
|
+
this.enabled = true;
|
153
|
+
this.needsSwap = false;
|
154
|
+
this._oldClearColor = new Color();
|
155
|
+
this.oldClearAlpha = 1;
|
156
|
+
this.fsQuad = new FullScreenQuad(this.materialCopy);
|
157
|
+
this.tempPulseColor1 = new Color();
|
158
|
+
this.tempPulseColor2 = new Color();
|
159
|
+
this.textureMatrix = new Matrix4();
|
160
|
+
|
161
|
+
function replaceDepthToViewZ(string, camera) {
|
162
|
+
const type = camera.isPerspectiveCamera ? 'perspective' : 'orthographic';
|
163
|
+
return string.replace(/DEPTH_TO_VIEW_Z/g, type + 'DepthToViewZ');
|
164
|
+
}
|
95
165
|
}
|
96
|
-
};
|
97
166
|
|
98
|
-
|
99
|
-
constructor: OutlinePass,
|
100
|
-
dispose: function () {
|
167
|
+
dispose() {
|
101
168
|
this.renderTargetMaskBuffer.dispose();
|
102
169
|
this.renderTargetDepthBuffer.dispose();
|
103
170
|
this.renderTargetMaskDownSampleBuffer.dispose();
|
@@ -105,11 +172,13 @@ OutlinePass.prototype = Object.assign(Object.create(Pass.prototype), {
|
|
105
172
|
this.renderTargetBlurBuffer2.dispose();
|
106
173
|
this.renderTargetEdgeBuffer1.dispose();
|
107
174
|
this.renderTargetEdgeBuffer2.dispose();
|
108
|
-
}
|
109
|
-
|
175
|
+
}
|
176
|
+
|
177
|
+
setSize(width, height) {
|
110
178
|
this.renderTargetMaskBuffer.setSize(width, height);
|
111
|
-
|
112
|
-
|
179
|
+
this.renderTargetDepthBuffer.setSize(width, height);
|
180
|
+
let resx = Math.round(width / this.downSampleRatio);
|
181
|
+
let resy = Math.round(height / this.downSampleRatio);
|
113
182
|
this.renderTargetMaskDownSampleBuffer.setSize(resx, resy);
|
114
183
|
this.renderTargetBlurBuffer1.setSize(resx, resy);
|
115
184
|
this.renderTargetEdgeBuffer1.setSize(resx, resy);
|
@@ -119,9 +188,10 @@ OutlinePass.prototype = Object.assign(Object.create(Pass.prototype), {
|
|
119
188
|
this.renderTargetBlurBuffer2.setSize(resx, resy);
|
120
189
|
this.renderTargetEdgeBuffer2.setSize(resx, resy);
|
121
190
|
this.separableBlurMaterial2.uniforms['texSize'].value.set(resx, resy);
|
122
|
-
}
|
123
|
-
|
124
|
-
|
191
|
+
}
|
192
|
+
|
193
|
+
changeVisibilityOfSelectedObjects(bVisible) {
|
194
|
+
const cache = this._visibilityCache;
|
125
195
|
|
126
196
|
function gatherSelectedMeshesCallBack(object) {
|
127
197
|
if (object.isMesh) {
|
@@ -135,30 +205,31 @@ OutlinePass.prototype = Object.assign(Object.create(Pass.prototype), {
|
|
135
205
|
}
|
136
206
|
|
137
207
|
for (let i = 0; i < this.selectedObjects.length; i++) {
|
138
|
-
|
208
|
+
const selectedObject = this.selectedObjects[i];
|
139
209
|
selectedObject.traverse(gatherSelectedMeshesCallBack);
|
140
210
|
}
|
141
|
-
}
|
142
|
-
|
143
|
-
|
144
|
-
|
211
|
+
}
|
212
|
+
|
213
|
+
changeVisibilityOfNonSelectedObjects(bVisible) {
|
214
|
+
const cache = this._visibilityCache;
|
215
|
+
const selectedMeshes = [];
|
145
216
|
|
146
217
|
function gatherSelectedMeshesCallBack(object) {
|
147
218
|
if (object.isMesh) selectedMeshes.push(object);
|
148
219
|
}
|
149
220
|
|
150
221
|
for (let i = 0; i < this.selectedObjects.length; i++) {
|
151
|
-
|
222
|
+
const selectedObject = this.selectedObjects[i];
|
152
223
|
selectedObject.traverse(gatherSelectedMeshesCallBack);
|
153
224
|
}
|
154
225
|
|
155
226
|
function VisibilityChangeCallBack(object) {
|
156
227
|
if (object.isMesh || object.isSprite) {
|
157
228
|
// only meshes and sprites are supported by OutlinePass
|
158
|
-
|
229
|
+
let bFound = false;
|
159
230
|
|
160
231
|
for (let i = 0; i < selectedMeshes.length; i++) {
|
161
|
-
|
232
|
+
const selectedObjectId = selectedMeshes[i].id;
|
162
233
|
|
163
234
|
if (selectedObjectId === object.id) {
|
164
235
|
bFound = true;
|
@@ -167,7 +238,7 @@ OutlinePass.prototype = Object.assign(Object.create(Pass.prototype), {
|
|
167
238
|
}
|
168
239
|
|
169
240
|
if (bFound === false) {
|
170
|
-
|
241
|
+
const visibility = object.visible;
|
171
242
|
|
172
243
|
if (bVisible === false || cache.get(object) === true) {
|
173
244
|
object.visible = bVisible;
|
@@ -188,23 +259,25 @@ OutlinePass.prototype = Object.assign(Object.create(Pass.prototype), {
|
|
188
259
|
}
|
189
260
|
|
190
261
|
this.renderScene.traverse(VisibilityChangeCallBack);
|
191
|
-
}
|
192
|
-
|
262
|
+
}
|
263
|
+
|
264
|
+
updateTextureMatrix() {
|
193
265
|
this.textureMatrix.set(0.5, 0.0, 0.0, 0.5, 0.0, 0.5, 0.0, 0.5, 0.0, 0.0, 0.5, 0.5, 0.0, 0.0, 0.0, 1.0);
|
194
266
|
this.textureMatrix.multiply(this.renderCamera.projectionMatrix);
|
195
267
|
this.textureMatrix.multiply(this.renderCamera.matrixWorldInverse);
|
196
|
-
}
|
197
|
-
|
268
|
+
}
|
269
|
+
|
270
|
+
render(renderer, writeBuffer, readBuffer, deltaTime, maskActive) {
|
198
271
|
if (this.selectedObjects.length > 0) {
|
199
272
|
renderer.getClearColor(this._oldClearColor);
|
200
273
|
this.oldClearAlpha = renderer.getClearAlpha();
|
201
|
-
|
274
|
+
const oldAutoClear = renderer.autoClear;
|
202
275
|
renderer.autoClear = false;
|
203
276
|
if (maskActive) renderer.state.buffers.stencil.setTest(false);
|
204
277
|
renderer.setClearColor(0xffffff, 1); // Make selected objects invisible
|
205
278
|
|
206
279
|
this.changeVisibilityOfSelectedObjects(false);
|
207
|
-
|
280
|
+
const currentBackground = this.renderScene.background;
|
208
281
|
this.renderScene.background = null; // 1. Draw Non Selected objects in the depth buffer
|
209
282
|
|
210
283
|
this.renderScene.overrideMaterial = this.depthMaterial;
|
@@ -243,7 +316,7 @@ OutlinePass.prototype = Object.assign(Object.create(Pass.prototype), {
|
|
243
316
|
this.tempPulseColor2.copy(this.hiddenEdgeColor);
|
244
317
|
|
245
318
|
if (this.pulsePeriod > 0) {
|
246
|
-
|
319
|
+
const scalar = (1 + 0.25) / 2 + Math.cos(performance.now() * 0.01 / this.pulsePeriod) * (1.0 - 0.25) / 2;
|
247
320
|
this.tempPulseColor1.multiplyScalar(scalar);
|
248
321
|
this.tempPulseColor2.multiplyScalar(scalar);
|
249
322
|
} // 3. Apply Edge Detection Pass
|
@@ -260,25 +333,25 @@ OutlinePass.prototype = Object.assign(Object.create(Pass.prototype), {
|
|
260
333
|
|
261
334
|
this.fsQuad.material = this.separableBlurMaterial1;
|
262
335
|
this.separableBlurMaterial1.uniforms['colorTexture'].value = this.renderTargetEdgeBuffer1.texture;
|
263
|
-
this.separableBlurMaterial1.uniforms['direction'].value =
|
336
|
+
this.separableBlurMaterial1.uniforms['direction'].value = this.BlurDirectionX;
|
264
337
|
this.separableBlurMaterial1.uniforms['kernelRadius'].value = this.edgeThickness;
|
265
338
|
renderer.setRenderTarget(this.renderTargetBlurBuffer1);
|
266
339
|
renderer.clear();
|
267
340
|
this.fsQuad.render(renderer);
|
268
341
|
this.separableBlurMaterial1.uniforms['colorTexture'].value = this.renderTargetBlurBuffer1.texture;
|
269
|
-
this.separableBlurMaterial1.uniforms['direction'].value =
|
342
|
+
this.separableBlurMaterial1.uniforms['direction'].value = this.BlurDirectionY;
|
270
343
|
renderer.setRenderTarget(this.renderTargetEdgeBuffer1);
|
271
344
|
renderer.clear();
|
272
345
|
this.fsQuad.render(renderer); // Apply Blur on quarter res
|
273
346
|
|
274
347
|
this.fsQuad.material = this.separableBlurMaterial2;
|
275
348
|
this.separableBlurMaterial2.uniforms['colorTexture'].value = this.renderTargetEdgeBuffer1.texture;
|
276
|
-
this.separableBlurMaterial2.uniforms['direction'].value =
|
349
|
+
this.separableBlurMaterial2.uniforms['direction'].value = this.BlurDirectionX;
|
277
350
|
renderer.setRenderTarget(this.renderTargetBlurBuffer2);
|
278
351
|
renderer.clear();
|
279
352
|
this.fsQuad.render(renderer);
|
280
353
|
this.separableBlurMaterial2.uniforms['colorTexture'].value = this.renderTargetBlurBuffer2.texture;
|
281
|
-
this.separableBlurMaterial2.uniforms['direction'].value =
|
354
|
+
this.separableBlurMaterial2.uniforms['direction'].value = this.BlurDirectionY;
|
282
355
|
renderer.setRenderTarget(this.renderTargetEdgeBuffer2);
|
283
356
|
renderer.clear();
|
284
357
|
this.fsQuad.render(renderer); // Blend it additively over the input texture
|
@@ -304,8 +377,9 @@ OutlinePass.prototype = Object.assign(Object.create(Pass.prototype), {
|
|
304
377
|
renderer.setRenderTarget(null);
|
305
378
|
this.fsQuad.render(renderer);
|
306
379
|
}
|
307
|
-
}
|
308
|
-
|
380
|
+
}
|
381
|
+
|
382
|
+
getPrepareMaskMaterial() {
|
309
383
|
return new ShaderMaterial({
|
310
384
|
uniforms: {
|
311
385
|
depthTexture: {
|
@@ -318,11 +392,36 @@ OutlinePass.prototype = Object.assign(Object.create(Pass.prototype), {
|
|
318
392
|
value: null
|
319
393
|
}
|
320
394
|
},
|
321
|
-
vertexShader:
|
322
|
-
|
395
|
+
vertexShader: `#include <morphtarget_pars_vertex>
|
396
|
+
#include <skinning_pars_vertex>
|
397
|
+
varying vec4 projTexCoord;
|
398
|
+
varying vec4 vPosition;
|
399
|
+
uniform mat4 textureMatrix;
|
400
|
+
void main() {
|
401
|
+
#include <skinbase_vertex>
|
402
|
+
#include <begin_vertex>
|
403
|
+
#include <morphtarget_vertex>
|
404
|
+
#include <skinning_vertex>
|
405
|
+
#include <project_vertex>
|
406
|
+
vPosition = mvPosition;
|
407
|
+
vec4 worldPosition = modelMatrix * vec4( transformed, 1.0 );
|
408
|
+
projTexCoord = textureMatrix * worldPosition;
|
409
|
+
}`,
|
410
|
+
fragmentShader: `#include <packing>
|
411
|
+
varying vec4 vPosition;
|
412
|
+
varying vec4 projTexCoord;
|
413
|
+
uniform sampler2D depthTexture;
|
414
|
+
uniform vec2 cameraNearFar;
|
415
|
+
void main() {
|
416
|
+
float depth = unpackRGBAToDepth(texture2DProj( depthTexture, projTexCoord ));
|
417
|
+
float viewZ = - DEPTH_TO_VIEW_Z( depth, cameraNearFar.x, cameraNearFar.y );
|
418
|
+
float depthTest = (-vPosition.z > viewZ) ? 1.0 : 0.0;
|
419
|
+
gl_FragColor = vec4(0.0, depthTest, 1.0, 1.0);
|
420
|
+
}`
|
323
421
|
});
|
324
|
-
}
|
325
|
-
|
422
|
+
}
|
423
|
+
|
424
|
+
getEdgeDetectionMaterial() {
|
326
425
|
return new ShaderMaterial({
|
327
426
|
uniforms: {
|
328
427
|
maskTexture: {
|
@@ -338,36 +437,36 @@ OutlinePass.prototype = Object.assign(Object.create(Pass.prototype), {
|
|
338
437
|
value: new Vector3(1.0, 1.0, 1.0)
|
339
438
|
}
|
340
439
|
},
|
341
|
-
vertexShader:
|
342
|
-
void main() {
|
343
|
-
vUv = uv
|
344
|
-
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 )
|
345
|
-
}
|
346
|
-
fragmentShader:
|
347
|
-
uniform sampler2D maskTexture
|
348
|
-
uniform vec2 texSize
|
349
|
-
uniform vec3 visibleEdgeColor
|
350
|
-
uniform vec3 hiddenEdgeColor
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
vec4
|
355
|
-
vec4
|
356
|
-
vec4
|
357
|
-
vec4
|
358
|
-
|
359
|
-
float
|
360
|
-
float
|
361
|
-
float
|
362
|
-
float
|
363
|
-
float
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
}'
|
440
|
+
vertexShader: `varying vec2 vUv;
|
441
|
+
void main() {
|
442
|
+
vUv = uv;
|
443
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
444
|
+
}`,
|
445
|
+
fragmentShader: `varying vec2 vUv;
|
446
|
+
uniform sampler2D maskTexture;
|
447
|
+
uniform vec2 texSize;
|
448
|
+
uniform vec3 visibleEdgeColor;
|
449
|
+
uniform vec3 hiddenEdgeColor;
|
450
|
+
void main() {
|
451
|
+
vec2 invSize = 1.0 / texSize;
|
452
|
+
vec4 uvOffset = vec4(1.0, 0.0, 0.0, 1.0) * vec4(invSize, invSize);
|
453
|
+
vec4 c1 = texture2D( maskTexture, vUv + uvOffset.xy);
|
454
|
+
vec4 c2 = texture2D( maskTexture, vUv - uvOffset.xy);
|
455
|
+
vec4 c3 = texture2D( maskTexture, vUv + uvOffset.yw);
|
456
|
+
vec4 c4 = texture2D( maskTexture, vUv - uvOffset.yw);
|
457
|
+
float diff1 = (c1.r - c2.r)*0.5;
|
458
|
+
float diff2 = (c3.r - c4.r)*0.5;
|
459
|
+
float d = length( vec2(diff1, diff2) );
|
460
|
+
float a1 = min(c1.g, c2.g);
|
461
|
+
float a2 = min(c3.g, c4.g);
|
462
|
+
float visibilityFactor = min(a1, a2);
|
463
|
+
vec3 edgeColor = 1.0 - visibilityFactor > 0.001 ? visibleEdgeColor : hiddenEdgeColor;
|
464
|
+
gl_FragColor = vec4(edgeColor, 1.0) * vec4(d);
|
465
|
+
}`
|
368
466
|
});
|
369
|
-
}
|
370
|
-
|
467
|
+
}
|
468
|
+
|
469
|
+
getSeperableBlurMaterial(maxRadius) {
|
371
470
|
return new ShaderMaterial({
|
372
471
|
defines: {
|
373
472
|
MAX_RADIUS: maxRadius
|
@@ -386,40 +485,40 @@ OutlinePass.prototype = Object.assign(Object.create(Pass.prototype), {
|
|
386
485
|
value: 1.0
|
387
486
|
}
|
388
487
|
},
|
389
|
-
vertexShader:
|
390
|
-
void main() {
|
391
|
-
vUv = uv
|
392
|
-
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 )
|
393
|
-
}
|
394
|
-
fragmentShader:
|
395
|
-
varying vec2 vUv
|
396
|
-
uniform sampler2D colorTexture
|
397
|
-
uniform vec2 texSize
|
398
|
-
uniform vec2 direction
|
399
|
-
uniform float kernelRadius
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
vec2
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
vec4
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
}'
|
488
|
+
vertexShader: `varying vec2 vUv;
|
489
|
+
void main() {
|
490
|
+
vUv = uv;
|
491
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
492
|
+
}`,
|
493
|
+
fragmentShader: `#include <common>
|
494
|
+
varying vec2 vUv;
|
495
|
+
uniform sampler2D colorTexture;
|
496
|
+
uniform vec2 texSize;
|
497
|
+
uniform vec2 direction;
|
498
|
+
uniform float kernelRadius;
|
499
|
+
float gaussianPdf(in float x, in float sigma) {
|
500
|
+
return 0.39894 * exp( -0.5 * x * x/( sigma * sigma))/sigma;
|
501
|
+
}
|
502
|
+
void main() {
|
503
|
+
vec2 invSize = 1.0 / texSize;
|
504
|
+
float weightSum = gaussianPdf(0.0, kernelRadius);
|
505
|
+
vec4 diffuseSum = texture2D( colorTexture, vUv) * weightSum;
|
506
|
+
vec2 delta = direction * invSize * kernelRadius/float(MAX_RADIUS);
|
507
|
+
vec2 uvOffset = delta;
|
508
|
+
for( int i = 1; i <= MAX_RADIUS; i ++ ) {
|
509
|
+
float w = gaussianPdf(uvOffset.x, kernelRadius);
|
510
|
+
vec4 sample1 = texture2D( colorTexture, vUv + uvOffset);
|
511
|
+
vec4 sample2 = texture2D( colorTexture, vUv - uvOffset);
|
512
|
+
diffuseSum += ((sample1 + sample2) * w);
|
513
|
+
weightSum += (2.0 * w);
|
514
|
+
uvOffset += delta;
|
515
|
+
}
|
516
|
+
gl_FragColor = diffuseSum/weightSum;
|
517
|
+
}`
|
420
518
|
});
|
421
|
-
}
|
422
|
-
|
519
|
+
}
|
520
|
+
|
521
|
+
getOverlayMaterial() {
|
423
522
|
return new ShaderMaterial({
|
424
523
|
uniforms: {
|
425
524
|
maskTexture: {
|
@@ -444,40 +543,38 @@ OutlinePass.prototype = Object.assign(Object.create(Pass.prototype), {
|
|
444
543
|
value: 0.0
|
445
544
|
}
|
446
545
|
},
|
447
|
-
vertexShader:
|
448
|
-
void main() {
|
449
|
-
vUv = uv
|
450
|
-
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 )
|
451
|
-
}
|
452
|
-
fragmentShader:
|
453
|
-
uniform sampler2D maskTexture
|
454
|
-
uniform sampler2D edgeTexture1
|
455
|
-
uniform sampler2D edgeTexture2
|
456
|
-
uniform sampler2D patternTexture
|
457
|
-
uniform float edgeStrength
|
458
|
-
uniform float edgeGlow
|
459
|
-
uniform bool usePatternTexture
|
460
|
-
|
461
|
-
|
462
|
-
vec4
|
463
|
-
vec4
|
464
|
-
vec4
|
465
|
-
|
466
|
-
|
467
|
-
vec4
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
}',
|
546
|
+
vertexShader: `varying vec2 vUv;
|
547
|
+
void main() {
|
548
|
+
vUv = uv;
|
549
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
550
|
+
}`,
|
551
|
+
fragmentShader: `varying vec2 vUv;
|
552
|
+
uniform sampler2D maskTexture;
|
553
|
+
uniform sampler2D edgeTexture1;
|
554
|
+
uniform sampler2D edgeTexture2;
|
555
|
+
uniform sampler2D patternTexture;
|
556
|
+
uniform float edgeStrength;
|
557
|
+
uniform float edgeGlow;
|
558
|
+
uniform bool usePatternTexture;
|
559
|
+
void main() {
|
560
|
+
vec4 edgeValue1 = texture2D(edgeTexture1, vUv);
|
561
|
+
vec4 edgeValue2 = texture2D(edgeTexture2, vUv);
|
562
|
+
vec4 maskColor = texture2D(maskTexture, vUv);
|
563
|
+
vec4 patternColor = texture2D(patternTexture, 6.0 * vUv);
|
564
|
+
float visibilityFactor = 1.0 - maskColor.g > 0.0 ? 1.0 : 0.5;
|
565
|
+
vec4 edgeValue = edgeValue1 + edgeValue2 * edgeGlow;
|
566
|
+
vec4 finalColor = edgeStrength * maskColor.r * edgeValue;
|
567
|
+
if(usePatternTexture)
|
568
|
+
finalColor += + visibilityFactor * (1.0 - maskColor.r) * (1.0 - patternColor.r);
|
569
|
+
gl_FragColor = finalColor;
|
570
|
+
}`,
|
473
571
|
blending: AdditiveBlending,
|
474
572
|
depthTest: false,
|
475
573
|
depthWrite: false,
|
476
574
|
transparent: true
|
477
575
|
});
|
478
576
|
}
|
479
|
-
|
480
|
-
|
481
|
-
OutlinePass.BlurDirectionY = new Vector2(0.0, 1.0);
|
577
|
+
|
578
|
+
}
|
482
579
|
|
483
580
|
export { OutlinePass };
|