I should have sleep now, but the code is not work, unfortunately.
This is my shader code, modifieied from https://github.com/mrdoob/three.js/issues/12355
// after this.meshObj was loaded
var outer = this.meshObj.getObjectByName("l_box005_01")
outer.visible = false;
this.flashObj = this.meshObj.getObjectByName("l_box005");
var newMat = function() {
var mat = new THREE.ShaderMaterial({
uniforms: THREE.UniformsUtils.merge([
THREE.UniformsLib.fog,
THREE.UniformsLib.lights,
THREE.UniformsLib.shadowmap,
{
mapMain: {value: null},
mapGlow: {value: null}
}
]),
vertexShader: [
"varying vec3 vNormal;",
"varying vec3 vViewPosition;",
"varying vec3 fPosition;",
"varying vec2 vUv;",
"varying vec2 vUvM;",
"uniform vec4 offsetRepeat;",
// THREE.ShaderChunk.common,
THREE.ShaderChunk.shadowmap_pars_vertex,
THREE.ShaderChunk.fog_pars_vertex,
// "gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);",
"void main(){",
THREE.ShaderChunk.beginnormal_vertex,
THREE.ShaderChunk.defaultnormal_vertex,
"vUvM = uv * offsetRepeat.zw + offsetRepeat.xy;",
"vUv = uv;",
"vNormal = normalize( transformedNormal );",
THREE.ShaderChunk.begin_vertex,
THREE.ShaderChunk.project_vertex,
//THREE.ShaderChunk.logdepthbuf_vertex,
"fPosition = position;",
"vViewPosition = - mvPosition.xyz;",
THREE.ShaderChunk.worldpos_vertex,
THREE.ShaderChunk.shadowmap_vertex,
THREE.ShaderChunk.fog_vertex,
"}"
].join("\n"),
fragmentShader: [
"uniform sampler2D mapMain;",
"uniform sampler2D mapGlow;",
THREE.ShaderChunk.common,
THREE.ShaderChunk.packing,
THREE.ShaderChunk.dithering_pars_fragment,
THREE.ShaderChunk.emissivemap_pars_fragment,
THREE.ShaderChunk.fog_pars_fragment,
THREE.ShaderChunk.bsdfs,
THREE.ShaderChunk.lights_pars,
THREE.ShaderChunk.lights_phong_pars_fragment,
THREE.ShaderChunk.shadowmap_pars_fragment,
THREE.ShaderChunk.specularmap_pars_fragment,
"uniform vec3 topColor;",
"uniform vec3 bottomColor;",
"varying vec2 vUv;",
"varying vec2 vUvM;",
"void main(){",
"vec4 mainColor = texture2D(mapMain, vUv);",
"vec3 glowColor = texture2D(mapGlow, vUvM).rgb;",
"vec3 glow = (1.0 - mainColor.a) * glowColor;",
THREE.ShaderChunk.lights_template,
"gl_FragColor = vec4(mainColor.rgb + glow, 1.0);",
// THREE.ShaderChunk.shadowmap_fragment,
THREE.ShaderChunk.tonemapping_fragment,
THREE.ShaderChunk.encodings_fragment,
THREE.ShaderChunk.fog_fragment,
THREE.ShaderChunk.premultiplied_alpha_fragment,
THREE.ShaderChunk.dithering_fragment,
"}"
].join("\n")
});
return mat;
}
this.flashObj.material = newMat();
this.flashObj.material.needsUpdate = true;
var loader = new THREE.TextureLoader();
loader.load("resource/model/test/l_box005/l_box005_colour_1.tga", function(texture) {
// set main texture, which has alpha channel
this.flashObj.material.uniforms.mapMain.value = texture
this.flashObj.material.needsUpdate = true;
var self = this;
var loader = new THREE.TextureLoader();
loader.load("resource/model/test/l_box005/glow.png", function(texture) {
this.flashObj.material.uniforms.mapGlow.value = texture
this.flashObj.material.needsUpdate = true;
}.bind(self))
}.bind(this))
The result scene is black, no error show in console, please help me.
the shader logic is fine, ie, the logic of calculation final color , I haved tested in unity, so the wrong thing is related with three.js specific.