TextureRenderTarget2D saved to PNG is much darker

floky001
Thu, 03 Mar 2016 15:30:55 +0000
Asset Creation

After a ton of digging around I’ve managed to create an UTextureRenderTarget2D from C++ to capture a LDR screenshot in it using ScreenCaptureComponent2D set to “Final Color (LDR with PostProcess)”.

The screenshot looks ok while displayed on a image widget in the game but it’s much darker after saving it to a PNG file. I assume it’s something caused by the gamma correction but I’ve literally tried all combinations of rendertarget texture settings that came to mind to try to make it look ok but without any success.

Theoretically I would have to save it to disk without any gamma correction so that when viewing externally it gets gamma corrected again and it should look ok. Now it looks as it’s being double gamma corrected. But the question is HOW in UE4?

I’m saving the texture to disk exactly as described here:

Unreal Engine Forums – 13 Nov 15

How can I save a RenderTarget or a Texture to a file?

I’ve seen this question asked in a few different ways, but no one seems to be able to give a definitive answer. To sum up, I’m using a SceneCaptureComponent2D to render to a RenderTarget. I want to save that RenderTarget to disk, at runtime....

To create the rendertarget texture from code I do this (in case it helps someone else):

UTextureRenderTarget2D *rtResult = NewObject<UTextureRenderTarget2D>();
rtResult->ClearColor = FLinearColor::Black;
rtResult->InitCustomFormat(width, height, PF_B8G8R8A8, true);

What am I missing?
Any suggestions are welcomed.

Here’s what I see after saving to PNG:

free upload

Here’s what it should like (when taking screenshot from UE4 directly):

image upload no limit

8 posts - 1 participant