title: Outline object (normal scale + stencil mask) three.js
body: <p>For some time, I've been trying to figure out how to do an object selection outline in my game. (So the player can see the object over everything else, on mouse-over)</p>
  
  <p>This is how the result should look:</p>
  
  <p><img src="https://i.stack.imgur.com/UM3lc.png" alt="enter image description here"></p>
  
  <p>The solution I would like to use goes like this:</p>
  
  <ol>
  <li>Layer 1: Draw model in regular shading.</li>
  <li>Layer 2: Draw a copy in red color, scaled along normals using vertex shader.</li>
  <li>Mask: Draw a black/white flat color of the model to use it as a stencil mask for the second layer, to hide insides and show layer 1.</li>
  </ol>
  
  <p>And here comes the problem. I can't really find any good learning materials about masks. Can I subtract the insides from the outline shape? What am I doing wrong?</p>
  
  <p>I can't figure out how to stack my render passes to make the mask work. :(</p>
  
  <p><strong>Here's a <a href="http://jsfiddle.net/Eskel/g593q/4/" rel="noreferrer">jsfiddle demo</a></strong></p>
  
  <pre><code>renderTarget = new THREE.WebGLRenderTarget(window.innerWidth, window.innerHeight, renderTargetParameters)
  
  composer    = new THREE.EffectComposer(renderer, renderTarget)
  // composer   = new THREE.EffectComposer(renderer)
  
  normal      = new THREE.RenderPass(scene, camera)
  outline     = new THREE.RenderPass(outScene, camera)
  mask        = new THREE.MaskPass(maskScene, camera)
  // mask.inverse = true
  clearMask   = new THREE.ClearMaskPass
  copyPass    = new THREE.ShaderPass(THREE.CopyShader)
  copyPass.renderToScreen = true
  
  composer.addPass(normal)
  composer.addPass(outline)
  composer.addPass(mask)
  composer.addPass(clearMask)
  composer.addPass(copyPass)
  </code></pre>
  
  <p>Also I have no idea whether to use render target or renderer for the source of the composer. :( Should I have the first pass in the composer at all? Why do I need the copy pass? So many questions, I know. But there are just not enough resources to learn from, I've been googling for days.</p>
  
  <p>Thanks for any advice!</p>