# GUI Text with Texture

**URL:** <https://forum.babylonjs.com/t/gui-text-with-texture/22493>\
**Category:** Questions\
**Created:** [July 20, 2021, 8:02am UTC](https://forum.babylonjs.com/t/gui-text-with-texture/22493 "2021-07-20T08:02:56Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![PichouPichou](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pichoupichou/32/316_2.png) [@PichouPichou](https://forum.babylonjs.com/u/PichouPichou)\
**Post date:** [July 20, 2021, 8:02am UTC](https://forum.babylonjs.com/t/gui-text-with-texture/22493/1 "2021-07-20T08:02:56Z")

</div>

Hello,

I am looking for a way to have a customizable Text on a Mesh with a material like in this image:

 ![Screenshot 2021-07-20 at 09.58.46](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/3/a/3aa0295a5047dee781504ef540fd831ecf5301a0.png)

I know we can use GUI to draw text on any Mesh but I did’nt find a way to have PBRMaterial applied on it. Is it possible?  
Maybe using something like a dynamicTexture? [https://playground.babylonjs.com/#5ZCGRM#2](https://playground.babylonjs.com/#5ZCGRM#2)

Thanks a lot for your ideas and help 😉

---

<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 20, 2021, 1:43pm UTC](https://forum.babylonjs.com/t/gui-text-with-texture/22493/2 "2021-07-20T13:43:56Z")

</div>

Gui is using canvas 2d to draw the text so nope it can not be rendered with a pbr material.

Nevertheless why not using it to generate your pbr textures or coupled to Node Material to achieve the desired effect ?

---

<div class="post-metadata">

**Author:** ![PichouPichou](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pichoupichou/32/316_2.png) [@PichouPichou](https://forum.babylonjs.com/u/PichouPichou)\
**Post date:** [July 20, 2021, 1:50pm UTC](https://forum.babylonjs.com/t/gui-text-with-texture/22493/3 "2021-07-20T13:50:21Z")

</div>

How can I do that?

I guess the idea is to use the GUI as an opacity texture and apply it to a mesh that has a PBRMaterial? Would it work?  
I am not an expert with node material so I would prefer a code solution 😉

---

<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 20, 2021, 1:56pm UTC](https://forum.babylonjs.com/t/gui-text-with-texture/22493/4 "2021-07-20T13:56:31Z")

</div>

yup it should work.

---

<div class="post-metadata">

**Author:** ![msDestiny14](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/msdestiny14/32/9572_2.png) [@msDestiny14](https://forum.babylonjs.com/u/msDestiny14)\
**Post date:** [July 20, 2021, 2:47pm UTC](https://forum.babylonjs.com/t/gui-text-with-texture/22493/5 "2021-07-20T14:47:57Z")

</div>

Tempted to make a demo for this myself. Will be back… 😉

---

<div class="post-metadata">

**Author:** ![PichouPichou](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pichoupichou/32/316_2.png) [@PichouPichou](https://forum.babylonjs.com/u/PichouPichou)\
**Post date:** [July 20, 2021, 8:10pm UTC](https://forum.babylonjs.com/t/gui-text-with-texture/22493/6 "2021-07-20T20:10:09Z")

</div>

I made some first test here: [https://playground.babylonjs.com/#ZI9AK7#1505](https://playground.babylonjs.com/#ZI9AK7#1505)  
But for now I don’t really understand what is happening haha

---

<div class="post-metadata">

**Author:** ![msDestiny14](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/msdestiny14/32/9572_2.png) [@msDestiny14](https://forum.babylonjs.com/u/msDestiny14)\
**Post date:** [July 20, 2021, 10:10pm UTC](https://forum.babylonjs.com/t/gui-text-with-texture/22493/7 "2021-07-20T22:10:58Z")

</div>

With this is it the UV wrapping that is not correct. I’m still playing around with a sphere atm. This might be easier to start.

[https://playground.babylonjs.com/#2FDQT5#14](https://playground.babylonjs.com/#2FDQT5#14)

---

<div class="post-metadata">

**Author:** ![PichouPichou](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pichoupichou/32/316_2.png) [@PichouPichou](https://forum.babylonjs.com/u/PichouPichou)\
**Post date:** [July 20, 2021, 11:49pm UTC](https://forum.babylonjs.com/t/gui-text-with-texture/22493/8 "2021-07-20T23:49:31Z")

</div>

Well at least it works on a sphere and with the metallic: [https://playground.babylonjs.com/#2FDQT5#985](https://playground.babylonjs.com/#2FDQT5#985)  
I put the background in blue and the text in green to follow PBR rules.

Next: doing that on a model and with opacity 💪

---

<div class="post-metadata">

**Author:** ![PichouPichou](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pichoupichou/32/316_2.png) [@PichouPichou](https://forum.babylonjs.com/u/PichouPichou)\
**Post date:** [July 21, 2021, 8:04am UTC](https://forum.babylonjs.com/t/gui-text-with-texture/22493/9 "2021-07-21T08:04:01Z")

</div>

So I tried with the opacityTexture but I can’t make it work, now the background is black and the text white for opacity: [https://playground.babylonjs.com/#2FDQT5#986](https://playground.babylonjs.com/#2FDQT5#986)

I tested to change alphaMode, transparencyMode or needAlphaBlending values but none have worked. Any ideas?

---

<div class="post-metadata">

**Author:** ![PichouPichou](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pichoupichou/32/316_2.png) [@PichouPichou](https://forum.babylonjs.com/u/PichouPichou)\
**Post date:** [July 21, 2021, 12:40pm UTC](https://forum.babylonjs.com/t/gui-text-with-texture/22493/10 "2021-07-21T12:40:02Z")

</div>

I manage to make it work using albedoTexture but not with opacityTexture:  
[https://playground.babylonjs.com/#2FDQT5#987](https://playground.babylonjs.com/#2FDQT5#987)

But my material already has a defined albedoTexture so I don’t want to modify it.  
What am I missing to make it work with opacityTexture?

---

<div class="post-metadata">

**Author:** ![PichouPichou](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pichoupichou/32/316_2.png) [@PichouPichou](https://forum.babylonjs.com/u/PichouPichou)\
**Post date:** [July 21, 2021, 12:46pm UTC](https://forum.babylonjs.com/t/gui-text-with-texture/22493/11 "2021-07-21T12:46:38Z")

</div>

Ok here we go: [https://playground.babylonjs.com/#2FDQT5#988](https://playground.babylonjs.com/#2FDQT5#988)

Playing with the PBR parameters made it work:

```auto
    pbr.alphaMode = BABYLON.Engine.ALPHA_ADD
    pbr.useRadianceOverAlpha = false;
    pbr.useSpecularOverAlpha = false;
    pbr.opacityTexture.getAlphaFromRGB = true

```

---

<div class="post-metadata">

**Author:** ![PichouPichou](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pichoupichou/32/316_2.png) [@PichouPichou](https://forum.babylonjs.com/u/PichouPichou)\
**Post date:** [July 21, 2021, 2:19pm UTC](https://forum.babylonjs.com/t/gui-text-with-texture/22493/12 "2021-07-21T14:19:44Z")

</div>

If I do the exact same thing on a model, it stops working: [https://playground.babylonjs.com/#ZI9AK7#1506](https://playground.babylonjs.com/#ZI9AK7#1506)

But I can’t see why?

---

<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 21, 2021, 2:37pm UTC](https://forum.babylonjs.com/t/gui-text-with-texture/22493/13 "2021-07-21T14:37:14Z")

</div>

The model UVs need to fit with the texture you are trying to apply

---

<div class="post-metadata">

**Author:** ![PichouPichou](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pichoupichou/32/316_2.png) [@PichouPichou](https://forum.babylonjs.com/u/PichouPichou)\
**Post date:** [July 21, 2021, 3:26pm UTC](https://forum.babylonjs.com/t/gui-text-with-texture/22493/14 "2021-07-21T15:26:45Z")

</div>

How can make my texture and model UVs match?

I need to place the texte wherever I want on the mesh. I should be able to do that playing with texture offset and scale right?

---

<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 21, 2021, 3:54pm UTC](https://forum.babylonjs.com/t/gui-text-with-texture/22493/15 "2021-07-21T15:54:06Z")

</div>

Not really, as what you are describing here is more a decals

---

<div class="post-metadata">

**Author:** ![PichouPichou](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pichoupichou/32/316_2.png) [@PichouPichou](https://forum.babylonjs.com/u/PichouPichou)\
**Post date:** [July 21, 2021, 5:31pm UTC](https://forum.babylonjs.com/t/gui-text-with-texture/22493/16 "2021-07-21T17:31:29Z")

</div>

Indeed @sebavan the solution is maybe to use decal: [https://playground.babylonjs.com/#1BAPRM#537](https://playground.babylonjs.com/#1BAPRM#537)

---

<div class="post-metadata">

**Author:** ![PichouPichou](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pichoupichou/32/316_2.png) [@PichouPichou](https://forum.babylonjs.com/u/PichouPichou)\
**Post date:** [July 21, 2021, 5:35pm UTC](https://forum.babylonjs.com/t/gui-text-with-texture/22493/17 "2021-07-21T17:35:16Z")

</div>

Working with an opacityTexture: [https://playground.babylonjs.com/#1BAPRM#538](https://playground.babylonjs.com/#1BAPRM#538)  
💥

Now I just have to figure out how to place and scale precisely the decal!

---

<div class="post-metadata">

**Author:** ![jtcheng](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@jtcheng](https://forum.babylonjs.com/u/jtcheng)\
**Post date:** [December 11, 2021, 9:23am UTC](https://forum.babylonjs.com/t/gui-text-with-texture/22493/18 "2021-12-11T09:23:02Z")

</div>

@PichouPichou

so, finally, how to place the decal for a Irregular mesh？

---

<div class="post-metadata">

**Author:** ![PichouPichou](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pichoupichou/32/316_2.png) [@PichouPichou](https://forum.babylonjs.com/u/PichouPichou)\
**Post date:** [December 11, 2021, 8:51pm UTC](https://forum.babylonjs.com/t/gui-text-with-texture/22493/19 "2021-12-11T20:51:12Z")

</div>

Hi @jtcheng,

If your mesh is irregular, the decal above it also will.  
For my case, I have a flat object where I just set the position so that the text is at the right place and scale it so that it has the correct size.

Hope that helps

---

<div class="post-metadata">

**Author:** ![jeremy-coleman](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jeremy-coleman/32/15493_2.png) [@jeremy-coleman](https://forum.babylonjs.com/u/jeremy-coleman)\
**Post date:** [December 12, 2021, 4:07am UTC](https://forum.babylonjs.com/t/gui-text-with-texture/22493/20 "2021-12-12T04:07:51Z")

</div>

@PichouPichou  
totally unrelated to anything, but if you ever need a stunt double or something, my brothers best friend can do the job

![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/3/3/33501387b7bd8a5c74114e262b4359aeb1934c26.png)

[Next page](https://forum.babylonjs.com/t/gui-text-with-texture/22493.md?page=2)
