Firstly, everything works fine when I pass one lightPos
struct UniformBufferObject {
alignas(16) glm::mat4 model;
alignas(16) glm::mat4 view;
alignas(16) glm::mat4 proj;
alignas(16) glm::vec3 lightColor;
alignas(16) glm::vec3 viewPos;
alignas(16) glm::vec3 lightPos;
};
but when I change the lightPos to array
struct UniformBufferObject {
alignas(16) glm::mat4 model;
alignas(16) glm::mat4 view;
alignas(16) glm::mat4 proj;
alignas(16) glm::vec3 lightColor;
alignas(16) glm::vec3 viewPos;
alignas(32) glm::vec3 lightPos[2];
};
I think I meet some alignment issue. I pass the same value to lightPos0 and lightPos1, but the values I get in frag shader are strange
glm::vec3 defaultLightPos1 = {0.0f, 0.0f, 1.0f};
UniformBufferObject ubo{};
ubo.lightPos[0] = defaultLightPos1;
ubo.lightPos[1] = defaultLightPos1;
//frag shader
layout(binding = 0) uniform UniformBufferObject {
mat4 model;
mat4 view;
mat4 proj;
vec3 lightColor;
vec3 viewPos;
vec3 lightPos[2];
} ubo;
void main() {
outColor = vec4(ubo.lightPos[0/1], 1.0);
}
when the
outColor = vec4(ubo.lightPos[0], 1.0);
I get
when the
outColor = vec4(ubo.lightPos[1], 1.0);
I get
the result don't change when I change the
alignas(32) glm::vec3 lightPos[2]
to
alignas(16) glm::vec3 lightPos[2]