Im writing in shader:
struct Particle
{
vec3 position;
vec3 velocity;
};
layout(std430, binding = 0) buffer NumsBuffer {
Particle particles[];
};
But the data obtained from the shader is not correct. I know that SSBO does not work well with vec3, but how to fix this error without switching to vec4 or float[3]?
Switch to vec4
. The structure will be 32 bytes (8 words) whether you use vec3
or vec4
, but if you use vec4
you can use the same structure in both GLSL and C++.
If you want the structure to be tightly packed, you’ll have to use float[3]
and assign each member individually. Vectors cannot straddle 4-word boundaries. First-generation programmable GPUs essentially used vec4
internally for everything, and GLSL was designed around that.
1 Like