TimmHess / UnrealImageCapture

A small tutorial repository on capturing images with semantic annotation from UnrealEngine to disk.
MIT License
224 stars 49 forks source link

weird camera exposure & color #8

Closed HaiyiMei closed 3 years ago

HaiyiMei commented 3 years ago

Hi, It's me again :) I have one problem. When rendering pictures by code, I got weird camera exposure and color issues. The detail can be seen in the following, the first is the preview screen when hit the play button in the ue4 editor, and the second is rendered by code.

微信截图_20210302163917

000000000018

I'm running the rendering code as you are, including the config of the UTextureRenderTarget2D. I think the problem comes from the config of UTextureRenderTarget2D and I don't know how to modify the config. Am I right or do you know the reason? Thanks a lot~

TimmHess commented 3 years ago

Hey, this looks very much like a 'gamma' value issue. I assume you do have 'eye adaption' enabled in your camera? - I typically disabled it via an unbound post-process volume and set a exposure bias of 0.0f. I suppose that is how I overcame this issue, because I definitely had these very result myself.

The better fix might be to switch from

renderTarget2D->TargetGamma = 1.2f;

to

renderTarget2D->TargetGamma = GEngine->GetDisplayGamma();

and move this also into the capture function call, such that the render target's gamma is updated for every frame according to the current display gamma. That would be this line:

void ACaptureManager::CaptureColorNonBlocking(...){
// Re-read the display for the render-target
CaptureComponent->GetCaptureComponent2D()->TextureTarget->TargetGamma = GEngine->GetDisplayGamma();

 // Get RenderConterxt
.... 
}
HaiyiMei commented 3 years ago

@TimmHess Precisely! You solved my problem. Thanks for your quick and detailed reply! You are the best 🥇

TimmHess commented 3 years ago

Awesome! Glad it worked :)

safdarzareef commented 1 year ago

Hi @TimmHess, thanks for this repo. I am having similar issues. Would you be able to help me with it? I tried what you suggested above (the GEngine->GetDisplayGamma() part) but they change very little. Right now, I have:

Editor: image

Saved Image: image

I am using jpegs to save by the way - I changed the ERGB format on CameraCaptureManager.cpp Tick() to RGBA. Also changed the pixel format on SetupCameraComponent to PF_R8G8B8A8 to match it.

Thanks a lot for your help!