Render Texture not capturing Image Effect Shaders on ARCamera
I have a scene with an ARCamera. The app allows the user to enable the ARCamera to view target images. I am adding a feature which allows the user to apply screen 'Image Effects'. I have successfully added an Image Effect script to the ARCamera which, for example, will pixelate the entire screen. Everything works fine in the app and the effects work as intended - where the user chooses the screen effect from a button and the image effect shader is applied.
The problem is, when I take a picture through the native camera, the image effect shaders do not render. All of my other elements are rendering as desired (the AR, particle effects, borders, etc...).
I read somewhere that Image Effect Shaders are a code which runs before the render, and thus it can't be captured that way.
My Code (both scripts are attached to the ARCamera) (these are snippets from my code, and not the entire code): I am using an Image Effect Shader Script which uses the method 'Graphics.Blit' to apply the custom shader: void OnRenderImage(RenderTexture src, RenderTexture dst) { if (EffectMaterial != null) Graphics.Blit(src, dst, EffectMaterial); else Graphics.Blit(src, dst); }
I am using a Screen Capture script to take a picture with my native device camera: private void OnPostRender() { if (ShareScreenshotOnNextFrame) { ShareScreenshotOnNextFrame = false; RenderTexture renderTexture = myCamera.targetTexture; Texture2D renderResult = new Texture2D(renderTexture.width, renderTexture.height, TextureFormat.ARGB32, false); Rect rect = new Rect(0, 0, renderTexture.width, renderTexture.height); renderResult.ReadPixels(rect, 0, 0); byte[] byteArray = renderResult.EncodeToPNG(); //... the rest of the code that goes below here just writes to a file path, then retrieves the png from that path and draws it on a Rect to be displayed as a preview image for the user before they share the image on social media }
In easier to understand words: Basically, when I open my app on my phone, initialize the AR Camera, and apply a screen effect (pixelated) from the options menu, everything works fine. But when i take a picture, the pixelated effect isn't rendered with the image.
Please help me understand how to fix my issue =P Thanks Community!