#version 450 layout(location = 0) in vec3 inPosition; layout(location = 1) in vec3 inColor; layout(location = 0) out vec3 fragColor; // --- 修改:匹配 ubo_vs 的内存布局 --- // ubo_vs 在 C++ 中的布局是 projection(0), model(64), view_pos(128), lod_bias(144) // 我们只需要 projection 和 model layout(binding = 0) uniform UniformBufferObject { mat4 proj; // 对应 ubo_vs.projection (偏移 0) mat4 model; // 对应 ubo_vs.model (偏移 64) // view_pos 和 lod_bias 在内存中,但这里不声明,着色器不会直接访问它们 // 重要的是 proj 和 model 的位置和大小必须匹配 ubo_vs 中的对应部分 } ubo; // --- 修改结束 --- void main() { // 注意:通常 MVP 是 Model * View * Projection // 但您的 ubo_vs.model 似乎已经包含了 View 变换 (ubo_vs.model = view_matrix * ...) // 所以这里直接使用 ubo.model 和 ubo.proj // 如果渲染结果不正确,请检查 ubo_vs.model 的构成 gl_Position = ubo.proj * ubo.model * vec4(inPosition, 1.0); fragColor = inColor; gl_PointSize = 5.0; }