Search Unity

Question Shader always on top

Discussion in 'Shader Graph' started by darkesco, Jul 16, 2019.

  1. darkesco

    darkesco

    Joined:
    Mar 19, 2015
    Posts:
    61
    Sorry for the trivial question. I assume this is so easy that no one asks, but here goes: I am trying to make health bars, inventory dialogs, etc. I need to know how to disable depth so the UI is always on top. I believe this was ZTEST Always or something in shader lab. How do I set this in shader graph?

    Thank you.
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,336
    You don't, it's not a feature that's currently supported.
     
  3. ph_

    ph_

    Joined:
    Sep 5, 2013
    Posts:
    232
    I've created a plugin on the asset store that add the ZTest / ZWrite / Cull settings in ShaderGraph, among a lot of other features (like SimpleLit master node, toon and custom lighting, lot of different noises ...).
    Here's what it looks like
    sge_settings.jpg

    If you're interested, you can get it there: ShaderGraph Essentials on the asset store
    Don't hesitate to pm if you have any question!
     
    bgolus likes this.
  4. darkesco

    darkesco

    Joined:
    Mar 19, 2015
    Posts:
    61
    Thanks bgolus. If I impliment this myself, do you know if it will cause performance issues? Honestly, I don't understand render pipelines and wonder if this will disrupt the flow. I can test it myself possibly, just wondering if this is why it's not added yet. I would think UI elements would be a critical shader technique for almost all apps and games, so maybe there is a reason Unity didn't add it yet.
     
  5. darkesco

    darkesco

    Joined:
    Mar 19, 2015
    Posts:
    61
    I will check this out. Looks really neat! Thank you.
     
    ph_ likes this.
  6. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,336
    None that I know of.

    Okay ... let's go down this hole.

    Shader Graph in its current form was designed for making shaders that go on objects in the scene. Any use beyond that is outside of the scope of its current functionality. Unity has stated explicitly that Shader Graph isn't intended to be used for UI or post process effects. I don't think there's any grand "reason" for this outside of looking to limit the scope of Shader Graph to get it into a working state for users. Unfortunately anyone coming from other tools with similar node based material editors, or even users of Shader Forge and Amplify Shader Editor are already used to using the node based editor to make shaders for basically everything, and Shader Graph simply wasn't created with that in mind. It probably doesn't help that Shader Graph is being written at the same time as the LWRP (now Universal RP) and the HDRP which have significantly different and frequently changing requirements. One of the original intents for Shader Graph was having a single shader that can be used in both pipelines equally, but that has already been kind of lost as for the HDRP they added the Lit Master Node which is incompatible with the LWRP, and there remains no way to make a Shader Graph that uses the LWRP's more efficient Simple Lit shading model.

    The PBR Master Node remains, being more expensive than what many LWRP users want to use, and less featured than either pipeline user wants access to.

    I have no doubt that more features will come eventually, but I don't envy the Shader Graph team's task. Some of this speaks to the amazing job Amplify have done with their own node based editor, though that was partially built on top of almost a decade of Unity's work on Surface Shaders and targeting the mature and mostly static built in rendering paths, they do also now support the LWRP and HDRP. It also speaks to the huge gulf Unity has in their goal to finally catch up to and potentially surpass Unreal in areas Unity has traditionally been lacking in.
     
  7. darkesco

    darkesco

    Joined:
    Mar 19, 2015
    Posts:
    61
    That makes perfect sense. Thank you for the clarification.
     
    ph_ likes this.
  8. cptSwing

    cptSwing

    Joined:
    Jul 2, 2015
    Posts:
    8
    With the new Scriptable Render Passes you can choose to not render a certain layer and then render it specifically at a certain order in your render queue :cool:
     
  9. Flow-Fire-Games

    Flow-Fire-Games

    Joined:
    Jun 11, 2015
    Posts:
    305
    you can make a mesh / plane and change the "Priority" in the mesh renderer
    We definitely use shaders for UI, with a bit of fiddling it does work, but you may need to make other UI parts as mesh with shader as well, and as always seperate camera for UI
     
    ROBYER1 likes this.
  10. Strieglitz

    Strieglitz

    Joined:
    May 11, 2017
    Posts:
    13
    I found the solution in another thread but i dont find it right now to link it, so if anybody finds it let me know.

    you do your Shader as you usually do in Shadergraph and save it. Then click on the Master Node and click "Show Generated Code"

    Unbenannt.png

    this will open your ide with the Generated Shadercode, if you make you changes here unity will automaticly override them.

    Unbenannt2.png

    So you need to copy the whole shadercode and go to your asset folder, and generate an new shader ( not a shadergraph one ) then you copy your shadercode into the new one , give it a name on the top line and make your changes like

    ZTest LEqual -> ZTest Always
    ZWrite On -> ZWrite Off

    Unbenannt3.png

    then you should have your Shadergraph Shader always on top ( maby you have to set the renderQueue Higher )
     
    Last edited: May 11, 2020
    Evercloud, pmain8, CyrilGhys and 6 others like this.
  11. BruinsCat

    BruinsCat

    Joined:
    Feb 11, 2018
    Posts:
    2
    This worked for me! Thank you!
     
    Strieglitz and Kokowolo like this.
  12. Kokowolo

    Kokowolo

    Joined:
    Mar 26, 2020
    Posts:
    59
    Thanks, Strieglitz! Super helpful!
     
    Strieglitz likes this.