You can make a material with emissive (glow) map support by extending the shaders from existing three.js materials (MeshPhong, MeshLambert, etc).
The benefit is you retain all the functionality from the standard three.js material and also add glow map support.
For the purposes of this example, I'll use the three.js Phong shader as a starting point:
- Make a "PhongGlowShader" by extending (via UniformsLib/ShaderChunk) the existing Phong shader
Add glow map uniforms:
"glowMap" : { type: "t", value: null },
"glowIntensity": { type: "f", value: 1 },
Add a glow map factor to its fragment shader:
float glow = texture2D(glowMap, vUv).x * glowIntensity * 2.0; // optional * 2.0 and clamp
gl_FragColor.xyz = texelColor.xyz * clamp(emissive + totalDiffuse + ambientLightColor * ambient + glow, 0.0, 2.0) + totalSpecular;
Create a new THREE.ShaderMaterial using that shader, and pass the glow texture along with its usual uniforms
For further details, take a look at this fiddle: http://jsfiddle.net/Qr7Bb/2/.
You'll notice I made a "MeshPhongGlowMaterial" class that inherits from THREE.ShaderMaterial. That's purely optional; you can also just have a function that creates a new THREE.ShaderMaterial with the above shaders and uniforms.
The standard "emissive" property affects the entire surface of the mesh, it has nothing to do with the glow map (instead use the custom "glowIntensity" property for that).
MeshPhongMaterialdoes not support emissive maps. - WestLangleyShaderMaterial. - WestLangley