# Fragment\_Custom\_Alpha

**URL:** <https://forum.babylonjs.com/t/fragment-custom-alpha/35573>\
**Category:** Questions\
**Created:** [November 10, 2022, 8:57am UTC](https://forum.babylonjs.com/t/fragment-custom-alpha/35573 "2022-11-10T08:57:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![NinjaGamer](https://avatars.discourse-cdn.com/v4/letter/n/b77776/32.png) [@NinjaGamer](https://forum.babylonjs.com/u/NinjaGamer)\
**Post date:** [November 10, 2022, 8:57am UTC](https://forum.babylonjs.com/t/fragment-custom-alpha/35573/1 "2022-11-10T08:57:06Z")

</div>

Hey there,  
Im using diffuseTexture on standard material for texture and when i add texture then mesh will have black color background and i tried Fragment\_Custom\_Alpha but its not working.  
By the way i’m implementing in React App.

![Ninja](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/e/a/ead50c0397e25e657aad96c51b081a6ed598ebb3.jpeg)

---

<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:** [November 10, 2022, 9:53am UTC](https://forum.babylonjs.com/t/fragment-custom-alpha/35573/2 "2022-11-10T09:53:08Z")

</div>

Welcome aboard!

Is your material an instance of `CustomMaterial` and not `StandardMaterial`?

If you can make a repro in [the Playground](https://playground.babylonjs.com/) it will be easier to help you.

---

<div class="post-metadata">

**Author:** ![NinjaGamer](https://avatars.discourse-cdn.com/v4/letter/n/b77776/32.png) [@NinjaGamer](https://forum.babylonjs.com/u/NinjaGamer)\
**Post date:** [November 10, 2022, 10:02am UTC](https://forum.babylonjs.com/t/fragment-custom-alpha/35573/3 "2022-11-10T10:02:28Z")

</div>

Hi @Evgeni_Popov , Thanks for response.

It works fine in pg but in React app, not able to achive same output, This is source code i have in React app.

```auto
     var mat = new BABYLON.CustomMaterial("mat", scene);
    mat.diffuseTexture = new BABYLON.Texture(textureImage, scene, false, false);
    materialedMeshes.forEach(mesh => mesh.material = mat);
    mat.emissiveColor = new BABYLON.Color3(1, 1, 1);
    
    // mat.diffuseColor = new BABYLON.Color3(1, 0, 1);
    // mat.specularColor = new BABYLON.Color3(0.5, 0.6, 0.87);
    // mat.emissiveColor = new BABYLON.Color3(1, 1, 1);
    // mat.ambientColor = new BABYLON.Color3(0.23, 0.98, 0.53);

    mat.diffuseTexture.uOffset = -0.1000;
    mat.diffuseTexture.vOffset = -1.1800;
    mat.diffuseTexture.uScale = 1.2200;
    mat.diffuseTexture.vScale = 2.2200;
    mat.diffuseTexture.uAng = Math.PI;
    mat.diffuseTexture.wrapU = BABYLON.Constants.TEXTURE_CLAMP_ADDRESSMODE;
    mat.diffuseTexture.wrapV = BABYLON.Constants.TEXTURE_CLAMP_ADDRESSMODE;
    mat.Fragment_Custom_Alpha(`
    if (baseColor.r == 0. && baseColor.g == 0. && baseColor.b == 0.) {
        baseColor.rgb = vec3(0.85, 0.85, 0.85);
    }
    baseColor.rgb = mix(vec3(0.85, 0.85, 0.85), baseColor.rgb, baseColor.a);
`);

```

---

<div class="post-metadata">

**Author:** ![Pavanpk](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pavanpk/32/27529_2.png) [@Pavanpk](https://forum.babylonjs.com/u/Pavanpk)\
**Post date:** [November 10, 2022, 11:27am UTC](https://forum.babylonjs.com/t/fragment-custom-alpha/35573/4 "2022-11-10T11:27:22Z")

</div>

@NinjaGamer Try with this. Im not sure how it should be used in React but in pg it works.

```auto
mat.Fragment_Custom_Diffuse(`
     vec2 updatedUV = vDiffuseUV + uvOffset;
         if (updatedUV.x < 0.0 || updatedUV.x > 1.0 || updatedUV.y < 0.0 || updatedUV.y > 1.0) {
             baseColor.rgb = vec3(0.25, 0.85, 0.75);
         }        
     `);

```

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [December 9, 2022, 11:50am UTC](https://forum.babylonjs.com/t/fragment-custom-alpha/35573/5 "2022-12-09T11:50:36Z")

</div>

Hello @NinjaGamer just checking in if you’re still having issues?
