Search Unity

PostProcess using OnRenderImage and Texture2D

Discussion in 'Image Effects' started by ntclark, May 18, 2022.

  1. ntclark

    ntclark

    Joined:
    Nov 10, 2020
    Posts:
    10
    Hi All,
    I'm having extreme difficulty get this to work.

    I am attempting to do post processing by implementing OnRenderImage on the camera gameobject

    The post processing idea is to simply overlay an additional image (Texture2D) over top of the source and then to Blit the changed source onto the destination.

    Here is code:
    private void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
    Graphics.Blit(tex2D,source);
    Graphics.Blit(source,destination);
    }

    tex2D is my external Texture2D (Note that I can encode it to png and save it, and it appears valid in the saved file)

    The problem is that no matter what I do I get a gray screen in the window. I have tried everything!!

    A few things:
    1. OnRenderImage IS being called, this is not a pipeline issue. In fact I have two other post processing effects that work perfectly
    2. I realized I have to take the imported image file (I've tried both png and jpg, dragged into my Unity project), and make the "Texture type" (Sprite (2D and UI)) - Until I did that, the texture would not encode to PNG and appeared to be invalid.
    3). I've tried creating a RenderTexture and Blitting my text2D into that, no help there
    4) If it matters this implementation is using the VideoPlayer to display the Skybox
    5) when I stop PlayMode, the screen flashes momentarily with what I WANT !!!! It's like the gray screen is hiding my results and somehow they appear very briefly as the playmode is shutting down

    and probably others.

    Does anyone know why I would be getting a gray screen simply by attempting blit a Texture2D into the source and then blitting the source into the destination ?

    Any help is hugely appreciated
     
    Last edited: May 20, 2022
  2. ntclark

    ntclark

    Joined:
    Nov 10, 2020
    Posts:
    10
    This problem has been "partially" solved. Partially meaning that I still have the problem, though it's being caused when I use the Windows Mixed Reality OpenXR implementation and THAT, I believe is because WMR uses single pass instancing and shader changes are probably required. Essentially it only renders in one eye, gray screen in the other)

    Still, I have adjusted those shaders to account for this problem for SPI and they work properly when I take the source rendertexture and blit it into the destinaioan on OnRenderImage

    But, as soon as I try to take another texture to overlay into the mix, I get the problem back

    So I found another way to get what I want