Skip to content

docs: Fix camera orientation in "Monocular Light Injection" example - #2891

Open
pullfrog[bot] wants to merge 1 commit into
mainfrom
pullfrog/2890-fix-camera-orientation-monocular
Open

docs: Fix camera orientation in "Monocular Light Injection" example#2891
pullfrog[bot] wants to merge 1 commit into
mainfrom
pullfrog/2890-fix-camera-orientation-monocular

Conversation

@pullfrog

@pullfrog pullfrog Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Fixes #2890.

The camera sometimes appeared rotated 90° on iOS Safari in the "Monocular Light Injection" example. The orientation fix already exists in the other camera examples (see selfie-segmentation, commit a49d357): a uvTransform matrix derived from screen.orientation.type, applied as uvTransform * (sourceUv - 0.5) + 0.5 when sampling the external camera texture.

The monocular example used the same rotation matrices but additionally swapped the source texture's width/height axes (swapAxes) before the square-crop + rotation for portrait orientations. That extra axis-swap diverged from the verified-working pattern and is what rotated the camera for portrait captures.

This removes swapAxes end-to-end (camera-session.ts, index.ts, renderer.ts, shaders.ts, inference/preprocess.ts), aligning the geometry exactly with the other camera examples: identical rotation matrices, a centered min(w,h) square crop, no axis swap, and consistent mirror handling between the depth-inference input crop and the displayed relit/color view.

Validation:

  • apps/typegpu-docs pnpm run test:types (astro check): 0 errors
  • oxlint on the example: 0 warnings/errors
  • oxfmt --check on the changed files: passes
  • Pre-commit reviewfrog self-review: no actionable defects found

Pullfrog  | View workflow run | via Pullfrog | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@github-actions

Copy link
Copy Markdown

Bundle size comparison (import * as ... in PR vs import * as ... in target):

🟢 Decreased ➖ Unchanged 🔴 Increased ❔ Unknown
0 325 0 0

import { ... } in PR vs import * as ... in PR (is the library tree-Shakeable?):

Test tsdown
tgpu_init.ts 263.10 kB ($${\color{green}-3.5\%}$$)
tgpu_initFromDevice.ts 262.56 kB ($${\color{green}-3.7\%}$$)
tgpu_resolve.ts 161.75 kB ($${\color{green}-40.7\%}$$)
tgpu_resolveWithContext.ts 161.68 kB ($${\color{green}-40.7\%}$$)
tgpu_bindGroupLayout.ts 62.32 kB ($${\color{green}-77.1\%}$$)
tgpu_mutableAccessor.ts 57.04 kB ($${\color{green}-79.1\%}$$)
tgpu_accessor.ts 57.04 kB ($${\color{green}-79.1\%}$$)
tgpu_privateVar.ts 55.73 kB ($${\color{green}-79.6\%}$$)
tgpu_workgroupVar.ts 55.73 kB ($${\color{green}-79.6\%}$$)
tgpu_const.ts 55.15 kB ($${\color{green}-79.8\%}$$)
tgpu_lazy.ts 54.95 kB ($${\color{green}-79.8\%}$$)
tgpu_fragmentFn.ts 39.68 kB ($${\color{green}-85.4\%}$$)
tgpu_fn.ts 39.62 kB ($${\color{green}-85.5\%}$$)
tgpu_vertexFn.ts 39.50 kB ($${\color{green}-85.5\%}$$)
tgpu_computeFn.ts 39.20 kB ($${\color{green}-85.6\%}$$)
tgpu_vertexLayout.ts 28.33 kB ($${\color{green}-89.6\%}$$)
tgpu_comptime.ts 15.93 kB ($${\color{green}-94.2\%}$$)
tgpu_unroll.ts 1.75 kB ($${\color{green}-99.4\%}$$)
tgpu_slot.ts 1.70 kB ($${\color{green}-99.4\%}$$)

If you wish to run a comparison for other, slower bundlers, run the 'Tree-shake test' from the GitHub Actions menu.

@github-actions

Copy link
Copy Markdown

pkg.pr.new

No packages changed since release

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes an iOS Safari camera-orientation issue in the “Monocular Light Injection” docs example by aligning its UV/crop pipeline with the other camera-based examples (apply uvTransform after a centered square crop, without swapping axes).

Changes:

  • Removed swapAxes from the camera frame transform path and from all GPU/CPU parameter plumbing.
  • Updated preprocessing and relighting sampling to always use the external texture’s native dimensions for the centered square crop, then apply uvTransform.
  • Simplified frame option/types passed through the example (camera session → renderer → inference preprocess → shaders).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
apps/typegpu-docs/src/examples/image-processing/monocular-light-injection/shaders.ts Drops swapAxes from uniforms and samples/crops using native texture dimensions before applying uvTransform.
apps/typegpu-docs/src/examples/image-processing/monocular-light-injection/renderer.ts Removes swapAxes state and stops passing/writing it through render + inference params.
apps/typegpu-docs/src/examples/image-processing/monocular-light-injection/inference/preprocess.ts Removes swapAxes from preprocess options/uniforms and uses native texture dimensions for crop + uvTransform.
apps/typegpu-docs/src/examples/image-processing/monocular-light-injection/index.ts Updates static-image render path to match the new frame options (no swapAxes).
apps/typegpu-docs/src/examples/image-processing/monocular-light-injection/camera-session.ts Removes swapAxes from DepthCameraFrame and iOS orientation transforms (UV rotation only).

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@github-actions

Copy link
Copy Markdown

Resolution Time Benchmark

---
config:
  themeVariables:
    xyChart:
      plotColorPalette: "#E63946, #3B82F6, #059669"
---
xychart
  title "Random Branching (🔴 PR | 🔵 main | 🟢 release)"
  x-axis "max depth" [1, 2, 3, 4, 5, 6, 7, 8]
  y-axis "time (ms)"
  line [1.02, 1.99, 4.47, 6.78, 8.32, 11.54, 26.02, 26.68]
  line [0.93, 1.89, 4.12, 6.99, 7.77, 11.68, 25.15, 24.12]
  line [0.94, 1.93, 4.36, 7.16, 8.21, 10.72, 23.86, 26.36]
Loading
---
config:
  themeVariables:
    xyChart:
      plotColorPalette: "#E63946, #3B82F6, #059669"
---
xychart
  title "Linear Recursion (🔴 PR | 🔵 main | 🟢 release)"
  x-axis "max depth" [1, 2, 3, 4, 5, 6, 7, 8]
  y-axis "time (ms)"
  line [0.29, 0.53, 0.72, 0.88, 1.14, 1.29, 1.55, 1.64]
  line [0.32, 0.50, 0.77, 0.93, 1.11, 1.24, 1.54, 1.67]
  line [0.34, 0.57, 0.67, 0.80, 1.09, 1.19, 1.35, 1.51]
Loading
---
config:
  themeVariables:
    xyChart:
      plotColorPalette: "#E63946, #3B82F6, #059669"
---
xychart
  title "Full Tree (🔴 PR | 🔵 main | 🟢 release)"
  x-axis "max depth" [1, 2, 3, 4, 5, 6, 7, 8]
  y-axis "time (ms)"
  line [1.08, 2.69, 5.09, 7.88, 13.62, 27.47, 57.64, 120.02]
  line [0.91, 2.25, 3.49, 7.60, 13.06, 27.31, 58.10, 118.69]
  line [0.90, 2.35, 3.69, 7.20, 12.82, 26.60, 56.37, 116.77]
Loading

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.

docs: Fix camera orientation in "Monocular Light Injection" example

1 participant