I’m rendering a material to a render target on the render thread, the material renders fine except there are no alpha channel values other than 0. I’ve tried setting the material to be a Post Process material with alpha out enabled and I’ve tried Surface > Unlit > Alpha Composite Blend/Translucent/Masked and no luck.
The render target format is set as RGBA16f so the RT has alpha enabled.
Does anyone have any idea? I’ve seen others with a similar issue but using the BP function to do it.
To render on the render thread I use the following code. It’s run inside a Scene View Extension function and is based on the UKismetRenderingLibrary::DrawMaterialToRenderTarget() function.
// Get the material
UMaterialInterface* MaterialInterface = Resource->GetMaterial();
UMaterial* Material = MaterialInterface->GetMaterial();
// Ensure it's compiled
Material->EnsureIsComplete()
const FMaterialRenderProxy* MaterialRenderProxy = MaterialInterface->GetRenderProxy();
FRDGTextureRef TemporaryTexture = Resource->CreateTemporaryTexture(GraphBuilder);
FVector2D TempTextureSize = FVector2D(TemporaryTexture->Desc.Extent.X, TemporaryTexture->Desc.Extent.Y);
FScreenPassRenderTarget TemporaryTextureRenderTarget = FScreenPassRenderTarget(TemporaryTexture, ERenderTargetLoadAction::ENoAction);
check(TemporaryTextureRenderTarget.IsValid());
// Create the tile item used for rendering the material
FCanvasTileItem TileItem(FVector2D::ZeroVector, MaterialRenderProxy, TempTextureSize);
const FSceneViewFamily& ViewFamily = *View.Family;
FCanvas& RenderCanvas = *FCanvas::Create(GraphBuilder, TemporaryTextureRenderTarget.Texture, nullptr, ViewFamily.Time, View.GetFeatureLevel());
RenderCanvas.SetRenderTargetRect(TemporaryTextureRenderTarget.ViewRect);
RenderCanvas.DrawItem(TileItem);
RenderCanvas.Flush_RenderThread(GraphBuilder);
// Copy the texture to the render target
URenderTargetProxy* OutRenderTarget = Resource->GetRenderTarget();
FRDGTextureRef OutRenderTargetTexture = Resource->GetPooledTextureRef();
AddCopyTexturePass(GraphBuilder, TemporaryTexture, OutRenderTargetTexture);