OutlinePass.js 18 KB

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