Search Unity

Resolved shader graph alpha testing issue with selection outline shader and lightmapping

Discussion in 'Shader Graph' started by larsbertram1, Jul 19, 2019.

  1. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    no matter if i use shader graph or write a shader manually: when it uses alpha testing neither the editor selection outline shader gives me a proper alpha tested preview nor the progressive light mapper will take alpha testing into account (enlighten does).
    i wonder what it needs to make this work...
     
  2. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    from HDPR:
    // HACK: GI Baking system relies on some properties existing in the shader ("_MainTex", "_Cutoff" and "_Color") for opacity handling, so we need to store our version of those parameters in the hard-coded name the GI baking system recognizes.

    adding these fixed lightmapping and the outline selection shader.
     
  3. Bordeaux_Fox

    Bordeaux_Fox

    Joined:
    Nov 14, 2018
    Posts:
    589
    Is this still the case? Because I'm wondering some of my GI is a bit off and I'm using a lot of Shadergraphs. Such things should be highly documented by Unity ...
     
  4. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    agreed.
    you find some hints in the hdrp shader code (comments).
    and i think it is still the case, yes.
     
  5. frostyone

    frostyone

    Joined:
    Aug 2, 2018
    Posts:
    8
    Yeah... Doesn't work in URP
     
  6. crdmrn

    crdmrn

    Joined:
    Dec 24, 2013
    Posts:
    152
    Anyone found a solution to this for URP? This is extremely frustrating :S
     
  7. alexvector

    alexvector

    Joined:
    Oct 9, 2019
    Posts:
    26
    With URP I was able to make the alpha clip work in lightmap shadows by properly naming the input parameters to "_MainTex", "_Cutoff" and "_Color" in their "reference" name.

    upload_2021-6-2_10-37-36.png

    However, anything you do in the graph with that _Cutoff value before connecting it to to the Alpha Clip Threshold pin is ignored since the light mapper only looks at the input value in the material it seems.

    The underlying issue is reported here:
    https://issuetracker.unity3d.com/is...graphs-is-not-factored-in-during-lightmapping

    But it is in postponed state....
     
    CountDoom likes this.
  8. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    you should be able to tweak the alpha value instead and keep the _Cutoff value untouched?!
     
  9. alexvector

    alexvector

    Joined:
    Oct 9, 2019
    Posts:
    26
    Possibly, but in my use case it doesn't matter so I have not tried it. I would not be surprised if the light mapper ignores that too and fetches _MainTex and _Color directly to do the clip.
     
  10. alexvector

    alexvector

    Joined:
    Oct 9, 2019
    Posts:
    26
    I just did a quick test, and indeed, the light mapper ignores what goes on in the graph. It probably reads the input parameters ("_MainTex", "_Cutoff" and "_Color") and emulates the clip that would happen if you had used a standard shader. So if you do anything special in your graph to manipulate the alpha it wont be taken into account.
     
  11. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    So, so jenky.

    We already have to write a dozen passes across SRPs that could handle this case, why not just use one of them instead?
     
  12. Beauque

    Beauque

    Joined:
    Mar 7, 2017
    Posts:
    61
    I am making a custom URP shader based on Cyanilux's tutorial and templates. Before that I was using Amplify Shader Editor and the URP PBR Template. In both cases I was facing the baked shadows not affected by alpha clipping issue.

    Found out that simply setting the RenderType Tag to "TransparentCutout" in the SubShader solves the issue.
    I named my properties _BaseMap, _BaseColor and _Cutoff and have no problem with that (at least in Unity 2021.3.0f1 / URP 12.1.6)
    Can be done via script / custom shader GUI:
    Code (CSharp):
    1. material.SetOverrideTag("RenderType", "TransparentCutout");
    Hope it helps
     
    Last edited: May 12, 2022
    Bordeaux_Fox likes this.