Transparency in Render Target 2D shows up black

Hi,

I’m trying to render a 3d widget onto a 2d texture, using a render target 2d asset created from within the editor and the FWidgetRenderer class at runtime, from within C++. But any transparency in the widget shows up as black in the resulting texture (I’m using this in the context of stereo layers for VR).

Is there anything I need to do to enable transparency when rendering or displaying the rendered texture?

UPDATE:

I just did some tests and it seams the deal is that I cannot set the clear color of the texture to “Transparent” from within the editor. That is, if in C++ I grab a reference to the texture I created in the editor and at runtime do Texture->ClearColor = FLinearColor::Transparent; then from that point onwards transparency does work.

So I guess the question is how does one set the clear color of a render target texture from within the editor?

According to the 4.14 release notes:

The “SceneColor (HDR) in RGB, Inv Opacity in A” option can be used to render objects with translucency into a texture which can then be alpha-blended over a scene or widget blueprint.

Not sure if that’s any help. It’s under the “New: Scene Capture Improvements on Mobile” section of the release notes for 4.14.

@CleanCut Thanks for the info. I’ll check it out. However, I updated my question since it looks like it’s about the texture’s clear color; I don’t know how to set it to transparent from within the editor (I only know how to from C++).

Maybe they renamed ClearColor to ChromaKeyColor in blueprints?

121542-screen+shot+2017-01-10+at+5.31.46+pm.png

ChromaKeyColor is a separate property.

You could try exposing FLinearColor ClearColor in TextureRenderTarget2D.h?

You can use “Clear Render Target 2D” in blueprint: https://puu.sh/us8HR/c2732b52e0.jpg
I’m using this to fix blackness on StereoLayer when rendering a 2D UMG .

@DeathUman the picture you posted is missing. Can you repost your solution by chance? I got the same problem with blackness on my StereoLayer using a color (0,0,0,1) if i call clear with (0,0,0,0) then all subsequent draws are not showing up, even with a material that has an alpha map.

Thanks.

This is my setup btw… it works in PIE, but once i package it, it turns black. Im on 4.17 btw.

This works for me

	Instructions_RT = NewObject<UCanvasRenderTarget2D>(this);
	Instructions_RT->InitAutoFormat(ViewSize.X / 2, ViewSize.Y);
	Instructions_RT->ClearColor = FLinearColor(0.0f, 0.0f, 0.0f, 0.0f);
	Instructions_RT->UpdateResource();

@DeathUman This is the reason why I hate people linking images for 3rd party sites. -_-

@DenisDubinin Can you expand on this. My Stereo Layer can’t show transparent when I have Support Depth on, the transparent parts just show up as black. But it works fine when it’s off.
I’ve tried all sorts of ways to change my clear colour, BP and C++ but neither seems to work. Could you please expand on what you did?

@saldavonschwartz
I’ve seen your update and you say you’ve got it working?
My stereo Layer shows as black in the (whats supposed to be) transparent parts only while I’ve got Support Depth on.
I did what you said and got a reference to the Texture (I assume you meant render target of the Widget?) and set the ClearColor but that didn’t seem to help.
Can you give any other context for how you fixed it? I’ve been trying to fix this for about 10 hours now and I’m losing my mind.

Hello, can you tell me if it was possible to fix this problem? If yes. then please tell us how you did it. Thanks

Idk what the deal is. If you set the clear color to straight alpha 0, the whole image won’t render. Ever. Even you render something with full alpha on top of it.

But in case it helps someone in the future. I just made a custom rendertarget function that allows you to set some additional parameters.

#include "Engine/CanvasRenderTarget2D.h"

	UFUNCTION(BlueprintCallable, Category = "Canvas Render Target 2D", meta = (WorldContext = "WorldContextObject"))
	static UCanvasRenderTarget2D* CreateCustomCanvasRenderTarget2D(UObject* WorldContextObject, TSubclassOf<UCanvasRenderTarget2D> CanvasRenderTarget2DClass, int32 Width = 1024, int32 Height = 1024, FLinearColor clearColor = FLinearColor(0,0,0,1), EPixelFormat pixelFormat = EPixelFormat::PF_A16B16G16R16, bool forceGamma = false);

cpp

UCanvasRenderTarget2D* UGameUtilities::CreateCustomCanvasRenderTarget2D(UObject* WorldContextObject, TSubclassOf<UCanvasRenderTarget2D> CanvasRenderTarget2DClass, int32 Width, int32 Height, FLinearColor clearColor, EPixelFormat pixelFormat, bool forceGamma)
{
	if ((Width > 0) && (Height > 0) && (CanvasRenderTarget2DClass != NULL))
	{
		UCanvasRenderTarget2D* NewCanvasRenderTarget = UCanvasRenderTarget2D::CreateCanvasRenderTarget2D(WorldContextObject, CanvasRenderTarget2DClass, Width, Height);
		if (NewCanvasRenderTarget)
		{
			NewCanvasRenderTarget->ClearColor = clearColor;
			NewCanvasRenderTarget->InitCustomFormat(Width, Height, pixelFormat, forceGamma);
			return NewCanvasRenderTarget;
		}
	}

	return nullptr;
}

good luck to everyone. I’m content with a .5 alpha on my particular project, but I don’t feel like digging anymore into source to find out why alpha clear of 0 just negates all future renders

EDIT: I’m actually wondering if the Canvas is the bigger problem with the clear. I’m not sure. It gets a little too advanced for me at those depths and I don’t have the patience to navigate them right now

EDIT2: Setting my decal to AlphaComposite allowed me to clear to transparent black without the following calls also being disregarded. However, I am still unable to render something black (full alpha) on top of it without it being discarded. Maybe someone more patient than me can figure out the right set of settings.