How to use UStereoLayerComponent with HTC/Vive?

Hello,

I’ve been working on implementing a kind of Heads Up Display (HUD) for my VR game.

I’ve found that UStereoLayerComponent is the component to go for.

I need a cylinder HUD layer and it seems the cylinder layer parameters were not exposed to the C++ code (they are protected in engine code but exposed to the editor). Hence I inherited a new UTWVRHUDLayerComponent (TWVR comes from my project name) from UStereoLayerComponent and exposed the cylinder layer parameters from it via public functions.

Then I’ve written a separate component called UPlayerUIManager and attached it to my player pawn class. This component creates a render target, a new UTWVRHUDLayerComponent and spawns my custom Hud Widget within itself. This hud widget is exposed to the editor so it can be designed and set there.

Initialization code then assigns the render target to the UPlayerHUDLayerComponent. And it looks like this:

To draw my custom widget on to the render texture I keep an instance of FWidgetRenderer within the class as well. (initialized at the end)

At each tick of the parent actor I render the widget again on the render target and set my stereo layer component so that it updates itself. This happens via Update_Internal function that is called from the player pawn class within its Tick().

My problem is… no matter what I do I fail to render the widget on the HUD. At runtime I checked the values set to my TWVRHudLayerComponent and it seems that the widget is rendered and set to the render target correctly. But somehow it is not displayed on the layer and nothing happens.

What may be the cause of this problem? Is StereoLayer supported in HTC Vive?

I’ve also noticed that I cannot debug the DrawWidget() function.

Eventually I’ve found a solution to my own question. I post it here for other fellows who get stuck with this…

It appears that the UStereoLayerComponent (or any class which extends from it) shall not be attached directly to the pawn’s camera as a component.

UStereoLayerComponent should be first attached to a seperate actor (I called mine APlayerHUDActor) and then an instance of this actor (APlayerHUDActor) should be spawned and attached to the camera component within the player controlled pawn class (whatever you have).

APlayerHUDActor can instantiate and attach its default UStereoLayerComponent in its own constructor.

This way you can set the stereo layer parameters directly from a blueprint inheritting the APlayerHUDActor within the editor. And this blueprint’s viewport will also display a neat shape estimation of the hud (when you click its UStereoLayerComponent).

My UPlayerUIManager above now holds a reference to the class type of widget and the APlayerHUDActor which can both be set from the editor. It spawns both of them and initializes the APlayerHUDActor with the spawned widget. APlayerHUDActor includes most of the above linked code (creation of the render target, renderer, the update routine etc) but only keeps the shared widget pointer within itself.

However it appears that only the Quad shape stereo layer is currently supported in HTC/Vive. And if you set its parameter to cylinder the UI will not draw.

You’ll need to set relative transform of the UStereoLayerComponent so that the x-value (forward direction) is set to something between 30-100 centimeters. Lower values than 30 centimeters is hard to focus with the eye and appears blurry. Also you may want to set the z-value to something like -10 centimeters as it appears that the stereo layer is placed slightly above the image center in HTC/Vive.