# Getting good Alpha from textures

**URL:** <https://forum.babylonjs.com/t/getting-good-alpha-from-textures/4025>\
**Category:** Questions\
**Created:** [June 20, 2019, 9:48pm UTC](https://forum.babylonjs.com/t/getting-good-alpha-from-textures/4025 "2019-06-20T21:48:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![JCPalmer](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jcpalmer/32/42_2.png) [@JCPalmer](https://forum.babylonjs.com/u/JCPalmer)\
**Post date:** [June 20, 2019, 9:48pm UTC](https://forum.babylonjs.com/t/getting-good-alpha-from-textures/4025/1 "2019-06-20T21:48:37Z")

</div>

This has been happening forever in STD materials, but now that I am really playing with PBR, I have come to a conclusion that alpha in textures is not really working well for me.

I have a number of meshes, shown here in Blender 2.80, in solid mode.

 ![MHFromBlenderSolid](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/d/d295d7215a3d79cdb189a582fa713f40f105f410.jpeg)

When in Blender materials mode, edges of the hair & eye browsers look very nice. BTW, they also look like this MakeHuman.

 ![MHFromBlender](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/6/6c5126e98c6b656de40ca64f99ef4201415c1a01.jpeg)

Here is what they look like in PBR in Edge Browser (slightly different from in STD, but not as it relates to alpha)

 ![MHFromBJS](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/3/3b8afe752b4776851a91d45c5b7b80459a578ef7.jpeg)

Here is the code generated for the eyebrowse material (looks the same as when coming from JSON)

```javascript
material = new BABYLON.PBRMaterial("MH.eyebrow005", scene);
material.backFaceCulling = true;
material.checkReadyOnlyOnce = false;
material.maxSimultaneousLights = 4;
material.environmentIntensity = 1;
material.reflectivityColor = new QI.C(.5,.5,.5);
material.roughness = .5;
material.alpha = 1;
material.transparencyMode = BABYLON.PBRMaterial.PBRMATERIAL_ALPHATEST;
material.metallic = 0;
nPendingTextures++;
texture = new BABYLON.Texture(resourcesRootDir + "eyebrow005.png", scene, false, true, BABYLON.Texture.TRILINEAR_SAMPLINGMODE, onTexturesLoaded, onTextureError);
texture.hasAlpha = true;
texture.level = 1;
texture.coordinatesIndex = 0;
texture.coordinatesMode = 0;
texture.uOffset = 0;
texture.vOffset = 0;
texture.uScale = 1;
texture.vScale = 1;
texture.uAng = 0;
texture.vAng = 0;
texture.wAng = 0;
texture.wrapU = 1;
texture.wrapV = 1;
material.albedoTexture = texture;
material.useAlphaFromAlbedoTexture = true;

```

There is clearly some alpha, but is there anyway this might be improved?

---

<div class="post-metadata">

**Author:** ![gryff](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/gryff/32/1855_2.png) [@gryff](https://forum.babylonjs.com/u/gryff)\
**Post date:** [June 21, 2019, 12:13am UTC](https://forum.babylonjs.com/t/getting-good-alpha-from-textures/4025/2 "2019-06-21T00:13:52Z")

</div>

@JCPalmer : Did you try setting the “_Transparency Mode_” to “_Alpha blend_” ? See image below. the MH hairbrow file mapped onto a plane , exported and viewed in Sandbox against a white background. Without the change the transparency was very blotchy.

cheers, gryff 🙂

 ![eyebrows1](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/b/b4a74da39221a954e6cfe30e9bd65fae22078a7d.png)

---

<div class="post-metadata">

**Author:** ![JCPalmer](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jcpalmer/32/42_2.png) [@JCPalmer](https://forum.babylonjs.com/u/JCPalmer)\
**Post date:** [June 21, 2019, 3:10pm UTC](https://forum.babylonjs.com/t/getting-good-alpha-from-textures/4025/3 "2019-06-21T15:10:42Z")

</div>

@gryff, thanks. This ties into [an earlier question](https://forum.babylonjs.com/t/texture-hasalpha-causes-clipping-with-pbr/3676) when I was trying to even get export working at all without clipping for textures with alpha.

`PBRMATERIAL_ALPHATEST` got me the same as STD materials. I now want better. Think I am going to have to go through a 4 modes. I seem to remember `PBRMATERIAL_ALPHABLEND` did not work right. Think because the exporter is setting everything the same.

May need to add a custom property to the materials section of the exporter to allow setting the transparency mode, or set the [material.\_alphaCutOff](https://github.com/BabylonJS/Babylon.js/blob/master/src/Materials/PBR/pbrBaseMaterial.ts#L567), in which case you are screwed in the .babylon exporter cause it is not serialized.

@sebavan, is there a reason alphaCutOff is protected & not serializable?

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [June 21, 2019, 3:24pm UTC](https://forum.babylonjs.com/t/getting-good-alpha-from-textures/4025/4 "2019-06-21T15:24:04Z")

</div>

It actually is, here is the definition:  
/\*\*  
\* Defines the alpha limits in alpha test mode.  
\*/  
@serialize()  
@expandToProperty("\_markAllSubMeshesAsTexturesAndMiscDirty")  
public alphaCutOff = 0.4;

---

<div class="post-metadata">

**Author:** ![JCPalmer](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jcpalmer/32/42_2.png) [@JCPalmer](https://forum.babylonjs.com/u/JCPalmer)\
**Post date:** [June 21, 2019, 4:38pm UTC](https://forum.babylonjs.com/t/getting-good-alpha-from-textures/4025/5 "2019-06-21T16:38:25Z")

</div>

Ok, I tried setting everything to `PBRMATERIAL_ALPHABLEND`, and it looked great at certain angles, BUT you sometimes get clipping at other angles & distances.

. ![All%20Alpha%20Blend](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/8/8186839db0acdd9482de84d555ed42de9b7cf0e7.jpeg)

Everything set to `PBRMATERIAL_ALPHATESTANDBLEND` looked better than `PBRMATERIAL_ALPHATEST`, but not as good as `PBRMATERIAL_ALPHABLEND`. It also had the clipping problem.

Setting the body to `PBRMATERIAL_OPAQUE` and the hair materials to `PBRMATERIAL_ALPHABLEND` (below) looked fantastic & no clipping ever. I had avoiding eyelashes on male meshes, because it looked like a mascara screw up, but will have to revisit this soon.

 ![opaque%20body%20%26%20alpha%20hair](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/5/5c11b46f839e34614cdaed8aece197ad3f38c196.jpeg)

Think I am going to make 2 additional custom exporter properties for both the transparency mode & and cutoff. Defaults will be `PBRMATERIAL_OPAQUE` & 0.4, respectively. Do not really need cutoff for my needs for MH, but am not doing this a third time. Will not show up in the .babylon exporter right now. Am busy coordinating multiple Blender addins & working my own work flow. Soonish.

Just checking, are there equivalents for STD materials, @sebavan ?

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [June 21, 2019, 4:41pm UTC](https://forum.babylonjs.com/t/getting-good-alpha-from-textures/4025/6 "2019-06-21T16:41:46Z")

</div>

I do not think so, we added those to support gltf in the PBR material.
