However, I’m curious as to why I need to do it that way, when using pure WebGL does not have these artifacts? jsfiddle[dot]net/6p8xr1mc/ (broke the link due to being a new user and only able to post 2 links in a post)
Interestingly, if I set change canvas.getContext('webgl'); to canvas.getContext('webgl', {premultipliedAlpha: false}); I get the same black outline that we get in BJS. So I wonder if that’s what BJS is doing. I wonder if that is configurable?
I did try dynamicTexture.update(true, true) to set the texture to premultiplied (after rendering the text), but the black outline just gets thicker.
Either way, I agree BJS seems to be doing the right thing with the texture, on the other hand, I spent quite a number of hours trying to get the black outline to go away. Food for thought.
You need to set the dynamic texture as pre-multiplied as well as enable the right blending mode.
This blending mode should be set to ALPHA_PREMULTIPLIED_PORTERDUFF but when doing this there’s a line in the shader code that is added: color.rgb *= alpha. However, we don’t want this to happen, we only want to set the OpenGL blending factors to 1 / ONE_MINUS_SRC_ALPHA / 1 / ONE_MINUS_SRC_ALPHA.
The easiest way is to override the blending factors and set the ones we want in the material.onBind observable:
Yes! There we go, that’s what I want. Maybe there should be another version of alphaMode similar to ALPHA_PREMULTIPLIED_PORTERDUFF that doesn’t multiply the rgb.