So here is my example script from another thread ( How to use memoryless? ) that I added comments that hopefully will help.
using UnityEngine;
public class memoryless : MonoBehaviour
{
// I like using descriptors, but it's not really necessary to do it this way.
RenderTextureDescriptor mainrtdesc;
RenderTexture rt;
void Awake()
{
// I'm setting it to be Screen.width and Screen.height, but it could be any resolution, it doesn't really matter.
// Although since it is intended to be blitted to screen at the end, if it's lower than Screen, stuff will look
// blurry.
mainrtdesc = new RenderTextureDescriptor(Screen.width, Screen.height, RenderTextureFormat.Default, 24);
// Setting Memoryless MSAA to save some memory
mainrtdesc.memoryless = RenderTextureMemoryless.MSAA;
mainrtdesc.useMipMap = false;
mainrtdesc.msaaSamples = 2;
}
void OnPreRender()
{
rt = RenderTexture.GetTemporary(mainrtdesc);
// Setting the camera in my game to render to my RenderTexture instead of the back buffer.
GetComponent<Camera>().targetTexture = rt;
}
void OnPostRender()
{
GetComponent<Camera>().targetTexture = null;
// Here I'm just blitting my RenderTexture to the backbuffer (when you set target to null in a Blit, Unity renders to backbuffer), so we can see it on screen.
Graphics.Blit(rt, null as RenderTexture);
RenderTexture.ReleaseTemporary(rt);
}
}
// This script in general is pretty stupid, it does practically nothing. Presumably for this to make sense, I would
// Blit with a material / shader, so I can do some processing to the RenderTexture before Blitting to screen, or
// it could be the start of a chain of Blits to do all my post processing, before blitting the final RT to screen.
// For example, here is a chain of Blits I do for our custom post FX
/*
// Downsample
TapMat.SetFloat(ShaderID.brightdepthID, DepthBrightness);
Graphics.Blit(rt, downRT, TapMat); // First Downscale
// Do Bloom
Graphics.Blit(downRT, bloomRT, BloomMat); // Prepare for Bloom
advMat.SetFloat(ShaderID.OffSetID, 0.55f);
Graphics.Blit(bloomRT, bloomRT2, advMat, 1); // Blur Bloom #1
RenderTexture.ReleaseTemporary(bloomRT);
bloomRT = GetTemporaryRenderTexture(capturertdesclow);
Graphics.Blit(bloomRT2, bloomRT, advMat, 3); // Blur Bloom #2 : bloomRT is final bloom rt
RenderTexture.ReleaseTemporary(bloomRT2);
bloomRT2 = GetTemporaryRenderTexture(capturertdesclow);
advMat.SetFloat(ShaderID.OffSetID, 1.5f);
Graphics.Blit(bloomRT, bloomRT2, advMat, 5); // Blur Bloom #3
RenderTexture.ReleaseTemporary(bloomRT);
advMat.SetFloat(ShaderID.OffSetID, 2.5f);
bloomRT = GetTemporaryRenderTexture(capturertdesclow);
Graphics.Blit(bloomRT2, bloomRT, advMat, 5); // Blur Bloom #4
RenderTexture.ReleaseTemporary(bloomRT2);
// Do DOF
advMat.SetFloat(ShaderID.OffSetID, 1.55f);
Graphics.Blit(downRT, downRT2, advMat, 0); // Blur #1 for dof
RenderTexture.ReleaseTemporary(downRT);
downRT = GetTemporaryRenderTexture(capturertdesc);
Graphics.Blit(downRT2, downRT, advMat, 0); // Blur #2 for dof
RenderTexture.ReleaseTemporary(downRT2);
Graphics.Blit(downRT, null as RenderTexture, advMat, finalPass);
RenderTexture.ReleaseTemporary(rt);
RenderTexture.ReleaseTemporary(bloomRT);
RenderTexture.ReleaseTemporary(downRT);
*/