threex.glowkeycolor

three.js extension to have a screenspace glow based on keycolor


License
MIT
Install
bower install threex.glowkeycolor

Documentation

threex.glowkeycolor

It is a three.js extension which provide a glow based on key-color. There is a single scene which is rendered only once. It all happens in screenspace.

Show Don't Tell

How To Use It

It happens in 2 steps. First you need to add the keycolor somewhere. via material or via texture. Then you need to render it

How To Add a Glowing Object

One way is to use a THREE.MeshBasicMaterial with the keycolor, say hotpink. It would make the whole mesh glow.

var geometry	= new THREE.SphereGeometry( 0.5 )
var material	= new THREE.MeshBasicMaterial({
	color	: keyColor
});
var mesh	= new THREE.Mesh( geometry, material )
scene.add( mesh )

Maybe you want to put the keyColor in a texture, thus only this part of the texture will glow. see minecraft_tron example.

The easiest way to render it is with the renderer.

var glowRenderer  = new THREEx.GlowKeyColor.Renderer(renderer, camera, scene, keyColor, glowColor)
updateFcts.push(function(delta, now){
  glowRenderer.update(delta, now)
})

API Description

threex.glowkeycolor.postproc.js

Here is how to instanciate it. It needs to be updated at every frame

var glowPostProc= new THREEx.GlowKeyColor.PostProc(renderer, camera, colorRenderTarget);
updateFcts.push(function(delta, now){
  glowPostProc.update(delta, now);
})
  • glowPostProc.filterEffect : shader pass for ColorPassBand
  • glowPostProc.nBlurPass : number of blur pass
  • glowPostProc.blurHLevel : level of horizontal blur
  • glowPostProc.blurVLevel : level of vertical blur
  • glowPostProc.composer : the THREE.EffectComposer
  • glowPostProc.dstRenderTarget : the destination render target

here is a possible customisation

glowPostProc.filterEffect.uniforms.keyColor.value = keyColor
glowPostProc.filterEffect.uniforms.glowColor.value  = glowColor

threex.glowkeycolor.postprocdatgui.js

You can add a dat.gui for fine tuning.

THREEx.GlowKeyColor.addPostProcDatGui(glowRenderer)

threex.glowkeycolor.renderer.js

var glowRenderer	= new THREEx.GlowKeyColor.Renderer(renderer, camera, scene, keyColor, glowColor)
updateFcts.push(function(delta, now){
	// to update at every frame
	glowRenderer.update(delta, now)
})

threex.glowkeycolor.rendererdatgui.js

You can add a dat.gui for fine tuning.

THREEx.GlowKeyColor.addRendererDatGui(glowRenderer)

Algorithm Steps

  • it is starting from a existing scene
    • the non glowing objects are rendered normally
    • the glowing objects are rendered with a key color and THREE.MeshBasicMaterial
    • for example 'hotpink'
  • you render this scene in a render target
  • the rendertarget is downsampled (PRO as it consume less gpu to process)
      • black out all non key color pixel
      • change keycolor pixel to glow color
  • this render target is then blurred
    • in horizontal, then vertical.
    • it may be repeated several time to provide better looking glow, but slower
  • then the original render is blended with the blur rendertarget
  • it is that simple.

Possible Improvements