Search Unity

HDRP no custom shaders?

Discussion in 'Shaders' started by jister, Aug 22, 2018.

  1. jister

    jister

    Joined:
    Oct 9, 2009
    Posts:
    1,749
    We ported a project of ours to use HDRP in 2018.2.2. as a test. First thing we noticed is that all custom shaders go pink. After some googling I read in some post around june 2018 that custom shaders (and even the Graph) are not supported (yet?).
    Some people said rewrite them, but i don't find any hint as to what to rewrite or how, also read "make a custom pipeline", but since there is not to much documentation yet it's kind of a blank on how to do that either.
    Is there any work around at the moment to get them to work?
     
  2. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,028
    For a shader to be compatible with a scriptable render pipeline, it has to have a tag.

    Example for HDRP:
    Code (CSharp):
    1. Tags{ "RenderPipeline" = "HDRenderPipeline" }
     
  3. Julien_Unity

    Julien_Unity

    Unity Technologies

    Joined:
    Nov 17, 2015
    Posts:
    72
    Adding this tag is not sufficient. For a shader to be really compatible with a given pipeline it needs to have a set of passes specific to this pipeline.
    Porting a shader to HDRP, is actually a pretty involved process. We don't have documentation for this for now but the recommended way to do that in the future will be to use the Shader Graph.
     
    hippocoder likes this.
  4. jister

    jister

    Joined:
    Oct 9, 2009
    Posts:
    1,749
    is there a way to convert custom shaders to Shader Graph?
     
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Not automatically, no. You’d have to recreate them from scratch in Shader Graph, just like you would have to write new vertex fragment shader passes for the LW or HD pipelines, but you would only need to do it once for both. However it should be noted that Shader Graph is like an even more limited Surface Shader which you can only create unlit or PBR shaders in, no custom lighting models.
     
  6. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,550
    I'm wondering if there are any plans to make a "surface shader" equivalent for the HDRP to make converting a lot of people's shader easier. It might have to be a little more complex than the old SURF setup, but a predefined structure that we can mostly just paste our code where it needs to go and link things up would be great for getting a lot of old shaders working with little effort.
     
  7. jister

    jister

    Joined:
    Oct 9, 2009
    Posts:
    1,749
    is there an example out there that shows a rewritten shader?
    Will this change in the future?
     
  8. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    My understanding is that Shader Graph was intended to replace the concept of Surface Shaders, and they had no plans on extending or otherwise making a written code based shader generation system like it. There’s enough of us that have asked for it that they’ve made some comments about reevaluating this choice again at some point in the future. For now though, don’t expect it.

    Not really, no. The render pipelines have been in flux as they’ve still in active development. There’s no guarantee a custom shader written today will work with tomorrow’s version of either of the new pipelines.

    They’ve been adding some features that would allow to do some limited custom shading on otherwise unlit shaders, but so far it looks to be limited to ambient lighting and a single unshadowed directional light. This is similar to the he direction Unreal has taken where they’ve completely removed any support for custom lighting models being created within the node based material system. Instead if you want that, they’ll likely push you toward directly customizing the render pipeline itself, which is also what Unreal does.
     
    jister likes this.
  9. Shinao

    Shinao

    Joined:
    Mar 7, 2014
    Posts:
    36
    I'm still waiting for custom HDRP shaders before transitioning to the SRP. At least a way to generate an empty shader from the Shader Graph and we will have to plug into it our code. Without this I can't see how HDRP gains some traction there are too many features that would take time if at all possible to implement in the Shader Graph :
    - Use of instanced indirect
    - Custom StructuredBuffer
    - Custom shader variant
    I'm not an asset creator but I know some assets that I own that will also depend in some of those features and more.
     
  10. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,550
    You can. Just create a new PBR or Unlit shadergraph shader. Then write a code-node script that defines what inputs and outputs your node has and the functionality of it. So can write your whole fragment program in it and then simply create the node in the shader graph and connect its output to the master node.
     
    jister likes this.
  11. Shinao

    Shinao

    Joined:
    Mar 7, 2014
    Posts:
    36
    You just discarded half of my post though... Unless I am missing something I still can't use custom buffers and use them in a code-node script or have shader variants.
    To be honest even if it was possible to declare the buffers and create a special node to use in the Shader Graph the debugging and tweaking of the shader at the moment is a bliss and I think it would be a pain on the Shader Graph side (toggling comments, switching values, ordering, etc), though I see it useful if you already know what you want.
     
    Snowirbis likes this.
  12. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,550
    I was only replying to that part of your post, because yes it's limited in that way. Just wanted to point out that at least that feature exists and can be expanded upon as they develop things further.
     
    jister likes this.
  13. Davood_Kharmanzar

    Davood_Kharmanzar

    Joined:
    Sep 20, 2017
    Posts:
    411
    hello,
    there is an attached Fur shader that i tried to adding RenderPipeline tag to using it on HDRP ...
    but its not completely working ... can someone make this shader full support for HDRP?
     

    Attached Files:

    • Fur.zip
      File size:
      42 KB
      Views:
      513
  14. Kronnect

    Kronnect

    Joined:
    Nov 16, 2014
    Posts:
    2,906
    Indeed. I saw a pull request where they renamed the function that samples shadow for main light in 4.0.0-preview so I agree creating custom shaders atm is just a ticking bomb.
     
  15. WILEz1975

    WILEz1975

    Joined:
    Mar 23, 2013
    Posts:
    375
    In practice, for projects already started some time ago they can forget about the HDR Pipeline.
    Well.
     
  16. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    This Unity tutorial claims (about 1 minute in) that hand-written shaders can coexist with ShaderGraph shaders. Is that no longer true? Or does it apply to some pipelines and not others?

     
    twobob likes this.
  17. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    ... o_O

    Custom shaders work fine with any SRP. Shader Graph itself is only used by the editor to generate normal vertex fragment shader code that is what the engine actually sees and uses. Most of the built in shaders for the SRPs are custom shaders since there are a lot of features that Shader Graph doesn’t yet support.

    The only difficulty is both SRPs are renderers in active development, which means things can change. To be fair, this has been true even for the built in renderers with common macros changing every couple of versions of Unity 5.
     
  18. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    OK, that's useful information. I'm not sure if it's practical information, though, since creating a starter shader with any of the "Create > Shader" options produces a non-HDRP compatible shader, as does following the manual on writing shaders. And in my searching this morning, I found plenty of Unity folks saying "custom shaders will have to be rewritten" but not a peep about what exactly has to be done.

    So, is there any information on what must be added, removed, or changed to make even a trivial custom shader work under HDRP? I'm sure the information is out there (perhaps in the form of source code) but I don't know where to find it.
     
    PraetorBlue, fct509 and EricWilliams like this.
  19. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Unlit shaders work fine.
    Lit shaders Unity is going to direct you to use Shader Graph, and as best I can tell don't want to have to support or actively document the actual HLSL shader code.

    In lieu of that, you can look at the code yourself, and see both what the shaders do and the code that sets the values they're using. Or you can start from Shader Graph and use it to generate a starting shader.

    As mentioned, things are in flux still. I think someone in the community put out tutorial and example shader for Lightweight a month or two ago that I think is already out of date.

    And yes, it means a lot of the documentation isn't applicable for the SRPs.
     
    Last edited: Aug 29, 2019
    JoeStrout likes this.
  20. carcasanchez

    carcasanchez

    Joined:
    Jul 15, 2018
    Posts:
    177
    Bumping this.
    With the release of 2019.3, I would like to know if there's any plan on documenting about custom shaders in HDRP.
    Besides, the latest version of shader graph features new vertex outputs (Position, Normal and Tangent), instead of the old Position, which messes with all the vertex displacement calculations I have done.
    I am in a crossroad right now, because I have a very complex shader written for the standard pipeline that I have no idea on how to convert to HDRP nor Shader Graph, due to the lack of non-outdated tutorials.

    I have checked the code of the Lit shader and some shaders that a guy from Unity Japan posted in github, but the files are infinitely large, and (besides HLSL seeming very much usable than CG) its difficult to tell what is needed to create a shader in HDRP.
     
  21. Laex410

    Laex410

    Joined:
    Mar 18, 2015
    Posts:
    51
    I recommend looking at the HDRP/Lit shader and stripping it down until you have a basic framework you can edit and work with. It will help you understand the structure of the shader and you'll understand how to setup the SurfaceData and BuiltinData structs required for using Unity's lighting model.

    It's really a pain to do all of that (took me about 2 full days) but in return you'll have a proper framework for your custom shaders in which you actually know what's going on.

    Just focus on what's important. If you don't need dxr, remove everything related to it, if you don't need sss, remove everything needed for that and so on.
     
    hertz-rat likes this.
  22. carcasanchez

    carcasanchez

    Joined:
    Jul 15, 2018
    Posts:
    177
    That's my intention. However, I have a little doubt: taking for example the Unlit shader, why there are like four files of different type (Unlit.cs, Unlit.hlsl, Unlit.shader and Unlit.cs.hlsl)?
    I am aware how Unlit.hlsl and Unlit.shader work, but what role the .cs files take in the workflow?
    I see there is a line called [GenerateHLSL], and the other file contains a comment that "This is a generated file. Don't edit by hand". Is this a new way of generating shader files from C#?
     
  23. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    1,168
    Are there any tools or helper we could use to convert old cg shader into new shadergraph easier?

    I think at least most cg function are possible to be converted to a custom function node. If this true then there should be tools or at least a guideline for conversion. Is it possible?
     
  24. hertz-rat

    hertz-rat

    Joined:
    Nov 3, 2019
    Posts:
    71
    I'm extremely confused about the situation. This is what I've gathered over the last week of exploring shaders, is it correct?

    1. The shading language will change frequently, and so will continue to be undocumented and sort of a case of 'use at your own risk'? IE, all the effort is going into making Shader Graph the new go-to, so that manual shaders are unnecessary?
    2. If we want to use shader features not in shader graph, we have to downgrade from URP or HDRP back to the standard shader, or else try to figure things out on a 'use at your own risk' basis?
    3. The old standard shader is going to be deprecated in the next year or two?
    4. The shader graph provides an abstraction layer and will continue to work as the underlying language changes?
     
    Last edited: Feb 28, 2020
  25. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,550
    1. Yes
    2. Yes
    3. I haven't seen a definitive date set but from what I gather it will be phased out at some point as LWRP/URP replaces it as a "default" eventually. I wouldn't expect this to happen until Unity 2022 at least though.
    4. Yes that is the main benefit of shader graph, you can almost liken it to what Surface shaders were, even though the underlying shader system change a fair bit over the years, the surface shaders continued to work since they'd simply recompile to suit the updated code. There is still a small chance some graphs could break far down the road from a decision they might have to make, but with shadergraph that's usually just going to mean replacing a node or making some new connection.
     
    hertz-rat likes this.
  26. gputhread

    gputhread

    Joined:
    Dec 7, 2018
    Posts:
    36
  27. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Nope. Literally impossible to convert. The SRPs don’t support multi-pass shaders, so that one can never be converted.
     
    gputhread likes this.
  28. gputhread

    gputhread

    Joined:
    Dec 7, 2018
    Posts:
    36
    Ok thankyou:). Any key inputs nodes by which I can make similar effect with shadergraph?
     
  29. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Not really, no. This style of fur rendering needs support for multi-pass shaders or geometry shaders. As mentioned multi-pass isn’t supported at all, and Shader Graph has no support for geometry shaders. This is something you’d have to write from scratch which is possible, but exceedingly non-trivial with how complex the HDRP is.
     
    gputhread likes this.
  30. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,550
    You can still technically do a multi-pass type setup by moving the passes to multiple materials and applying them all onto the object's materials slot. It's not as ideal/clean though.
     
  31. TOES2

    TOES2

    Joined:
    May 20, 2013
    Posts:
    135
    Any news on this? I would really like to see a working minimal HDRP shader code that can be extended.

    I tried to use Shadergraph, but it is too slow, its intended for artists and does not allow coding special effects that's super important in games, and managing variants is a huge headachet. By using shadergraph I ended up with hundred thousands variants for even the most basic shaders. Unitys recommended way to solve this is to take a snapshot of all loaded variants in the scene and only generate those for the runtime, but this does not work with dynamically loaded content where the shader variants is unknown. Compiling them all takes an hour and ends in crashing Unity.

    Unity, please do not force us to use Shadergraph that is so heavy without allowing custom code, that is such a huge setback and blocks creativity and innovation forcing everyone into a much smaller box than before.
     
    JoeStrout likes this.
  32. DEEnvironment

    DEEnvironment

    Joined:
    Dec 30, 2018
    Posts:
    437

    not certain about SG however amplify has this
    Unity Products:Amplify Shader Editor/Custom Expression - Amplify Creations Wiki