Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.

    Read our full announcement for more information and let us know if you have any questions.

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. }