OutlinePass.js 18 KB

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