Jump to content

check if texture alpha channel exists


Kesshi
 Share

Recommended Posts

Hi,

 

after loading a texture how can i check if the source image (PNG) has an alpha channel/transparent pixels or not?

I need to know this to set the flags material.diffuseTexture.hasAlpha and material.useAlphaFromDiffuseTexture to true.

In my scenario the images/textures which will be used later in the application are not predefined.

The only way is that i automatically detect if i need to enable the alpha flags.

Link to comment
Share on other sites

There is always a way!

 

In this case, not with BabylonJS, but there is a way :-)

 

You will have to download the image on your own, then check the 25's byte of the data. This byte contains the PNG type: Possible values are:

  • 0 - grey
  • 2 - RGB
  • 3 - RGB with palette
  • 4 - grey + alpha
  • 6 - RGB + alpha

So, you will need to check the 25th byte

var alpha = downloadedData[25] >=4;

After downloading the image yourself, you can convert it to Base64 and use it as data for a texture.

 

Does it make sense?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...