Search Unity

Feature Request Shader Graph for custom Terrain Shader ?

Discussion in 'Shader Graph' started by Luuke, Mar 10, 2020.

  1. Luuke

    Luuke

    Joined:
    Jan 18, 2017
    Posts:
    13
    Hey everyone,

    I hope that I picked the right thread here and that my question is not redundant.
    My question is weather it is possible to build custom Terrain shaders that work with unitys Terrain system using the Shader Graph Tool. I searched around the internet for a while now and couldnt really find positive answers for this.
    I would like to implement some height based blending and triplanar mapping for my terrain AND use unitys terrain system.
    If it is not possible with Shader Graph, why is it not ? What are the things to concider with terrain shaders ?

    Thanks in andvance

    Lucas
     
  2. mangax

    mangax

    Joined:
    Jul 17, 2013
    Posts:
    336
    i think you can use shader graph to generate terrain-compatiable shaders, espcially by using custom function nodes in shader graph.. you need to check up/ Explore functions used in unity's shaders libraries so you can call them in your shader function and read that data so you can blend/apply your textures in your shader graph shader..

    for example this is a terrain shader in URP: https://github.com/Unity-Technologi...l/Shaders/Terrain/TerrainLitBasemapGen.shader

    you need to see how unity terrain shaders work, apparently they are using splatmaps, so you need to know which functions are being called obtain splatmaps then replicate that effect in shader graph then add your own stuff as well..
     
    Luuke likes this.
  3. ArthyShow

    ArthyShow

    Joined:
    Aug 6, 2016
    Posts:
    23
    Do we have an ETA (or a task on a road-map) for this feature?? Shader-Graph are here since end-2017 and Terrain even more...
     
  4. Fressbrett

    Fressbrett

    Joined:
    Apr 11, 2018
    Posts:
    97
    I would too like this. Waaay too complicated creating terrain shaders with ShaderGraph. I just want a triplanar terrain shader, and can't get it to work :/
     
  5. Bordeaux_Fox

    Bordeaux_Fox

    Joined:
    Nov 14, 2018
    Posts:
    589
    Fressbrett likes this.
  6. Fressbrett

    Fressbrett

    Joined:
    Apr 11, 2018
    Posts:
    97
    boy, the URP is a mess :( thanks for your input though
     
  7. Bordeaux_Fox

    Bordeaux_Fox

    Joined:
    Nov 14, 2018
    Posts:
    589
    Well, in Unity, many things are not achievable out of the box (terrain, water, foliage, etc.) or are very limited, not performent or not good looking. You need either to buy a lot of good asset from the store or have a very good graphic programmer on your side. That's my experience so far. Unless you are an allround talent. Nevertheless custom solutions are in most cases needed and this is not easy. :)
     
    Last edited: Jul 22, 2020
    ArthyShow likes this.
  8. Fressbrett

    Fressbrett

    Joined:
    Apr 11, 2018
    Posts:
    97
    True. I just wish the URP were documented a bit more thoroughly, digging into the repo often feels like shooting into the dark. For anyone interested, the URP Terrain shaders are here
     
    _protagonist, futex and Kalificus like this.
  9. Juvennn

    Juvennn

    Joined:
    Apr 21, 2020
    Posts:
    2
    Hi i wrote a terrain shader with shader graph.


    https://github.com/Gnarly-Games/CustomTerrainShader
     
    ProGameDevUser, Luuke and meg97 like this.
  10. JJRivers

    JJRivers

    Joined:
    Oct 16, 2018
    Posts:
    137
    Thank you for the example mate, been meaning to give this a shot and with an example i'll certainly attempt it aswell.

    Edit; Can make this work fine with URP but attempting conversion to HDRP even after four hours of digging through the TerrainLit shaders it turns into a vertex monster.
     
    Last edited: Apr 20, 2021
  11. Scott_Flinders

    Scott_Flinders

    Joined:
    Mar 31, 2021
    Posts:
    3
    I downloaded your custom terrain shader Juvennn.
    Whenever I apply it to a terrain I get the error "Cant use material with shaders which need tangent geometry on terrain"
    Which is the same error I was getting with my own custom shader.
    Any ideas how to resolve this ? Otherwise it isn't really usable.
     
    _protagonist likes this.
  12. MTUA

    MTUA

    Joined:
    Oct 26, 2018
    Posts:
    29
    Hi

    In my experience, draw instancing is in terrain settings is usually responsible for the vertex monster. My PC is a potato and I get 2 frames a second whether I'm draw instancing or not. But in my PCs defense, I was running a scene with about 2 million tree prefabs. Yes occlusion was active.
     
  13. JJRivers

    JJRivers

    Joined:
    Oct 16, 2018
    Posts:
    137
    You
    Convert the normals to object/worldspace.
    Also note that particular error will show up with a shadergraph shader regardless of whether you fetch any tangent data or not.
    So make sure you arent using tangent space for anything and output normals in object or worldspace.
     
    Last edited: Jul 12, 2021
  14. JJRivers

    JJRivers

    Joined:
    Oct 16, 2018
    Posts:
    137
    As an update, you can in fact actually use tangents on the terrain despite what the warning says which really just presumes that the shader you use for the terrain doesn't use them, you can suppress that warning somewhere but i cant remember where now.
    And it is also possible to make a shader graph for HDRP Terrain use but it is quite a bit more involved than just copying or updating Juvennn's initial work which was a very good starting point to terrain shaders but there's quite a bit more to it if you want to recreate the full functionality of a decent terrain shader.

    However as a bonus effect if you make your own graph however you can also support lots of features that Unity TerrainLit does Not support, any number of lights your SRP supports, vertex animation, tangent space normals and special effects masks and the like.

    Or the infamous TODO: Triplanar / POM comments that remain in the Unity shaders since who knows how long ago :)
     
    _protagonist and Luuke like this.
  15. Fressbrett

    Fressbrett

    Joined:
    Apr 11, 2018
    Posts:
    97
    Update: For a project I have been working on we used this triplanar shader, which our artists created. They said its using splat maps, and as such only supports up to 4 different textures. Not sure if this ended up working 100%, but this might be a good starting point for anyone working with URP:

     

    Attached Files:

  16. TinySynapse

    TinySynapse

    Joined:
    Feb 29, 2020
    Posts:
    10
    So instead of painting textures with the terrain brush tool you manually create splatmaps and feed them in later? Oh boy still not a great solution. Like you said URP is a mess. Thanks for your input. I'm currently at the same roadblock.
     
  17. JJRivers

    JJRivers

    Joined:
    Oct 16, 2018
    Posts:
    137
    That sounds like a horrible workflow and utterly unnecessary if so o.0, why not just apply the stuff to the terrain itself.

    Only real downside atleast in HDRP is that one can't use instancing with a ShaderGraph shader. One could propably fix that by injecting the requisite matrices with an include but i haven't seen the need yet.
    For URP it was ten times easier to get it working.
     
  18. TinySynapse

    TinySynapse

    Joined:
    Feb 29, 2020
    Posts:
    10
    I was wrong with my last post. After seeing a explanation here
    everything makes more sense now.
     
  19. JJRivers

    JJRivers

    Joined:
    Oct 16, 2018
    Posts:
    137
    Had a peek at that, just be sure to not include mistakes from that (too many unique sampler states on most things for example will result in a failed compilation/crash on hardware that URP projects often target, there's a limit to the number of them you can use) and it'll work well enough yup