Optimize ImageEffects

Hello guys,

I am currently developing a mobile game and one of the aspects of my game is the radial blur image effect.

I wonder if my optimalization is used correctly.

The idea is to have a script on the camera that renders the camera view to a lower resolution RenderTexture and after the image effects are applied. However i am not sure if this working correctly since i do not know if the view is correctly rendered to RenderTexture and also to the camera buffer. Another point is if the temporary render texture should be refreshed every frame with GetTemporary().

Here is my script:

using UnityEngine;

[RequireComponent(typeof(Camera))]
public class ImageEffectOptimalization : MonoBehaviour {

    public enum Factor
    {
        Full = 1,
        Half = 2,
        Third = 3,
        Fourth = 4
    }

    public Factor m_Factor = Factor.Full;

    private RenderTexture m_tex;
    private Camera m_camera;

    void Awake()
    {
        m_camera = GetComponent<Camera>();
    }

    void OnPreRender()
    {
        if (m_Factor == Factor.Full)
            return;
        m_tex = RenderTexture.GetTemporary((int)(m_camera.pixelWidth / (float) m_Factor), (int)(m_camera.pixelHeight / (float)m_Factor));
        m_camera.targetTexture = m_tex;
    }

    void OnPostRender()
    {
        if (m_Factor == Factor.Full)
            return;
        m_camera.targetTexture = null;
        RenderTexture.ReleaseTemporary(m_tex);
    }
}

If you have any other tips and techniques to optimize image effects for mobile I would appreciate if shared.

Thanks,

Ilija

What is the use of the RenderTexture m_tex ?
I think you at least need to render m_tex back to framebuffer

void OnPostRender()
    {
        if (m_Factor == Factor.Full)
            return;
        m_camera.targetTexture = null;

          //I added this line
        Graphics.Blit(m_tex,null as RenderTexture,imageEffectMaterial,imageEffectMaterialPassNum);

        RenderTexture.ReleaseTemporary(m_tex);
    }