Send view and project matrices in push constant

This commit is contained in:
Camden Dixie O'Brien committed 2025-10-03 23:42:54 +01:00
1 parent f3aa7435ec
commit ea82627695
4 files changed
+67 -59

No files matched your search

+24 -28
View File
@@ -62,32 +62,28 @@ int main(int argc, char *argv[])
const vec3_t cam = { 0, 4, -4 };
const vec3_t tgt = { 0, 0.5, 0 };
mvp_t mvp1 = {
.model = mat4_mul(
MAT4_TRANSLATE(1, 0, 0),
(mat4_t) {
{ 0, 0, -1, 0 },
{ -1, 0, 0, 0 },
{ 0, 1, 0, 0 },
{ 0, 0, 0, 1 },
}),
.view = mat4_lookat(cam, tgt, (vec3_t) { 0, 1, 0 }),
.proj = mat4_perspective((float)W / H, PI / 8, 0.1, 10.0),
};
mvp_t mvp2 = {
.model = mat4_mul(
MAT4_TRANSLATE(2, 0, 0),
mat4_mul(
MAT4_ROTATE_Y(PI),
(mat4_t) {
{ 0, 0, -1, 0 },
{ -1, 0, 0, 0 },
{ 0, 1, 0, 0 },
{ 0, 0, 0, 1 },
})),
const vp_t vp = {
.view = mat4_lookat(cam, tgt, (vec3_t) { 0, 1, 0 }),
.proj = mat4_perspective((float)W / H, PI / 8, 0.1, 10.0),
};
mat4_t transform1 = mat4_mul(
MAT4_TRANSLATE(1, 0, 0),
(mat4_t) {
{ 0, 0, -1, 0 },
{ -1, 0, 0, 0 },
{ 0, 1, 0, 0 },
{ 0, 0, 0, 1 },
});
mat4_t transform2 = mat4_mul(
MAT4_TRANSLATE(2, 0, 0),
mat4_mul(
MAT4_ROTATE_Y(PI),
(mat4_t) {
{ 0, 0, -1, 0 },
{ -1, 0, 0, 0 },
{ 0, 1, 0, 0 },
{ 0, 0, 0, 1 },
}));
const mat4_t rot1 = MAT4_ROTATE_Y(PI / 170);
const mat4_t rot2 = MAT4_ROTATE_Y(-PI / 340);
@@ -96,13 +92,13 @@ int main(int argc, char *argv[])
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
mvp1.model = mat4_mul(rot1, mvp1.model);
mvp2.model = mat4_mul(rot2, mvp2.model);
transform1 = mat4_mul(rot1, transform1);
transform2 = mat4_mul(rot2, transform2);
animation_update(&anim, &model, DT);
gpu_render_begin(&gpu);
gpu_render_model(&gpu, &gpu_model1, &mvp1, anim.bone_matrices);
gpu_render_model(&gpu, &gpu_model2, &mvp2, anim.bone_matrices);
gpu_render_begin(&gpu, vp);
gpu_render_model(&gpu, &gpu_model1, anim.bone_matrices, transform1);
gpu_render_model(&gpu, &gpu_model2, anim.bone_matrices, transform2);
gpu_render_submit(&gpu);
}