Search Unity

Bliting to framebuffer doesn't work?

Discussion in 'Image Effects' started by look001, May 19, 2019.

  1. look001

    look001

    Joined:
    Mar 23, 2017
    Posts:
    111
    Hi everyone,
    i am new to image effects. I want to apply an image effect to my game in android. Therefore i can not use OnRenderImage() (see here). Instead i used this:
    Code (CSharp):
    1. [ExecuteInEditMode]
    2. public class PostProcess : MonoBehaviour
    3. {
    4.     public Material blitMaterial;
    5.  
    6.     [SerializeField] Camera cam;
    7.  
    8.     RenderTexture myRenderTexture;
    9.     void OnPreRender()
    10.     {
    11.         myRenderTexture = RenderTexture.GetTemporary(Screen.width, Screen.height, 16);
    12.         cam.targetTexture = myRenderTexture;
    13.     }
    14.     void OnPostRender()
    15.     {
    16.         cam.targetTexture = null;
    17.         Graphics.Blit(myRenderTexture, null as RenderTexture, blitMaterial);
    18.         RenderTexture.ReleaseTemporary(myRenderTexture);
    19.     }
    20. }
    The blitMaterial simply returns a green color for test purpose. However after applying everything nothing changes. The whole game still looks like it was before. The assigned camera in the inspector is correct. I also tried to blit it to a raw image and it worked but for the framebuffer it doesn't. So it looks like it has something to do with Graphics.Blit(). I also tried without HDR and MSAA.
    I realy don't know what else might be the problem :( Therefore i want to ask you for help...

    Thank you so much!
     
  2. look001

    look001

    Joined:
    Mar 23, 2017
    Posts:
    111
    Ups, I didn't set my camera to Main.Camera. Therefore graphics.blit didn't blit to the view. Also i had to turn of MSAA. OnRenderImage() causes a black screen on some devices so i rather not use it. It was fixed with OnPreRender and OnPostRender.

    For that android build I had to put the shader under Assets/Resources to make sure it is added to the build. I think i could also add the shader to "Project Settings -> Graphics -> Always include shader".

    I attached the final Outline post effect (working on android). I used the command buffer explained similar to this blog...

    I'm very glad it works now!
     

    Attached Files:

    Last edited: Jun 2, 2019