Post Process Mobile Performance : Alternatives To Graphics.Blit , OnRenderImage ?

Graphics.Blit is just a convenient call which render a full screen quad.It will not be the big problem.
I don’t use OnRenderImage(…)

void OnRenderImage(RenderTexture src, RenderTexture dest)
{
    Graphics.Blit(src,dest);
}

because if you did not supply a RenderTexture to the camera’s targetTexture, Unity will trigger CPU ReadPixel(get data back from GPU), which will stall the whole GPU until finish. Super slow, don’t do this.

What you can do is:

RenderTexture myRenderTexture;
void OnPreRender()
{
    myRenderTexture = RenderTexture.GetTemporary(width,height,16);
    camera.targetTexture = myRenderTexture;
}
void OnPostRender()
{
    camera.targetTexture = null; //null means framebuffer
    Graphics.Blit(myRenderTexture,null as RenderTexture, postProcessMaterial, postProcessMaterialPassNum);
    RenderTexture.ReleaseTemporary(myRenderTexture);
}

I can build combined bloom imageEffects working 60fps on galaxy S2 & Note2.(Build using Unity5.3.4)

So I guess your S5 can do better.

If you are still not reaching 60fps, try the following:
-using lower resolution RenderTextures
-lower shader precisions
-when sampling a texture in fragment shader, try to use the uv directly from vertex shader, because “dependent texture read” is slower.

19 Likes