Skip to content

Commit 359e8c7

Browse files
authored
XR/OpenXrVk changes related to the new RPI sample added to AtomSampleViewer (#22)
* Added a new XR level that tests a proper VR multi-view pipeline. It creates a render pipeline for each eye and runs than consecutively with a pipeline for PC. The two XR pipelines themselves are a variant of low end render pipeline as a start but in future they will be modified for performance and memory improvements. For example currently we are doing the ShadowMap passes for both the pipelines. This sample adds a ground plane and a few meshes on top of the plane. It also added support for rendering and updating Quest 2 controller related meshes. There is support to switch through different lighting presets for testing purposes as well as support for iterating through differnt ground materials in order to test shadows, reflections, etc. The sample supports Quest 2 controllers to fly around the world. It has support to use button presses for specific functionality in the scene. The schema for each controller is below - Left controller Joystick - Camera movement, Button X - Camera Up (View space y-axis), Button Y - Camera Down (View space Y axis), Squeeze - Scales Controller model - Right controller Joystick - View Orientation if Trigger button is pressed, otherwise it will use device for view tracking, Button A - Iterate through lighting preset, Button B - Iterate through ground plane material, Squeeze - Scales Controller model Signed-off-by: moudgils <[email protected]> * Address feedback Signed-off-by: moudgils <[email protected]> * Address feedback Signed-off-by: moudgils <[email protected]> * Removing const before uint32_t types Signed-off-by: moudgils <[email protected]> * Addressed feedback Signed-off-by: moudgils <[email protected]> Signed-off-by: moudgils <[email protected]>
1 parent 836fd5c commit 359e8c7

File tree

14 files changed

+510
-108
lines changed

14 files changed

+510
-108
lines changed

Gems/OpenXRVk/Code/Include/OpenXRVk/OpenXRVkDevice.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ namespace OpenXRVk
3030
// Create the xr specific native device object and populate the XRDeviceDescriptor with it.
3131
AZ::RHI::ResultCode InitDeviceInternal(AZ::RHI::XRDeviceDescriptor* instanceDescriptor) override;
3232
//! Get the Fov data of the view specified by view index
33-
AZ::RPI::FovData GetViewFov(AZ::u32 viewIndex) const override;
33+
AZ::RHI::ResultCode GetViewFov(AZ::u32 viewIndex, AZ::RPI::FovData& outFovData) const override;
3434
//! Get the Pose data of the view specified by view index
35-
AZ::RPI::PoseData GetViewPose(AZ::u32 viewIndex) const override;
35+
AZ::RHI::ResultCode GetViewPose(AZ::u32 viewIndex, AZ::RPI::PoseData& outPoseData) const override;
3636
//////////////////////////////////////////////////////////////////////////
3737

3838
//! Returns true if rendering data is valid for the current frame.

Gems/OpenXRVk/Code/Include/OpenXRVk/OpenXRVkInput.h

Lines changed: 67 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ namespace OpenXRVk
4343
void LocateVisualizedSpace(XrTime predictedDisplayTime, XrSpace space, XrSpace baseSpace, OpenXRVk::SpaceType visualizedSpaceType);
4444

4545
//! Return Pose data for a controller attached to a view index
46-
AZ::RPI::PoseData GetControllerPose(AZ::u32 viewIndex) const;
46+
AZ::RHI::ResultCode GetControllerPose(AZ::u32 handIndex, AZ::RPI::PoseData& outPoseData) const;
4747

4848
//! Return scale for a controller attached to a view index
4949
float GetControllerScale(AZ::u32 viewIndex) const;
5050

5151
//! Return Pose data for a tracked space type (i.e visualizedSpaceType)
52-
AZ::RPI::PoseData GetVisualizedSpacePose(OpenXRVk::SpaceType visualizedSpaceType) const;
52+
AZ::RHI::ResultCode GetVisualizedSpacePose(OpenXRVk::SpaceType visualizedSpaceType, AZ::RPI::PoseData& outPoseData) const;
5353

54-
//! Get the Grab action
55-
XrAction GetGrabAction() const;
54+
//! Get the Pose action
55+
XrAction GetSqueezeAction() const;
5656

5757
//! Get the Pose action
5858
XrAction GetPoseAction() const;
@@ -62,8 +62,51 @@ namespace OpenXRVk
6262

6363
//! Get the Quit action
6464
XrAction GetQuitAction() const;
65+
66+
//! Get the X button state
67+
float GetXButtonState() const;
68+
69+
//! Get the Y button state
70+
float GetYButtonState() const;
71+
72+
//! Get the A button state
73+
float GetAButtonState() const;
74+
75+
//! Get the B button state
76+
float GetBButtonState() const;
77+
78+
//! Get the joystick state for x-axis
79+
float GetXJoyStickState(AZ::u32 handIndex) const;
80+
81+
//! Get the joystick state for y-axis
82+
float GetYJoyStickState(AZ::u32 handIndex) const;
83+
84+
//! Get the Squeeze action
85+
float GetSqueezeState(AZ::u32 handIndex) const;
86+
87+
//! Get the Squeeze action
88+
float GetTriggerState(AZ::u32 handIndex) const;
89+
6590
private:
6691

92+
struct SingleActionData
93+
{
94+
XrAction m_actionHandle{ XR_NULL_HANDLE };
95+
float m_actionState = 0.0f;
96+
};
97+
98+
struct DualActionData
99+
{
100+
XrAction m_actionHandle{ XR_NULL_HANDLE };
101+
AZStd::array<float, AZ::RPI::XRMaxNumControllers> m_actionState = { { 0.0f, 0.0f } };
102+
};
103+
104+
struct ControllerActionData
105+
{
106+
SingleActionData m_actionData;
107+
uint16_t m_handIndex = 0;
108+
};
109+
67110
//! Create a XrAction
68111
void CreateAction(XrAction& action, XrActionType actionType,
69112
const char* actionName, const char* localizedActionName,
@@ -72,17 +115,31 @@ namespace OpenXRVk
72115
//! Destroy native objects
73116
void ShutdownInternal() override;
74117

118+
bool GetActionState(XrSession xrSession, XrAction xrAction, uint16_t handIndex, float& outputSate);
119+
bool UpdateActionState(XrSession xrSession, SingleActionData& actionData, uint16_t handIndex);
120+
bool UpdateActionState(XrSession xrSession, DualActionData& actionData, uint16_t handIndex);
121+
75122
XrActionSet m_actionSet{ XR_NULL_HANDLE };
76-
XrAction m_grabAction{ XR_NULL_HANDLE };
77123
XrAction m_poseAction{ XR_NULL_HANDLE };
78124
XrAction m_vibrateAction{ XR_NULL_HANDLE };
79125
XrAction m_quitAction{ XR_NULL_HANDLE };
80-
AZStd::array<XrPath, 2> m_handSubactionPath;
81-
AZStd::array<XrSpace, 2> m_handSpace;
82-
AZStd::array<float, 2> m_handScale = { { 1.0f, 1.0f } };
83-
AZStd::array<XrBool32, 2> m_handActive;
126+
DualActionData m_squeezeAction{ XR_NULL_HANDLE, 0.0f };
127+
DualActionData m_triggerAction{ XR_NULL_HANDLE, 0.0f };
84128

85-
AZStd::array<XrSpaceLocation, 2> m_handSpaceLocation;
129+
AZStd::array<XrPath, AZ::RPI::XRMaxNumControllers> m_handSubactionPath;
130+
AZStd::array<XrSpace, AZ::RPI::XRMaxNumControllers> m_handSpace;
131+
AZStd::array<float, AZ::RPI::XRMaxNumControllers> m_handScale = { { 1.0f, 1.0f } };
132+
AZStd::array<XrBool32, AZ::RPI::XRMaxNumControllers> m_handActive;
133+
134+
AZStd::array<XrSpaceLocation, AZ::RPI::XRMaxNumControllers> m_handSpaceLocation;
86135
AZStd::array<XrSpaceLocation, SpaceType::Count> m_xrVisualizedSpaceLocations;
136+
137+
//Todo: This is assuming Quest 2 controller. Needs better abstraction to cover other types of controllers
138+
SingleActionData m_xButtonAction{XR_NULL_HANDLE, 0.0f};
139+
SingleActionData m_yButtonAction{XR_NULL_HANDLE, 0.0f};
140+
SingleActionData m_aButtonAction{XR_NULL_HANDLE, 0.0f};
141+
SingleActionData m_bButtonAction{XR_NULL_HANDLE, 0.0f};
142+
DualActionData m_joyStickXAction{ XR_NULL_HANDLE, 0.0f };
143+
DualActionData m_joyStickYAction{ XR_NULL_HANDLE, 0.0f };
87144
};
88145
}

Gems/OpenXRVk/Code/Include/OpenXRVk/OpenXRVkSession.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <AzCore/std/smart_ptr/intrusive_ptr.h>
1212
#include <OpenXRVk_Platform.h>
1313
#include <OpenXRVk/OpenXRVkSpace.h>
14+
#include <OpenXRVk/OpenXRVkInput.h>
1415
#include <XR/XRSession.h>
1516

1617
namespace OpenXRVk
@@ -49,16 +50,27 @@ namespace OpenXRVk
4950
bool IsExitRenderLoopRequested() const override;
5051
void PollEvents() override;
5152
void LocateControllerSpace(AZ::u32 handIndex) override;
52-
AZ::RPI::PoseData GetControllerPose(AZ::u32 handIndex) const override;
53-
AZ::RPI::PoseData GetViewFrontPose() const override;
53+
AZ::RHI::ResultCode GetControllerPose(AZ::u32 handIndex, AZ::RPI::PoseData& outPoseData) const override;
54+
AZ::RHI::ResultCode GetControllerStagePose(AZ::u32 handIndex, AZ::RPI::PoseData& outPoseData) const override;
55+
AZ::RHI::ResultCode GetViewFrontPose(AZ::RPI::PoseData& outPoseData) const override;
56+
AZ::RHI::ResultCode GetViewLocalPose(AZ::RPI::PoseData& outPoseData) const override;
5457
float GetControllerScale(AZ::u32 handIndex) const override;
58+
float GetXButtonState() const override;
59+
float GetYButtonState() const override;
60+
float GetAButtonState() const override;
61+
float GetBButtonState() const override;
62+
float GetXJoyStickState(AZ::u32 handIndex) const override;
63+
float GetYJoyStickState(AZ::u32 handIndex) const override;
64+
float GetSqueezeState(AZ::u32 handIndex) const override;
65+
float GetTriggerState(AZ::u32 handIndex) const override;
5566
//////////////////////////////////////////////////////////////////////////
5667

5768
private:
5869

5970
void ShutdownInternal() override;
6071
void LogActionSourceName(XrAction action, const AZStd::string_view actionName) const;
61-
72+
Input* GetNativeInput() const;
73+
6274
XrSession m_session = XR_NULL_HANDLE;
6375
XrSessionState m_sessionState = XR_SESSION_STATE_UNKNOWN;
6476
XrEventDataBuffer m_eventDataBuffer;

Gems/OpenXRVk/Code/Source/OpenXRVkDevice.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -243,35 +243,35 @@ namespace OpenXRVk
243243
return m_context;
244244
}
245245

246-
AZ::RPI::FovData Device::GetViewFov(AZ::u32 viewIndex) const
246+
AZ::RHI::ResultCode Device::GetViewFov(AZ::u32 viewIndex, AZ::RPI::FovData& outFovData) const
247247
{
248-
AZ::RPI::FovData viewFov;
249248
if(viewIndex < m_projectionLayerViews.size())
250249
{
251-
viewFov.m_angleLeft = m_projectionLayerViews[viewIndex].fov.angleLeft;
252-
viewFov.m_angleRight = m_projectionLayerViews[viewIndex].fov.angleRight;
253-
viewFov.m_angleUp = m_projectionLayerViews[viewIndex].fov.angleUp;
254-
viewFov.m_angleDown = m_projectionLayerViews[viewIndex].fov.angleDown;
250+
outFovData.m_angleLeft = m_projectionLayerViews[viewIndex].fov.angleLeft;
251+
outFovData.m_angleRight = m_projectionLayerViews[viewIndex].fov.angleRight;
252+
outFovData.m_angleUp = m_projectionLayerViews[viewIndex].fov.angleUp;
253+
outFovData.m_angleDown = m_projectionLayerViews[viewIndex].fov.angleDown;
254+
return AZ::RHI::ResultCode::Success;
255255
}
256-
return viewFov;
256+
return AZ::RHI::ResultCode::Fail;
257257
}
258258

259-
AZ::RPI::PoseData Device::GetViewPose(AZ::u32 viewIndex) const
260-
{
261-
AZ::RPI::PoseData viewPose;
259+
AZ::RHI::ResultCode Device::GetViewPose(AZ::u32 viewIndex, AZ::RPI::PoseData& outPoseData) const
260+
{
262261
if (viewIndex < m_projectionLayerViews.size())
263262
{
264263
const XrQuaternionf& orientation = m_projectionLayerViews[viewIndex].pose.orientation;
265264
const XrVector3f& position = m_projectionLayerViews[viewIndex].pose.position;
266-
viewPose.orientation = AZ::Quaternion(orientation.x,
267-
orientation.y,
268-
orientation.z,
269-
orientation.w);
270-
viewPose.position = AZ::Vector3(position.x,
271-
position.y,
272-
position.z);
273-
}
274-
return viewPose;
265+
outPoseData.m_orientation.Set(orientation.x,
266+
orientation.y,
267+
orientation.z,
268+
orientation.w);
269+
outPoseData.m_position.Set(position.x,
270+
position.y,
271+
position.z);
272+
return AZ::RHI::ResultCode::Success;
273+
}
274+
return AZ::RHI::ResultCode::Fail;
275275
}
276276

277277
XrTime Device::GetPredictedDisplayTime() const

0 commit comments

Comments
 (0)