From 21b061b951ec3a65bc479fabeb2d9565e08a807e Mon Sep 17 00:00:00 2001 From: skal Date: Sun, 8 Mar 2026 10:38:19 +0100 Subject: fix: transpose matrices on GPU upload (row-major → column-major) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit mini_math mat4 is row-major; WGSL mat4x4f is column-major. Matrices uploaded without transposing were interpreted as their own transpose on the GPU, causing RotatingCube and Renderer3D to render upside-down. - Add gpu_upload_mat4() to post_process_helper for standalone uploads - Add Uniforms::make() to RotatingCube::Uniforms (handles transpose) - Add GlobalUniforms::make() and ObjectData::make() to renderer.h - Update renderer_draw.cc and visual_debug.cc to use make() handoff(Gemini): matrix layout bug fixed across all rasterized effects. Co-Authored-By: Claude Sonnet 4.6 --- src/effects/rotating_cube_effect.cc | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'src/effects/rotating_cube_effect.cc') diff --git a/src/effects/rotating_cube_effect.cc b/src/effects/rotating_cube_effect.cc index 099d06c..757d64c 100644 --- a/src/effects/rotating_cube_effect.cc +++ b/src/effects/rotating_cube_effect.cc @@ -5,6 +5,7 @@ #include "effects/shaders.h" #include "gpu/bind_group_builder.h" #include "gpu/gpu.h" +#include "gpu/post_process_helper.h" #include "util/fatal_error.h" RotatingCube::RotatingCube(const GpuContext& ctx, @@ -137,15 +138,10 @@ void RotatingCube::render(WGPUCommandEncoder encoder, const mat4 model = T * R * S; // Update uniforms - const Uniforms uniforms = { - .view_proj = view_proj, - .inv_view_proj = view_proj.inverse(), - .camera_pos_time = - vec4(camera_pos.x, camera_pos.y, camera_pos.z, params.time), - .params = vec4(1.0f, 0.0f, 0.0f, 0.0f), - .resolution = params.resolution, - .aspect_ratio = params.aspect_ratio, - }; + const Uniforms uniforms = Uniforms::make( + view_proj, + vec4(camera_pos.x, camera_pos.y, camera_pos.z, params.time), + vec4(1.0f, 0.0f, 0.0f, 0.0f), params.resolution, params.aspect_ratio); const ObjectData obj_data = { .model = model, -- cgit v1.2.3