I want to create some image effect. I've written a script that draws a cube mesh at the render target and then copies the render texture at the screen. I don't want to render anything except Mesh(M) in my RenderTexture(rt):

    void OnRenderImage(RenderTexture src, RenderTexture dest)
        RenderTexture rt = RenderTexture.GetTemporary(Screen.width / 1, Screen.height / 1 );

        Graphics.DrawMeshNow(M, new Vector3(0.0f, 0.0f, -8.0f), Quaternion.identity);
        Graphics.Blit(rt, dest);


Where M is GameObject.CreatePrimitive(PrimitiveType.Cube).GetComponent<MeshFilter>().sharedMesh;

When I moved my camera, I see this: enter image description here

It seems like the RenderTexture didn't cleared itself when released. Or maybe I did something wrong? Please explain why this happened and how can I fix this.


1 Answer 1


That is correct: RenderTextures are not necessarily cleared after being released or reacquired.

According to the documentation:

You can not depend on any particular contents of the RenderTexture you get from GetTemporary function. It might be garbage, or it might be cleared to some color, depending on the platform.

If you want the RenderTexture to be cleared, then you'll need to clear it yourself after acquiring it.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .