Why it Happens: Incorrect MipMap level blends alpha channel.
protected createAtlasTexture(image: ImageData) {
const texture = this.gl.createTexture()!
this.gl.bindTexture(this.gl.TEXTURE_2D, texture)
const ext = this.gl.getExtension('EXT_texture_filter_anisotropic')
|| this.gl.getExtension('MOZ_EXT_texture_filter_anisotropic')
|| this.gl.getExtension('WEBKIT_EXT_texture_filter_anisotropic');
if (ext) {
this.gl.texParameterf(
this.gl.TEXTURE_2D,
ext.TEXTURE_MAX_ANISOTROPY_EXT,
4 // try 2, 4, 8, or 16 depending on performance/quality balance
);
}
this.gl.texImage2D(this.gl.TEXTURE_2D, 0, this.gl.RGBA, this.gl.RGBA, this.gl.UNSIGNED_BYTE, image)
// only sample up to mip level 4 because Minecraft block texture usually 16x16 pixels
this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_BASE_LEVEL, 0);
this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_MAX_LEVEL, 4);
// linear blend between the two closest mipmap levels, nearest texel in each.
this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_MIN_FILTER, this.gl.NEAREST_MIPMAP_LINEAR)
this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_MAG_FILTER, this.gl.NEAREST)
this.gl.generateMipmap(this.gl.TEXTURE_2D)
return texture
}
I can draft a PR if you wish.
Before Fix:

After Fix:

Why it Happens: Incorrect MipMap level blends alpha channel.
The Fix:
I can draft a PR if you wish.