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. Dismiss Notice

Question 2D URP + ShaderGraph + Graphics.Blit + Material + Transparency Question

Discussion in 'Universal Render Pipeline' started by diesoftgames, Jul 5, 2023.

  1. diesoftgames

    diesoftgames

    Joined:
    Nov 27, 2018
    Posts:
    114
    I'm in Unity 2020.3 looking to use ShaderGraph to create a Shader which I can then use for a Material which will be used in a Graphics.Blit call. In my Graph Settings > Target Settings, if I use "Unlit", the Blit call simply results in the RenderTexture being completely transparent, but if I use "Sprite Unlit" I can get everything working except transparency. When I do this, the resulting RenderTexture always has an alpha of 1 for the entirety of the texture, no matter what the ShaderGraph's alpha output is set to.

    Perhaps there's some other way to achieve this, but is there a way I can use a ShaderGraph-based Material and "apply" it to an input texture and get an output texture that has 4 channels of data? Thank you.
     
  2. diesoftgames

    diesoftgames

    Joined:
    Nov 27, 2018
    Posts:
    114
    Still looking for some help with this. It seems like maybe it's a bug with Graphics.Blit and URP interaction, but whether it's intended or not to ignore the alpha channel to not be considered when doing a Graphics.Blit call, I need some workaround if anyone is also working in 2D URP + ShaderGraph and has found something that works.
     
  3. diesoftgames

    diesoftgames

    Joined:
    Nov 27, 2018
    Posts:
    114
    I've found a pretty silly workaround for this:
    The issue is with the Blend mode specified in the generated shader code. If you generate code from your ShaderGraph, and then manually remove the
    , One OneMinusSrcAlpha
    bit from the Blend mode in the "Sprite Unlit" pass, it will observe the correct alpha. I cannot find any way to reproduce this from within the ShaderGraph interface.