Rendering 3D Widget to Stereo Layer

Hi,

Is there a way to render a 3D Widget to the Stereo Layer Component?

My goal is to use the Stereo Layer component for world located user interfaces since text is better readable. But it should remain interactive.

Cheers,

Bump. The only workaround I have is to use separate textures: “Score = 1”, “Score = 2”. Not as useful as automagic UMG.

Rendering widgets is actually rather simple. Just look at how WidgetComponent does it for a reference. The magic comes from FWidgetRenderer, which is the logic that UMG uses to draw a WidgetComponent to a render target. WidgetComponent renders to a surface using a material, and StereoLayer merely takes a Texture as an input, so it’s even simpler.

Basically, just create a render target, pass that render target to your stereo layer:

		UTextureRenderTarget2D* WidgetTarget = NewObject<UTextureRenderTarget2D>();
		WidgetTarget->Filter = TF_Bilinear;
		WidgetTarget->ClearColor = FLinearColor::Transparent;
		//WidgetTarget->SRGB = true;
		WidgetTarget->TargetGamma = 1;
		WidgetTarget->InitCustomFormat( 2048, 2048, PF_B8G8R8A8, true );
		WidgetTarget->UpdateResource();

		UStereoLayerComponent* StereoLayer = NewObject<UStereoLayerComponent>( Controller );
		StereoLayer->RelativeLocation = FVector( 100.0f, 0.0f, 0.0f );
		StereoLayer->SetQuadSize( FVector2D( 150.0f, 150.0f ) );
		StereoLayer->SetTexture( WidgetTarget );
		StereoLayer->RegisterComponentWithWorld( Controller->GetWorld() );

Then, just call FWidgetRenderer’s DrawWidget whenever your UI needs an update:

StereoWidgetRenderer->DrawWidget( WidgetTarget, Widget.ToSharedRef(), FVector2D( 2048.0f, 2048.0f ), DeltaTime );
StereoLayer->MarkTextureForUpdate();

If your widget updates every tick, you might as well set bLiveTexture = true on your stereo layer and avoid calling MarkTextureForUpdate.

Just bear in mind that these are just sample values – rendering UI through a stereo layer is more expensive due to an extra pass, so don’t use 2048x2048 render targets unless you really need it.

Making widgets respond to input is a wholly different beast, and one I honestly haven’t bothered with.

Hi,
as said you have to pass the texture of your widget to the stereo layer.

there’s a tutorial on youtube named “Mitch’s VR Lab Ep11 - UE4 - Stereo Layers for UI”. You can see there how to pass the texture from the widget to the stereolayer on blueprint.

If the stereolayer is aligned in world with the widget then you can use the widgetinteraction just fine. I’ve tried it and it worked. However I am having issues with the positionning of the stereo layer, that i am still working on.

A note about the world locked vs tracker locked.
Now world locked is activated in the editor (at least 4.24 fwd) but if you link the Stereo Layer to something (like myself the dash screen made in UMG to a vehicle) the world locked doesn’t work right. There is weird laggy floating going on. You can fix this with using tracker locked.

But then you need to offset the position to compensate for the location/movement.
Let’s say you have stereo layer attached to a carousel - you need to sort relative transform between player pawn and the desired location. If you do this it will all be good.