# Minimal WebGPU ShaderMaterial

**URL:** <https://forum.babylonjs.com/t/minimal-webgpu-shadermaterial/45496>\
**Category:** Questions\
**Created:** [November 6, 2023, 5:29pm UTC](https://forum.babylonjs.com/t/minimal-webgpu-shadermaterial/45496 "2023-11-06T17:29:49Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![axeljaeger](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/axeljaeger/32/21445_2.png) [@axeljaeger](https://forum.babylonjs.com/u/axeljaeger)\
**Post date:** [November 6, 2023, 5:29pm UTC](https://forum.babylonjs.com/t/minimal-webgpu-shadermaterial/45496/1 "2023-11-06T17:29:49Z")

</div>

Hello,  
I am taking my first steps towards WebGPU and try to make the most minimalistic Shader Material. As I have no clue what to do, I googled minimal WebGPU shader, found this example online: [Hello Triangle - WebGPU Samples](https://webgpu.github.io/webgpu-samples/samples/helloTriangle#../../shaders/triangle.vert.wgsl) and tried to hook it up to babylon:

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

I get a shader compilation error basically on the first character of the source. In the original example, there is another ‘decorator’ on the first line, saying `@vertex` and `@fragment` respectively but it does not help either.

Can someone point me into the right direction or has another minimal WebGPU example at hand?

Best regards,  
Axel

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [November 6, 2023, 6:31pm UTC](https://forum.babylonjs.com/t/minimal-webgpu-shadermaterial/45496/2 "2023-11-06T18:31:40Z")

</div>

Hi! This page might be helpful 🙂 [Writing shaders for WebGPU in WGSL | Babylon.js Documentation (babylonjs.com)](https://doc.babylonjs.com/setup/support/webGPU/webGPUWGSL)

---

<div class="post-metadata">

**Author:** ![axeljaeger](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/axeljaeger/32/21445_2.png) [@axeljaeger](https://forum.babylonjs.com/u/axeljaeger)\
**Post date:** [November 7, 2023, 7:50pm UTC](https://forum.babylonjs.com/t/minimal-webgpu-shadermaterial/45496/3 "2023-11-07T19:50:17Z")

</div>

Hi Carolhmj,  
Thanks for the link. I went a bit further by:

1. Setting the correct Shading Language as pointed out in the link.
2. Adding again `@vertex` and `@fragment` to the shaders.  
[https://playground.babylonjs.com/#D7UL8N#1](https://playground.babylonjs.com/#D7UL8N#1)

Now I get a bunch of warnings that I do not understand:

```auto
  vertexInputs = input; // error: unresolved identifier 'input'

```

as well as

```auto
error: unresolved identifier 'input'
fn main() -> @location(0) vec4<f32> { fragmentInputs = input;

```

I cannot find either either of the pieces in my code so I assume there is some pre-processing going on that I do not know about yet.

---

<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:** [November 7, 2023, 8:33pm UTC](https://forum.babylonjs.com/t/minimal-webgpu-shadermaterial/45496/4 "2023-11-07T20:33:48Z")

</div>

Assigned @Evgeni\_Popov on November 7, 2023, 8:33pm UTC



---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [November 7, 2023, 8:57pm UTC](https://forum.babylonjs.com/t/minimal-webgpu-shadermaterial/45496/5 "2023-11-07T20:57:09Z")

</div>

You can’t simply copy/paste existing wgsl code, you have to modify a number of things to make it compatible with Babylon WebGPU sub-system.

Everything is described in the link given by @carolhmj, and this PG should clear things up:

> **[Babylon.js Playground](https://playground.babylonjs.com/?webgpu#6GFJNR%23178)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

Let us know if something is still not clear.

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [November 12, 2023, 12:34pm UTC](https://forum.babylonjs.com/t/minimal-webgpu-shadermaterial/45496/6 "2023-11-12T12:34:36Z")

</div>

Unassigned @Evgeni\_Popov on November 12, 2023, 12:34pm UTC



---

<div class="post-metadata">

**Author:** ![axeljaeger](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/axeljaeger/32/21445_2.png) [@axeljaeger](https://forum.babylonjs.com/u/axeljaeger)\
**Post date:** [November 22, 2023, 9:59am UTC](https://forum.babylonjs.com/t/minimal-webgpu-shadermaterial/45496/7 "2023-11-22T09:59:01Z")

</div>

Hi all,  
thank you all for the replies. With @Evgeni_Popov 's playground, I should have everything to figure out everything myself. Yes, I was expecting that it would not work just copy&pasting code, but coming from a WebGL background and now seeing the difference between the minimal code that works outside babylon and what I need in order to get it working, I am a but surprised TBH. But this is just an issue for the first time and I will get used to it pretty quickly. I’ll report back once I got it working.

Thanks again everyone for the help and wish you all the best.

Axel
