完成mvp矩阵和shader
This commit is contained in:
@@ -5,23 +5,17 @@ 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 中的对应部分
|
||||
mat4 proj;
|
||||
mat4 model;
|
||||
mat4 view;
|
||||
} 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);
|
||||
// 预计算MVP矩阵以减少乘法次数
|
||||
mat4 mvp = ubo.proj * ubo.view * ubo.model;
|
||||
//vec3 pos = vec3(2.0, inPosition.y, inPosition.z);
|
||||
gl_Position = mvp * vec4(inPosition, 1.0);
|
||||
fragColor = inColor;
|
||||
gl_PointSize = 2.0;
|
||||
}
|
||||
Binary file not shown.
Reference in New Issue
Block a user