Search Unity

Question LOD CrossFade Shader in URP

Discussion in 'Universal Render Pipeline' started by iscf, Aug 11, 2020.

  1. iscf

    iscf

    Joined:
    Aug 30, 2018
    Posts:
    24
    Hello,
    I wanted to make some optimizations on my game and i tried LOD Group and it work perfectly, i gained 5-10 FPS.
    Just a detail, it's too obvious when the object disapear immediatly when culled, so i read about crossfade effect.
    But i haven't found an easy way to do it without replacing all the shaders i use, and even the documentation is not very detailed about how implement it in URP.
    I'm new at shader so i prefer to don't write custom shader and replace one by one all my materials with textures already associated.

    Is there any way to simply "Upgrade" the standart URP shaders to take in account the crossfade with an alpha blending or something like that ?

    And if not it could be very generous that feature is added to the URP Package ;) .
     
  2. iscf

    iscf

    Joined:
    Aug 30, 2018
    Posts:
    24
    Bump, nobody know how to do it ?
     
  3. Kibelon

    Kibelon

    Joined:
    Jan 25, 2015
    Posts:
    4
    Have you played with this settings? It works for me.
    upload_2020-8-14_20-37-30.png
    If this kind of fadings don't work, maybe the LOD objects are too diferent.
     
  4. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,260
    Unfortunately it would come down to creating a custom shader that performs dithering based on the LOD fade value (unity_LODFade.x) passed by the LOD group. The default URP shaders don't incorporate this, assuming because none of the default features (except SpeedTree) use this, so it isn't on anyone's rader.

    The Boat Attack demo includes a LOD crossfade shader you can look into.
     

    Attached Files:

    gotiobg, Kaim and gmgannon like this.
  5. iscf

    iscf

    Joined:
    Aug 30, 2018
    Posts:
    24
    @Kibelon It need object ? And when it culled completely ? I'm a bit more radical and removing some renderers so maybe because of that it's not working.

    upload_2020-8-17_17-46-59.png

    Thank you very much @StaggartCreations, i will try to incorporate the node in a custom shadergraph, but it need the renderer component to be on the same object than LOD group or not ?

    EDIT : With this sub graph nothing happened, even with transparent it's not working.
     
    Last edited: Aug 17, 2020
  6. Kibelon

    Kibelon

    Joined:
    Jan 25, 2015
    Posts:
    4
    Well. After some digging, I've found a solution.Staggart Creations was actually pretty helpful.
    To implement cross-fade you need to make your own shader, but you can use shadergraph. It's pretty easy.
    Add this to your shader:
    upload_2020-8-19_16-40-35.png
    And in the custom function add this
    Code (CSharp):
    1. if(unity_LODFade.x > 0){
    2. fadeValue = unity_LODFade.x;
    3. }
    4. else{
    5. fadeValue = 1;
    6. }
    The random noise is to get a dithering effect.
    Sadly, the exiting LOD still pops for some reason. The Unity team will have to answer that. But in your case it should work perfectly.

    Also, I see in your picture the fade transition width is 0. This value is the distance width the fade out occurs. So it should be > 0.

    Now all the fading in my game will be better. ;)
     
    moritzcerst likes this.
  7. iscf

    iscf

    Joined:
    Aug 30, 2018
    Posts:
    24
    Oh wonderfull ! I will try it when i have time and i will see if all work.
     
  8. iscf

    iscf

    Joined:
    Aug 30, 2018
    Posts:
    24
    Thanks @Kibelon and @StaggartCreations it work like a charm !
    There is the actual shadergraph

    upload_2020-8-21_9-33-15.png

    One more thing maybe on the same subject, i try to do it with UI World Space but it seems LODGroup doesn't worked with Canvas Renderer (yeah i use it in a very specific way), so i use a special layer culling distance, but it's not quite what i want, and it doesn't call a crossfade effect. It's already great that LOD now work with MeshRenderer but any idea how to handle it ?
     
    Last edited: Aug 21, 2020
    moritzcerst, Ghosthowl and gmgannon like this.