Unigine.VR Class
The base class for managing virtual reality in UNIGINE.
VR Initialization#
By default, VR is not initialized. To run the engine with VR, you need to specify the -vr_app command-line option on the application start-up.
Supported Graphics APIs#
The following graphics APIs are supported out of the box:
- DirectX 11
- DirectX 12
- Vulkan
For OpenGL API support, use the corresponding VR plugins (deprecated).
VR Class
Enums
API#
Name | Description |
---|---|
NULL = 0 | VR API is not initialized. |
VARJO = 1 | Varjo API. |
OPENVR = 2 | OpenVR API. |
OPENXR = 3 | OpenXR API. |
VIEWPORT_TYPE#
Name | Description |
---|---|
CONTEXT = 0 | Context (low-res) viewport. |
FOCUS = 1 | Focus (high-res) viewport. |
NUM = 2 | Number of viewport types. |
EYE_TYPE#
Name | Description |
---|---|
LEFT = 0 | Left eye. |
RIGHT = 1 | Right eye. |
NUM = 2 | Number of eye types. |
MIRROR_MODE#
WINDOW_MODE#
TRACKING_SPACE#
DEBUG_MODE#
RUNTIME_TYPE#
Properties
bool RenderEnabled#
Console: vr_render_enabled
The value indicating if rendering into the head-mounted display is enabled.
The default value is false.bool PeripheralRenderingModeEnabled#
Console: vr_peripheral_rendering_mode_enabled
The value indicating if the peripheral rendering mode is enabled. In this mode, the HMD has two context (peripheral) and two focus displays. You can disable two additional viewports to improve peformance.
The default value is false.This feature is available for the Varjo devices only.
VR.MIRROR_MODE MirrorMode#
Console: vr_mirror_mode
The mirror mode that defines how the mirrored image (i.e. VR image) will be displayed in the target window.
One of the following values:- 0 - black screen (no image is displayed).
- 1 - image rendered for the left eye.
- 2 - image rendered for the right eye.
- 3 - stereo image (both the left and right eyes). (by default)
VR.WINDOW_MODE WindowMode#
Console: vr_window_mode
The window mode that defines which window will display the mirrored image (i.e. VR image).
One of the following values:- 0 - mirroring is disabled.
- 1 - main window displays the mirrored image. (by default)
VR.TRACKING_SPACE TrackingSpace#
Console: vr_tracking_space
The zero pose of the tracking origin.
One of the following values:- 0 - seated.
- 1 - standing. (by default)
- 2 - raw (uncalibrated).
bool MotionPrediction#
Console: vr_motion_prediction
The value indicating if motion prediction in the Varjo headsets is enabled. When enabled, the engine submits the velocity value from the GBuffer to the Varjo Composer.
The default value is false.float MotionPredictionVelocityPrecision#
The factor of velocity scale before packing a floating point value into a 2x8 bit unsigned integer (uint).
This feature is available for the Varjo devices only.
Range of values: [eps, inf]. The default value is : 32.0f.
float MotionPredictionVelocityTimeDelta#
The factor for optimizing between fast and slow-moving objects. A smaller number works better for fast-moving objects, and vice versa.
This feature is available for the Varjo devices only.
Range of values: [eps, inf]. The default value is : 1.0f / 60.0f.
bool FoveatedRenderingEnabled#
Console: vr_foveated_rendering_enabled
The value indicating if foveated rendering is enabled. Foveated rendering makes use of the eye tracking functionality in the Varjo headsets to improve performance by reducing the image quality in peripheral areas where the user is not looking. Foveation allows applications to render fewer pixels and achieve a better VR experience.
The default value is true.This feature is available for the Varjo devices only.
string ApiName#
The name of the VR API.
VR.API ApiType#
The type of the VR API.
float HMDRefreshRate#
The refresh rate of the head-mounted display.
vec3 HandTrackingOffset#
The hand tracking offset (for the Ultraleap device only).
bool IsHandTrackingOffsetSupported#
The value indicating if the hand tracking offset is supported.
bool IsPeripheralRenderingModeUsed#
The value indicating if the peripheral rendering is used.
bool IsHMDConnected#
The value indicating if the head-mounted display is connected.
bool IsUsingFoveatedRendering#
The value indicating if the foveated rendering is used.
Viewport Viewport#
The viewport. It can be useful when implementing extra VR logic.
mat4 PlayerIModelview#
The inverse model-view matrix of the camera that renders VR.
mat4 PlayerModelview#
The model-view matrix of the camera that renders VR.
mat4 PlayerWorldTransform#
The world transformation of the camera that renders VR.
Event<bool> EventRenderModelsVisibility#
The Event triggered when the render models visibility is changed. You can subscribe to events via
Connect()
and unsubscribe via
Disconnect(). You can also use
EventConnection
and
EventConnections
classes for convenience (see examples below).
The event handler signature is as follows: myhandler(bool visible )
For more details see the Event Handling article.
Usage Example
// implement the RenderModelsVisibility event handler
void rendermodelsvisibility_event_handler(bool visible)
{
Log.Message("\Handling RenderModelsVisibility event\n");
}
//////////////////////////////////////////////////////////////////////////////
// 1. Multiple subscriptions can be linked to an EventConnections instance
// class that you can use later to remove all these subscriptions at once
//////////////////////////////////////////////////////////////////////////////
// create an instance of the EventConnections class
EventConnections rendermodelsvisibility_event_connections = new EventConnections();
// link to this instance when subscribing to an event (subscription to various events can be linked)
VR.EventRenderModelsVisibility.Connect(rendermodelsvisibility_event_connections, rendermodelsvisibility_event_handler);
// other subscriptions are also linked to this EventConnections instance
// (e.g. you can subscribe using lambdas)
VR.EventRenderModelsVisibility.Connect(rendermodelsvisibility_event_connections, (bool visible) => {
Log.Message("Handling RenderModelsVisibility event lambda\n");
}
);
// later all of these linked subscriptions can be removed with a single line
rendermodelsvisibility_event_connections.DisconnectAll();
//////////////////////////////////////////////////////////////////////////////
// 2. You can subscribe and unsubscribe via the handler function directly
//////////////////////////////////////////////////////////////////////////////
// subscribe to the RenderModelsVisibility event with a handler function
VR.EventRenderModelsVisibility.Connect(rendermodelsvisibility_event_handler);
// remove subscription to the RenderModelsVisibility event later by the handler function
VR.EventRenderModelsVisibility.Disconnect(rendermodelsvisibility_event_handler);
//////////////////////////////////////////////////////////////////////////////
// 3. Subscribe to an event and unsubscribe later via an EventConnection instance
//////////////////////////////////////////////////////////////////////////////
// define a connection to be used to unsubscribe later
EventConnection rendermodelsvisibility_event_connection;
// subscribe to the RenderModelsVisibility event with a lambda handler function and keeping the connection
rendermodelsvisibility_event_connection = VR.EventRenderModelsVisibility.Connect((bool visible) => {
Log.Message("Handling RenderModelsVisibility event lambda\n");
}
);
// ...
// you can temporarily disable a particular event connection
rendermodelsvisibility_event_connection.Enabled = false;
// ... perform certain actions
// and enable it back when necessary
rendermodelsvisibility_event_connection.Enabled = true;
// ...
// remove the subscription later using the saved connection
rendermodelsvisibility_event_connection.Disconnect();
//////////////////////////////////////////////////////////////////////////////
// 4. Ignoring RenderModelsVisibility events when necessary
//////////////////////////////////////////////////////////////////////////////
// you can temporarily disable the event to perform certain actions without triggering it
VR.EventRenderModelsVisibility.Enabled = false;
// ... actions to be performed
// and enable it back when necessary
VR.EventRenderModelsVisibility.Enabled = true;
Event EventAudioSettingsChanged#
The Event triggered when the audio settings changed. You can subscribe to events via
Connect()
and unsubscribe via
Disconnect(). You can also use
EventConnection
and
EventConnections
classes for convenience (see examples below).
The event handler signature is as follows: myhandler( )
For more details see the Event Handling article.
Usage Example
// implement the AudioSettingsChanged event handler
void audiosettingschanged_event_handler()
{
Log.Message("\Handling AudioSettingsChanged event\n");
}
//////////////////////////////////////////////////////////////////////////////
// 1. Multiple subscriptions can be linked to an EventConnections instance
// class that you can use later to remove all these subscriptions at once
//////////////////////////////////////////////////////////////////////////////
// create an instance of the EventConnections class
EventConnections audiosettingschanged_event_connections = new EventConnections();
// link to this instance when subscribing to an event (subscription to various events can be linked)
VR.EventAudioSettingsChanged.Connect(audiosettingschanged_event_connections, audiosettingschanged_event_handler);
// other subscriptions are also linked to this EventConnections instance
// (e.g. you can subscribe using lambdas)
VR.EventAudioSettingsChanged.Connect(audiosettingschanged_event_connections, () => {
Log.Message("Handling AudioSettingsChanged event lambda\n");
}
);
// later all of these linked subscriptions can be removed with a single line
audiosettingschanged_event_connections.DisconnectAll();
//////////////////////////////////////////////////////////////////////////////
// 2. You can subscribe and unsubscribe via the handler function directly
//////////////////////////////////////////////////////////////////////////////
// subscribe to the AudioSettingsChanged event with a handler function
VR.EventAudioSettingsChanged.Connect(audiosettingschanged_event_handler);
// remove subscription to the AudioSettingsChanged event later by the handler function
VR.EventAudioSettingsChanged.Disconnect(audiosettingschanged_event_handler);
//////////////////////////////////////////////////////////////////////////////
// 3. Subscribe to an event and unsubscribe later via an EventConnection instance
//////////////////////////////////////////////////////////////////////////////
// define a connection to be used to unsubscribe later
EventConnection audiosettingschanged_event_connection;
// subscribe to the AudioSettingsChanged event with a lambda handler function and keeping the connection
audiosettingschanged_event_connection = VR.EventAudioSettingsChanged.Connect(() => {
Log.Message("Handling AudioSettingsChanged event lambda\n");
}
);
// ...
// you can temporarily disable a particular event connection
audiosettingschanged_event_connection.Enabled = false;
// ... perform certain actions
// and enable it back when necessary
audiosettingschanged_event_connection.Enabled = true;
// ...
// remove the subscription later using the saved connection
audiosettingschanged_event_connection.Disconnect();
//////////////////////////////////////////////////////////////////////////////
// 4. Ignoring AudioSettingsChanged events when necessary
//////////////////////////////////////////////////////////////////////////////
// you can temporarily disable the event to perform certain actions without triggering it
VR.EventAudioSettingsChanged.Enabled = false;
// ... actions to be performed
// and enable it back when necessary
VR.EventAudioSettingsChanged.Enabled = true;
Event<int> EventDeviceRenderModelChanged#
The Event triggered when the render model of the VR device is changed. You can subscribe to events via
Connect()
and unsubscribe via
Disconnect(). You can also use
EventConnection
and
EventConnections
classes for convenience (see examples below).
The event handler signature is as follows: myhandler(int vr_device_number )
For more details see the Event Handling article.
Usage Example
// implement the DeviceRenderModelChanged event handler
void devicerendermodelchanged_event_handler(int vr_device_number)
{
Log.Message("\Handling DeviceRenderModelChanged event\n");
}
//////////////////////////////////////////////////////////////////////////////
// 1. Multiple subscriptions can be linked to an EventConnections instance
// class that you can use later to remove all these subscriptions at once
//////////////////////////////////////////////////////////////////////////////
// create an instance of the EventConnections class
EventConnections devicerendermodelchanged_event_connections = new EventConnections();
// link to this instance when subscribing to an event (subscription to various events can be linked)
VR.EventDeviceRenderModelChanged.Connect(devicerendermodelchanged_event_connections, devicerendermodelchanged_event_handler);
// other subscriptions are also linked to this EventConnections instance
// (e.g. you can subscribe using lambdas)
VR.EventDeviceRenderModelChanged.Connect(devicerendermodelchanged_event_connections, (int vr_device_number) => {
Log.Message("Handling DeviceRenderModelChanged event lambda\n");
}
);
// later all of these linked subscriptions can be removed with a single line
devicerendermodelchanged_event_connections.DisconnectAll();
//////////////////////////////////////////////////////////////////////////////
// 2. You can subscribe and unsubscribe via the handler function directly
//////////////////////////////////////////////////////////////////////////////
// subscribe to the DeviceRenderModelChanged event with a handler function
VR.EventDeviceRenderModelChanged.Connect(devicerendermodelchanged_event_handler);
// remove subscription to the DeviceRenderModelChanged event later by the handler function
VR.EventDeviceRenderModelChanged.Disconnect(devicerendermodelchanged_event_handler);
//////////////////////////////////////////////////////////////////////////////
// 3. Subscribe to an event and unsubscribe later via an EventConnection instance
//////////////////////////////////////////////////////////////////////////////
// define a connection to be used to unsubscribe later
EventConnection devicerendermodelchanged_event_connection;
// subscribe to the DeviceRenderModelChanged event with a lambda handler function and keeping the connection
devicerendermodelchanged_event_connection = VR.EventDeviceRenderModelChanged.Connect((int vr_device_number) => {
Log.Message("Handling DeviceRenderModelChanged event lambda\n");
}
);
// ...
// you can temporarily disable a particular event connection
devicerendermodelchanged_event_connection.Enabled = false;
// ... perform certain actions
// and enable it back when necessary
devicerendermodelchanged_event_connection.Enabled = true;
// ...
// remove the subscription later using the saved connection
devicerendermodelchanged_event_connection.Disconnect();
//////////////////////////////////////////////////////////////////////////////
// 4. Ignoring DeviceRenderModelChanged events when necessary
//////////////////////////////////////////////////////////////////////////////
// you can temporarily disable the event to perform certain actions without triggering it
VR.EventDeviceRenderModelChanged.Enabled = false;
// ... actions to be performed
// and enable it back when necessary
VR.EventDeviceRenderModelChanged.Enabled = true;
bool IsSteamVRDashboardActive#
The value indicating if the SteamVR controllers are rendered. When you access the SteamVR menu during the application runtime, the SteamVR controllers start to be rendered along with the application controllers. You can use this function to check the state of the SteamVR controllers and disable the application controllers to avoid performance drops caused by the simultaneous rendering of both controllers.
VR.RUNTIME_TYPE InputRuntimeType#
The type of the VR input runtime.
string InputRuntimeName#
The name of the VR input runtime.
VR.DEBUG_MODE DebugMode#
The debug mode for VR. If the debug mode is disabled, displaying of GAPI errors in VR runtime is also disabled.
Members
ivec2 GetHMDResolution ( VR.VIEWPORT_TYPE viewport_type = Enum.VR.VIEWPORT_TYPE.CONTEXT ) #
Returns the current resolution of the head-mounted display. For HMDs having context (peripheral) and focus displays, you should specify the viewport type.Arguments
- VR.VIEWPORT_TYPE viewport_type - Type of the viewport (for HMDs having context (peripheral) and focus displays).
Return value
HMD resolution.bool HasFeatureMixedReality ( ) #
Returns a value indicating if the mixed reality mode is available. Mixed reality enables you to combine real-world view from front-facing cameras mounted on the headset with the VR image rendered. This feature is available for the Varjo devices only.If VR is not initialized, the function will return false.
Return value
true if the feature is available; otherwise, false.bool HasFeatureEyeTracking ( ) #
Returns a value indicating if eye tracking is available. This feature is available for the Varjo devices only.If VR is not initialized, the function will return false.
Return value
true if the feature is available; otherwise, false.bool HasFeatureHandTracking ( ) #
Returns a value indicating if hand tracking is available. This feature is available for the Varjo devices only.If VR is not initialized, the function will return false.
Return value
true if the feature is available; otherwise, false.bool HasFeatureTrackingSpaceRaw ( ) #
Returns a value indicating if poses can be provided in the coordinate system defined by the tracker driver.If VR is not initialized, the function will return false.
Return value
true if the feature is available; otherwise, false.bool HasFeatureMotionPrediction ( ) #
Returns a value indicating if motion prediction is available. This feature is available for the Varjo devices only. It allows the engine to submit the velocity from the GBuffer to the Varjo Composer.If VR is not initialized, the function will return false.
Return value
true if the feature is available; otherwise, false.bool HasFeatureFoveatedRendering ( ) #
Returns a value indicating if foveated rendering is available. This feature is available for the Varjo devices only. Foveated rendering enhances performance by using the eye tracking functionality in Varjo headsets: it decreases the image quality in the peripheral areas where the user is not looking. Foveation allows applications to render fewer pixels and achieve a better VR experience.If VR is not initialized, the function will return false.
Return value
true if the feature is available; otherwise, false.bool HasFeatureReportProximitySensor ( ) #
Returns a value indicating if proximity sensor reporting is available.If VR is not initialized, the function will return false.
Return value
true if the feature is available; otherwise, false.bool HasFeatureSupportForTreadmill ( ) #
Returns a value indicating if the user treadmill support is available.If VR is not initialized, the function will return false.
Return value
true if the feature is available; otherwise, false.bool HasFeatureSupportForBaseStations ( ) #
Returns a value indicating if the base stations support is available.If VR is not initialized, the function will return false.
Return value
true if the feature is available; otherwise, false.bool HasFeatureSupportForTrackers ( ) #
Returns a value indicating if support for trackers is available.If VR is not initialized, the function will return false.
Return value
true if the feature is available; otherwise, false.bool HasFeatureSupportForRenderModelComponents ( ) #
Returns a value indicating if support for render model components is available.If VR is not initialized, the function will return false.
Return value
true if the feature is available; otherwise, false.bool ResetZeroPose ( ) #
Sets the zero pose to the current tracker position.Return value
true if the pose is reset successfully; otherwise, false.bool HasFeatureSupportForRenderModel ( ) #
Returns a value indicating if VR API can provide Render Models for the controllers.If VR is not initialized, the function will return false.
Return value
true if the feature is available; otherwise, false.bool HasFeatureFadeToColor ( ) #
Returns a value indicating if the FadeToColor feature is available.If VR is not initialized, the function will return false.
Return value
true if the feature is available; otherwise, false.bool HasFeatureFadeGrid ( ) #
Returns the value indicating if the FadeGrid feature is available.If VR is not initialized, the function will return false.
Return value
true if the feature is available; otherwise, false.bool HasFeatureGetAudioDevice ( ) #
Returns the value indicating if VR API can return Audio Device name (usually Oculus only).If VR is not initialized, the function will return false.
Return value
true if the feature is available; otherwise, false.void FadeToColor ( float seconds, vec4 color, bool background ) #
Fades the engine render to the specified color over time.Arguments
- float seconds - Fade period, in seconds.
- vec4 color - Target color.
- bool background
void FadeGrid ( float seconds, bool fade_in ) #
Fades the engine render to/from the grid over the specified time.Arguments
- float seconds - Fade period, in seconds.
- bool fade_in - true fades render to grid; false fades grid to render.
Last update:
2024-12-13
Help improve this article
Was this article helpful?
(or select a word/phrase and press Ctrl+Enter)