I’ve been experimenting with how to create high res screenshots with a transparent background. I’ve found out how to do it, but my method has created problems for colleagues who were using other screenshot functionality and so I clearly need a different solution.
I’m interested to know what is really going on here and how to best create transparent screenshots without knock on effects.
Essentially I enabled Alpha Output and worked to ensure that my post process materials and tonemapper replacing materials were propogating alpha through.
I found that it all worked right up until the end where in UGameViewportClient::ProcessScreenshots() ~line 2182 there was code where right before passing the screenshot data to a delegate, it iterated through everything and set the alpha to 255! No wonder the transparent background disappeared!
So I commented this code out.
Then I found that I was generating an image with inverted alpha, where the main object was transparent, and background fully opaque black.
I had no idea why this was the case but as an experiment in my post process tonemapper material I simply inverted the alpha and then suddenly everything worked perfectly.
This would all be fine except that my changes to the engine, commenting out this stomping of alpha, has caused unintentional side effects for other colleagues doing unrelated screenshot work. Whoops.
So why is alpha inverted here, why is it being stomped with 255 to make it opaque and what is the real fix for this problem?
I feel I’m doing kludges on kludges here and I’m not going to have a good outcome until I understand why this is setup the way it is with inverted alpha.
(As an aside, I tried an idea of keeping the engine change commented out and having my screenshot delegate invert the alpha in code instead of the tonemapper material but this didn’t work well with some other post process 2D texture overlays, which unintentionally had their alpha inverted too. So I discovered that the objects in the scene need to have their alpha fixed up prior to post process work of 2D textures being applied over the camera. This is why my earlier fix of adding the invert alpha into the tone mapper worked.)
(edit: I’m aware that there is an option to create screenshots with transparent backgrounds using depth mask but we are unsatisfied with this solution due to some visual artifact issues and that’s why we’re interested in other approaches)