Hi everybody! I’m trying to migrate a Three.js project into babylon and have gotten super stuck. I had a feature where a user can upload an image file (using JSFileManager). This image file is then saved to that user’s profile (using firebase) before being applied to a 2D circle geometry (using the image’s firebase src link). I’ve managed to get everything working save for images with transparent backgrounds. When trying to apply an image with a transparent background. The area that should be rendered transparent is rendered black, like so:
The only thing that seems to somewhat remedy this is setting material.opacityTexture.getAlphaFromRGB = true
but this then seems to make the image look strange (faded + wrong colour) you can see what I mean here:
Unfortunately, I can’t seem to recreate this in a playground so i’m starting to think that maybe its got more to do with the image src itself rather than how i’m applying the material. Below is the function i use to create the material:
/** Return an image material using a given image URL */
getImageMaterial(src, alpha=1) {
// Create material from image url
console.log("src: " + src)
let texture = new BABYLON.Texture(src, this.scene)
texture.vScale = -1
texture.hasAlpha = true
let material = new BABYLON.StandardMaterial("ImageMaterial: src=" + src, this.scene)
material.diffuseTexture = texture
material.opacityTexture = texture
// material.opacityTexture.getAlphaFromRGB = true
material.specularColor = new BABYLON.Color3(0, 0, 0)
// material.opacityFresnel = true;
// material.diffuseColor = new BABYLON.Color3(0, 0, 0)
// material.useAlphaFromDiffuseTexture = true
// material.transparencyMode = BABYLON.Material.MATERIAL_ALPHABLEND
material.alpha = alpha || 1
return material
}
You can see by all my commented out lines that I have tried a lot of different things without success so i would really appreciate any assistance or ideas you can provide to try and fix this issue. Thanks!