refactor: remove the legacy full view_proj (CPU cull now relative-to-eye)

The GPU draws exclusively via the rotation-only `view_rot` + eye double-
single; the full view-projection survived only to project AABBs in the
CPU frustum-cull / scissor / LOD passes. Migrate those to the same
relative-to-eye math (project `point - eye` through `view_rot`) — pixel-
equivalent but precise at UTM scale — then drop the dead uniform:

- pipeline cull/scissor/LOD helpers take (view_rot, eye) instead of the
  full view_proj; render.rs reconstructs eye from the uniform's
  eye_high/eye_low and passes the cropped view_rot.
- Remove the `view_proj` field from the shared Uniforms struct and all six
  shader structs that only declared it for layout (none read it), and
  delete Camera::view_proj(). The struct shrinks by one mat4 on both
  sides, keeping the Rust / WGSL layouts in lock-step.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Hakan SevenandClaude Opus 4.8 committed 2026-06-24 20:14:41 +03:00
1 parent 5a8ec35f4f
commit 04c93df2c4
10 files changed
+57 -80

No files matched your search

-22
View File
@@ -91,28 +91,6 @@ impl Camera {
// ── Projection matrices ────────────────────────────────────────────────
pub fn view_proj(&self, bounds: Rectangle) -> Mat4 {
let aspect = bounds.width / bounds.height;
// Up vector: use the rotation to find which world direction is "up"
// in the current camera frame.
let up_dir = self.rotation * Vec3::Y;
let view = Mat4::look_at_rh(self.eye(), self.target.as_vec3(), up_dir);
let proj = match self.projection {
Projection::Perspective => {
Mat4::perspective_rh(self.fov_y, aspect, self.distance * 0.001, self.distance * 1000.0)
}
Projection::Orthographic => {
let h = self.ortho_size();
let w = h * aspect;
let (near, far) = self.ortho_depth_range();
Mat4::orthographic_rh(-w, w, -h, h, near, far)
}
};
OPENGL_TO_WGPU * proj * view
}
/// Orthographic near/far that CENTRE the target plane at ndc-z ≈ 0.5.
///
/// The draw-order depth bias shifts clip-z by ±`DRAW_ORDER_BIAS` (0.001).
+15 -10
View File
@@ -305,13 +305,20 @@ impl shader::Primitive for Primitive {
// refreshed every frame it's present, so a drag never re-uploads
// the resident base wire buffer.
inner.upload_preview_wires(device, &vp.preview_wires[..], &vp.draw_depths);
let vproj = vp.uniforms.view_proj;
inner.compute_wire_scissors(vproj, clip_size.width, clip_size.height);
inner.compute_wipeout_scissors(vproj, clip_size.width, clip_size.height);
inner.compute_image_scissors(vproj, clip_size.width, clip_size.height);
inner.compute_hatch_lod(queue, vproj, clip_size.width, clip_size.height);
inner.compute_wipeout_lod(vproj, clip_size.width, clip_size.height);
inner.compute_mesh_lod(vproj, clip_size.width, clip_size.height);
// Cull / scissor / LOD project AABBs relative-to-eye (matching the
// GPU's RTE path) so the math stays precise at UTM-scale coords.
let view_rot = vp.uniforms.view_rot;
let eye = glam::DVec3::new(
vp.uniforms.eye_high[0] as f64 + vp.uniforms.eye_low[0] as f64,
vp.uniforms.eye_high[1] as f64 + vp.uniforms.eye_low[1] as f64,
vp.uniforms.eye_high[2] as f64 + vp.uniforms.eye_low[2] as f64,
);
inner.compute_wire_scissors(view_rot, eye, clip_size.width, clip_size.height);
inner.compute_wipeout_scissors(view_rot, eye, clip_size.width, clip_size.height);
inner.compute_image_scissors(view_rot, eye, clip_size.width, clip_size.height);
inner.compute_hatch_lod(queue, view_rot, eye, clip_size.width, clip_size.height);
inner.compute_wipeout_lod(view_rot, eye, clip_size.width, clip_size.height);
inner.compute_mesh_lod(view_rot, eye, clip_size.width, clip_size.height);
if vp.show_viewcube {
inner.viewcube.upload(
queue,
@@ -743,9 +750,7 @@ impl Scene {
};
let mut uniforms =
Uniforms::new(&inst.camera, full_bounds, self.document.header.lineweight_display);
uniforms.view_proj = crop_view_proj(uniforms.view_proj, uo, vo, us, vs);
// The RTE matrix is a view-projection too, so the same clip-space crop
// applies — keep it in lock-step with view_proj for tiled / sub-rect panes.
// Crop the rotation-only RTE view-projection to the visible sub-rect.
uniforms.view_rot = crop_view_proj(uniforms.view_rot, uo, vo, us, vs);
uniforms.viewport_size = [visible_w, visible_h];
uniforms.flat_shade = if flags.flat_shade { 1.0 } else { 0.0 };