playcanvas / engine

JavaScript game engine built on WebGL, WebGPU, WebXR and glTF
https://playcanvas.com
MIT License
9.57k stars 1.34k forks source link

Implement support for Uniform Buffers #4261

Open mvaligursky opened 2 years ago

mvaligursky commented 2 years ago

Uniform Buffer Objects let you specify a bunch of uniforms from a buffer. The advantages are:

Also, WebGPU allows uniforms to only be set using uniform buffers.

Basic design: UniformBufferFormat - describes the content of the buffer (similar to VertexFormat) - list of uniforms and their types and so on. UniformBuffer - an actual buffer, storing uniforms in a format described by UniformBufferFormat

WebGPU specifically has API that connects multiple uniform buffers as well as other buffer objects (textures) into a binding, and all of those can be set on a device (assigned to a bind slot) by a single call. The engine will support this as a way of setting up textures and uniform buffers as well. Design: BindGroupFormat - describes the format as an array of uniform buffers / textures. BindGroup - an actual instance of the BindGroupFormat, attaching actual uniform buffers and textures into the bind group. This can then be set on device using a single call.

In general, the engine will use 3 sets of BindGroups:

willeastcott commented 1 year ago

I notice we have UniformBuffer class in the engine now. Can this be closed yet?

mvaligursky commented 1 year ago

Not yet I think. We have Uniform Buffers, but their integration is limited to Scene and Mesh Uniform Buffers, and we still need to implement Material Uniform buffers.

Additionally, this is only WebGPU implementation, and we need WebGL2 implementation using Uniform Buffer Objects.

We could spin up separate tickets for this, but at the moment this covers all this work.

MatthewDZane commented 5 days ago

Webgl2 Uniform Buffer Objects support would be great!!