完成mvp矩阵和shader

This commit is contained in:
xsl
2025-09-20 21:48:43 +08:00
parent 1b201b8831
commit 4e7ef7ed93
2 changed files with 7 additions and 13 deletions
+7 -13
View File
@@ -5,23 +5,17 @@ layout(location = 1) in vec3 inColor;
layout(location = 0) out vec3 fragColor; 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 { layout(binding = 0) uniform UniformBufferObject {
mat4 proj; // 对应 ubo_vs.projection (偏移 0) mat4 proj;
mat4 model; // 对应 ubo_vs.model (偏移 64) mat4 model;
// view_pos 和 lod_bias 在内存中,但这里不声明,着色器不会直接访问它们 mat4 view;
// 重要的是 proj 和 model 的位置和大小必须匹配 ubo_vs 中的对应部分
} ubo; } ubo;
// --- 修改结束 ---
void main() { void main() {
// 注意:通常 MVP 是 Model * View * Projection // 预计算MVP矩阵以减少乘法次数
// 但您的 ubo_vs.model 似乎已经包含了 View 变换 (ubo_vs.model = view_matrix * ...) mat4 mvp = ubo.proj * ubo.view * ubo.model;
// 所以这里直接使用 ubo.model 和 ubo.proj //vec3 pos = vec3(2.0, inPosition.y, inPosition.z);
// 如果渲染结果不正确,请检查 ubo_vs.model 的构成 gl_Position = mvp * vec4(inPosition, 1.0);
gl_Position = ubo.proj * ubo.model * vec4(inPosition, 1.0);
fragColor = inColor; fragColor = inColor;
gl_PointSize = 2.0; gl_PointSize = 2.0;
} }
Binary file not shown.