Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

HDRP: replacing alpha fade with dither opaque fade in graph?

Discussion in 'Graphics Experimental Previews' started by hippocoder, Jan 28, 2019.

  1. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Hi all, anyone got a nice HDRP example of dither-fading something opaque instead of using transparency/alpha? I do not know where to start and it would be a lovely effect for when the 3rd person player is too close to camera. Unfortunately transparent is out of the question as it pops with different lighting and has multiple meshes.

    I would probably be using it on most things, and may further modify it so it's got a spherical radius etc - but can do that later.

    (Graph of course)

    Thanks!
     
  2. Jick87

    Jick87

    Joined:
    Oct 21, 2015
    Posts:
    124
    I've been using a custom node for this. I just put it on GitHub if you're interested: https://github.com/jamesdimick/UnityMiscellaneous/blob/master/ShaderGraphNode_FadeOverDistance.cs

    It has values for fading on a near plane AND fading on a far plane, at the same time. It fades based on a sphere around the given position (usually you just plug in the camera position, but I made it an input so you can fade around arbitrary positions also). Of course you can modify the code if you only want to fade at one distance.

    The fade values are a Vector4.
    The X is where it starts to fade from zero to one at the near distance (I usually set this to zero).
    The Y is where it will be done fading and be one from there on at the near distance (I like 0.15 so far).
    The Z is where it starts to fade from one to zero at the far distance (something like 50 or such works nice).
    The W is where it will be done fading to zero at the far distance (something like 55 would make it so it fades out from 50 meters until 55 meters).
    I guess maybe that isn't the best explanation, but you should see what it does if you play with the values a bit.

    It actually uses the same code as the built-in dither node they have in shader graph. I actually found some other code that allows you to dither based on a texture. I was thinking of implementing that but just never got around to it.

    Hope maybe it helps. Let me know if you find any way to improve it or if you find any issues. ;)
     
    Reanimate_L and hippocoder like this.
  3. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Thanks for being so kind to share! will check it out now :) I actually wanted a definable sphere position so that's basically everything!
     
  4. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Had a play, awesome. Works better with some DOF to mask it too! Was thinking - should it be jittered or is it better like this?
     
  5. Jick87

    Jick87

    Joined:
    Oct 21, 2015
    Posts:
    124
    Just pushed a change. There is now a jitter option. Might need to re-assign one or two of the outputs because I changed the slot ids to add the new field. Does that work how you were thinking it should?
     
    hippocoder likes this.
  6. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,792
    Based on what I see in other games, it's generally better jittered if it works nicely with the game's TAA.

    If there's no TAA, it's less distracting if there's no jitter.
     
  7. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Yeah, but TAA is changing in 2019.1 I think (will check when it goes beta - lots will change).

    Hey! that's fab! I don't know it's better or worse, but it seems situational to settings, keeping it regardless as a good dither fade like this has endless uses as you know! Thank you again :)
     
    Jick87 likes this.
  8. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    @Jick87 no fault of your own but this no longer will work in 2019.1 due to custom node API becoming private. I suppose we should wait a bit longer! :D
     
  9. Jick87

    Jick87

    Joined:
    Oct 21, 2015
    Posts:
    124
    Yeah, hopefully they will be releasing the new API in one of the next few betas (if they still plan to have it out by the time the full 2019.1 hits as they have stated before). I plan to update all my custom nodes when that happens. I would do it now if the API were already available. It would be cool to see what they have so far for the new API. As of now we have no idea what it's even going to look like or how it will differ from the current one...