Whats the proper way to update a uniform for each mesh? #3244
-
At the moment if I want to draw two different meshes that have two different vertex shader and index shaders I have to create an independent Thanks in advance. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You can create two or more uniform buffers — one for each set of uniform values you want to use during that frame. You will also need a bind group for each buffer. There are other options too, like storing arrays of values in a single buffer, which can then be indexed using attributes in the mesh data, or the instance number. Which one is best depends on exactly what you're drawing. The way to think about the problem in general is: there should be places somewhere in your buffers (and textures) for all the data you need for one frame, all at the same time, so that the order of operations can be thought of as “write, write, draw, draw” rather than “write, draw, write, draw”. There are various ways you could organize the data, but all the data should be conceptually present simultaneously. |
Beta Was this translation helpful? Give feedback.
You can create two or more uniform buffers — one for each set of uniform values you want to use during that frame. You will also need a bind group for each buffer.
There are other options too, like storing arrays of values in a single buffer, which can then be indexed using attributes in the mesh data, or the instance number. Which one is best depends on exactly what you're drawing.
The way to think about the problem in general is: there should be places somewhere in your buffers (and textures) for all the data you need for one frame, all at the same time, so that the order of operations can be thought of as “write, write, draw, draw” rather than “write, draw, write, draw”. There are vari…