Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
roxk opened this issue Dec 7, 2023 · 1 comment

Comments

@roxk
Copy link

roxk commented Dec 7, 2023

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

@Palmer-JC
Copy link
Collaborator

Received. That UI did not even exist at the time when this part was written. Think that so other people's exports are not broken, the only time it would be consulted would be to override existing logic when 'None'.

The line 135 reference is when the exporter was required to bake do to a material which will not export. This UI will not exist for this temporary texture. That is controlled by the exporter's Mesh custom properties.

The image texture node is currently read in this file . It is currently assigning alpha without using the field. Change needs to be there.

Will need to check how that interacts with Texture.py, but not for a while.

Post import, if you got the material in question, you could override with code (based on the type texture) for now:

material.(emissiveTexture | albedoTexture).hasAlpha = false;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants