Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Using Blit on a RenderTexture with a Shader Graph material results in black texture.

Discussion in 'General Graphics' started by sora3087, Aug 11, 2023.

  1. sora3087


    May 27, 2018
    I was trying to insert the render texture into a UI Toolkit view but when that wasn't working I tried to debug it by setting up a simple script.

    The shader graph has a _MainTex and _Color and both of them are set to the main input of their respective types.
    `mat` here is just to test something that would display the render texture.
    Running the Blit here without the frame shader results in the texture with no alpha being displayed.
    I have tried using SetTexture on the frame material before Blit and obviously that doesn't work.
    I have tested setting the renderer's material to the frame mat and it does display properly.
    I have tested with different values of depth for the render texture.

    I am at my wits end...

    Code (CSharp):
    1. public class TestRenderTexture : MonoBehaviour
    2. {
    3.   public Texture2D Icon;
    4.   public Material ShaderGraphReference;
    5.   public RenderTexture rt;
    6.   void Start()
    7.   {
    8.     var mat = new Material(Shader.Find("Unlit/Texture"));
    9.     GetComponent<MeshRenderer>().material = mat;
    10.     rt = new RenderTexture(128, 128, 16, RenderTextureFormat.ARGB32);
    11.     var frame = new Material(ShaderGraphReference);
    12.     frame.SetColor("_Color",;
    13.     Graphics.Blit(Icon, rt, frame);
    14.     mat.SetTexture("_MainTex", rt);
    15.   }
    16. }