Skip to content

Add focal X/Y coordinates to Zoom In and Zoom Out effects#27

Draft
Copilot wants to merge 3 commits into
masterfrom
copilot/add-zoom-effect-coordinates
Draft

Add focal X/Y coordinates to Zoom In and Zoom Out effects#27
Copilot wants to merge 3 commits into
masterfrom
copilot/add-zoom-effect-coordinates

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 4, 2026

Zoom effects previously always zoomed toward the screen center. This adds optional focal_x/focal_y properties so the zoom target can be any screen position, while defaulting to center for backwards compatibility.

Approach

Focal-point offset is implemented as a projection-matrix NDC translation rather than a transform.localPosition shift, which means:

  • No conflict with Camera Shake (transform-based) — they compose independently
  • Correct composition with Horizontal/Vertical Flip (CameraFlipOverlay) via [DefaultExecutionOrder(10)] on the new CameraZoomOverlay, ensuring the focal shift is applied on top of any active flip

Per-entry NDC contribution: focalNDC × (1 − 1/factor) — keeps the focal point stationary as camera size changes. Contributions from concurrent zoom effects with different focal points are summed.

Changes

  • CameraZoomServiceSetFactor gains a focalNDC parameter (Vector2, defaults to (0,0)). Adds CameraZoomOverlay MonoBehaviour (one per camera) that applies the composite NDC translation in OnPreCull and resets in OnPostRender.

  • ZoomInEffect / ZoomOutEffect — Add focal_x/focal_y template properties using NDC space: (0, 0) = screen center (default), (±1, ±1) = screen corners. Values are passed directly to the service with no conversion.

  • EntityExtensions — Adds GetFloat(key, fallback) overload so old saved events without focal_x/focal_y default to center zoom (0).

  • docs/effects/README.md — Documents focal_x/focal_y for both effects.

Original prompt

This section details on the original issue you should resolve

<issue_title>Zoom effects should have coordinates</issue_title>
<issue_description>Should be able to indicate X Y position to zoom on on different parts of the scene, not only on the center. By default, they should zoom towards the center to keep bsckwards compatibility with previous versions.

Make sure it correctly composes with other Zoom effects that might have different coordinates and with other camera position altering effects, like Camera Shake.</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

- Extend CameraZoomService to accept a focal point (NDC Vector2) per entry.
  Compute composite NDC translation as sum of per-entry focalNDC*(1-1/factor).
  Add CameraZoomOverlay MonoBehaviour (DefaultExecutionOrder 10) that applies
  the projection-matrix NDC shift in OnPreCull after CameraFlipOverlay (order 0),
  composing cleanly with flip effects and not conflicting with transform-based
  effects like Camera Shake.
- Update ZoomInEffect and ZoomOutEffect to add focal_x=0.5 / focal_y=0.5
  template properties, read them with a fallback (backwards compat), convert
  to NDC, and pass to CameraZoomService.SetFactor.
- Add EntityExtensions.GetFloat(key, fallback) for reading optional properties
  absent in events created before this change.
- Document focal_x/focal_y in docs/effects/README.md.

Co-authored-by: Brollyy <12004018+Brollyy@users.noreply.github.com>
Copilot AI changed the title [WIP] Add coordinates to zoom effects for flexible positioning Add focal X/Y coordinates to Zoom In and Zoom Out effects Mar 4, 2026
Copy link
Copy Markdown
Owner

@Brollyy Brollyy left a comment

Choose a reason for hiding this comment

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

@copilot address the comment

var zoomFactor = Mathf.Clamp(1f - _intensity * envelope, 0.01f, 1f);
CameraZoomService.SetFactor(_camera!, this, zoomFactor);

// Convert normalized screen coordinates [0, 1] to NDC [-1, 1]:
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I don't see why we would need to use (0.5, 0.5) for users - (0, 0) for center makes more sense

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changed in 31af111. Coordinate system is now (0, 0) = screen center, (±1, ±1) = screen corners (NDC space), with 0.0 as the default for both axes. The (x - 0.5) * 2 conversion was removed — values are now passed directly as NDC offsets.

- Template defaults changed from 0.5 to 0.0
- GetFloat fallbacks changed from 0.5f to 0.0f
- Removed the (x - 0.5) * 2 conversion; values are now passed directly as NDC
- Updated docs: (0,0) = center, ±1 = screen edges

Co-authored-by: Brollyy <12004018+Brollyy@users.noreply.github.com>
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.

Zoom effects should have coordinates

2 participants