Skip to content

Commit 8be477c

Browse files
authored
Merge pull request #1212 from BastiaanOlij/mobile_vr_interface_demo
Simple demo for Mobile VR Interface
2 parents 1cd5f27 + 16f4b10 commit 8be477c

File tree

13 files changed

+311
-0
lines changed

13 files changed

+311
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8

xr/mobile_vr_interface_demo/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Mobile VR interfae demo
2+
3+
This is a really simple demo that shows how the mobile VR interface can be enabled.
4+
This is a great little project to test stereo rendering on desktop without needing XR hardware.
5+
When used on mobile devices simple 3DOF headtracking can be tested.
6+
7+
Language: GDScript
8+
9+
Renderer: Compatibility, Mobile, Forward+
10+
11+
Check out this demo on the asset library: https://godotengine.org/asset-library/asset/0000
12+
13+
## How does it work?
14+
15+
This sample shows the simplest form for enabling and testing an XR application.
16+
It uses the build in Mobile VR Interface.
17+
18+
There is simple left/right/up/down movement on desktop.
19+
20+
## Shortcomings
21+
22+
Note that currently lens distortion in the mobile VR interface is **not** supported in the compatibility renderer.
23+
24+
## Screenshots
25+
26+
![Screenshot](screenshots/mobile_vr_interface_demo.png)

xr/mobile_vr_interface_demo/icon.svg

Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
[remap]
2+
3+
importer="texture"
4+
type="CompressedTexture2D"
5+
uid="uid://w0uxqbioh10s"
6+
path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"
7+
metadata={
8+
"vram_texture": false
9+
}
10+
11+
[deps]
12+
13+
source_file="res://icon.svg"
14+
dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"]
15+
16+
[params]
17+
18+
compress/mode=0
19+
compress/high_quality=false
20+
compress/lossy_quality=0.7
21+
compress/uastc_level=0
22+
compress/rdo_quality_loss=0.0
23+
compress/hdr_compression=1
24+
compress/normal_map=0
25+
compress/channel_pack=0
26+
mipmaps/generate=false
27+
mipmaps/limit=-1
28+
roughness/mode=0
29+
roughness/src_normal=""
30+
process/channel_remap/red=0
31+
process/channel_remap/green=1
32+
process/channel_remap/blue=2
33+
process/channel_remap/alpha=3
34+
process/fix_alpha_border=true
35+
process/premult_alpha=false
36+
process/normal_map_invert_y=false
37+
process/hdr_as_srgb=false
38+
process/hdr_clamp_exposure=false
39+
process/size_limit=0
40+
detect_3d/compress_to=1
41+
svg/scale=1.0
42+
editor/scale_with_editor_scale=false
43+
editor/convert_colors_with_editor_theme=false

xr/mobile_vr_interface_demo/main.gd

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
extends Node3D
2+
3+
var xr_interface : MobileVRInterface
4+
5+
# Called when the node enters the scene tree for the first time.
6+
func _ready():
7+
xr_interface = XRServer.find_interface("Native mobile")
8+
if xr_interface and xr_interface.initialize():
9+
# Disable lens distortion.
10+
# xr_interface.k1 = 0.0
11+
# xr_interface.k2 = 0.0
12+
13+
# setup viewport
14+
var vp = get_viewport()
15+
vp.use_xr = true
16+
vp.vrs_mode = Viewport.VRS_XR
17+
else:
18+
# How did we get here?
19+
get_tree().quit()
20+
21+
func _process(delta):
22+
var dir : Vector2 = Vector2()
23+
24+
if Input.is_action_pressed("ui_left"):
25+
dir.x = -1.0
26+
elif Input.is_action_pressed("ui_right"):
27+
dir.x = 1.0
28+
if Input.is_action_pressed("ui_up"):
29+
dir.y = -1.0
30+
elif Input.is_action_pressed("ui_down"):
31+
dir.y = 1.0
32+
33+
$XROrigin3D.global_position += $XROrigin3D.global_transform.basis.x * dir.x * delta
34+
$XROrigin3D.global_position += $XROrigin3D.global_transform.basis.z * dir.y * delta
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
uid://c1jgdguonfwbw

xr/mobile_vr_interface_demo/main.tscn

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
[gd_scene load_steps=11 format=3 uid="uid://bvdovvya3m7sx"]
2+
3+
[ext_resource type="Script" uid="uid://c1jgdguonfwbw" path="res://main.gd" id="1_1u602"]
4+
[ext_resource type="Texture2D" uid="uid://br4k6sn2rvgj" path="res://pattern.png" id="2_imhd6"]
5+
[ext_resource type="PackedScene" uid="uid://8m50ra15rpq1" path="res://wall.tscn" id="4_fdaxx"]
6+
7+
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_beswd"]
8+
sky_horizon_color = Color(0.64625, 0.65575, 0.67075, 1)
9+
ground_horizon_color = Color(0.64625, 0.65575, 0.67075, 1)
10+
11+
[sub_resource type="Sky" id="Sky_uvncs"]
12+
sky_material = SubResource("ProceduralSkyMaterial_beswd")
13+
14+
[sub_resource type="Environment" id="Environment_rgp66"]
15+
background_mode = 2
16+
sky = SubResource("Sky_uvncs")
17+
glow_enabled = true
18+
glow_intensity = 1.22
19+
volumetric_fog_density = 0.001
20+
21+
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_0wgu4"]
22+
albedo_color = Color(3.3691526e-07, 0.7481091, 0.1272395, 1)
23+
albedo_texture = ExtResource("2_imhd6")
24+
uv1_scale = Vector3(5, 5, 5)
25+
26+
[sub_resource type="PlaneMesh" id="PlaneMesh_y2phs"]
27+
material = SubResource("StandardMaterial3D_0wgu4")
28+
size = Vector2(25, 25)
29+
30+
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_a1cqg"]
31+
albedo_color = Color(0.713726, 0.545098, 0.780392, 1)
32+
albedo_texture = ExtResource("2_imhd6")
33+
uv1_scale = Vector3(8, 2, 1)
34+
35+
[sub_resource type="BoxMesh" id="BoxMesh_1vrbc"]
36+
material = SubResource("StandardMaterial3D_a1cqg")
37+
size = Vector3(4, 3, 1)
38+
39+
[node name="Main" type="Node3D"]
40+
script = ExtResource("1_1u602")
41+
42+
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
43+
transform = Transform3D(-0.86602384, -0.43301564, 0.2500005, 0, 0.49999815, 0.8660265, -0.50000286, 0.7499995, -0.4330103, 0, 0, 0)
44+
shadow_enabled = true
45+
46+
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
47+
environment = SubResource("Environment_rgp66")
48+
49+
[node name="XROrigin3D" type="XROrigin3D" parent="."]
50+
51+
[node name="XRCamera3D" type="XRCamera3D" parent="XROrigin3D"]
52+
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.5, 0)
53+
54+
[node name="Floor" type="MeshInstance3D" parent="."]
55+
mesh = SubResource("PlaneMesh_y2phs")
56+
57+
[node name="Wall01" type="MeshInstance3D" parent="."]
58+
transform = Transform3D(0.968213, -0.250127, 0, 0.250127, 0.968213, 0, 0, 0, 1, 0, 0.82946, -6.87257)
59+
mesh = SubResource("BoxMesh_1vrbc")
60+
61+
[node name="Wall02" type="MeshInstance3D" parent="."]
62+
transform = Transform3D(0.674941, 0.180131, 0.715546, -0.257858, 0.966183, 0, -0.691348, -0.184509, 0.698565, -3.04544, 0.82946, -5.53616)
63+
mesh = SubResource("BoxMesh_1vrbc")
64+
65+
[node name="Wall03" parent="." instance=ExtResource("4_fdaxx")]
66+
transform = Transform3D(0.90396, 0.0774667, -0.154893, 0.403151, -0.275157, 0.248304, -0.142568, -0.286902, -0.279961, -3.26749, 3.93987, -7.24752)
67+
68+
[node name="Wall04" type="MeshInstance3D" parent="."]
69+
transform = Transform3D(0.491527, 0, -0.870862, 0, 2.43615, 0, 0.870862, 0, 0.491527, 2.68331, 2.52217, -4.7792)
70+
mesh = SubResource("BoxMesh_1vrbc")
71+
72+
[node name="Wall05" parent="." instance=ExtResource("4_fdaxx")]
73+
transform = Transform3D(0.941075, 0.0774667, 0.112959, -0.0781437, -0.275157, 0.295486, 0.329045, -0.286902, -0.25289, 2.33372, 3.46393, -10.7686)
1.77 KB
Loading
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
[remap]
2+
3+
importer="texture"
4+
type="CompressedTexture2D"
5+
uid="uid://br4k6sn2rvgj"
6+
path.s3tc="res://.godot/imported/pattern.png-888ea151ee9fa7a079d3252596260765.s3tc.ctex"
7+
metadata={
8+
"imported_formats": ["s3tc_bptc"],
9+
"vram_texture": true
10+
}
11+
12+
[deps]
13+
14+
source_file="res://pattern.png"
15+
dest_files=["res://.godot/imported/pattern.png-888ea151ee9fa7a079d3252596260765.s3tc.ctex"]
16+
17+
[params]
18+
19+
compress/mode=2
20+
compress/high_quality=false
21+
compress/lossy_quality=0.7
22+
compress/uastc_level=0
23+
compress/rdo_quality_loss=0.0
24+
compress/hdr_compression=1
25+
compress/normal_map=0
26+
compress/channel_pack=0
27+
mipmaps/generate=true
28+
mipmaps/limit=-1
29+
roughness/mode=0
30+
roughness/src_normal=""
31+
process/channel_remap/red=0
32+
process/channel_remap/green=1
33+
process/channel_remap/blue=2
34+
process/channel_remap/alpha=3
35+
process/fix_alpha_border=true
36+
process/premult_alpha=false
37+
process/normal_map_invert_y=false
38+
process/hdr_as_srgb=false
39+
process/hdr_clamp_exposure=false
40+
process/size_limit=0
41+
detect_3d/compress_to=0
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
; Engine configuration file.
2+
; It's best edited using the editor UI and not directly,
3+
; since the parameters that go here are not all obvious.
4+
;
5+
; Format:
6+
; [section] ; section goes between []
7+
; param=value ; assign values to parameters
8+
9+
config_version=5
10+
11+
[application]
12+
13+
config/name="Test Stereo"
14+
run/main_scene="res://main.tscn"
15+
config/features=PackedStringArray("4.5", "Forward Plus")
16+
config/icon="res://icon.svg"
17+
run/main_scene.mobile="res://main_mobile.tscn"
18+
19+
[rendering]
20+
21+
renderer/rendering_method="gl_compatibility"
22+
renderer/rendering_method.mobile="gl_compatibility"
23+
24+
[xr]
25+
26+
openxr/foveation_level=3
27+
openxr/foveation_dynamic=true
28+
shaders/enabled=true

0 commit comments

Comments
 (0)