Skip to content

Proposal: Support Alpha settings in material even when image texture's file format is PNG #70

@roxk

Description

@roxk

The team and I are encountering a bug where, after exporting, textured-objects are rendered in babylonjs as if they are transparent, i.e. without depth-testing, resulting in overlap.

After some investigation, it's found that material with image textures all have hasAlpha set to true. I experimented setting alpha to none in the material -> surface panel, without success:

image

We then tested changing the texture to jpeg, and indeed this fixes the problem. Digging the exporter's source code, I found that in this line:

NON_ALPHA_FORMATS = {'BMP', 'JPEG'}

and in this line:

self.hasAlpha = bakedMaterial.image.file_format not in NON_ALPHA_FORMATS

hasAlpha is set according only to file format.

I propose that the exporter also supports the Alpha option as shown in the above screenshot. I'm not an expert as to what these options map to babylonjs, but at the very least it seems none should mean hasAlpha: false.

For our case, bmp and jpeg are not acceptable because:

  1. bmp is huge. The size of one of our texture goes from 20KB (png) to 6MP (bmp). While this size might be acceptable for desktop games, this is not really a good fit for games served on the internet
  2. jpeg, despite its excellent file size, is lossy

I don't mind contributing. It'd be great if you can provide pointer as to where to grab that Alpha settings in the material -> surface panel. Then it should be a matter of switching on the enum values and set to true/false accordingly.

Thanks!

Info:
Blender version: 3.6.5
Exporter version: 3.3.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions