# PBR fully ported to WebGPU / WGSL

**URL:** <https://forum.babylonjs.com/t/pbr-fully-ported-to-webgpu-wgsl/52350>\
**Category:** Announcements\
**Created:** [July 26, 2024, 6:32pm UTC](https://forum.babylonjs.com/t/pbr-fully-ported-to-webgpu-wgsl/52350 "2024-07-26T18:32:25Z")\
**Posts on this page:** 18\
**Page:** 1

<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 26, 2024, 6:32pm UTC](https://forum.babylonjs.com/t/pbr-fully-ported-to-webgpu-wgsl/52350/1 "2024-07-26T18:32:25Z")

</div>

Hey team! I need your help:)

I’ve ported the full PBR shader (yeah the big monster) to WGSL 😉

This was quite of a massive work. I also included port of nme to wgsl!

If you have time and you are currently targetting webgpu for your apps/games, can you please take that branch and test if everything work?

[Port PBR material to WGSL by deltakosh · Pull Request #15333 · BabylonJS/Babylon.js (github.com)](https://github.com/BabylonJS/Babylon.js/pull/15333)

By default the PBR materials will go to the wgsl code path. (you can still turn that off with a parameter in the material constructor)

Thanks for the help!!

---

<div class="post-metadata">

**Author:** ![CrashMaster](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/crashmaster/32/23662_2.png) [@CrashMaster](https://forum.babylonjs.com/u/CrashMaster)\
**Post date:** [July 27, 2024, 7:13pm UTC](https://forum.babylonjs.com/t/pbr-fully-ported-to-webgpu-wgsl/52350/2 "2024-07-27T19:13:16Z")

</div>

Awesome! Does this mean that material plugins will support wgsl as well?

---

<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 29, 2024, 4:56pm UTC](https://forum.babylonjs.com/t/pbr-fully-ported-to-webgpu-wgsl/52350/3 "2024-07-29T16:56:50Z")

</div>

to be fair, I believe material plugin should work directly (as long as you provide wgsl and not glsl)

---

<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 29, 2024, 10:09pm UTC](https://forum.babylonjs.com/t/pbr-fully-ported-to-webgpu-wgsl/52350/4 "2024-07-29T22:09:10Z")

</div>

cc @roland: For now I’m forcing the PBR material of the GreasedLines to be GLSL only:  
[Port PBR and Background materials to WGSL by deltakosh · Pull Request #15333 · BabylonJS/Babylon.js (github.com)](https://github.com/BabylonJS/Babylon.js/pull/15333/commits/4446187f25d07463d7ccf47a8083f35495facafe)

This will need you to also port your shaders to pure wgsl to support both (later :))

---

<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 29, 2024, 10:50pm UTC](https://forum.babylonjs.com/t/pbr-fully-ported-to-webgpu-wgsl/52350/5 "2024-07-29T22:50:36Z")

</div>

Yep, will do it!

---

<div class="post-metadata">

**Author:** ![pjoe](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pjoe/32/1906_2.png) [@pjoe](https://forum.babylonjs.com/u/pjoe)\
**Post date:** [August 1, 2024, 8:59am UTC](https://forum.babylonjs.com/t/pbr-fully-ported-to-webgpu-wgsl/52350/6 "2024-08-01T08:59:51Z")

</div>

FWIW: looks to be working well:

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

(Had a .glb lying around from playing with Halo MCC model export)

---

<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:** [August 1, 2024, 3:47pm UTC](https://forum.babylonjs.com/t/pbr-fully-ported-to-webgpu-wgsl/52350/7 "2024-08-01T15:47:26Z")

</div>

Thanks for testing it!!!

---

<div class="post-metadata">

**Author:** ![pjoe](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pjoe/32/1906_2.png) [@pjoe](https://forum.babylonjs.com/u/pjoe)\
**Post date:** [August 2, 2024, 4:45pm UTC](https://forum.babylonjs.com/t/pbr-fully-ported-to-webgpu-wgsl/52350/8 "2024-08-02T16:45:28Z")

</div>

Btw. I had a [wasm version of naga](https://github.com/pjoe/wasm-naga) (wgpu shader transpiler) some way back. Lemme know if that would be useful.

You can see it sort of working here: [https://wasm-shaders.pjohnsen.com/](https://wasm-shaders.pjohnsen.com/)

---

<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:** [August 2, 2024, 4:49pm UTC](https://forum.babylonjs.com/t/pbr-fully-ported-to-webgpu-wgsl/52350/9 "2024-08-02T16:49:14Z")

</div>

Yeah unfortunately (or fortunately depending on how you think about it), I’m doing the conversion manually to ensure max perf

---

<div class="post-metadata">

**Author:** ![aWeirdo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/aweirdo/32/52_2.png) [@aWeirdo](https://forum.babylonjs.com/u/aWeirdo)\
**Post date:** [August 4, 2024, 6:00am UTC](https://forum.babylonjs.com/t/pbr-fully-ported-to-webgpu-wgsl/52350/10 "2024-08-04T06:00:21Z")

</div>

I think this one messed up the PBRCustomMaterial 🤔 🙁

> Cannot read properties of undefined (reading ‘replace’)

> **[Babylon.js Playground](https://playground.babylonjs.com/#UEN6QY%2344)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

---

<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:** [August 5, 2024, 9:37am UTC](https://forum.babylonjs.com/t/pbr-fully-ported-to-webgpu-wgsl/52350/11 "2024-08-05T09:37:56Z")

</div>

I can not seem to repro with your playground @aWeirdo

---

<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:** [August 5, 2024, 4:36pm UTC](https://forum.babylonjs.com/t/pbr-fully-ported-to-webgpu-wgsl/52350/12 "2024-08-05T16:36:08Z")

</div>

No repro too ;(

---

<div class="post-metadata">

**Author:** ![pjoe](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pjoe/32/1906_2.png) [@pjoe](https://forum.babylonjs.com/u/pjoe)\
**Post date:** [August 5, 2024, 7:06pm UTC](https://forum.babylonjs.com/t/pbr-fully-ported-to-webgpu-wgsl/52350/13 "2024-08-05T19:06:52Z")

</div>

Hmm just tried the GI samples in 7.19, they are giving WGSL errors, maybe from this?

> **[Babylon.js Playground](https://playground.babylonjs.com/#VW8IG3%2382)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

Here is the error I see (Chrome, Windows):

```auto
Error while parsing WGSL: :232:1 error: invalid character found
#extension GL_EXT_draw_buffers : require
^

 - While validating [ShaderModuleDescriptor "fragment"]
 - While calling [Device "BabylonWebGPUDevice0"].CreateShaderModule([ShaderModuleDescriptor "fragment"]).

```

---

<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:** [August 5, 2024, 8:17pm UTC](https://forum.babylonjs.com/t/pbr-fully-ported-to-webgpu-wgsl/52350/14 "2024-08-05T20:17:21Z")

</div>

Whilst @Deltakosh is on a path to migrate it all, there are still material plugins not migrated which currently breaks in your playground.

You can workaround it by forcing GLSL in the playground [https://playground.babylonjs.com/#VW8IG3#84](https://playground.babylonjs.com/#VW8IG3#84)

Sorry for the inconvenient.

---

<div class="post-metadata">

**Author:** ![aWeirdo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/aweirdo/32/52_2.png) [@aWeirdo](https://forum.babylonjs.com/u/aWeirdo)\
**Post date:** [August 5, 2024, 11:37pm UTC](https://forum.babylonjs.com/t/pbr-fully-ported-to-webgpu-wgsl/52350/15 "2024-08-05T23:37:33Z")

</div>

@sebavan & @Deltakosh  
As of 7.19.0 i can’t repro either, must have been fixed already 😄 👍

---

<div class="post-metadata">

**Author:** ![pjoe](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pjoe/32/1906_2.png) [@pjoe](https://forum.babylonjs.com/u/pjoe)\
**Post date:** [August 6, 2024, 2:38pm UTC](https://forum.babylonjs.com/t/pbr-fully-ported-to-webgpu-wgsl/52350/16 "2024-08-06T14:38:46Z")

</div>

The GI one still fails for me when using WebGPU/WGSL on 7.19.1

NOTE: @sebavan’s version forces using GLSL on WebGPU

Here is a version with `ForceGLSL=false`: [https://playground.babylonjs.com/#VW8IG3#85](https://playground.babylonjs.com/#VW8IG3#85)

---

<div class="post-metadata">

**Author:** ![Baktrian](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/baktrian/32/29646_2.png) [@Baktrian](https://forum.babylonjs.com/u/Baktrian)\
**Post date:** [August 6, 2024, 3:30pm UTC](https://forum.babylonjs.com/t/pbr-fully-ported-to-webgpu-wgsl/52350/17 "2024-08-06T15:30:37Z")

</div>

Phenomenal! 👏 👏

---

<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:** [August 6, 2024, 3:46pm UTC](https://forum.babylonjs.com/t/pbr-fully-ported-to-webgpu-wgsl/52350/18 "2024-08-06T15:46:03Z")

</div>

It must use the flag because the GI code is generating GLSL so it must be compiled
