XRCamera3D / XRInterface.get_transform_for_view() position update delayed

Godot Version



Hello :slight_smile:

we are currently working on object specific outlines in VR. The idea is that we have two additional cameras (left & right eye) which render only a single render layer. The rendering itself works just fine.

The problem is that the rendering of the outline lags behind the actual rendered object but only when we move our head. When only moving the object the outline is correct.

Left Image: Correct “outline”
Right Image: Wrong “outline” while moving our head

The “MeshInstance3D” is a full screen quad with a shader responsible for a black and white image.

extends Node3D

@export var left_camera : Camera3D
@export var right_camera : Camera3D
@export var origin : XROrigin3D
@export var leftvp : SubViewport
@export var rightvp : SubViewport

func _ready():
	var m = $"../MeshInstance3D".mesh.surface_get_material(0)
	m.set("shader_parameter/left_eye", leftvp.get_texture())
	m.set("shader_parameter/right_eye", rightvp.get_texture())
	$"../MeshInstance3D".mesh.surface_set_material(0, m);

func _process(delta):
	left_camera.global_transform = XRServer.primary_interface.get_transform_for_view(0, origin.global_transform)
	right_camera.global_transform = XRServer.primary_interface.get_transform_for_view(1, origin.global_transform)

The core problem is probably the update function for our two cameras. We are using the get_transform_for_view() of the OpenXRInterface to get the current eye-locations. The documentation already states that the XRCamera3D can lag a few milliseconds behind the actual position.

Is there a way to fix this delay issue. Or any other ideas for better approaches?
Thank you for reading :slight_smile: