A simple way to use a render target and scene capture component to render to a Scaleform4/AS3 based HUD without color masking or other kind of complex material.

Download: RTT20130413.7z 4Shared

There is only really one bit of AS3 to worry about, which is the addRTT function:

		public function addRTT(name:String, source:String):void {
			var RTTParent:DisplayObject = getChildByName(name);

			// Only proceed if we have a valid object.
			if (RTTParent) {
				var ViewLoader:UILoader = new UILoader();
				ViewLoader.name = name + "_RTT";
				ViewLoader.source = source;
				// If you need to turn them on/off etc, enabled this.
				ViewLoader.enableInitCallback = false;
				// Not a mistake - don't think it cares if its true or false.
				ViewLoader.visible = false;
				// Enabling this will make you have a bad day.
				ViewLoader.autoSize = false;
				// Make sure the alpha is set correctly!
				ViewLoader.alpha = 255;
				ViewLoader.x = RTTParent.x;
				ViewLoader.y = RTTParent.y;
				ViewLoader.width = RTTParent.width;
				ViewLoader.height = RTTParent.height;

Note the alpha.
If your mesh is translucent, adjust it.

In your GFx related UScript class, you will need call the AS3 function with the follow:

function AddRTT(string ParentName, string RTTPath)

This can be in a Widget or Movie – you just need to adjust the string a bit.
See RTTGFxHUD:AddRTT() for more information.

When creating the TextureRenderTarget2D, you must make be sure that its background color matches the SceneCapture2DComponent’s clear color.

UIRenderTexture = class'TextureRenderTarget2D'.static.Create(width, height, , MakeLinearColor(0.0f, 0.0f, 0.0f, 1.0f));

And finally, the SceneCapture2DComponent needs one important change – the far plane.
You need to set this far enough to encompass what you want to render. Beyond this distance nothing will be sent to the renderedtexture, thereby eliminating the need to mask out colours etc.

	Begin Object Class=SceneCapture2DComponent Name=RTTComponent
	End Object

And there you go – done.
No need for a material or even a background mesh.

Included in the source is a simple actor that you can spawn that with an attached SceneCapture2DComponent that also creates the TextureRenderTarget2D and keeps a reference to it for usage in a HUD/UI. The only thing you need to remember to do is create it out in an unused part of the map or use the bOnlyOwnerSee variable etc.

Hope you find this useful.

3 thoughts on “UI Render To Texture

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s