# How to change opacity of each texture in MixMaterial?

**URL:** <https://forum.babylonjs.com/t/how-to-change-opacity-of-each-texture-in-mixmaterial/21640>\
**Category:** Questions\
**Created:** [June 13, 2021, 1:27pm UTC](https://forum.babylonjs.com/t/how-to-change-opacity-of-each-texture-in-mixmaterial/21640 "2021-06-13T13:27:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bozworth](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bozworth/32/6484_2.png) [@bozworth](https://forum.babylonjs.com/u/bozworth)\
**Post date:** [June 13, 2021, 1:27pm UTC](https://forum.babylonjs.com/t/how-to-change-opacity-of-each-texture-in-mixmaterial/21640/1 "2021-06-13T13:27:58Z")

</div>

> **[Mix Material | Babylon.js Documentation](https://doc.babylonjs.com/toolsAndResources/assetLibraries/materialsLibrary/mixMat)**
>
> The Babylon.js materials library mix map textures.

This works really well so far and I love it, so I’m using all of the textures here but some of them I want to change the opacity so it is not as solid, is it possible to do so?

so diffuseTexture1 will have 100% opacity while diffuseTexture2 might have 50% opacity.

All using the same mixmaterial

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [June 14, 2021, 9:25am UTC](https://forum.babylonjs.com/t/how-to-change-opacity-of-each-texture-in-mixmaterial/21640/2 "2021-06-14T09:25:02Z")

</div>

It is already what it is doing through the `mixTexture1`/`mixTexture2` properties.

In these textures, you use the r/g/b/a channels to mix the different textures. For eg, using 255 will make the corresponding layer fully opaque, using 128 will blend this layer with the next one in 50%/50% proportion.

---

<div class="post-metadata">

**Author:** ![bozworth](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bozworth/32/6484_2.png) [@bozworth](https://forum.babylonjs.com/u/bozworth)\
**Post date:** [June 14, 2021, 4:40pm UTC](https://forum.babylonjs.com/t/how-to-change-opacity-of-each-texture-in-mixmaterial/21640/3 "2021-06-14T16:40:54Z")

</div>

I tried this and not sure if im getting something wrong. If you have 2 mixmaps and make the 2nd mix map have 50% opacity on photoshop, does that mean that the textures drawn on the mix material will be 50% opacity too?  
im not getting that result. Im using the same mixmap for both mixmaps on mixmaterial.

When you say 255, do you mean the rgba values but specifically the A?

I would however like to try and get that opacity at a layer/texture level as well on the mixmaterial, so i will try a few things.

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [June 14, 2021, 5:18pm UTC](https://forum.babylonjs.com/t/how-to-change-opacity-of-each-texture-in-mixmaterial/21640/4 "2021-06-14T17:18:35Z")

</div>

From my understanding of the code, `mixmap.g` is the blend factor between texture1/texture2, `mixmap.b` the blend factor between texture2/texture3 and `1-mixmap.a` the blend factor between texture3/texture4. `mixmap.r` is a static multiplication factor for texture1:

```auto
	vec4 mixColor = texture2D(mixMap1Sampler, vTextureUV);

	mixColor.rgb *= vTextureInfos.y;
	
	vec4 diffuse1Color = texture2D(diffuse1Sampler, vTextureUV * diffuse1Infos);
	vec4 diffuse2Color = texture2D(diffuse2Sampler, vTextureUV * diffuse2Infos);
	vec4 diffuse3Color = texture2D(diffuse3Sampler, vTextureUV * diffuse3Infos);
	vec4 diffuse4Color = texture2D(diffuse4Sampler, vTextureUV * diffuse4Infos);
	
	diffuse1Color.rgb *= mixColor.r;
   	diffuse2Color.rgb = mix(diffuse1Color.rgb, diffuse2Color.rgb, mixColor.g);
   	diffuse3Color.rgb = mix(diffuse2Color.rgb, diffuse3Color.rgb, mixColor.b);
	finalMixColor.rgb = mix(diffuse3Color.rgb, diffuse4Color.rgb, 1.0 - mixColor.a);

```
