Skip to content

gfx, threedim: camera lens shift, off-axis frustum and raw projection - #2426

Open
jcelerier wants to merge 1 commit into
split/calibration-mathfrom
split/camera-projection
Open

jcelerier wants to merge 1 commit into
split/calibration-mathfrom
split/camera-projection

Conversation

@jcelerier

Copy link
Copy Markdown
Member

depends on: #2425, and libossia#995 (ossia/libossia#995)

The camera component can now describe what a calibrated projector or a viewer-tracked screen needs: a lens shift, an explicit off-axis frustum, or a raw OpenGL projection matrix. The component fields come from libossia#995. The gitlink here points at 687133544e, which is the same change applied on master's libossia 9123607b46, and it will be repointed once #995 merges.

  • cameraProjection() turns a component into score's reverse-Z projection. Scene flattening, the shadow cascades and packCameraUBO all go through it. As a result, an orthographic glTF / FBX camera now also gives an orthographic legacy projection and orthographic cascade slices; they were always perspective before.
  • cameraFrustumTangents() gives a perspective camera's tangents: from its frustum, or from its FOV and shift at a given aspect. An unshifted FOV camera keeps exactly the matrix it had before.

The Camera process takes, besides look-at and FOV:

  • a lens shift;
  • OpenCV intrinsics of an image size (positive focal lengths);
  • pose and projection matrices as text, written row by row as matrices are printed. A projection matrix reports its own near, far, vertical FOV and kind; an orthographic matrix makes an orthographic camera;
  • a Screen mode: the Kooima frustum and orientation of a screen seen from the eye (Gfx/Calibration/OffAxis.hpp, from Crash on drop of device in device explorer #11).

A matrix that does not parse, a pose that is not affine, non-positive focal lengths, or a degenerate screen all fall back to look-at and FOV. The pose, target and planes are computed once per change, not per frame.

The camera switch blends off-axis frusta as tangents. A FOV camera without an aspect of its own takes the frustum cameras' aspect, so a crossfade between a Screen camera and a FOV camera rendering to the same aspect does not jump. Raw matrices are blended only when every weighted camera has one.

Commits

  • 9c713152e7 gfx, threedim: camera lens shift, off-axis frustum and raw projection

Tests

  • New test_threedim_camera_off_axis (tests/threedim/CameraOffAxis.cpp) checks closed-form projections: shift, intrinsics against the OpenCV pinhole, raw matrices in reverse-Z, the screen corners landing on the image corners, frustum tangents, OpenGL world-from-camera and view poses, the fallbacks (bad matrices and focal lengths, a screen behind the eye), and the camera switch blending without a jump.
  • test_threedim_shadow_cascades gains a case for cascades fitted to an off-axis and to an orthographic camera, and now links score_plugin_gfx.
  • The whole series was built and tested with ctest on Linux (Xvfb, lavapipe Vulkan and Mesa OpenGL). Nothing failed beyond master's own known failures (test_gfx_shader_corpus_targets, test_gfx_window_layout, test_threedim_ply_fingerprint, test_unit_miniaudio_alsa and the few others master's run lists).

Notes for review

🤖 Generated with Claude Code

https://claude.ai/code/session_01KdPgujQFUTMVZBdH6Hv7Vj

The camera component (libossia 687133544e) carries a lens shift, an
explicit off-axis frustum or a raw OpenGL projection matrix.
cameraProjection() turns a component into score's reverse-Z projection,
and scene flattening, the shadow cascades and packCameraUBO all go
through it, so an orthographic glTF / FBX camera now also gives an
orthographic legacy projection and orthographic cascade slices (they
were always perspective). cameraFrustumTangents() gives a perspective
camera's tangents (its frustum, or its FOV and shift at an aspect), and
an unshifted FOV camera keeps its former matrix exactly.

The Camera process takes, besides look-at and FOV:
- a lens shift;
- OpenCV intrinsics of an image size (positive focal lengths);
- pose and projection matrices as text, written row by row as matrices
  are printed; a projection matrix reports its own near, far, vertical
  FOV and kind (an orthographic one is an orthographic camera);
- a Screen mode: the Kooima frustum and orientation of a screen seen from
  the eye (Gfx/Calibration/OffAxis.hpp).
A matrix that does not parse, a pose that is not affine, non-positive
focal lengths or a degenerate screen fall back to look-at and FOV. The
pose, target and planes are computed once per change, not per frame.

The camera switch blends off-axis frusta as tangents; a FOV camera
without an aspect of its own takes the frustum cameras' aspect, so a
crossfade between a Screen camera and a FOV camera rendering to the same
aspect does not jump. Raw matrices are blended only when every weighted
camera has one.

Tests: closed-form projections (shift, intrinsics against the OpenCV
pinhole, raw matrices, the screen corners landing on the image corners),
the fallbacks, the switch's blending, and shadow cascades fitted to an
off-axis and to an orthographic camera (test_threedim_shadow_cascades
now links score_plugin_gfx).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KdPgujQFUTMVZBdH6Hv7Vj

This branch is waiting to be deployed

1 waiting deployment
full-ci — 9c713152 Waiting Nov 25, 2026 by jcelerier via Approve full PR suite #15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant