I need to transform a simd_float4x4's position to screen space

Generated on 9/17/2024

1 search

To transform a simd_float4x4's position to screen space in visionOS, you need to work with the projection view matrix. This matrix is a combination of the projection matrix and the view matrix, which can be expanded into two transforms:

  1. Device from Origin: This transform brings the origin space to the device space.
  2. View from Device: This transform brings the device space to the view space.

The projection view matrix is calculated as the projection matrix times the inverse of origin from device, multiplied by device from view. You can acquire the device from view transform by calling CpView get transform in the compositor services API. This matrix brings the rendered view to the device space.

For better positioning of rendered content with real-world objects, you can use a scene-aware projection matrix, which combines camera intrinsics and real-time scene understanding factors. This is particularly useful for mixed immersion experiences.

For more detailed guidance, you can refer to the session Render Metal with passthrough in visionOS (09:52) where these concepts are discussed in depth.