View in English

  • Apple Developer
    • Get Started

    Explore Get Started

    • Overview
    • Learn
    • Apple Developer Program

    Stay Updated

    • Latest News
    • Hello Developer
    • Platforms

    Explore Platforms

    • Apple Platforms
    • iOS
    • iPadOS
    • macOS
    • tvOS
    • visionOS
    • watchOS
    • App Store

    Featured

    • Design
    • Distribution
    • Games
    • Accessories
    • Web
    • Home
    • CarPlay
    • Technologies

    Explore Technologies

    • Overview
    • Xcode
    • Swift
    • SwiftUI

    Featured

    • Accessibility
    • App Intents
    • Apple Intelligence
    • Games
    • Machine Learning & AI
    • Security
    • Xcode Cloud
    • Community

    Explore Community

    • Overview
    • Meet with Apple events
    • Community-driven events
    • Developer Forums
    • Open Source

    Featured

    • WWDC
    • Swift Student Challenge
    • Developer Stories
    • App Store Awards
    • Apple Design Awards
    • Apple Developer Centers
    • Documentation

    Explore Documentation

    • Documentation Library
    • Technology Overviews
    • Sample Code
    • Human Interface Guidelines
    • Videos

    Release Notes

    • Featured Updates
    • iOS
    • iPadOS
    • macOS
    • watchOS
    • visionOS
    • tvOS
    • Xcode
    • Downloads

    Explore Downloads

    • All Downloads
    • Operating Systems
    • Applications
    • Design Resources

    Featured

    • Xcode
    • TestFlight
    • Fonts
    • SF Symbols
    • Icon Composer
    • Support

    Explore Support

    • Overview
    • Help Guides
    • Developer Forums
    • Feedback Assistant
    • Contact Us

    Featured

    • Account Help
    • App Review Guidelines
    • App Store Connect Help
    • Upcoming Requirements
    • Agreements and Guidelines
    • System Status
  • Quick Links

    • Events
    • News
    • Forums
    • Sample Code
    • Videos
 

Vídeos

Abrir menu Fechar menu
  • Coleções
  • Todos os vídeos
  • Sobre

Mais vídeos

  • Sobre
  • Código
  • Bring your iOS or iPadOS game to visionOS

    Discover how to transform your iOS or iPadOS game into a uniquely visionOS experience. Increase the immersion (and fun factor!) with a 3D frame or an immersive background. And invite players further into your world by adding depth to the window with stereoscopy or head tracking.

    Capítulos

    • 0:00 - Introduction
    • 1:42 - Render on visionOS
    • 3:48 - Compatible to native
    • 6:41 - Add a frame and a background
    • 8:00 - Enhance the rendering

    Recursos

    • Rendering a windowed game in stereo
    • Forum: Graphics & Games
      • Vídeo HD
      • Vídeo SD

    Vídeos relacionados

    WWDC24

    • Build a spatial drawing app with RealityKit
    • Build compelling spatial photo and video experiences
    • Discover RealityKit APIs for iOS, macOS, and visionOS
    • Explore game input in visionOS
    • Render Metal with passthrough in visionOS

    WWDC23

    • Build spatial experiences with RealityKit
  • Buscar neste vídeo...
    • 5:44 - Render with Metal in a UIView

      // Render with Metal in a UIView.
      
      class CAMetalLayerBackedView: UIView, CAMetalDisplayLinkDelegate {
      
          var displayLink: CAMetalDisplayLink!
      
          override class var layerClass : AnyClass { return CAMetalLayer.self }
      
          func setup(device: MTLDevice) {
              let displayLink = CAMetalDisplayLink(metalLayer: self.layer as! CAMetalLayer)
              displayLink.add(to: .current, forMode: .default)
              self.displayLink.delegate = self
          }
      
          func metalDisplayLink(_ link: CAMetalDisplayLink,
                    needsUpdate update: CAMetalDisplayLink.Update) {
              let drawable = update.drawable
              renderFunction?(drawable)
          }
      }
    • 6:20 - Render with Metal to a RealityKit LowLevelTexture

      // Render Metal to a RealityKit LowLevelTexture.
      
      let lowLevelTexture = try! LowLevelTexture(descriptor: .init(
          pixelFormat: .rgba8Unorm,
          width: resolutionX,
          height: resolutionY,
          depth: 1,
          mipmapLevelCount: 1,
          textureUsage: [.renderTarget]
      ))
      
      let textureResource = try! TextureResource(
          from: lowLevelTexture
      )
      // assign textureResource to a material
      
      let commandBuffer: MTLCommandBuffer = queue.makeCommandBuffer()!
      let mtlTexture: MTLTexture = texture.replace(using: commandBuffer)
      // Draw into the mtlTexture
    • 7:06 - Metal viewport with a 3D RealityKit frame around it

      // Metal viewport with a 3D RealityKit frame 
      // around it.
      
      struct ContentView: View {
      
          @State var game = Game()
      
          var body: some View {
              ZStack {
                 CAMetalLayerView { drawable in
                                   game.render(drawable) }
      
                 RealityView { content in
                      content.add(try! await 
                                  Entity(named: "Frame"))
                  }.frame(depth: 0)
              }
          }
      }
    • 7:45 - Windowed game with an immersive background

      // Windowed game with an immersive background
      
      @main
      struct TestApp: App {
      
          @State private var appModel = AppModel()
      
          var body: some Scene {
              WindowGroup {
                  // Metal render
                  ContentView(appModel)
              }
      
              ImmersiveSpace(id: "ImmersiveSpace") {
                  // RealityKit background
                  ImmersiveView(appModel)
              }.immersionStyle(selection: .constant(.progressive),
                                    in: .progressive)
          }
      }
    • 13:11 - Render to multiple views for stereoscopy

      // Render to multiple views for stereoscopy.
      
      override func draw(provider: DrawableProviding) {
      
          encodeShadowMapPass()
      
          for viewIndex in 0..<provider.viewCount {
              scene.update(viewMatrix: provider.viewMatrix(viewIndex: viewIndex),
                     projectionMatrix: provider.projectionMatrix(viewIndex: viewIndex))
              var commandBuffer = beginDrawableCommands()
              if let color = provider.colorTexture(viewIndex: viewIndex, for: commandBuffer),
                 let depthStencil = provider.depthStencilTexture(viewIndex: viewIndex,
                                                                       for: commandBuffer)
              {
                  encodePass(into: commandBuffer, color: color, depth: depth)
              }
              endFrame(commandBuffer)
          }
      }
    • 13:55 - Query the head position from ARKit every frame

      // Query the head position from ARKit every frame.
      
      import ARKit
      
      let arSession = ARKitSession()
      let worldTracking = WorldTrackingProvider()
      
      try await arSession.run([worldTracking])
      
      // Every frame
      
      guard let deviceAnchor = worldTracking.queryDeviceAnchor(
          atTimestamp: CACurrentMediaTime() + presentationTime
      ) else { return }
      
      let transform: simd_float4x4 = deviceAnchor
          .originFromAnchorTransform
    • 14:22 - Convert the head position from the ImmersiveSpace to a window

      // Convert the head position from the ImmersiveSpace to a window.
      
      let headPositionInImmersiveSpace: SIMD3<Float> = deviceAnchor
          .originFromAnchorTransform
          .position
      
      let windowInImmersiveSpace: float4x4 = windowEntity
          .transformMatrix(relativeTo: .immersiveSpace)
      
      let headPositionInWindow: SIMD3<Float> = windowInImmersiveSpace
          .inverse
          .transform(headPositionInImmersiveSpace)
      
      renderer.setCameraPosition(headPositionInWindow)
    • 15:05 - Query the head position from ARKit every frame

      // Query the head position from ARKit every frame.
      
      import ARKit
      
      let arSession = ARKitSession()
      let worldTracking = WorldTrackingProvider()
      
      try await arSession.run([worldTracking])
      
      // Every frame
      
      guard let deviceAnchor = worldTracking.queryDeviceAnchor(
          atTimestamp: CACurrentMediaTime() + presentationTime
      ) else { return }
      
      let transform: simd_float4x4 = deviceAnchor
          .originFromAnchorTransform
    • 15:47 - Build the camera and projection matrices

      // Build the camera and projection matrices.
      
      let cameraPosition: SIMD3<Float>
      let viewportBounds: BoundingBox
      
      // Camera facing -Z
      let cameraTransform = simd_float4x4(AffineTransform3D(translation: Size3D(cameraPosition)))
      
      let zNear: Float = viewportBounds.max.z - cameraPosition.z
      let l /* left */: Float = viewportBounds.min.x - cameraPosition.x
      let r /* right */: Float = viewportBounds.max.x - cameraPosition.x
      let b /* bottom */: Float = viewportBounds.min.y - cameraPosition.y
      let t /* top */: Float = viewportBounds.max.y - cameraPosition.y
      
      let cameraProjection = simd_float4x4(rows: [
          [2*zNear/(r-l),             0, (r+l)/(r-l),      0],
          [            0, 2*zNear/(t-b), (t+b)/(t-b),      0],
          [            0,             0,           1, -zNear],
          [            0,             0,           1,      0]
      ])

Developer Footer

  • Vídeos
  • WWDC24
  • Bring your iOS or iPadOS game to visionOS
  • Open Menu Close Menu
    • iOS
    • iPadOS
    • macOS
    • tvOS
    • visionOS
    • watchOS
    • App Store
    Open Menu Close Menu
    • Swift
    • SwiftUI
    • Swift Playground
    • TestFlight
    • Xcode
    • Xcode Cloud
    • Icon Composer
    • SF Symbols
    Open Menu Close Menu
    • Accessibility
    • Accessories
    • Apple Intelligence
    • Audio & Video
    • Augmented Reality
    • Business
    • Design
    • Distribution
    • Education
    • Games
    • Health & Fitness
    • In-App Purchase
    • Localization
    • Maps & Location
    • Machine Learning & AI
    • Security
    • Safari & Web
    Open Menu Close Menu
    • Documentation
    • Downloads
    • Sample Code
    • Videos
    Open Menu Close Menu
    • Help Guides & Articles
    • Contact Us
    • Forums
    • Feedback & Bug Reporting
    • System Status
    Open Menu Close Menu
    • Apple Developer
    • App Store Connect
    • Certificates, IDs, & Profiles
    • Feedback Assistant
    Open Menu Close Menu
    • Apple Developer Program
    • Apple Developer Enterprise Program
    • App Store Small Business Program
    • MFi Program
    • Mini Apps Partner Program
    • News Partner Program
    • Video Partner Program
    • Security Bounty Program
    • Security Research Device Program
    Open Menu Close Menu
    • Meet with Apple
    • Apple Developer Centers
    • App Store Awards
    • Apple Design Awards
    • Apple Developer Academies
    • WWDC
    Read the latest news.
    Get the Apple Developer app.
    Copyright © 2026 Apple Inc. All rights reserved.
    Terms of Use Privacy Policy Agreements and Guidelines