Search Unity

OnRenderImage to Replace RenderTexture on iOS

Discussion in 'General Graphics' started by boehmzViacommix, Oct 18, 2017.

  1. boehmzViacommix

    boehmzViacommix

    Joined:
    May 4, 2017
    Posts:
    16
    I am trying to get an effect where the renderer "pauses" by showing the last frame for x seconds. I am using the method where I take a screenshot of the current frame then Blit that to the src RenderTexture in OnRenderImage while the renderer should be paused. It works fine in editor.
    On iOS, when I draw the texture instead of what the camera rendered, I get a lot of flickering between the screenshot and the current game view. It is as if OnRenderImage is being called every other rendered frame.
    Code (CSharp):
    1. void OnRenderImage(RenderTexture src, RenderTexture dest) {
    2.         Texture2D renderOverride = getScreenShotOverride ();
    3.         if (renderOverride != null) {
    4.             Graphics.Blit (renderOverride, src);
    5.         } else {
    6.             Graphics.Blit (src, dest);
    7.         }
    8.     }
    getScreenShotOverride() is a method that returns the texture that I want drawn instead of whatever the current camera sees or null if I want to simply draw the current camera.
    I have used debug statements to confirm that getScreenShotOverride() is never null during the time it should be shown and I am not changing it explicitly in my code (assuming that Graphics.Blit isn't changing it either, since it's always the source parameter).
    Has anyone ran into this working fine in editor but not on iOS? Is there another, more mobile friendly, method that I could be using to get this same effect where I won't see the flickering?
     
  2. daxiongmao

    daxiongmao

    Joined:
    Feb 2, 2016
    Posts:
    412
    I haven't looked at the API but shouldn't you be copying your screen shot to dest not src?