Search Unity

Terrain Grass Detail hack for HDRP (Shader inside)

Discussion in 'World Building' started by Flamacore, Mar 5, 2019.

  1. Flamacore

    Flamacore

    Joined:
    Dec 17, 2013
    Posts:
    122
    Hey there all. Since I've seen a few different posts and threads on this, thought I'd share what I have in my hand. Many people (like me) have a need for detail textures on the newest terrain engine for hdrp. The original one drew all the details in pink as they had no shader support.

    So I've come up with a rather hack than a great shader. Using the ShaderGraph, one can actually make a supporting lit shader for painting detail on terrain. Just use a main texture with reference name _MainText and put your shader under path Hidden/TerrainEngine/Details and name it WavingDoublePass.

    Please bear in mind that this is a very basic shader hack. No idea on performance. Please try/use with caution and definitely back your scene/project up before using this.

    Here's the link:
    https://github.com/flamacore/UnityHDRPTerrainDetailGrass
     
  2. Flamacore

    Flamacore

    Joined:
    Dec 17, 2013
    Posts:
    122
    Updated with experimental wind :)
     
  3. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,268
    If anyone knows how to get billboarding working on this that would be great. Its the only feature thats missing to make it a drop in replacement for the current broken in built
     
  4. Flamacore

    Flamacore

    Joined:
    Dec 17, 2013
    Posts:
    122
    Well I've tried my best to replace BillboardWavingDoublePass with a billboard I designed in shadergraph as well but somehow it simply refuses to render anything when set to billboard. Not sure why at this point... The shader works fine when I try it on a simple mesh and really makes it a perfect billboard but when I rename it to BillboardWavingDoublePass in the same folder as the normal one, it simply just does not want to draw...
     
  5. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,268
    @wyatttt would you be able to advise how to hook this up? The shader is working so thats the harder bit done I feel :)
     
  6. Flamacore

    Flamacore

    Joined:
    Dec 17, 2013
    Posts:
    122
    This is the bit that generates billboard view but as I said, somehow the billboard renderer on terrain does not render this. Simply shows blank :)
     

    Attached Files:

  7. Flamacore

    Flamacore

    Joined:
    Dec 17, 2013
    Posts:
    122
    Also I've updated github once more to provide better alpha shading.
     
    MadeFromPolygons likes this.
  8. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,268
    Im going to look into this over weekend as Ill be back to doing dev on my personal project which I needed the grass for, if I make a breakthrough I will submit a pull request to the repo :)
     
  9. wyattt_

    wyattt_

    Unity Technologies

    Joined:
    May 9, 2018
    Posts:
    375
    @Flamacore if you go to one of the wireframe debug views for the scene view, does it show the geometry for the grass?
     
    MadeFromPolygons likes this.
  10. Flamacore

    Flamacore

    Joined:
    Dec 17, 2013
    Posts:
    122
    @wyatttt Interesting question and the answer is no. The wireframe disappears. Any leads I can follow from here?
     
  11. wyattt_

    wyattt_

    Unity Technologies

    Joined:
    May 9, 2018
    Posts:
    375
    What about modifying the Shader Category for the graph? Did you do that for both?
     
    MadeFromPolygons likes this.
  12. Flamacore

    Flamacore

    Joined:
    Dec 17, 2013
    Posts:
    122
    Umm okay not exactly sure what you mean by that. I gotta say I'm not an expert at shaders or grapsh :) I2m just a mere tinkerer... So care to elaborate a bit? :)
     
  13. wyattt_

    wyattt_

    Unity Technologies

    Joined:
    May 9, 2018
    Posts:
    375
    Of course. Sorry about that. So for the shader that works, you have set the shader category/path to "Hidden/TerrainEngine/Details". Did you also do that for the Billboard ShaderGraph?
     
    MadeFromPolygons likes this.
  14. Flamacore

    Flamacore

    Joined:
    Dec 17, 2013
    Posts:
    122
    Ah ok got it, Definitely did so. Both shaders are under that category. Maybe we're talking about a naming issue or something else? Also as another note, this might be of interest; When I take a look at the original BillboardWavingDoublePass shader, I see the render mode is set to "GrassBillboard" but as far as I know there's nothing like that I can set to in Shader Graph. So, could this be a lead?

    Thanks for all the help btw. Really appreciate your time :) @wyatttt
     
    MadeFromPolygons likes this.
  15. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,268
    Guys just wanted to chime in and say that the work you guys are putting into this issue is not going un-noticed! I myself have been wanting a solution to this for a while and I know a few other people such as @hippocoder will directly benefit from the time you are putting in so a very warm thank you!
     
    Sonorpearl likes this.
  16. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    27,971
    I will use Unity's own or Vegetation Studio Pro. This is not a criticism, just the original plan :D but very grateful to community for stepping up.

    Also I think maybe Unity's graphics depts could use a few more hands!
     
  17. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,268
    Is vegetation studio worthit? I have been teetering on the edge for a while now, still not sure if its worth the purchase?
     
  18. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    27,971
    Best talk to the author. It doesn't work until custom nodes return to SRP though (soon ish). It's by far the best vegetation rendering in Unity though, by miles. But that's partly due to Unity entirely lacking in this department too.

    I think it's performance and tools are very valid and useful additions to anyone's terrain-based toolbox. Weirdly I don't want to use it but probably will have to. The reason I don't want to use it is nothing to do with the asset, simply I like to use built in stuff where possible in case of depreciation.
     
    MadeFromPolygons likes this.
  19. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,268
    Thats mostly my concern, I have had too many assets get unsupported or removed entirely from asset store that I try my best to stay clear of them entirely. But as you say it seems to be the best solution for vegetation currently so I guess I may have to bite the bullet. Anyway I will contact the author for more information and watch some videos regarding it, thanks!
     
    hippocoder likes this.
  20. abstractfragment

    abstractfragment

    Joined:
    Jan 16, 2014
    Posts:
    15
    For some reason, I'm not getting this workaround to take in 2019.2 HDRP alpha? I drop it into the assets folder and nothing happens. Am I missing something?
     
  21. mr-Fox

    mr-Fox

    Joined:
    Jun 10, 2015
    Posts:
    2
    This no more working since 2019 version, because way to engine find shaders by name is broken. You can copy HDRenderPipelineEditorResources from default package folder, paste it to any place, set it to use by HDRenderPipelineAsset and assign shaders there. But grass appears only in scene view.
     
  22. abstractfragment

    abstractfragment

    Joined:
    Jan 16, 2014
    Posts:
    15
    Dang it but thanks anyways.
     
  23. Psychoram

    Psychoram

    Joined:
    Jun 1, 2014
    Posts:
    4
    In unity 2019.1 Hdrp 5.13 is not working. how to solve?
     
  24. FNGamesAlex

    FNGamesAlex

    Joined:
    Sep 22, 2013
    Posts:
    4
    Any news on how to make grass show in unity 2019.1?
     
  25. Troast

    Troast

    Joined:
    Mar 5, 2017
    Posts:
    11
    Yeah I also need grass to work in HDRP and Unity 2019!
     
    ROBYER1 likes this.
  26. crysicle

    crysicle

    Joined:
    Oct 24, 2018
    Posts:
    93
    Can a dev comment on the expected date when the terrain component with all of it's features would be synced with the rendering pipelines? With the constant changes to the HDRP and LWRP and some features that were expected in 2019.1, but were pushed back to 2019.3 it doesn't look like it would be any time soon. This makes me think that creating your own painting tools when it comes to details and wind effects would be more appropriate rather than looking to find a new hack on a new released unity or pipeline version.
     
    warthos3399 and ROBYER1 like this.
  27. wondermanstudio

    wondermanstudio

    Joined:
    Dec 14, 2018
    Posts:
    1
    Is that ok to use any prefab placement tools instead? How to get a good performance?
     
    Phoenix116 likes this.
  28. Phoenix116

    Phoenix116

    Joined:
    Jun 30, 2016
    Posts:
    39
    Good question, I have the same doubt, if we place grass manually and set them to static, we should get the same performance than the default grass, right?
     
  29. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    27,971
    You'll get awful performance. Possibly the worst.

    Static batching: this will consume much more memory and go via CPU, it's just bad for lots of little things. Static batching is for fewer big infrequent and different objects that would not normally batch.

    However, some developers choose to actually make clusters of grass as single meshes. This is *not* the same as static batching. It's just combining grass meshes ahead of time into bigger groups. This will hurt you if you don't lod/manage them though.

    For grass it's best to use a proper instancing asset from asset store, something that can handle general cases like asteroid belts, rocks, grasses etc.

    Technically you'd want to use a compute shader to decide what to draw and draw mesh instanced indirect, but that's not for the faint hearted (experienced devs only) and that's what asset store solves in that respect.

    Otherwise the best option would be to use a regular object with camera culling layers set up so they are culled past a certain distance, and ensure the material has gpu instancing enabled.
     
    warthos3399 and wyattt_ like this.
  30. Sonorpearl

    Sonorpearl

    Joined:
    Sep 8, 2017
    Posts:
    32
    @Flamacore How do you use the Shader, or can you even use the Shader in Unity 2019.2 with HDRP? When we paint Terrain Details, even with the Shader inside the project, the Textures are still pink.
     
  31. jonathan_unity900

    jonathan_unity900

    Joined:
    Jul 4, 2019
    Posts:
    1
    Same Question!
     
  32. Flamacore

    Flamacore

    Joined:
    Dec 17, 2013
    Posts:
    122
    Hey, sorry for the late responses but this is not tested for any other version than 2018.3 so I'm not sure how it would perform on 2019 :) As I stated on the github page, it's experimental and may not work as expected depending on many things. For example they may have changed the default name or location for the default unity shaders so they may not get replaced anymore.

    It could be any number of things and unfortunately I don't have the time to test every possibility around that.
     
  33. florianalexandru05

    florianalexandru05

    Joined:
    Mar 31, 2014
    Posts:
    1,386
    Does not work at all in Unity 2020... I made a shader as well but I can't seem to replace it anymore.
     
  34. Goatogrammetry

    Goatogrammetry

    Joined:
    Apr 27, 2017
    Posts:
    184
    Folks. 18 months later I come back to Unity to update an asset pack to 2020.3 LTS (because now the shaders are broken) and there's still no terrain detail shader, but we have eyeball shaders? Frankly I'd like it if we had 50 shaders built in... 5 kinds of snow, 10 kinds of water, tons of FX shaders, yadda yadda. But you know, grass, foliage, and terrain detail shaders are kinda critical. Please just have someone throw one together for us this very week! (Marking my calendar)
     
  35. Carrion-Crow

    Carrion-Crow

    Joined:
    Apr 3, 2015
    Posts:
    13
    It's just insanity to release an LTS version without working standard functions.
    Releases and patches at the Cyberpunk 2077 level


    It should be a shame.......
     
unityunity