Search Unity

Unity 4.2 / Camera.AAResolve / iOS / OnRenderImage

Discussion in 'Editor & General Support' started by logicalerror, Aug 27, 2013.

  1. logicalerror

    logicalerror

    Joined:
    Jan 2, 2013
    Posts:
    207
    At first I was rendering my scene (on iOS / Unity 4.2) in the following order:

    1. Render scene with postprocessing using OnRenderImage
    2. Render UI

    Rendered seperately step 1 cost about 16ms and the UI 8 ms.
    But I wanted to perform the postprocessing on both the scene and UI combined, so I changed it to

    1. Render scene
    2. Render UI with postprocessing using OnRenderImage

    To my surprise my rendering now cost about 280ms! Crazy!
    In my profiler "Camera.AAResolve" showed up twice taking up about 250ms.
    AAResolve makes me think this is anti-aliasing related, even though it's turned off everywhere (bug?)
    On the unity3d IRC chat someone told me that this always happens on iOS when you have more than 1 camera and perform postprocessing on a camera other than the first.

    This is probably a bug.

    It took me a couple of days to figure out a solution, but since I couldn't find a solution myself I figured I'd share it with the internet.
    The trick is to set up (and create) all your rendertextures in OnPreRender/OnPostRender manually, then you can work around this AAResolve thing which only seems to happen when you use OnRenderImage.

    Hope this avoids you some headaches!
     
  2. pain_gwar

    pain_gwar

    Joined:
    Apr 14, 2013
    Posts:
    22
    Hi logicalerror,

    i encountered the exact problem and i want to thanks for posting this. Unfortunately i'm a newbie in graphics programming. Could you be more specific?

    I'm using the Unity Image Effects (Noise and Vortex) so i checked this script and more precisely all of them has the method:
    OnRenderImage (RenderTexture source, RenderTexture destination)

    From what i understood the problem is that when the effects are not applied to the first camera, Unity tooks a lot of time to create the RenderTexture (source i think) with Camera.AAResolve -> RenderTexture.GrabPixels (i saw in the profiler).

    So, my newbie question is, how can create the render texture if not with GrabPixels from the screen?

    If you can give me some hint or some links for documentation or both, i'll appreciate very much.

    Thanks again.
     
  3. mcmorry

    mcmorry

    Joined:
    Dec 2, 2012
    Posts:
    580
    I'm interested too. I'm testing SunShafts image effect on mobile. I understand that could be too much for mobile phones, but if there is any way to optimise this GrabPixels function, I'd be more than happy.
     
  4. Archain

    Archain

    Joined:
    Nov 16, 2013
    Posts:
    1
    I'm sorry, logicalerror, but I can't understand what in mean when you describe the trick, can you do me a favour for telling me more details about it?