CaptureScreenshotAsTexture behave differently than CaptureScreenshot
Hi,
I'm using CaptureScreenshotAsTexture to render and store image from my game. Because I need to have nice and smooth masked images and standard Mask component creates jagged output, I implemented shader and material to correctly mask image. Shader is from https://forum.unity.com/threads/soft-mask-a-replacement-of-unity-ui-mask-with-alpha-support.454707/#post-2950253.
The result is nice and smooth, but when I take screenshot using CaptureScreenshotAsTexture, the material is not applied. Using CaptureScreenshot yeild in correct result (material is applied), but since the latter ignore my camera's background color alpha (which is set to 0), I ended up with image without transaprency. Compare for yourself:
CaptureScreenshot:
CaptureScreenshotAsTexture: (Note that although here is in the background color with no alpha, this is because I scale it down in MS paint and unfortunatelly it discarded alpha value. Original image has correct background alpha values)
Expected result: I expect to have output screenshot with material applied and having alpha to 0 where no image is rendered in the scene.
My possible workaround Since I'm rendering an editor-like environment, I need to take a screenshot using CaptureScreenshot in correct supersize (final image must meet certain dimensions), then load it to memory, crop it and using flood algorithm correct alfa values (where pixel is 100% white).
Question: Is there any other way to solve or workaround this bug (filled as #1053957)?
Answer by QuincyC · Sep 26, 2018 at 06:54 PM
I believe you need to call this function at end of frame to guarantee that everything renders correctly. Try using a co-routine as detailed in the documentation.
Your answer
Follow this Question
Related Questions
How to pause screen rendering? 2 Answers
Instantiated Child doesnt render if multiple objects share same name as parenting object? 1 Answer
Rendering Problem 0 Answers
GPU spikes in profiler - used to be 100fps, now 30fps? 1 Answer
I need a Simple and Clear example for how to add a texture (image) to a quad in C# 3 Answers