three-stdlib 2.8.12 → 2.10.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,103 +1,170 @@
1
- import { Color, Vector2, MeshBasicMaterial, DoubleSide, WebGLRenderTarget, MeshDepthMaterial, RGBADepthPacking, NoBlending, UniformsUtils, ShaderMaterial, Matrix4, Vector3, AdditiveBlending, LinearFilter, RGBAFormat } from 'three';
2
- import { FullScreenQuad, Pass } from './Pass.js';
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
- var OutlinePass = function (resolution, scene, camera, selectedObjects) {
6
- this.renderScene = scene;
7
- this.renderCamera = camera;
8
- this.selectedObjects = selectedObjects !== undefined ? selectedObjects : [];
9
- this.visibleEdgeColor = new Color(1, 1, 1);
10
- this.hiddenEdgeColor = new Color(0.1, 0.04, 0.02);
11
- this.edgeGlow = 0.0;
12
- this.usePatternTexture = false;
13
- this.edgeThickness = 1.0;
14
- this.edgeStrength = 3.0;
15
- this.downSampleRatio = 2;
16
- this.pulsePeriod = 0;
17
- this._visibilityCache = new Map();
18
- this.resolution = resolution !== undefined ? new Vector2(resolution.x, resolution.y) : new Vector2(256, 256);
19
- var pars = {
20
- minFilter: LinearFilter,
21
- magFilter: LinearFilter,
22
- format: RGBAFormat
23
- };
24
- var resx = Math.round(this.resolution.x / this.downSampleRatio);
25
- var resy = Math.round(this.resolution.y / this.downSampleRatio);
26
- this.maskBufferMaterial = new MeshBasicMaterial({
27
- color: 0xffffff
28
- });
29
- this.maskBufferMaterial.side = DoubleSide;
30
- this.renderTargetMaskBuffer = new WebGLRenderTarget(this.resolution.x, this.resolution.y, pars);
31
- this.renderTargetMaskBuffer.texture.name = 'OutlinePass.mask';
32
- this.renderTargetMaskBuffer.texture.generateMipmaps = false;
33
- this.depthMaterial = new MeshDepthMaterial();
34
- this.depthMaterial.side = DoubleSide;
35
- this.depthMaterial.depthPacking = RGBADepthPacking;
36
- this.depthMaterial.blending = NoBlending;
37
- this.prepareMaskMaterial = this.getPrepareMaskMaterial();
38
- this.prepareMaskMaterial.side = DoubleSide;
39
- this.prepareMaskMaterial.fragmentShader = replaceDepthToViewZ(this.prepareMaskMaterial.fragmentShader, this.renderCamera);
40
- this.renderTargetDepthBuffer = new WebGLRenderTarget(this.resolution.x, this.resolution.y, pars);
41
- this.renderTargetDepthBuffer.texture.name = 'OutlinePass.depth';
42
- this.renderTargetDepthBuffer.texture.generateMipmaps = false;
43
- this.renderTargetMaskDownSampleBuffer = new WebGLRenderTarget(resx, resy, pars);
44
- this.renderTargetMaskDownSampleBuffer.texture.name = 'OutlinePass.depthDownSample';
45
- this.renderTargetMaskDownSampleBuffer.texture.generateMipmaps = false;
46
- this.renderTargetBlurBuffer1 = new WebGLRenderTarget(resx, resy, pars);
47
- this.renderTargetBlurBuffer1.texture.name = 'OutlinePass.blur1';
48
- this.renderTargetBlurBuffer1.texture.generateMipmaps = false;
49
- this.renderTargetBlurBuffer2 = new WebGLRenderTarget(Math.round(resx / 2), Math.round(resy / 2), pars);
50
- this.renderTargetBlurBuffer2.texture.name = 'OutlinePass.blur2';
51
- this.renderTargetBlurBuffer2.texture.generateMipmaps = false;
52
- this.edgeDetectionMaterial = this.getEdgeDetectionMaterial();
53
- this.renderTargetEdgeBuffer1 = new WebGLRenderTarget(resx, resy, pars);
54
- this.renderTargetEdgeBuffer1.texture.name = 'OutlinePass.edge1';
55
- this.renderTargetEdgeBuffer1.texture.generateMipmaps = false;
56
- this.renderTargetEdgeBuffer2 = new WebGLRenderTarget(Math.round(resx / 2), Math.round(resy / 2), pars);
57
- this.renderTargetEdgeBuffer2.texture.name = 'OutlinePass.edge2';
58
- this.renderTargetEdgeBuffer2.texture.generateMipmaps = false;
59
- var MAX_EDGE_THICKNESS = 4;
60
- var MAX_EDGE_GLOW = 4;
61
- this.separableBlurMaterial1 = this.getSeperableBlurMaterial(MAX_EDGE_THICKNESS);
62
- this.separableBlurMaterial1.uniforms['texSize'].value.set(resx, resy);
63
- this.separableBlurMaterial1.uniforms['kernelRadius'].value = 1;
64
- this.separableBlurMaterial2 = this.getSeperableBlurMaterial(MAX_EDGE_GLOW);
65
- this.separableBlurMaterial2.uniforms['texSize'].value.set(Math.round(resx / 2), Math.round(resy / 2));
66
- this.separableBlurMaterial2.uniforms['kernelRadius'].value = MAX_EDGE_GLOW; // Overlay material
67
-
68
- this.overlayMaterial = this.getOverlayMaterial(); // copy material
69
-
70
- if (CopyShader === undefined) console.error('THREE.OutlinePass relies on CopyShader');
71
- var copyShader = CopyShader;
72
- this.copyUniforms = UniformsUtils.clone(copyShader.uniforms);
73
- this.copyUniforms['opacity'].value = 1.0;
74
- this.materialCopy = new ShaderMaterial({
75
- uniforms: this.copyUniforms,
76
- vertexShader: copyShader.vertexShader,
77
- fragmentShader: copyShader.fragmentShader,
78
- blending: NoBlending,
79
- depthTest: false,
80
- depthWrite: false,
81
- transparent: true
82
- });
83
- this.enabled = true;
84
- this.needsSwap = false;
85
- this._oldClearColor = new Color();
86
- this.oldClearAlpha = 1;
87
- this.fsQuad = new FullScreenQuad(null);
88
- this.tempPulseColor1 = new Color();
89
- this.tempPulseColor2 = new Color();
90
- this.textureMatrix = new Matrix4();
91
-
92
- function replaceDepthToViewZ(string, camera) {
93
- var type = camera.isPerspectiveCamera ? 'perspective' : 'orthographic';
94
- return string.replace(/DEPTH_TO_VIEW_Z/g, type + 'DepthToViewZ');
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
- OutlinePass.prototype = Object.assign(Object.create(Pass.prototype), {
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
- setSize: function (width, height) {
175
+ }
176
+
177
+ setSize(width, height) {
110
178
  this.renderTargetMaskBuffer.setSize(width, height);
111
- var resx = Math.round(width / this.downSampleRatio);
112
- var resy = Math.round(height / this.downSampleRatio);
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
- changeVisibilityOfSelectedObjects: function (bVisible) {
124
- var cache = this._visibilityCache;
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
- var selectedObject = this.selectedObjects[i];
208
+ const selectedObject = this.selectedObjects[i];
139
209
  selectedObject.traverse(gatherSelectedMeshesCallBack);
140
210
  }
141
- },
142
- changeVisibilityOfNonSelectedObjects: function (bVisible) {
143
- var cache = this._visibilityCache;
144
- var selectedMeshes = [];
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
- var selectedObject = this.selectedObjects[i];
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
- var bFound = false;
229
+ let bFound = false;
159
230
 
160
231
  for (let i = 0; i < selectedMeshes.length; i++) {
161
- var selectedObjectId = selectedMeshes[i].id;
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
- var visibility = object.visible;
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
- updateTextureMatrix: function () {
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
- render: function (renderer, writeBuffer, readBuffer, deltaTime, maskActive) {
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
- var oldAutoClear = renderer.autoClear;
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
- var currentBackground = this.renderScene.background;
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
- var scalar = (1 + 0.25) / 2 + Math.cos(performance.now() * 0.01 / this.pulsePeriod) * (1.0 - 0.25) / 2;
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 = OutlinePass.BlurDirectionX;
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 = OutlinePass.BlurDirectionY;
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 = OutlinePass.BlurDirectionX;
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 = OutlinePass.BlurDirectionY;
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
- getPrepareMaskMaterial: function () {
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: ['#include <morphtarget_pars_vertex>', '#include <skinning_pars_vertex>', 'varying vec4 projTexCoord;', 'varying vec4 vPosition;', 'uniform mat4 textureMatrix;', 'void main() {', ' #include <skinbase_vertex>', ' #include <begin_vertex>', ' #include <morphtarget_vertex>', ' #include <skinning_vertex>', ' #include <project_vertex>', ' vPosition = mvPosition;', ' vec4 worldPosition = modelMatrix * vec4( position, 1.0 );', ' projTexCoord = textureMatrix * worldPosition;', '}'].join('\n'),
322
- fragmentShader: ['#include <packing>', 'varying vec4 vPosition;', 'varying vec4 projTexCoord;', 'uniform sampler2D depthTexture;', 'uniform vec2 cameraNearFar;', 'void main() {', ' float depth = unpackRGBAToDepth(texture2DProj( depthTexture, projTexCoord ));', ' float viewZ = - DEPTH_TO_VIEW_Z( depth, cameraNearFar.x, cameraNearFar.y );', ' float depthTest = (-vPosition.z > viewZ) ? 1.0 : 0.0;', ' gl_FragColor = vec4(0.0, depthTest, 1.0, 1.0);', '}'].join('\n')
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
- getEdgeDetectionMaterial: function () {
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: 'varying vec2 vUv;\n\
342
- void main() {\n\
343
- vUv = uv;\n\
344
- gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\
345
- }',
346
- fragmentShader: 'varying vec2 vUv;\
347
- uniform sampler2D maskTexture;\
348
- uniform vec2 texSize;\
349
- uniform vec3 visibleEdgeColor;\
350
- uniform vec3 hiddenEdgeColor;\
351
- \
352
- void main() {\n\
353
- vec2 invSize = 1.0 / texSize;\
354
- vec4 uvOffset = vec4(1.0, 0.0, 0.0, 1.0) * vec4(invSize, invSize);\
355
- vec4 c1 = texture2D( maskTexture, vUv + uvOffset.xy);\
356
- vec4 c2 = texture2D( maskTexture, vUv - uvOffset.xy);\
357
- vec4 c3 = texture2D( maskTexture, vUv + uvOffset.yw);\
358
- vec4 c4 = texture2D( maskTexture, vUv - uvOffset.yw);\
359
- float diff1 = (c1.r - c2.r)*0.5;\
360
- float diff2 = (c3.r - c4.r)*0.5;\
361
- float d = length( vec2(diff1, diff2) );\
362
- float a1 = min(c1.g, c2.g);\
363
- float a2 = min(c3.g, c4.g);\
364
- float visibilityFactor = min(a1, a2);\
365
- vec3 edgeColor = 1.0 - visibilityFactor > 0.001 ? visibleEdgeColor : hiddenEdgeColor;\
366
- gl_FragColor = vec4(edgeColor, 1.0) * vec4(d);\
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
- getSeperableBlurMaterial: function (maxRadius) {
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: 'varying vec2 vUv;\n\
390
- void main() {\n\
391
- vUv = uv;\n\
392
- gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\
393
- }',
394
- fragmentShader: '#include <common>\
395
- varying vec2 vUv;\
396
- uniform sampler2D colorTexture;\
397
- uniform vec2 texSize;\
398
- uniform vec2 direction;\
399
- uniform float kernelRadius;\
400
- \
401
- float gaussianPdf(in float x, in float sigma) {\
402
- return 0.39894 * exp( -0.5 * x * x/( sigma * sigma))/sigma;\
403
- }\
404
- void main() {\
405
- vec2 invSize = 1.0 / texSize;\
406
- float weightSum = gaussianPdf(0.0, kernelRadius);\
407
- vec4 diffuseSum = texture2D( colorTexture, vUv) * weightSum;\
408
- vec2 delta = direction * invSize * kernelRadius/float(MAX_RADIUS);\
409
- vec2 uvOffset = delta;\
410
- for( int i = 1; i <= MAX_RADIUS; i ++ ) {\
411
- float w = gaussianPdf(uvOffset.x, kernelRadius);\
412
- vec4 sample1 = texture2D( colorTexture, vUv + uvOffset);\
413
- vec4 sample2 = texture2D( colorTexture, vUv - uvOffset);\
414
- diffuseSum += ((sample1 + sample2) * w);\
415
- weightSum += (2.0 * w);\
416
- uvOffset += delta;\
417
- }\
418
- gl_FragColor = diffuseSum/weightSum;\
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
- getOverlayMaterial: function () {
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: 'varying vec2 vUv;\n\
448
- void main() {\n\
449
- vUv = uv;\n\
450
- gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\
451
- }',
452
- fragmentShader: 'varying vec2 vUv;\
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
- void main() {\
462
- vec4 edgeValue1 = texture2D(edgeTexture1, vUv);\
463
- vec4 edgeValue2 = texture2D(edgeTexture2, vUv);\
464
- vec4 maskColor = texture2D(maskTexture, vUv);\
465
- vec4 patternColor = texture2D(patternTexture, 6.0 * vUv);\
466
- float visibilityFactor = 1.0 - maskColor.g > 0.0 ? 1.0 : 0.5;\
467
- vec4 edgeValue = edgeValue1 + edgeValue2 * edgeGlow;\
468
- vec4 finalColor = edgeStrength * maskColor.r * edgeValue;\
469
- if(usePatternTexture)\
470
- finalColor += + visibilityFactor * (1.0 - maskColor.r) * (1.0 - patternColor.r);\
471
- gl_FragColor = finalColor;\
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
- OutlinePass.BlurDirectionX = new Vector2(1.0, 0.0);
481
- OutlinePass.BlurDirectionY = new Vector2(0.0, 1.0);
577
+
578
+ }
482
579
 
483
580
  export { OutlinePass };