OutlinePass.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. /**
  2. * @author spidersharma / http://eduperiment.com/
  3. */
  4. THREE.OutlinePass = function ( resolution, scene, camera, selectedObjects ) {
  5. this.renderScene = scene;
  6. this.renderCamera = camera;
  7. this.selectedObjects = selectedObjects !== undefined ? selectedObjects : [];
  8. this.visibleEdgeColor = new THREE.Color( 1, 1, 1 );
  9. this.hiddenEdgeColor = new THREE.Color( 0.1, 0.04, 0.02 );
  10. this.edgeGlow = 0.0;
  11. this.usePatternTexture = false;
  12. this.edgeThickness = 1.0;
  13. this.edgeStrength = 3.0;
  14. this.downSampleRatio = 2;
  15. this.pulsePeriod = 0;
  16. THREE.Pass.call( this );
  17. this.resolution = ( resolution !== undefined ) ? new THREE.Vector2( resolution.x, resolution.y ) : new THREE.Vector2( 256, 256 );
  18. var pars = { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter, format: THREE.RGBAFormat };
  19. var resx = Math.round( this.resolution.x / this.downSampleRatio );
  20. var resy = Math.round( this.resolution.y / this.downSampleRatio );
  21. this.maskBufferMaterial = new THREE.MeshBasicMaterial( { color: 0xffffff } );
  22. this.maskBufferMaterial.side = THREE.DoubleSide;
  23. this.renderTargetMaskBuffer = new THREE.WebGLRenderTarget( this.resolution.x, this.resolution.y, pars );
  24. this.renderTargetMaskBuffer.texture.generateMipmaps = false;
  25. this.depthMaterial = new THREE.MeshDepthMaterial();
  26. this.depthMaterial.side = THREE.DoubleSide;
  27. this.depthMaterial.depthPacking = THREE.RGBADepthPacking;
  28. this.depthMaterial.blending = THREE.NoBlending;
  29. this.prepareMaskMaterial = this.getPrepareMaskMaterial();
  30. this.prepareMaskMaterial.side = THREE.DoubleSide;
  31. this.renderTargetDepthBuffer = new THREE.WebGLRenderTarget( this.resolution.x, this.resolution.y, pars );
  32. this.renderTargetDepthBuffer.texture.generateMipmaps = false;
  33. this.renderTargetMaskDownSampleBuffer = new THREE.WebGLRenderTarget( resx, resy, pars );
  34. this.renderTargetMaskDownSampleBuffer.texture.generateMipmaps = false;
  35. this.renderTargetBlurBuffer1 = new THREE.WebGLRenderTarget( resx, resy, pars );
  36. this.renderTargetBlurBuffer1.texture.generateMipmaps = false;
  37. this.renderTargetBlurBuffer2 = new THREE.WebGLRenderTarget( Math.round( resx / 2 ), Math.round( resy / 2 ), pars );
  38. this.renderTargetBlurBuffer2.texture.generateMipmaps = false;
  39. this.edgeDetectionMaterial = this.getEdgeDetectionMaterial();
  40. this.renderTargetEdgeBuffer1 = new THREE.WebGLRenderTarget( resx, resy, pars );
  41. this.renderTargetEdgeBuffer1.texture.generateMipmaps = false;
  42. this.renderTargetEdgeBuffer2 = new THREE.WebGLRenderTarget( Math.round( resx / 2 ), Math.round( resy / 2 ), pars );
  43. this.renderTargetEdgeBuffer2.texture.generateMipmaps = false;
  44. var MAX_EDGE_THICKNESS = 4;
  45. var MAX_EDGE_GLOW = 4;
  46. this.separableBlurMaterial1 = this.getSeperableBlurMaterial( MAX_EDGE_THICKNESS );
  47. this.separableBlurMaterial1.uniforms[ "texSize" ].value = new THREE.Vector2( resx, resy );
  48. this.separableBlurMaterial1.uniforms[ "kernelRadius" ].value = 1;
  49. this.separableBlurMaterial2 = this.getSeperableBlurMaterial( MAX_EDGE_GLOW );
  50. this.separableBlurMaterial2.uniforms[ "texSize" ].value = new THREE.Vector2( Math.round( resx / 2 ), Math.round( resy / 2 ) );
  51. this.separableBlurMaterial2.uniforms[ "kernelRadius" ].value = MAX_EDGE_GLOW;
  52. // Overlay material
  53. this.overlayMaterial = this.getOverlayMaterial();
  54. // copy material
  55. if ( THREE.CopyShader === undefined )
  56. console.error( "THREE.OutlinePass relies on THREE.CopyShader" );
  57. var copyShader = THREE.CopyShader;
  58. this.copyUniforms = THREE.UniformsUtils.clone( copyShader.uniforms );
  59. this.copyUniforms[ "opacity" ].value = 1.0;
  60. this.materialCopy = new THREE.ShaderMaterial( {
  61. uniforms: this.copyUniforms,
  62. vertexShader: copyShader.vertexShader,
  63. fragmentShader: copyShader.fragmentShader,
  64. blending: THREE.NoBlending,
  65. depthTest: false,
  66. depthWrite: false,
  67. transparent: true
  68. } );
  69. this.enabled = true;
  70. this.needsSwap = false;
  71. this.oldClearColor = new THREE.Color();
  72. this.oldClearAlpha = 1;
  73. this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
  74. this.scene = new THREE.Scene();
  75. this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null );
  76. this.quad.frustumCulled = false; // Avoid getting clipped
  77. this.scene.add( this.quad );
  78. this.tempPulseColor1 = new THREE.Color();
  79. this.tempPulseColor2 = new THREE.Color();
  80. this.textureMatrix = new THREE.Matrix4();
  81. };
  82. THREE.OutlinePass.prototype = Object.assign( Object.create( THREE.Pass.prototype ), {
  83. constructor: THREE.OutlinePass,
  84. dispose: function () {
  85. this.renderTargetMaskBuffer.dispose();
  86. this.renderTargetDepthBuffer.dispose();
  87. this.renderTargetMaskDownSampleBuffer.dispose();
  88. this.renderTargetBlurBuffer1.dispose();
  89. this.renderTargetBlurBuffer2.dispose();
  90. this.renderTargetEdgeBuffer1.dispose();
  91. this.renderTargetEdgeBuffer2.dispose();
  92. },
  93. setSize: function ( width, height ) {
  94. this.renderTargetMaskBuffer.setSize( width, height );
  95. var resx = Math.round( width / this.downSampleRatio );
  96. var resy = Math.round( height / this.downSampleRatio );
  97. this.renderTargetMaskDownSampleBuffer.setSize( resx, resy );
  98. this.renderTargetBlurBuffer1.setSize( resx, resy );
  99. this.renderTargetEdgeBuffer1.setSize( resx, resy );
  100. this.separableBlurMaterial1.uniforms[ "texSize" ].value = new THREE.Vector2( resx, resy );
  101. resx = Math.round( resx / 2 );
  102. resy = Math.round( resy / 2 );
  103. this.renderTargetBlurBuffer2.setSize( resx, resy );
  104. this.renderTargetEdgeBuffer2.setSize( resx, resy );
  105. this.separableBlurMaterial2.uniforms[ "texSize" ].value = new THREE.Vector2( resx, resy );
  106. },
  107. changeVisibilityOfSelectedObjects: function ( bVisible ) {
  108. function gatherSelectedMeshesCallBack( object ) {
  109. if ( object instanceof THREE.Mesh ) object.visible = bVisible;
  110. }
  111. for ( var i = 0; i < this.selectedObjects.length; i ++ ) {
  112. var selectedObject = this.selectedObjects[ i ];
  113. selectedObject.traverse( gatherSelectedMeshesCallBack );
  114. }
  115. },
  116. changeVisibilityOfNonSelectedObjects: function ( bVisible ) {
  117. var selectedMeshes = [];
  118. function gatherSelectedMeshesCallBack( object ) {
  119. if ( object instanceof THREE.Mesh ) selectedMeshes.push( object );
  120. }
  121. for ( var i = 0; i < this.selectedObjects.length; i ++ ) {
  122. var selectedObject = this.selectedObjects[ i ];
  123. selectedObject.traverse( gatherSelectedMeshesCallBack );
  124. }
  125. function VisibilityChangeCallBack( object ) {
  126. if ( object instanceof THREE.Mesh ) {
  127. var bFound = false;
  128. for ( var i = 0; i < selectedMeshes.length; i ++ ) {
  129. var selectedObjectId = selectedMeshes[ i ].id;
  130. if ( selectedObjectId === object.id ) {
  131. bFound = true;
  132. break;
  133. }
  134. }
  135. if ( ! bFound ) {
  136. var visibility = object.visible;
  137. if ( ! bVisible || object.bVisible ) object.visible = bVisible;
  138. object.bVisible = visibility;
  139. }
  140. }
  141. }
  142. this.renderScene.traverse( VisibilityChangeCallBack );
  143. },
  144. updateTextureMatrix: function () {
  145. this.textureMatrix.set( 0.5, 0.0, 0.0, 0.5,
  146. 0.0, 0.5, 0.0, 0.5,
  147. 0.0, 0.0, 0.5, 0.5,
  148. 0.0, 0.0, 0.0, 1.0 );
  149. this.textureMatrix.multiply( this.renderCamera.projectionMatrix );
  150. this.textureMatrix.multiply( this.renderCamera.matrixWorldInverse );
  151. },
  152. render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {
  153. if ( this.selectedObjects.length === 0 ) return;
  154. this.oldClearColor.copy( renderer.getClearColor() );
  155. this.oldClearAlpha = renderer.getClearAlpha();
  156. var oldAutoClear = renderer.autoClear;
  157. renderer.autoClear = false;
  158. if ( maskActive ) renderer.context.disable( renderer.context.STENCIL_TEST );
  159. renderer.setClearColor( 0xffffff, 1 );
  160. // Make selected objects invisible
  161. this.changeVisibilityOfSelectedObjects( false );
  162. // 1. Draw Non Selected objects in the depth buffer
  163. this.renderScene.overrideMaterial = this.depthMaterial;
  164. renderer.render( this.renderScene, this.renderCamera, this.renderTargetDepthBuffer, true );
  165. // Make selected objects visible
  166. this.changeVisibilityOfSelectedObjects( true );
  167. // Update Texture Matrix for Depth compare
  168. this.updateTextureMatrix();
  169. // Make non selected objects invisible, and draw only the selected objects, by comparing the depth buffer of non selected objects
  170. this.changeVisibilityOfNonSelectedObjects( false );
  171. this.renderScene.overrideMaterial = this.prepareMaskMaterial;
  172. this.prepareMaskMaterial.uniforms[ "cameraNearFar" ].value = new THREE.Vector2( this.renderCamera.near, this.renderCamera.far );
  173. this.prepareMaskMaterial.uniforms[ "depthTexture" ].value = this.renderTargetDepthBuffer.texture;
  174. this.prepareMaskMaterial.uniforms[ "textureMatrix" ].value = this.textureMatrix;
  175. renderer.render( this.renderScene, this.renderCamera, this.renderTargetMaskBuffer, true );
  176. this.renderScene.overrideMaterial = null;
  177. this.changeVisibilityOfNonSelectedObjects( true );
  178. // 2. Downsample to Half resolution
  179. this.quad.material = this.materialCopy;
  180. this.copyUniforms[ "tDiffuse" ].value = this.renderTargetMaskBuffer.texture;
  181. renderer.render( this.scene, this.camera, this.renderTargetMaskDownSampleBuffer, true );
  182. this.tempPulseColor1.copy( this.visibleEdgeColor );
  183. this.tempPulseColor2.copy( this.hiddenEdgeColor );
  184. if ( this.pulsePeriod > 0 ) {
  185. var scalar = ( 1 + 0.25 ) / 2 + Math.cos( performance.now() * 0.01 / this.pulsePeriod ) * ( 1.0 - 0.25 ) / 2;
  186. this.tempPulseColor1.multiplyScalar( scalar );
  187. this.tempPulseColor2.multiplyScalar( scalar );
  188. }
  189. // 3. Apply Edge Detection Pass
  190. this.quad.material = this.edgeDetectionMaterial;
  191. this.edgeDetectionMaterial.uniforms[ "maskTexture" ].value = this.renderTargetMaskDownSampleBuffer.texture;
  192. this.edgeDetectionMaterial.uniforms[ "texSize" ].value = new THREE.Vector2( this.renderTargetMaskDownSampleBuffer.width, this.renderTargetMaskDownSampleBuffer.height );
  193. this.edgeDetectionMaterial.uniforms[ "visibleEdgeColor" ].value = this.tempPulseColor1;
  194. this.edgeDetectionMaterial.uniforms[ "hiddenEdgeColor" ].value = this.tempPulseColor2;
  195. renderer.render( this.scene, this.camera, this.renderTargetEdgeBuffer1, true );
  196. // 4. Apply Blur on Half res
  197. this.quad.material = this.separableBlurMaterial1;
  198. this.separableBlurMaterial1.uniforms[ "colorTexture" ].value = this.renderTargetEdgeBuffer1.texture;
  199. this.separableBlurMaterial1.uniforms[ "direction" ].value = THREE.OutlinePass.BlurDirectionX;
  200. this.separableBlurMaterial1.uniforms[ "kernelRadius" ].value = this.edgeThickness;
  201. renderer.render( this.scene, this.camera, this.renderTargetBlurBuffer1, true );
  202. this.separableBlurMaterial1.uniforms[ "colorTexture" ].value = this.renderTargetBlurBuffer1.texture;
  203. this.separableBlurMaterial1.uniforms[ "direction" ].value = THREE.OutlinePass.BlurDirectionY;
  204. renderer.render( this.scene, this.camera, this.renderTargetEdgeBuffer1, true );
  205. // Apply Blur on quarter res
  206. this.quad.material = this.separableBlurMaterial2;
  207. this.separableBlurMaterial2.uniforms[ "colorTexture" ].value = this.renderTargetEdgeBuffer1.texture;
  208. this.separableBlurMaterial2.uniforms[ "direction" ].value = THREE.OutlinePass.BlurDirectionX;
  209. renderer.render( this.scene, this.camera, this.renderTargetBlurBuffer2, true );
  210. this.separableBlurMaterial2.uniforms[ "colorTexture" ].value = this.renderTargetBlurBuffer2.texture;
  211. this.separableBlurMaterial2.uniforms[ "direction" ].value = THREE.OutlinePass.BlurDirectionY;
  212. renderer.render( this.scene, this.camera, this.renderTargetEdgeBuffer2, true );
  213. // Blend it additively over the input texture
  214. this.quad.material = this.overlayMaterial;
  215. this.overlayMaterial.uniforms[ "maskTexture" ].value = this.renderTargetMaskBuffer.texture;
  216. this.overlayMaterial.uniforms[ "edgeTexture1" ].value = this.renderTargetEdgeBuffer1.texture;
  217. this.overlayMaterial.uniforms[ "edgeTexture2" ].value = this.renderTargetEdgeBuffer2.texture;
  218. this.overlayMaterial.uniforms[ "patternTexture" ].value = this.patternTexture;
  219. this.overlayMaterial.uniforms[ "edgeStrength" ].value = this.edgeStrength;
  220. this.overlayMaterial.uniforms[ "edgeGlow" ].value = this.edgeGlow;
  221. this.overlayMaterial.uniforms[ "usePatternTexture" ].value = this.usePatternTexture;
  222. if ( maskActive ) renderer.context.enable( renderer.context.STENCIL_TEST );
  223. renderer.render( this.scene, this.camera, readBuffer, false );
  224. renderer.setClearColor( this.oldClearColor, this.oldClearAlpha );
  225. renderer.autoClear = oldAutoClear;
  226. },
  227. getPrepareMaskMaterial: function () {
  228. return new THREE.ShaderMaterial( {
  229. uniforms: {
  230. "depthTexture": { value: null },
  231. "cameraNearFar": { value: new THREE.Vector2( 0.5, 0.5 ) },
  232. "textureMatrix": { value: new THREE.Matrix4() }
  233. },
  234. vertexShader:
  235. "varying vec2 vUv;\
  236. varying vec4 projTexCoord;\
  237. varying vec4 vPosition;\
  238. uniform mat4 textureMatrix;\
  239. void main() {\
  240. vUv = uv;\
  241. vPosition = modelViewMatrix * vec4( position, 1.0 );\
  242. vec4 worldPosition = modelMatrix * vec4( position, 1.0 );\
  243. projTexCoord = textureMatrix * worldPosition;\
  244. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\
  245. }",
  246. fragmentShader:
  247. "#include <packing>\
  248. varying vec2 vUv;\
  249. varying vec4 vPosition;\
  250. varying vec4 projTexCoord;\
  251. uniform sampler2D depthTexture;\
  252. uniform vec2 cameraNearFar;\
  253. \
  254. void main() {\
  255. float depth = unpackRGBAToDepth(texture2DProj( depthTexture, projTexCoord ));\
  256. float viewZ = -perspectiveDepthToViewZ( depth, cameraNearFar.x, cameraNearFar.y );\
  257. float depthTest = (-vPosition.z > viewZ) ? 1.0 : 0.0;\
  258. gl_FragColor = vec4(0.0, depthTest, 1.0, 1.0);\
  259. }"
  260. } );
  261. },
  262. getEdgeDetectionMaterial: function () {
  263. return new THREE.ShaderMaterial( {
  264. uniforms: {
  265. "maskTexture": { value: null },
  266. "texSize": { value: new THREE.Vector2( 0.5, 0.5 ) },
  267. "visibleEdgeColor": { value: new THREE.Vector3( 1.0, 1.0, 1.0 ) },
  268. "hiddenEdgeColor": { value: new THREE.Vector3( 1.0, 1.0, 1.0 ) },
  269. },
  270. vertexShader:
  271. "varying vec2 vUv;\n\
  272. void main() {\n\
  273. vUv = uv;\n\
  274. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\
  275. }",
  276. fragmentShader:
  277. "varying vec2 vUv;\
  278. uniform sampler2D maskTexture;\
  279. uniform vec2 texSize;\
  280. uniform vec3 visibleEdgeColor;\
  281. uniform vec3 hiddenEdgeColor;\
  282. \
  283. void main() {\n\
  284. vec2 invSize = 1.0 / texSize;\
  285. vec4 uvOffset = vec4(1.0, 0.0, 0.0, 1.0) * vec4(invSize, invSize);\
  286. vec4 c1 = texture2D( maskTexture, vUv + uvOffset.xy);\
  287. vec4 c2 = texture2D( maskTexture, vUv - uvOffset.xy);\
  288. vec4 c3 = texture2D( maskTexture, vUv + uvOffset.yw);\
  289. vec4 c4 = texture2D( maskTexture, vUv - uvOffset.yw);\
  290. float diff1 = (c1.r - c2.r)*0.5;\
  291. float diff2 = (c3.r - c4.r)*0.5;\
  292. float d = length( vec2(diff1, diff2) );\
  293. float a1 = min(c1.g, c2.g);\
  294. float a2 = min(c3.g, c4.g);\
  295. float visibilityFactor = min(a1, a2);\
  296. vec3 edgeColor = 1.0 - visibilityFactor > 0.001 ? visibleEdgeColor : hiddenEdgeColor;\
  297. gl_FragColor = vec4(edgeColor, 1.0) * vec4(d);\
  298. }"
  299. } );
  300. },
  301. getSeperableBlurMaterial: function ( maxRadius ) {
  302. return new THREE.ShaderMaterial( {
  303. defines: {
  304. "MAX_RADIUS": maxRadius,
  305. },
  306. uniforms: {
  307. "colorTexture": { value: null },
  308. "texSize": { value: new THREE.Vector2( 0.5, 0.5 ) },
  309. "direction": { value: new THREE.Vector2( 0.5, 0.5 ) },
  310. "kernelRadius": { value: 1.0 }
  311. },
  312. vertexShader:
  313. "varying vec2 vUv;\n\
  314. void main() {\n\
  315. vUv = uv;\n\
  316. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\
  317. }",
  318. fragmentShader:
  319. "#include <common>\
  320. varying vec2 vUv;\
  321. uniform sampler2D colorTexture;\
  322. uniform vec2 texSize;\
  323. uniform vec2 direction;\
  324. uniform float kernelRadius;\
  325. \
  326. float gaussianPdf(in float x, in float sigma) {\
  327. return 0.39894 * exp( -0.5 * x * x/( sigma * sigma))/sigma;\
  328. }\
  329. void main() {\
  330. vec2 invSize = 1.0 / texSize;\
  331. float weightSum = gaussianPdf(0.0, kernelRadius);\
  332. vec3 diffuseSum = texture2D( colorTexture, vUv).rgb * weightSum;\
  333. vec2 delta = direction * invSize * kernelRadius/float(MAX_RADIUS);\
  334. vec2 uvOffset = delta;\
  335. for( int i = 1; i <= MAX_RADIUS; i ++ ) {\
  336. float w = gaussianPdf(uvOffset.x, kernelRadius);\
  337. vec3 sample1 = texture2D( colorTexture, vUv + uvOffset).rgb;\
  338. vec3 sample2 = texture2D( colorTexture, vUv - uvOffset).rgb;\
  339. diffuseSum += ((sample1 + sample2) * w);\
  340. weightSum += (2.0 * w);\
  341. uvOffset += delta;\
  342. }\
  343. gl_FragColor = vec4(diffuseSum/weightSum, 1.0);\
  344. }"
  345. } );
  346. },
  347. getOverlayMaterial: function () {
  348. return new THREE.ShaderMaterial( {
  349. uniforms: {
  350. "maskTexture": { value: null },
  351. "edgeTexture1": { value: null },
  352. "edgeTexture2": { value: null },
  353. "patternTexture": { value: null },
  354. "edgeStrength": { value: 1.0 },
  355. "edgeGlow": { value: 1.0 },
  356. "usePatternTexture": { value: 0.0 }
  357. },
  358. vertexShader:
  359. "varying vec2 vUv;\n\
  360. void main() {\n\
  361. vUv = uv;\n\
  362. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\
  363. }",
  364. fragmentShader:
  365. "varying vec2 vUv;\
  366. uniform sampler2D maskTexture;\
  367. uniform sampler2D edgeTexture1;\
  368. uniform sampler2D edgeTexture2;\
  369. uniform sampler2D patternTexture;\
  370. uniform float edgeStrength;\
  371. uniform float edgeGlow;\
  372. uniform bool usePatternTexture;\
  373. \
  374. void main() {\
  375. vec4 edgeValue1 = texture2D(edgeTexture1, vUv);\
  376. vec4 edgeValue2 = texture2D(edgeTexture2, vUv);\
  377. vec4 maskColor = texture2D(maskTexture, vUv);\
  378. vec4 patternColor = texture2D(patternTexture, 6.0 * vUv);\
  379. float visibilityFactor = 1.0 - maskColor.g > 0.0 ? 1.0 : 0.5;\
  380. vec4 edgeValue = edgeValue1 + edgeValue2 * edgeGlow;\
  381. vec4 finalColor = edgeStrength * maskColor.r * edgeValue;\
  382. if(usePatternTexture)\
  383. finalColor += + visibilityFactor * (1.0 - maskColor.r) * (1.0 - patternColor.r);\
  384. gl_FragColor = finalColor;\
  385. }",
  386. blending: THREE.AdditiveBlending,
  387. depthTest: false,
  388. depthWrite: false,
  389. transparent: true
  390. } );
  391. }
  392. } );
  393. THREE.OutlinePass.BlurDirectionX = new THREE.Vector2( 1.0, 0.0 );
  394. THREE.OutlinePass.BlurDirectionY = new THREE.Vector2( 0.0, 1.0 );