Search Unity

Feature Request Accessing LODs (unity_LODFade) in ShaderGraph (workaround inside)

Discussion in 'Shader Graph' started by _geo__, Aug 19, 2020.

  1. _geo__

    _geo__

    Joined:
    Feb 26, 2014
    Posts:
    1,334
    I wanted to add LOD fading to may shadergraph shaders but didn't find a premade node, so I made one via the custom node function. Maybe it will be useful to others too. Would be great to have this as a built in node.

    How to use it:
    lod-fade-in-shadergraph.png
    If you use alpha like in the example above, then don't forget to switch "Surface" to transparent.

    Code:
    Code (CSharp):
    1. //UNITY_SHADER_NO_UPGRADE
    2. #ifndef KAMGAM_LODFADE_INCLUDED
    3. #define KAMGAM_LODFADE_INCLUDED
    4. void LODFade_float(out float OUT)
    5. {
    6.     OUT = unity_LODFade > 0.001 ? OUT = unity_LODFade : 1;
    7. }
    8.  
    9. void LODFade_half(out half OUT)
    10. {
    11.     OUT = (half)unity_LODFade > 0.001 ? OUT = unity_LODFade : 1;
    12. }
    13. #endif // KAMGAM_LODFADE_INCLUDED
    The docs on unity_LODFade are a bit misleading because the unity_LODFade does not change from 0 to 1 but 1 to 0. This would be okay because we usually want to multiply the unity_LODFade with something (like alpha). But sadly the unity_LODFade value defaults to 0 whenever it is not fading. That's why I had to add the ">0.001" shenanigans to make it 1 by default.

    If you have any improvement suggestions, please let me know.
    Happy Graphing :)
     
    Last edited: Aug 19, 2020
    mgeorgedeveloper, SenaJP and abegue like this.