Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Shader Graph Transparency w Depth broken?

Discussion in 'Shader Graph' started by Flow-Fire-Games, Aug 29, 2019.

  1. Flow-Fire-Games

    Flow-Fire-Games

    Joined:
    Jun 11, 2015
    Posts:
    305
    Every shader graph shader I make spits out broken depth when transparency is used, something is very odd

    I think I had read about how to fix it but I just cant find it anymore

    This really should not be the default behavior:



    Opaque (correct depth)


    Transparent - The depth is broken as you can see, backside objects are shown front


    Transparent & Two-Sided - Now its even more broken with very weird edges



    It feels like the depth is inversed, like the most forward vertices are drawn most backward
    Whatever crazy happens with the two-sided, I have no clue

    I have the HDRP depth pass enabled
     
    Last edited: Aug 29, 2019
  2. Flow-Fire-Games

    Flow-Fire-Games

    Joined:
    Jun 11, 2015
    Posts:
    305
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    Use opaque w/ an alpha threshold.

    Correct and efficient sorting of real time transparencies is an unsolved problem.
     
  4. Flow-Fire-Games

    Flow-Fire-Games

    Joined:
    Jun 11, 2015
    Posts:
    305
    this is not an unsolved problem edge case, this is the alpha functionality of shader graph not working at all in any case

    Also Im very sure to have read about the solution somewhere couple months ago, it was something like decreasing a threshold somewhere, but just can't find it anymore. Was maybe of a older HDRP version, but camera, scene settings and HDRP file show nothing alike
     
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    Yes, it is.

    Read up on order independent transparency and you'll find hundreds of articles and papers talking about approximations, and follow up papers detailing why none of them work 100% of the time. You'll also find papers on things like A-Buffer or linked list pixel implementations (which would be true OIT) and see how they utterly tank the frame times when used even on modern GPUs.

    There are hacks and workarounds, some of which the HDRP uses with it's built-in shaders, but which are not (yet?) available for Shader Graph shaders. For example the HDRP Lit shader has an option for Transparent Depth Prepass which helps with objects that you want to look identical to the opaque version of an object, just transparent. This renders the object once only to the depth buffer before rendering it normally with an alpha blending. Again, this is not something available when using Shader Graph.

    This is completely unrelated btw. This is an optimization for scenes with a lot of opaque / alpha tested overdraw, and does nothing for transparencies.


    To repeat my original response, the solution here is to not use "Transparent" mode. Use Opaque and use a Vector1 node or property to set the alpha threshold. There's a UX issue with Shader Graph in that it has a default value assigned to the alpha threshold that looks like it should do something, but the value is totally ignored unless you have an actual node attached to that input.


    The issue with separate objects sorting out of order may be a bug with Unity's new SRP batcher, or maybe an issue with the material's queue being set wrong. Batching systems usually prefer to sort by material to reduce the draw call cost, so they may occasionally (incorrectly) ignore the distance sorting. You might want to report this as an issue to Unity using the in editor Help > Report a Bug menu.
     
    Last edited: Sep 9, 2019
  6. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    The two most commonly used OIT approximations are weighted blend and depth peeling. Weighted blend works relatively well on semi-transparent objects, but completely fails with anything that's near or completely opaque. There's a recent article from Pixar talking about how they used Weighted Blend OIT for previews and were unable to solve this issue after multiple years, so are exploring other options.

    Depth peeling was popular in the past. Basically it works by rendering the scene multiple times with different near and far clip planes. In the days of the PS2 this was great, but on modern GPUs this is terrible for performance. It can also only sort a hand full of objects and doesn't handle self-sorting without a lot more layers (which increases the draw calls and CPU usage considerably). A hand full of modern games use limited depth peeling for handing transparencies with depth of field post processing.

    Intel has an interesting paper where they use pixel syncing which is a hardware feature only Intel's integrated GPUs have ... so no one cares.
     
  7. Flow-Fire-Games

    Flow-Fire-Games

    Joined:
    Jun 11, 2015
    Posts:
    305
    Thanks for the detailed response.

    "none of them work 100% of the time."
    Thats what I meant. This works 0% of the time as of now.
    So this is just not developed in shader graph it seems.
    I will use opaque with alpha clip now and hope AA will solve the messy edges
     
  8. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    Yep. HDRP is completely designed with the assumption you’re using TAA.

    Out of curiosity, is there a particular reason you’re using Shader Graph and not the built in HDRP/Lit shader?
     
  9. Flow-Fire-Games

    Flow-Fire-Games

    Joined:
    Jun 11, 2015
    Posts:
    305
    TAA gives me some very messy black border artefacts in all versions of HDRP ive tested so far (camera TAA setting) but It will sure be fine by the time of our release. Also it has a very well tweaked FXAA implementation that is usable.

    ------------------------------------

    Shader Graph topic:

    I heavily doubt any Unity user / Studio that is professional ever uses the standard shader aside of for things with little complexity like some plants or stones. It does not matter how good the standard shader is, it is a fixed one size fits all solution that is just not realistic for real world professional usage. And for the amateurs who don't make custom shaders, those clearly are not doing channel packing. So the real usage of the lit shader is low-effort background props or bought assets with classic texture workflow or quick tests but for that the forced channel packing is a large inconvenience.

    The same issue with a standard terrain material. Its just never going to be viable in a professional environment, there are always a lot of custom needs and any time spent on the lit shader would be much more efficiently used in shader graph.
    Unity has harshly paid for the many years of lacking behind the unreal 3 or even UDK material editor and still trying to push people towards a standard shader is never going to end well and was really bad historically. Unity has gotten a reputation for looking bad as a cause, while UDK has thrived a community of tech savy artists one upping each other with the material editor. Not even the collaborating studios in the unity blog posts wanted to use the standard shader.
    Hell, cryengine had the best looking shaders for many years but still it was one of the main critique points that they were fixed.

    Really the same with the new terrain tools. They look amazing, but if its bound to one shader, I will have to use hard meshes with a custom shader. Its just not viable. The shader itself is way too simple, and even if it were cutting edge I still couldnt do the things I want, from how it looks, to effects like sand, glitter, animations, decals, deformation etc etc.


    For our hero unit shader workflow, I use a wear mask based approach that is very simple but effective.
    Things I have that the standard shader does not provide:

    - Uses a simple 2 material approach based on unique masks and tiling textures
    I make a wear mask that sets 2 materials apart basically, one usually metal (base layer) and one coating
    The coating is usually rough and the metal glossy, and this automatically makes a complete appearance with just one B&W wear mask and some flat colors required

    - Support for tiling camouflage / skins texture overlay "coat"
    - Support for secondary decal texture overlay
    - Support for degrading wear and coat layer based on the master wear mask
    - Support for hit flash animation
    - Support for AO Based Grime
    - Support for Pivot Ground contact Sand



    Here is a quick demo (pretty low res due to close up)
    I mean I couldnt even do something as basic as a secondary texture overlay with the lit shader, let alone a third, and the UX is a mess. There just can't be one size that fits all or even most. Maybe for most beginners but never for professionals.
     
    Last edited: Sep 13, 2019
  10. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    Yep, in total agreement. Technically we use a lot of the Standard shader in the projects I've been on for the environment, but I've always modified it at least a little, and have lots of custom shaders for hero assets.
     
  11. transporter_gate_studios

    transporter_gate_studios

    Joined:
    Oct 17, 2016
    Posts:
    219
    opaque with alpha clip is not transparent. This would not allow for any kind of gradient for things like... burn decals for instance. So, what you are telling me is that Transparency does not work in Unity? Wow, ok. How do you guys deal with that.
     
  12. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    No, transparency works.

    Just as well as any other game engine at least.

    Like I said above, there's still no perfect solution to transparency sorting, and all of the work arounds come with serious side effects or limitations, so most engines default to not using them even if they do support one or more of the OIT techniques. Literally every real time game engine contends with this problem and works around it in various ways. A lot of major AAA games have basically stopped using transparency at all unless absolutely necessary and lean heavily on dithered alpha testing and lean on TAA to hide it / make it look like smooth transparency. Name a major AAA game and I can probably find you a screenshot of that in action or a rendering talk where they show off a use case for it.

    That doesn't change the fact the correct solution for the case in this thread was to use an opaque shader. There's no reason for them to be transparent.
     
  13. transporter_gate_studios

    transporter_gate_studios

    Joined:
    Oct 17, 2016
    Posts:
    219
    dithered alpha, wow thats crazy I didnt know that. I assume that is basically a checkerboard of fully transparent pixels gradually shading the surface. TAA i have to lookup.
     
  14. KingAustin

    KingAustin

    Joined:
    Jan 12, 2016
    Posts:
    20
    ohhhh i use opaque alpha clipping not transparent alpha clipping.