when i use UniformBuffer .addUniform,i find when i addUniform(‘a1’,1),addUniform(‘a2’,2),addUniform(‘a3’,1) ,and i console the uniform buffer the data will get five data , you can see this Babylon.js Playground
i think the four data are just aligned
Member with size 1 is added. The uniform buffer pointer is now at offset 1, which is a multiple of 1, so no padding is added.
Member with size 2 is added. The uniform buffer pointer is now at 3, which is not a multiple of 2, so we pad to the nearest multiple, which is 4. Resulting in one 0 being added.
Member with size 1 is added. The uniform buffer pointer is now at 5, which is a multiple of 1, so again, no need of padding.
In the 1, 1, 2 case, we have:
Member with size 1 is added. The uniform buffer pointer is now at offset 1, which is a multiple of 1, so no padding is added.
Member with size 1 is added. The uniform buffer pointer is now at offset 2, which is a multiple of 1, so no padding is added.
Member with size 2 is added. The uniform buffer pointer is now at offset 4, which is a multiple of 2, so no padding is added.
That’s why one case has extra padding while the other doesn’t