# Defold PBR extension

**URL:** <https://forum.defold.com/t/defold-pbr-extension/73729>\
**Category:** Announcements\
**Created:** [July 31, 2023, 4:21pm UTC](https://forum.defold.com/t/defold-pbr-extension/73729 "2023-07-31T16:21:01Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jhonny.goransson](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/jhonny.goransson/32/3864_2.png) [@jhonny.goransson](https://forum.defold.com/u/jhonny.goransson)\
**Post date:** [July 31, 2023, 4:21pm UTC](https://forum.defold.com/t/defold-pbr-extension/73729/1 "2023-07-31T16:21:01Z")

</div>

## Defold PBR Support

We’ve been working on improving our 3D support during the past year or so, and we now feel it’s time to release an alpha version of the PBR extension! For issues, bug reports or suggestions - please navigate to the github project page open a ticket regarding the matter there.

Live demo: [defold-pbr 1.0](http://defold.com/defold-pbr/)  
Project repository: [GitHub - defold/defold-pbr · GitHub](https://github.com/defold/defold-pbr)  
Integration guide & manual: [https://github.com/defold/defold-pbr/blob/master/defold-pbr/README.md](https://github.com/defold/defold-pbr/blob/master/defold-pbr/README.md)

 ![image](https://forum-defold-uploads.b-cdn.net/original/3X/5/1/5115849b664dfcdca5acaa5ff117b4674d9673e3.jpeg)

### TODO

- linux support - the extension does currently not seem to work on the linux platform
- optimise shader size - the built GLSL shaders are quite large because of heavy use of includes
- add more GLTF PBR features - we currently support a somewhat small set of features from the reference GLSL from the GLTF viewer, but we would like to have more feature parity between our viewer and the official Khronos one.

---

<div class="post-metadata">

**Author:** ![anon95708182](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/a/ce7236/32.png) [@anon95708182](https://forum.defold.com/u/anon95708182)\
**Post date:** [July 31, 2023, 5:40pm UTC](https://forum.defold.com/t/defold-pbr-extension/73729/2 "2023-07-31T17:40:58Z")

</div>

Finally! 🥳 Just playing with the demo, runs without hick-ups so far on the mini m1. And is soooo cool. 🤩  
Thank you all!

---

<div class="post-metadata">

**Author:** ![Pawel](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pawel/32/24623_2.png) [@Pawel](https://forum.defold.com/u/Pawel)\
**Post date:** [August 1, 2023, 7:51am UTC](https://forum.defold.com/t/defold-pbr-extension/73729/3 "2023-08-01T07:51:51Z")

</div>

Looks awesome! ❤😍

---

<div class="post-metadata">

**Author:** ![totebo](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/totebo/32/36087_2.png) [@totebo](https://forum.defold.com/u/totebo)\
**Post date:** [August 1, 2023, 5:42pm UTC](https://forum.defold.com/t/defold-pbr-extension/73729/4 "2023-08-01T17:42:21Z")

</div>

Runs perfectly smoothly on the low spec Pixel 5, too! 🤩

---

<div class="post-metadata">

**Author:** ![jhonny.goransson](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/jhonny.goransson/32/3864_2.png) [@jhonny.goransson](https://forum.defold.com/u/jhonny.goransson)\
**Post date:** [August 1, 2023, 5:56pm UTC](https://forum.defold.com/t/defold-pbr-extension/73729/5 "2023-08-01T17:56:45Z")

</div>

Great to hear! 🙂

---

<div class="post-metadata">

**Author:** ![Potota](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/potota/32/33404_2.png) [@Potota](https://forum.defold.com/u/Potota)\
**Post date:** [August 1, 2023, 7:11pm UTC](https://forum.defold.com/t/defold-pbr-extension/73729/6 "2023-08-01T19:11:11Z")

</div>

> [@jhonny.goransson](#):
>
> ### TODO
> 
> - linux support - the extension does currently not seem to work on the linux platform

Working just fine here on Silverblue 38!

 ![image](https://forum-defold-uploads.b-cdn.net/original/3X/9/0/9099e0276dcec18864e4e075d49179cac2a9e8aa.jpeg)

---

<div class="post-metadata">

**Author:** ![jhonny.goransson](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/jhonny.goransson/32/3864_2.png) [@jhonny.goransson](https://forum.defold.com/u/jhonny.goransson)\
**Post date:** [August 1, 2023, 7:19pm UTC](https://forum.defold.com/t/defold-pbr-extension/73729/7 "2023-08-01T19:19:35Z")

</div>

> [@Potota](#):
>
> Working just fine here on Silverblue 38!

Oh, cool! I know @AGulev had some issues but glad it works! Is it the web demo or the desktop version? If it’s desktop could you try to generate a hdr env map? Should be one in the repo

---

<div class="post-metadata">

**Author:** ![Pawel](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pawel/32/24623_2.png) [@Pawel](https://forum.defold.com/u/Pawel)\
**Post date:** [August 1, 2023, 7:21pm UTC](https://forum.defold.com/t/defold-pbr-extension/73729/8 "2023-08-01T19:21:30Z")

</div>

So it looks like the problem is with Debian distros? This is test on my Ubuntu 20.04:

 ![image](https://forum-defold-uploads.b-cdn.net/original/3X/d/a/da7bb21a9755bc28b97bac1c3e40fb21418ebda4.jpeg)

---

<div class="post-metadata">

**Author:** ![Pkeod](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pkeod/32/606_2.png) [@Pkeod](https://forum.defold.com/u/Pkeod)\
**Post date:** [August 1, 2023, 7:59pm UTC](https://forum.defold.com/t/defold-pbr-extension/73729/9 "2023-08-01T19:59:24Z")

</div>

Does the browser version work for you? If not can you run it in debug mode and see if anything prints in the console?

---

<div class="post-metadata">

**Author:** ![Potota](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/potota/32/33404_2.png) [@Potota](https://forum.defold.com/u/Potota)\
**Post date:** [August 1, 2023, 11:04pm UTC](https://forum.defold.com/t/defold-pbr-extension/73729/10 "2023-08-01T23:04:40Z")

</div>

> [@jhonny.goransson](#):
>
> Oh, cool! I know @AGulev had some issues but glad it works! Is it the web demo or the desktop version?

That’s a screenshot of the desktop version and it runs just as well on Firefox and Brave.

> [@jhonny.goransson](#):
>
> If it’s desktop could you try to generate a hdr env map? Should be one in the repo

Guessing you mean the `Defold PBR - Create Environment Assets` command? I tried running that on both `.hdr` files in `/assets/environment-maps` but it gives a very odd error:

```cpp
ERROR:EXT: Defold PBR - Create Environment Assets's "run" in /defold-pbr/core.editor_script failed:
ERROR:EXT: {2, {["action"] = "shell", ["command"] = {"mkdir", "-p", "assets/environment-maps/blue_photo_studio_2k"}}} needs "action" key to be "set" or "shell"
ERROR:EXT: {3, {["action"] = "shell", ["command"] = {"build/plugins/defold-pbr/plugins/pbr-utils-linux", "assets/environment-maps/blue_photo_studio_2k.hdr", "assets/environment-maps/blue_photo_studio_2k", "--generate", "irradiance", "--generate", "prefilter", "--meta-data", "--verbose"}}} needs "action" key to be "set" or "shell"
ERROR:EXT: Defold PBR - Create Environment Assets's "run" in /defold-pbr/core.editor_script failed:
ERROR:EXT: {2, {["action"] = "shell", ["command"] = {"mkdir", "-p", "assets/environment-maps/christmas_photo_studio_07_2k"}}} needs "action" key to be "set" or "shell"
ERROR:EXT: {3, {["action"] = "shell", ["command"] = {"build/plugins/defold-pbr/plugins/pbr-utils-linux", "assets/environment-maps/christmas_photo_studio_07_2k.hdr", "assets/environment-maps/christmas_photo_studio_07_2k", "--generate", "irradiance", "--generate", "prefilter", "--meta-data", "--verbose"}}} needs "action" key to be "set" or "shell"

```

However, removing `get_platform_tool_prereq_cmd()` from the returned actions fixes it and leads to the next error:

```cpp
ERROR:EXT: Defold PBR - Create Environment Assets's "run" in /defold-pbr/core.editor_script failed:
ERROR:EXT: Cannot run program "build/plugins/defold-pbr/plugins/pbr-utils-linux" (in directory "/var/home/potota/Documents/Defold/defold-pbr-master"): error=13, Permission denied

```

And after setting that program as executable it finally opens a blank “PBR Utils” window for a few seconds and everything works!

More hardware/software details if you need it:

> **Summary**
>
> ![image](https://forum-defold-uploads.b-cdn.net/original/3X/5/1/51b857242ed3ea1ea77464717ffbe7f5e6d59b5e.png)

---

<div class="post-metadata">

**Author:** ![jhonny.goransson](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/jhonny.goransson/32/3864_2.png) [@jhonny.goransson](https://forum.defold.com/u/jhonny.goransson)\
**Post date:** [August 1, 2023, 11:41pm UTC](https://forum.defold.com/t/defold-pbr-extension/73729/11 "2023-08-01T23:41:22Z")

</div>

> [@Potota](#):
>
> However, removing `get_platform_tool_prereq_cmd()` from the returned actions fixes it and leads to the next error:

Thanks for testing it out! I haven’t tested all editor scripts on all platforms, there’s probably platform dependent caveats all around that we need to cater for.. but good that you could get it to run at least! So far so good 🤞

---

<div class="post-metadata">

**Author:** ![arly](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/a/71c47a/32.png) [@arly](https://forum.defold.com/u/arly)\
**Post date:** [August 2, 2023, 1:20am UTC](https://forum.defold.com/t/defold-pbr-extension/73729/12 "2023-08-02T01:20:12Z")

</div>

Hi, congrats on the alpha release. I’ve tested the link on an Android (13) phone, with device Samsung Galaxy A03s (Samsung SM-A037F, PowerVR Rogue GE8320), using DuckDuckGo (5.164.2.zp) browser. It shows everything except the reflection.

 ![unnamed](https://forum-defold-uploads.b-cdn.net/original/3X/4/4/44b83e22d93228783504112cf8f65124e915a958.jpeg)

I hope this helps.

---

<div class="post-metadata">

**Author:** ![jhonny.goransson](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/jhonny.goransson/32/3864_2.png) [@jhonny.goransson](https://forum.defold.com/u/jhonny.goransson)\
**Post date:** [August 2, 2023, 5:26pm UTC](https://forum.defold.com/t/defold-pbr-extension/73729/13 "2023-08-02T17:26:37Z")

</div>

If anyone (@Pawel or @AGulev maybe?) could try and capture a faulty frame in renderdoc I could perhaps deduce something from that 🤔 otherwise I’d have to get my hands on Linux on a non-VM

---

<div class="post-metadata">

**Author:** ![iotaHum](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/i/977dab/32.png) [@iotaHum](https://forum.defold.com/u/iotaHum)\
**Post date:** [August 2, 2023, 10:54pm UTC](https://forum.defold.com/t/defold-pbr-extension/73729/14 "2023-08-02T22:54:53Z")

</div>

> [@jhonny.goransson](#):
>
> linux support - the extension does currently not seem to work on the linux platform

I have run defold-pbr (88101508450f1ba07ef3c19cd21f87dc329ab27d) on Ubuntu 22.04.2 LTS. Looks good to me including reflections. Runs in the editor and as a Linux bundle using between 13% and 17% CPU. No errors. I also tried debug mode, no errors, nothing looks wrong.

---

<div class="post-metadata">

**Author:** ![jhonny.goransson](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/jhonny.goransson/32/3864_2.png) [@jhonny.goransson](https://forum.defold.com/u/jhonny.goransson)\
**Post date:** [August 3, 2023, 5:53am UTC](https://forum.defold.com/t/defold-pbr-extension/73729/15 "2023-08-03T05:53:56Z")

</div>

> [@iotaHum](#):
>
> I have run defold-pbr (88101508450f1ba07ef3c19cd21f87dc329ab27d) on Ubuntu 22.04.2 LTS. Looks good to me including reflections. Runs in the editor and as a Linux bundle using between 13% and 17% CPU. No errors. I also tried debug mode, no errors, nothing looks wrong.

So I guess it’s a driver issue then 🤔 the reflection cube map is using a half float format for performance reasons and I suspect it’s the culprit but that format has been around for a while so I would be surprised if it wouldn’t work..

---

<div class="post-metadata">

**Author:** ![paulbaucom](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/paulbaucom/32/37541_2.png) [@paulbaucom](https://forum.defold.com/u/paulbaucom)\
**Post date:** [August 5, 2023, 4:58am UTC](https://forum.defold.com/t/defold-pbr-extension/73729/16 "2023-08-05T04:58:07Z")

</div>

Tested on Fedora 38 KDE with a AMD RX 6800. Fresh install. Works and looks great!

 ![image](https://forum-defold-uploads.b-cdn.net/original/3X/1/4/14877f035014b4c75505f7198f784aaceb4e2119.jpeg)

---

<div class="post-metadata">

**Author:** ![einar](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/einar/32/31951_2.png) [@einar](https://forum.defold.com/u/einar)\
**Post date:** [September 30, 2023, 2:18pm UTC](https://forum.defold.com/t/defold-pbr-extension/73729/17 "2023-09-30T14:18:54Z")

</div>

I also had to remove get\_platform\_tool\_prereq\_cmd() to make the “Create Environment Assets” script run on Windows.

And a question: Does the script mirror the cubemap sides somehow? I tried to render a normal skybox using the 6 images from the Blue Photo Studio environment, and it displayed a mirrored version of the room (I guess from rendering the inside of a cube). So I either had to mirror the images myself or by negating the sample point z value in the vertex shader.

But when I used the generated prefilter texture it was already mirrored. Also, the entire was room was rotated by one side in the prefilter texture version, putting the sofa in the front.

The reason I’m using a separate skybox is to increase the resolution of the surroundings. It’s not really a problem, but right now I compensate for the mirroring and rotation at same time by switching x and z in the sample point:

```lua
var_position = vec3(position.z, position.y, position.x);

```

---

<div class="post-metadata">

**Author:** ![einar](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/einar/32/31951_2.png) [@einar](https://forum.defold.com/u/einar)\
**Post date:** [October 4, 2023, 4:16pm UTC](https://forum.defold.com/t/defold-pbr-extension/73729/18 "2023-10-04T16:16:55Z")

</div>

I’ve run into a peculiar problem. I wanted to play around with the fragment shader to display the different stages of the rendering process, similar to the what you can do using the debug menu.

The problem is, setting frag color is not always working. For example, when I wanted to render only the diffuse lighting, I wrote this in pbr.fp:

```glsl
gl_FragColor = vec4(lightInfo.diffuse, 1);

```

It just gives me a black helmet. If I wrap this statement in an if-statement with some non compile-time condition (e.g. comparing some uniform variable) it shows the diffuse component correctly.

```glsl
if (var_position_world.x > -100) gl_FragColor = vec4(lightInfo.diffuse, 1); //Works
if (true) gl_FragColor = vec4(lightInfo.diffuse, 1); //Doesn't work
gl_FragColor = vec4(lightInfo.diffuse, 1); //Doesn't work

```

Is there anything I’m missing when it comes to GLSL here? I can’t reproduce this in the starter 3D project, but there the model.fp doesn’t include any other GLSL code.

---

<div class="post-metadata">

**Author:** ![jhonny.goransson](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/jhonny.goransson/32/3864_2.png) [@jhonny.goransson](https://forum.defold.com/u/jhonny.goransson)\
**Post date:** [October 4, 2023, 6:22pm UTC](https://forum.defold.com/t/defold-pbr-extension/73729/19 "2023-10-04T18:22:44Z")

</div>

Yes that’s a side effect of our renderer binding textures to numerical units in OpenGL and not by sampler name (which is what we ultimately would like, but that’s another story) together with shader optimization the driver does. So in a sense we expect the order of the units to be bound in a certain way, and if you start removing stuff from the shader the order can be different and the texture can potentially be bound to the wrong samplers.

---

<div class="post-metadata">

**Author:** ![einar](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/einar/32/31951_2.png) [@einar](https://forum.defold.com/u/einar)\
**Post date:** [October 4, 2023, 9:59pm UTC](https://forum.defold.com/t/defold-pbr-extension/73729/20 "2023-10-04T21:59:50Z")

</div>

I see. If I understand it correctly, it also explains why I had to output both the diffuse and specular part first to make my hack work – to trick the optimizer not to optimize. What’s the best approach to make sure the textures aren’t bound to the wrong samplers then? Is it to write the fragment shader in such a way that it certainly uses all the samplers from the input?

I should probably try to write some shaders from scratch myself first I realize now. 😅 Thanks for the help!

[Next page](https://forum.defold.com/t/defold-pbr-extension/73729.md?page=2)
