# Does alphaTest not work when you export image textures with alpha channels with the GLB model?

**URL:** <https://discourse.threejs.org/t/does-alphatest-not-work-when-you-export-image-textures-with-alpha-channels-with-the-glb-model/73429>\
**Category:** Questions\
**Tags:** materials\
**Created:** [October 29, 2024, 1:48pm UTC](https://discourse.threejs.org/t/does-alphatest-not-work-when-you-export-image-textures-with-alpha-channels-with-the-glb-model/73429 "2024-10-29T13:48:03Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![panda\_warrior](https://avatars.discourse-cdn.com/v4/letter/p/ed655f/32.png) [@panda\_warrior](https://discourse.threejs.org/u/panda_warrior)\
**Post date:** [October 29, 2024, 1:48pm UTC](https://discourse.threejs.org/t/does-alphatest-not-work-when-you-export-image-textures-with-alpha-channels-with-the-glb-model/73429/1 "2024-10-29T13:48:03Z")

</div>

I have an image texture PNG that has an alpha channel. When I set it to alphaTest 0.5, it works when:

1. I export the GLB file from Blender with no materials.
2. Use textureloader to load the image texture and then attach it to the GLB file.

All the transparent places are cut out properly.

It does not work when:

1. I export the GLB file from Blender with the PNG image texture.
2. I find that material in the GLB file update it, and set its alphatest to 0.5.  
I’ve checked to see if the material was properly updated and it always shows alphatest 0.5, but the transparent places remain black rather than transparent. I’ve also tried setting transparency properties to true, but did not change the result.

**So my question:**  
Does alphaTest not work when you export image textures with alpha channels with the GLB model?

Or is it still possible I’m just missing something in my code?

---

<div class="post-metadata">

**Author:** ![Chaser\_Code](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/chaser_code/32/20199_2.png) [@Chaser\_Code](https://discourse.threejs.org/u/Chaser_Code)\
**Post date:** [October 29, 2024, 1:57pm UTC](https://discourse.threejs.org/t/does-alphatest-not-work-when-you-export-image-textures-with-alpha-channels-with-the-glb-model/73429/2 "2024-10-29T13:57:07Z")

</div>

Try `material.needsUpdate=true`

---

<div class="post-metadata">

**Author:** ![panda\_warrior](https://avatars.discourse-cdn.com/v4/letter/p/ed655f/32.png) [@panda\_warrior](https://discourse.threejs.org/u/panda_warrior)\
**Post date:** [October 29, 2024, 2:07pm UTC](https://discourse.threejs.org/t/does-alphatest-not-work-when-you-export-image-textures-with-alpha-channels-with-the-glb-model/73429/3 "2024-10-29T14:07:09Z")

</div>

Doesn’t seem to work unforuantely. I swear I got it working before though, but now I can’t.

---

<div class="post-metadata">

**Author:** ![Chaser\_Code](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/chaser_code/32/20199_2.png) [@Chaser\_Code](https://discourse.threejs.org/u/Chaser_Code)\
**Post date:** [October 29, 2024, 2:09pm UTC](https://discourse.threejs.org/t/does-alphatest-not-work-when-you-export-image-textures-with-alpha-channels-with-the-glb-model/73429/4 "2024-10-29T14:09:46Z")

</div>

Send glb here i will try to export image to see how it look in real after blender

---

<div class="post-metadata">

**Author:** ![panda\_warrior](https://avatars.discourse-cdn.com/v4/letter/p/ed655f/32.png) [@panda\_warrior](https://discourse.threejs.org/u/panda_warrior)\
**Post date:** [October 29, 2024, 2:13pm UTC](https://discourse.threejs.org/t/does-alphatest-not-work-when-you-export-image-textures-with-alpha-channels-with-the-glb-model/73429/5 "2024-10-29T14:13:20Z")

</div>

Awesome, thank you so much, here it is, I exported it with a PNG, it’s too big here so here’s a google drive link:

> **[Grass.glb](https://drive.google.com/file/d/1giiIAjW8dGmuPgOHwa7xpJ5sUj0QriSy/view?usp=sharing)**
>
> Google Drive file.

---

<div class="post-metadata">

**Author:** ![Chaser\_Code](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/chaser_code/32/20199_2.png) [@Chaser\_Code](https://discourse.threejs.org/u/Chaser_Code)\
**Post date:** [October 29, 2024, 2:26pm UTC](https://discourse.threejs.org/t/does-alphatest-not-work-when-you-export-image-textures-with-alpha-channels-with-the-glb-model/73429/6 "2024-10-29T14:26:21Z")

</div>

Yes. Texture is transparent png.

---

<div class="post-metadata">

**Author:** ![panda\_warrior](https://avatars.discourse-cdn.com/v4/letter/p/ed655f/32.png) [@panda\_warrior](https://discourse.threejs.org/u/panda_warrior)\
**Post date:** [October 29, 2024, 2:38pm UTC](https://discourse.threejs.org/t/does-alphatest-not-work-when-you-export-image-textures-with-alpha-channels-with-the-glb-model/73429/7 "2024-10-29T14:38:55Z")

</div>

So it’s possible to get it working with alphaTest if I export the PNG with the GLB model rather than seperately?

---

<div class="post-metadata">

**Author:** ![Chaser\_Code](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/chaser_code/32/20199_2.png) [@Chaser\_Code](https://discourse.threejs.org/u/Chaser_Code)\
**Post date:** [October 29, 2024, 2:49pm UTC](https://discourse.threejs.org/t/does-alphatest-not-work-when-you-export-image-textures-with-alpha-channels-with-the-glb-model/73429/8 "2024-10-29T14:49:01Z")

</div>

I try to see model in three.js example “webgl\_loader\_gltf.html” but cant see model. I see model in online glb viwer and there without transparency and cant access to mesh. Can you share with you code to load model in html

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/0/d/0dc6fbd5ab709fa0ee9ff24b83734d873f6ee20b.jpeg)

---

<div class="post-metadata">

**Author:** ![panda\_warrior](https://avatars.discourse-cdn.com/v4/letter/p/ed655f/32.png) [@panda\_warrior](https://discourse.threejs.org/u/panda_warrior)\
**Post date:** [October 29, 2024, 3:01pm UTC](https://discourse.threejs.org/t/does-alphatest-not-work-when-you-export-image-textures-with-alpha-channels-with-the-glb-model/73429/9 "2024-10-29T15:01:46Z")

</div>

Here it is!

```javascript
/*
Auto-generated by: https://github.com/pmndrs/gltfjsx
Command: npx gltfjsx@6.5.2 Grass.glb 
*/

import React, { useEffect } from "react";
import { useGLTF } from "@react-three/drei";
import * as THREE from "three";

export default function Model(props) {
  const { nodes, materials } = useGLTF("/Grass.glb");

  useEffect(() => {
    // Modify the material to support transparency
    if (materials["MergedBake_Baked.025"]) {
      materials["MergedBake_Baked.025"].transparent = true;
      materials["MergedBake_Baked.025"].alphaTest = 0.5; // Adjust this value as needed
      materials["MergedBake_Baked.025"].side = THREE.DoubleSide;

      // If using a texture
      if (materials["MergedBake_Baked.025"].map) {
        materials["MergedBake_Baked.025"].map.encoding = THREE.sRGBEncoding;
        materials["MergedBake_Baked.025"].map.flipY = false;
      }
    }
  }, [materials]);

  return (
    <group {...props} dispose={null}>
      <mesh
        geometry={nodes.grass_block_first_half_right_Baked.geometry}
        material={materials["MergedBake_Baked.025"]}
        position={[5.421, 67.409, -0.825]}
        rotation={[Math.PI / 2, 0, 0]}
      />
    </group>
  );
}

useGLTF.preload("/Grass.glb");

```

---

<div class="post-metadata">

**Author:** ![Chaser\_Code](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/chaser_code/32/20199_2.png) [@Chaser\_Code](https://discourse.threejs.org/u/Chaser_Code)\
**Post date:** [October 29, 2024, 3:04pm UTC](https://discourse.threejs.org/t/does-alphatest-not-work-when-you-export-image-textures-with-alpha-channels-with-the-glb-model/73429/10 "2024-10-29T15:04:41Z")

</div>

Thank you i already found model. it was on top

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/0/6/06a3a6c86536ff32769e2e18b660884c38a5173b.jpeg)

---

<div class="post-metadata">

**Author:** ![Chaser\_Code](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/chaser_code/32/20199_2.png) [@Chaser\_Code](https://discourse.threejs.org/u/Chaser_Code)\
**Post date:** [October 29, 2024, 3:15pm UTC](https://discourse.threejs.org/t/does-alphatest-not-work-when-you-export-image-textures-with-alpha-channels-with-the-glb-model/73429/11 "2024-10-29T15:15:14Z")

</div>

Your texture into `material.emmisiveMap` instead `material.map` and `transparent=false`  
and `_alphaTest=0`

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/c/7/c7852a7d16c96fc3e5c303e92e02b37a20e636f1.png)

---

<div class="post-metadata">

**Author:** ![panda\_warrior](https://avatars.discourse-cdn.com/v4/letter/p/ed655f/32.png) [@panda\_warrior](https://discourse.threejs.org/u/panda_warrior)\
**Post date:** [October 29, 2024, 3:21pm UTC](https://discourse.threejs.org/t/does-alphatest-not-work-when-you-export-image-textures-with-alpha-channels-with-the-glb-model/73429/12 "2024-10-29T15:21:03Z")

</div>

OHHHHHHHHHHHHHHHHH now I get it, thank you! I used an emission node in Blender, in the past it would still attach the image into the “map” and create a basic material, for some reason now it attaches it to the emissiveMap property.

Thank you so much!!!

---

<div class="post-metadata">

**Author:** ![Chaser\_Code](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/chaser_code/32/20199_2.png) [@Chaser\_Code](https://discourse.threejs.org/u/Chaser_Code)\
**Post date:** [October 29, 2024, 3:27pm UTC](https://discourse.threejs.org/t/does-alphatest-not-work-when-you-export-image-textures-with-alpha-channels-with-the-glb-model/73429/13 "2024-10-29T15:27:50Z")

</div>

Optimised size of png now 6mb instead 55mb

```javascript
let map=model.children[0].material.emissiveMap;
model.children[0].material=new THREE.MeshBasicMaterial();
model.children[0].material.map=map;
model.children[0].material.transparent=true;
model.children[0].material._alphaTest=0.5;
model.children[0].material.needsUpdate=true;

```

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/5/5/559b24aa1966617ac33edf09f90b946d59875a6e.jpeg)
