Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions xr/openxr_spectator_view/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Normalize EOL for all files that Git considers text files.
* text=auto eol=lf
2 changes: 2 additions & 0 deletions xr/openxr_spectator_view/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Godot 4+ specific ignores
.godot/
74 changes: 74 additions & 0 deletions xr/openxr_spectator_view/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# XR spectator view demo

This is a demo for an OpenXR project where the player sees a different view inside of the headset
compared to what a spectator sees on screen.
When deployed to a standalone XR device, only the player environment is exported.

Language: GDScript

Renderer: Compatibility

Check out this demo on the asset library: https://godotengine.org/asset-library/asset/????

## How does it work?

The VR game itself is contained within the `main.tscn` scene. This is similar to the other XR demos found on this repo.
This demo has a bare bones example as to not distract from the solution we're presenting here.

When run on standalone VR headsets, that scene is loaded.
![Project setup](screenshots/project_setup_main_scene.png)

When run on desktop, we load the `spectator.tscn` scene instead (used to be called `construct.tscn`). This scene has the `main.tscn` scene as a child of a
`SubViewport` which will be used to output the render result to the headset.

![Construct scene](screenshots/construct_scene.png)

The spectator scene also contains a `SubviewportContainer` with a `SubViewport` that renders the output that the user
sees on the desktop screen.
By default this will show a 3rd person camera that shows our player.

We've also configured our visual layers as follows:
1. Layer 1 is visible both inside of the headset and by the 3rd person camera.
2. Layer 2 is only visible inside of the headset.
3. Layer 3 is only visible in the 3rd person camera.
This is used to render the "head" of the player in spectator view only.

Finally, a dropdown also allows us to switch to:
- show the 3rd person camera view,
- show a 1st person camera view but with a stabilized camera,
- showing either the left eye or right eye result the player is seeing.

## Tracked camera

There is also an option in the demo to enable camera tracking.
This is currently only supported on SteamVR together with a properly configured HTC Vive Tracker.

When properly setup, this allows you to use a Vive tracker to position the 3rd person camera.
Attaching the Vive tracker to a physical camera, and setting the correct offset would allow
implementation of mixed reality capture by combining the 3rd person render result,
with a green screened captured camera.

## Action map

This project does not use the default action map but instead configures an action map that just contains the actions required for this example to work. This so we remove any clutter and just focus on the functionality being demonstrated.

There is only one action needed for this example:
- hand_pose is used to position the XR controllers

Also following OpenXR guidelines only bindings for controllers with which the project has been tested are supplied. XR Runtimes should provide proper re-mapping however not all follow this guideline. You may need to add a binding for the platform you are using to the action map.

## Running on PCVR

This project is specifically designed for PCVR. Ensure that an OpenXR runtime has been installed.
This project has been tested with the Oculus client and SteamVR OpenXR runtimes.
Note that Godot currently can't run using the WMR OpenXR runtime. Install SteamVR with WMR support.

## Running on standalone VR

This project also shows how deploying to standalone skips the spectator view option.
You must install the Android build templates and [OpenXR vendors plugin](https://github.com/GodotVR/godot_openxr_vendors/releases) and configure an export template for your device.
Please follow [the instructions for deploying on Android in the manual](https://docs.godotengine.org/en/stable/tutorials/xr/deploying_to_android.html).

## Screenshots

![Screenshot](screenshots/spectator_view_demo.png)
Binary file added xr/openxr_spectator_view/assets/pattern.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions xr/openxr_spectator_view/assets/pattern.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://rek0t7kubpx4"
path.s3tc="res://.godot/imported/pattern.png-cf6f03dfd1cdd4bc35da3414e912103d.s3tc.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
}

[deps]

source_file="res://assets/pattern.png"
dest_files=["res://.godot/imported/pattern.png-cf6f03dfd1cdd4bc35da3414e912103d.s3tc.ctex"]

[params]

compress/mode=2
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=0
1 change: 1 addition & 0 deletions xr/openxr_spectator_view/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions xr/openxr_spectator_view/icon.svg.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://cqneypbjryrwv"
path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://icon.svg"
dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false
9 changes: 9 additions & 0 deletions xr/openxr_spectator_view/main.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
extends "res://start_vr.gd"

@export var tracked_camera : Node3D:
set(value):
tracked_camera = value
if tracked_camera:
%CameraRemoteTransform3D.remote_path = tracked_camera.get_path()
else:
%CameraRemoteTransform3D.remote_path = NodePath()
1 change: 1 addition & 0 deletions xr/openxr_spectator_view/main.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://dknfswmyiegk8
52 changes: 52 additions & 0 deletions xr/openxr_spectator_view/main.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
[gd_scene load_steps=5 format=3 uid="uid://cn6s3kxlkt6ml"]

[ext_resource type="Script" path="res://main.gd" id="1_2eojn"]
[ext_resource type="PackedScene" uid="uid://ckuw0ps7vjw7e" path="res://world/world.tscn" id="2_j3t0x"]

[sub_resource type="SphereMesh" id="SphereMesh_b2416"]
radius = 0.1
height = 0.2

[sub_resource type="BoxMesh" id="BoxMesh_go2t1"]
size = Vector3(0.1, 0.1, 0.1)

[node name="Main" type="Node3D"]
script = ExtResource("1_2eojn")
maximum_refresh_rate = 120

[node name="XROrigin3D" type="XROrigin3D" parent="."]

[node name="XRCamera3D" type="XRCamera3D" parent="XROrigin3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.8, 0)
cull_mask = 1048571

[node name="PlaceholderHead" type="MeshInstance3D" parent="XROrigin3D/XRCamera3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.0335748, 0.0557129)
layers = 4
mesh = SubResource("SphereMesh_b2416")

[node name="LeftHand" type="XRController3D" parent="XROrigin3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.5, 1, -0.5)
tracker = &"left_hand"
pose = &"hand_pose"

[node name="PlaceholderHand" type="MeshInstance3D" parent="XROrigin3D/LeftHand"]
mesh = SubResource("BoxMesh_go2t1")

[node name="RightHand" type="XRController3D" parent="XROrigin3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.5, 1, -0.5)
tracker = &"right_hand"
pose = &"hand_pose"

[node name="PlaceholderHand" type="MeshInstance3D" parent="XROrigin3D/RightHand"]
mesh = SubResource("BoxMesh_go2t1")
skeleton = NodePath("../../LeftHand")

[node name="CameraTracker" type="XRController3D" parent="XROrigin3D"]
tracker = &"/user/vive_tracker_htcx/role/camera"
pose = &"camera_pose"

[node name="CameraRemoteTransform3D" type="RemoteTransform3D" parent="XROrigin3D/CameraTracker"]
unique_name_in_owner = true

[node name="World" parent="." instance=ExtResource("2_j3t0x")]
102 changes: 102 additions & 0 deletions xr/openxr_spectator_view/openxr_action_map.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
[gd_resource type="OpenXRActionMap" load_steps=24 format=3 uid="uid://dhxuabt5tjwbt"]

[sub_resource type="OpenXRAction" id="OpenXRAction_bmp3j"]
resource_name = "hand_pose"
localized_name = "Hand pose"
action_type = 3
toplevel_paths = PackedStringArray("/user/hand/left", "/user/hand/right", "/user/vive_tracker_htcx/role/left_foot", "/user/vive_tracker_htcx/role/right_foot", "/user/vive_tracker_htcx/role/left_shoulder", "/user/vive_tracker_htcx/role/right_shoulder", "/user/vive_tracker_htcx/role/left_elbow", "/user/vive_tracker_htcx/role/right_elbow", "/user/vive_tracker_htcx/role/left_knee", "/user/vive_tracker_htcx/role/right_knee", "/user/vive_tracker_htcx/role/waist", "/user/vive_tracker_htcx/role/chest", "/user/vive_tracker_htcx/role/camera", "/user/vive_tracker_htcx/role/keyboard", "/user/eyes_ext")

[sub_resource type="OpenXRAction" id="OpenXRAction_ei2gi"]
resource_name = "haptic"
localized_name = "Haptic"
action_type = 4
toplevel_paths = PackedStringArray("/user/hand/left", "/user/hand/right", "/user/vive_tracker_htcx/role/left_foot", "/user/vive_tracker_htcx/role/right_foot", "/user/vive_tracker_htcx/role/left_shoulder", "/user/vive_tracker_htcx/role/right_shoulder", "/user/vive_tracker_htcx/role/left_elbow", "/user/vive_tracker_htcx/role/right_elbow", "/user/vive_tracker_htcx/role/left_knee", "/user/vive_tracker_htcx/role/right_knee", "/user/vive_tracker_htcx/role/waist", "/user/vive_tracker_htcx/role/chest", "/user/vive_tracker_htcx/role/camera", "/user/vive_tracker_htcx/role/keyboard")

[sub_resource type="OpenXRActionSet" id="OpenXRActionSet_43ynn"]
resource_name = "godot"
localized_name = "Godot action set"
actions = [SubResource("OpenXRAction_bmp3j"), SubResource("OpenXRAction_ei2gi")]

[sub_resource type="OpenXRIPBinding" id="OpenXRIPBinding_6ivru"]
action = SubResource("OpenXRAction_bmp3j")
binding_path = "/user/hand/left/input/aim/pose"

[sub_resource type="OpenXRIPBinding" id="OpenXRIPBinding_vfhwq"]
action = SubResource("OpenXRAction_bmp3j")
binding_path = "/user/hand/right/input/aim/pose"

[sub_resource type="OpenXRIPBinding" id="OpenXRIPBinding_5w03k"]
action = SubResource("OpenXRAction_ei2gi")
binding_path = "/user/hand/left/output/haptic"

[sub_resource type="OpenXRIPBinding" id="OpenXRIPBinding_typ1r"]
action = SubResource("OpenXRAction_ei2gi")
binding_path = "/user/hand/right/output/haptic"

[sub_resource type="OpenXRInteractionProfile" id="OpenXRInteractionProfile_3e47y"]
interaction_profile_path = "/interaction_profiles/khr/simple_controller"
bindings = [SubResource("OpenXRIPBinding_6ivru"), SubResource("OpenXRIPBinding_vfhwq"), SubResource("OpenXRIPBinding_5w03k"), SubResource("OpenXRIPBinding_typ1r")]

[sub_resource type="OpenXRIPBinding" id="OpenXRIPBinding_clvbf"]
action = SubResource("OpenXRAction_bmp3j")
binding_path = "/user/hand/left/input/aim/pose"

[sub_resource type="OpenXRIPBinding" id="OpenXRIPBinding_5bppb"]
action = SubResource("OpenXRAction_bmp3j")
binding_path = "/user/hand/right/input/aim/pose"

[sub_resource type="OpenXRIPBinding" id="OpenXRIPBinding_3k6la"]
action = SubResource("OpenXRAction_ei2gi")
binding_path = "/user/hand/left/output/haptic"

[sub_resource type="OpenXRIPBinding" id="OpenXRIPBinding_i8esw"]
action = SubResource("OpenXRAction_ei2gi")
binding_path = "/user/hand/right/output/haptic"

[sub_resource type="OpenXRInteractionProfile" id="OpenXRInteractionProfile_ucbdf"]
interaction_profile_path = "/interaction_profiles/oculus/touch_controller"
bindings = [SubResource("OpenXRIPBinding_clvbf"), SubResource("OpenXRIPBinding_5bppb"), SubResource("OpenXRIPBinding_3k6la"), SubResource("OpenXRIPBinding_i8esw")]

[sub_resource type="OpenXRIPBinding" id="OpenXRIPBinding_um1hv"]
action = SubResource("OpenXRAction_bmp3j")
binding_path = "/user/hand/left/input/aim/pose"

[sub_resource type="OpenXRIPBinding" id="OpenXRIPBinding_oqnsu"]
action = SubResource("OpenXRAction_bmp3j")
binding_path = "/user/hand/right/input/aim/pose"

[sub_resource type="OpenXRIPBinding" id="OpenXRIPBinding_r5bl7"]
action = SubResource("OpenXRAction_ei2gi")
binding_path = "/user/hand/left/output/haptic"

[sub_resource type="OpenXRIPBinding" id="OpenXRIPBinding_ytptc"]
action = SubResource("OpenXRAction_ei2gi")
binding_path = "/user/hand/right/output/haptic"

[sub_resource type="OpenXRInteractionProfile" id="OpenXRInteractionProfile_oejwx"]
interaction_profile_path = "/interaction_profiles/bytedance/pico4_controller"
bindings = [SubResource("OpenXRIPBinding_um1hv"), SubResource("OpenXRIPBinding_oqnsu"), SubResource("OpenXRIPBinding_r5bl7"), SubResource("OpenXRIPBinding_ytptc")]

[sub_resource type="OpenXRIPBinding" id="OpenXRIPBinding_iphn4"]
action = SubResource("OpenXRAction_bmp3j")
binding_path = "/user/hand/left/input/aim/pose"

[sub_resource type="OpenXRIPBinding" id="OpenXRIPBinding_3p2as"]
action = SubResource("OpenXRAction_bmp3j")
binding_path = "/user/hand/right/input/aim/pose"

[sub_resource type="OpenXRIPBinding" id="OpenXRIPBinding_wdehm"]
action = SubResource("OpenXRAction_ei2gi")
binding_path = "/user/hand/left/output/haptic"

[sub_resource type="OpenXRIPBinding" id="OpenXRIPBinding_clfly"]
action = SubResource("OpenXRAction_ei2gi")
binding_path = "/user/hand/right/output/haptic"

[sub_resource type="OpenXRInteractionProfile" id="OpenXRInteractionProfile_ggrkr"]
interaction_profile_path = "/interaction_profiles/valve/index_controller"
bindings = [SubResource("OpenXRIPBinding_iphn4"), SubResource("OpenXRIPBinding_3p2as"), SubResource("OpenXRIPBinding_wdehm"), SubResource("OpenXRIPBinding_clfly")]

[resource]
action_sets = [SubResource("OpenXRActionSet_43ynn")]
interaction_profiles = [SubResource("OpenXRInteractionProfile_3e47y"), SubResource("OpenXRInteractionProfile_ucbdf"), SubResource("OpenXRInteractionProfile_oejwx"), SubResource("OpenXRInteractionProfile_ggrkr")]
Binary file not shown.
36 changes: 36 additions & 0 deletions xr/openxr_spectator_view/project.godot
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
; Engine configuration file.
; It's best edited using the editor UI and not directly,
; since the parameters that go here are not all obvious.
;
; Format:
; [section] ; section goes between []
; param=value ; assign values to parameters

config_version=5

[application]

config/name="Openxr Spectator View Demo"
run/main_scene="res://spectator.tscn"
config/features=PackedStringArray("4.5", "Mobile")
config/icon="res://icon.svg"
run/main_scene.android="res://main.tscn"

[layer_names]

3d_render/layer_1="Default"
3d_render/layer_2="VR only"
3d_render/layer_3="Spectator only"

[rendering]

renderer/rendering_method="gl_compatibility"
renderer/rendering_method.mobile="gl_compatibility"

[xr]

openxr/enabled=true
openxr/reference_space=2
openxr/foveation_level=3
openxr/foveation_dynamic=true
shaders/enabled=true
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading