GreasedLine webGPU support

Right now at Frame we have an Asset type that uses the grease line material, but when that tries to spawn we get this error:

Uncaught (in promise) The plugin "GreasedLinePluginMaterial" can't be added to the material "doodleMat.doodler1732047173675" because the plugin is not compatible with the shader language of the material

Is there some Boolean I need to flip or is there just generally no support for wgsl grease lines right now?

Looks like they do not exist in wgsl so far, maybe @roland ?

Hey guys! I already started to port the shaders to WGSL but Iā€™m pretty overwhelmed with my daily tasks so please be a bit patient :wink:

2 Likes

no rush and thanks a lot for the heads up

1 Like

itā€™s getting closeā€¦ :wink:

BETA, but you can guys track the progress. Iā€™ll make the code cleaner (+ dynamic imports of shader code, etc.) after everything will work.

Here is the list of passed tests:

1 Like

Guys I had a ā€œfreeā€ weekend so I was able to port almost every feature of GreasedLine into WGSL.

However Iā€™m figthing an interesting issue:

The lines are rendered correctly initially. When I start to rotate the camera the lines starts to jitter. I couldnā€™t solve this issue yet, I checked the shader code multiple times. Maybe Iā€™ve missed something so Iā€™ll go trough it again and again :wink:

Iā€™m using scene.viewProjection in the WGSL shader. Is this correct?:
[Grl webgpu by RolandCsibrei Ā· Pull Request #15917 Ā· BabylonJS/Babylon.js Ā· GitHub]
@Evgeni_Popov Thanks!

EDIT:
If I set the viewProjection in my code the jittering disappears and everything runs smoothly:
Material:
uniformBuffer.updateMatrix("viewProjection", this._scene.getTransformMatrix());

Shader:
let grlMatrix: mat4x4f = uniforms.viewProjection * finalWorld;

Shouldnā€™t the framework set the value of viewProjection in the same way?

@sebavan @Deltakosh @Evgeni_Popov

Uniform buffers (scene, mesh, material) are automatically used by the standard/PBR materials, but not by shader materials. You have to declare them explicitely if you use them in shader materials (through the uniformBuffers option parameter). However, if your code is part of a plugin material, I think scene.viewProjection should work => let me know if you are in this case and I will have a look.

1 Like

Yes, thatā€™s exactly the case.

But Iā€™ve recently pushed new code which uses this approach:

If I set the viewProjection in my code the jittering disappears and everything runs smoothly:
Material:
uniformBuffer.updateMatrix("viewProjection", this._scene.getTransformMatrix());

Shader:
let grlMatrix: mat4x4f = uniforms.viewProjection * finalWorld;

Do you want me to push the previous version which uses scene.viewProjection in the shader?

I just tested locally the PG you linked above, but with your previous code (so, I removed lines 265-271 in greasedLinePluginMaterial.ts and used scene.viewProjection instead of uniforms.viewProjection in the WGSL code), and it does work for me, I donā€™t have any jittering, the PG behaves in WebGPU as in WebGL. Can you re-test on your side/rollback to the old code in your PR?

1 Like

Maybe itā€™s a MacOS issue? Iā€™ll test it on a Windows device.

Meanwhile check out the screen capture from my Mac:
https://babylonjs.xyz/grl-jittering.mkv

thanks!

I confirm I donā€™t have any problems with the current code of the PR using the test link of the CI ( Babylon.js Playground) and testing the changes locally.

So, it must be a problem on MacOS. Do you use Safari or Chrome on your Mac?

1 Like

Chrome - jitters
Firefox - ok
Safari - ok

There seems to be a specific problem in Chrome, as the 3 browsers have 3 different WebGPU implementationsā€¦ To solve this problem, I think you should go back to using a uniform, but we should probably revisit this case later.

1 Like

PR ready to review :sunglasses:

CC: @Deltakosh

I created a PR for GRL SimpleMaterial.

The journey to port GRL to WGSL ends here :sunglasses:

1 Like

@RaananW Hello! Could you help me to understand and to get rid of this error please?

https://dev.azure.com/babylonjs/ContinousIntegration/_build/results?buildId=35532&view=logs&j=275f1d19-1bd8-5591-b06b-07d489ea915a&t=96b37e98-490b-5755-db43-568ff4a0ab3b

Thanks!

Of course!

The shaders need to be exported from an index.ts file as well, so that the UMD will include them in the main chunk.

Look at the other shaders and where they are exported, and add your shaders there

Oh, sure, thanks!

Is it ok to put the index.ts here?

Sure! I would assume the other files would be here as well? in what index.ts are they exported?