godotengine / godotengine/godot
Viewport Texture doesn't work with output override (OpenXR)
- Dominant language
- C++
- Stars
- 117k
- Forks
- 26.8k
- PR merge metrics
- PR metrics pending
Description
### Tested versions
- Unreproducible in 3.5
- Reproducible since 4.1.3 (maybe earlier)
- Reproducible in 4.4 master (47bc374edf6d2e775a5e6b937dc3fd73cdc6f59b)
### System information
Windows 11 - NVidia 4070ti - Quest 3 with SteamLink
### Issue description
This issue seems to have been introduced early in Godot 4's development but as this is a bit of a niche use case it hasn't gotten much attention especially as it seems to specifically be broken for OpenXR.
I decided to look into this again after someone reported the issue on Discord since I wanted to create a demo project for the setup anyway. Also initially I thought this was a Vulkan issue but it happens on OpenGL as well.
Basically, when grabbing a `ViewportTexture` from the `SubViewport` that is rendering content to the HMD, Godot renders a black screen.
Using the `MobileVRInterface` to create a similar scenario, rendering HMD output to a `SubViewport` and using a `ViewportTexture` to show the left and right eye output works fine
### Steps to reproduce
- Create a `SubViewport` for XR output, add a standard XR rig and enable `use_xr` on this viewport
- Create a ColorRect for the output to screen (so outside of the `SubViewport`) and add a `ShaderMaterial` like so:
```
shader_type canvas_item;
uniform sampler2DArray xr_texture : source_color;
uniform float layer;
void fragment() {
COLOR.rgb = texture(xr_texture, vec3(UV, layer)).rgb;
COLOR.a = 1.0;
}
```
- In a script set the `xr_texture` shader parameter to `SubViewport.get_texture()`
### Minimal reproduction project (MRP)
For reproducing this issue:
[openxr_spectator_view_demo.zip](https://github.com/user-attachments/files/18002150/openxr_spectator_view_demo.zip)
For a working example using the `MobileVRInterface`:
[teststereo.zip](https://github.com/user-attachments/files/18002159/teststereo.zip)
Contributor guide
Assessment
This issue has not been assessed yet.