Managed to get the bitmap text working but faced a lot of problems with the blending of the text with the scene.
Finally, I had to resort to modifying the customer shader that scenejs compiles for the case where texture is applied to alpha in multiply blendmode.
In this conditional, i changed the code as follows:
/* Alpha from Texture
* */
if (layer.applyTo == "alpha") {
if (layer.blendMode == "multiply") {
//src.push("alpha = alpha * texture2D(SCENEJS_uSampler" + i + ", vec2(textureCoord.x, 1.0 - textureCoord.y)).b;");
src.push("alpha = texture2D(SCENEJS_uSampler" + i + ", vec2(textureCoord.x, 1.0 - textureCoord.y)).a;");
src.push("color.rgb = color.rgb * texture2D(SCENEJS_uSampler" + i + ", vec2(textureCoord.x, 1.0 - textureCoord.y)).rgb;");
} else if (layer.blendMode == "add") {
src.push("alpha = ((1.0 - SCENEJS_uLayer" + i + "BlendFactor) * alpha) + (SCENEJS_uLayer" + i + "BlendFactor * texture2D(SCENEJS_uSampler" + i + ", vec2(textureCoord.x, 1.0 - textureCoord.y)).a);");
}
}
And at the end, changed the way gl_fragcolor is updated:
Line: 9747
if (debugCfg.whitewash == true) {
src.push(" gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);");
} else {
src.push("if(alpha <= 0.0) { discard; } else {");
src.push(" gl_FragColor = vec4(color.rgb, 1.0); }");
}
I am basically discarding the fragment if the text background is being drawn.
Would love to have a cleaner way of dealing with this problem. Any thoughts? I wonder why blending does not work at all!!!!
regards,
Siddharth