Search Unity

OnRenderImage's destination texture can't be stored anywhere for some reason

Discussion in 'General Graphics' started by Kaldrin, Dec 27, 2021.

  1. Kaldrin

    Kaldrin

    Joined:
    Jul 10, 2018
    Posts:
    46
    Hey everyone so I have a simple problem with the OnRenderImage function, I'm trying to make a GameOfLife as a post process shader (So running on the GPU for better performance) but my simple script in OnRenderImage doesn't seem to work I cannot store the result of the destination texture for use in the next frame to make the game of life evolve, for some reason its value equals always equals to null even if I definitely Graphics.Blit stuff in it, I don't understand how this function works and I couldn't find online a simple explanation on how to pass previous frames to the shader, my solution makes sense it should be working I think.
    (So the result as destination texture is null is that the screen is plain white)

    Code (CSharp):
    1. void OnRenderImage(RenderTexture source, RenderTexture destination)
    2.     {
    3.         if (!bufferSetUp)
    4.         {
    5.             bufferSetUp = true;
    6.             Graphics.CopyTexture(source, buffer);
    7.         }
    8.         Graphics.Blit(buffer, destination, postProcessingMat);
    9.         Graphics.CopyTexture(destination, buffer);
    10.         Debug.Log(destination);
    11.     }
    Thanks in advance to people checking this.