# GLTFExporter not working with PBRMaterial

**URL:** <https://forum.babylonjs.com/t/gltfexporter-not-working-with-pbrmaterial/52209>\
**Category:** Bugs\
**Tags:** material, glb\
**Created:** [July 20, 2024, 10:48am UTC](https://forum.babylonjs.com/t/gltfexporter-not-working-with-pbrmaterial/52209 "2024-07-20T10:48:08Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![hamid293](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/hamid293/32/41436_2.png) [@hamid293](https://forum.babylonjs.com/u/hamid293)\
**Post date:** [July 20, 2024, 10:48am UTC](https://forum.babylonjs.com/t/gltfexporter-not-working-with-pbrmaterial/52209/1 "2024-07-20T10:48:08Z")

</div>

Hello Guys,

I’m creating a simple plane with PBRMaterial on it. I’m applying an albedotexture and setting the unlit property to true. Then I’m using the export to glb option in the inspector to export the scene as a glb model.

It works correctly for StandardMaterial but when I switch it to PBRMaterial it doesn’t export the material/texture the created glb file has no texture.

[Playground Link](https://playground.babylonjs.com/#Q9VZS9#2142) for reproducing the issue.

Also, thank you creating an amazing 3d framework. One of the most easiest and simple to use.

---

<div class="post-metadata">

**Author:** ![roland](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/roland/32/38940_2.png) [@roland](https://forum.babylonjs.com/u/roland)\
**Post date:** [July 20, 2024, 6:11pm UTC](https://forum.babylonjs.com/t/gltfexporter-not-working-with-pbrmaterial/52209/2 "2024-07-20T18:11:31Z")

</div>

Hello and welcome!

The generated texture is all white in the resulting glb file.

The issue comes from the `readTexturePixels` function.

I’ve created a PR here for another reason. Fortunately it fixes your issue as well. So I suggest you to wait for this PR merge.

> [@Why async \_readTexturePixels uses synchronous version of readTexturePixels?](https://forum.babylonjs.com/t/why-async-readtexturepixels-uses-synchronous-version-of-readtexturepixels/51290/22):
>
> Calls readTexturePixels multiple times every 3 seconds: Old version: New version: [#ASX6HW#5](https://playground.babylonjs.com/?snapshot=refs/pull/15312/merge#ASX6HW#5)

However you can try it here already:

> **[Babylon.js Playground](https://playground.babylonjs.com/?snapshot=refs%2Fpull%2F15312%2Fmerge#Q9VZS9%232142)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

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

---

<div class="post-metadata">

**Author:** ![hamid293](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/hamid293/32/41436_2.png) [@hamid293](https://forum.babylonjs.com/u/hamid293)\
**Post date:** [July 20, 2024, 7:01pm UTC](https://forum.babylonjs.com/t/gltfexporter-not-working-with-pbrmaterial/52209/3 "2024-07-20T19:01:24Z")

</div>

Hello Roland,

Thank you for replying over the weekend.

In the playground you shared, it’s exporting the texture but it’s all weird now.

Below is the plane with the artwork fully covering the plane in Babylonjs

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/c/5/c57556ad88d0692ca4a753209ce89c9d76333dc7.jpeg)

Below is the same plane in another viewer. As you can see most of the plane is black and from what I can understand it’s somehow writing the canvas pixel values onto the plane. The purple border around the artwork is coming from the babylonjs canvas background, and it is being applied on to the plane as a texture.

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/4/7/47916469b5cc7305b5c4b90ddbe1a38dae266f86.png)

---

<div class="post-metadata">

**Author:** ![roland](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/roland/32/38940_2.png) [@roland](https://forum.babylonjs.com/u/roland)\
**Post date:** [July 20, 2024, 7:15pm UTC](https://forum.babylonjs.com/t/gltfexporter-not-working-with-pbrmaterial/52209/4 "2024-07-20T19:15:33Z")

</div>

> [@hamid293](#):
>
> The purple border around the artwork is coming from the babylonjs canvas background

Yep, it can be seen on my screenshot. Sorry, I didn’t pay attention to the details.

Let me see what’s the issue with the texture, why is it exported the way it is.

EDIT: fixing this

---

<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:** [July 22, 2024, 5:01pm UTC](https://forum.babylonjs.com/t/gltfexporter-not-working-with-pbrmaterial/52209/5 "2024-07-22T17:01:08Z")

</div>

cc @bghgary

---

<div class="post-metadata">

**Author:** ![bghgary](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bghgary/32/48532_2.png) [@bghgary](https://forum.babylonjs.com/u/bghgary)\
**Post date:** [July 22, 2024, 7:42pm UTC](https://forum.babylonjs.com/t/gltfexporter-not-working-with-pbrmaterial/52209/6 "2024-07-22T19:42:33Z")

</div>



---

<div class="post-metadata">

**Author:** ![bghgary](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bghgary/32/48532_2.png) [@bghgary](https://forum.babylonjs.com/u/bghgary)\
**Post date:** [July 22, 2024, 8:44pm UTC](https://forum.babylonjs.com/t/gltfexporter-not-working-with-pbrmaterial/52209/7 "2024-07-22T20:44:53Z")

</div>



---

<div class="post-metadata">

**Author:** ![hamid293](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/hamid293/32/41436_2.png) [@hamid293](https://forum.babylonjs.com/u/hamid293)\
**Post date:** [July 23, 2024, 11:26am UTC](https://forum.babylonjs.com/t/gltfexporter-not-working-with-pbrmaterial/52209/8 "2024-07-23T11:26:38Z")

</div>

@sebavan I just wanted to confirm if I should create an issue on GitHub for this.

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [July 23, 2024, 2:35pm UTC](https://forum.babylonjs.com/t/gltfexporter-not-working-with-pbrmaterial/52209/9 "2024-07-23T14:35:00Z")

</div>

Please:) I will have a look shortly. Unless @ryantrem wants to give it a try?

---

<div class="post-metadata">

**Author:** ![hamid293](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/hamid293/32/41436_2.png) [@hamid293](https://forum.babylonjs.com/u/hamid293)\
**Post date:** [July 23, 2024, 3:14pm UTC](https://forum.babylonjs.com/t/gltfexporter-not-working-with-pbrmaterial/52209/10 "2024-07-23T15:14:57Z")

</div>

I’ve created a GitHub issue for it. [Link](https://github.com/BabylonJS/Babylon.js/issues/15320)

---

<div class="post-metadata">

**Author:** ![ryantrem](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ryantrem/32/34010_2.png) [@ryantrem](https://forum.babylonjs.com/u/ryantrem)\
**Post date:** [July 23, 2024, 4:48pm UTC](https://forum.babylonjs.com/t/gltfexporter-not-working-with-pbrmaterial/52209/11 "2024-07-23T16:48:49Z")

</div>

I could probably look a little later in the week, though it sounds like it may require @roland’s other fix first, and it also sounds like @roland might already be looking?

---

<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:** [July 23, 2024, 5:26pm UTC](https://forum.babylonjs.com/t/gltfexporter-not-working-with-pbrmaterial/52209/12 "2024-07-23T17:26:45Z")

</div>

The main issue is not related to reading textures or at least it does not look like it.

It comes from how we convert spec/gloss pbr workflow into metal/rough ones as some cases are simply not possible there.

As it is done before applying extension like unlit to allow all the greatness of gltf later on, we end up with a converted white texture.

I would strongly advise to rely on a metal/rough workflow when using export to prevent any misleading surprises: [https://playground.babylonjs.com/#Q9VZS9#2155](https://playground.babylonjs.com/#Q9VZS9#2155)

---

<div class="post-metadata">

**Author:** ![hamid293](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/hamid293/32/41436_2.png) [@hamid293](https://forum.babylonjs.com/u/hamid293)\
**Post date:** [July 23, 2024, 8:25pm UTC](https://forum.babylonjs.com/t/gltfexporter-not-working-with-pbrmaterial/52209/13 "2024-07-23T20:25:27Z")

</div>

Thank you so much @sebavan. The playground you shared works for me.
