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

[RELEASED] DirectX 11 Grass Shader

Discussion in 'Assets and Asset Store' started by Nonakesh, Aug 17, 2015.

  1. Padilha

    Padilha

    Joined:
    Jun 6, 2016
    Posts:
    12
    I tried in a new terrain, the grass does not appear. The grass seems to work only on the "walls" of the terrain.

    Edit: Another problem, when i use a probuilder object give me the following error when i'm trying to Add/Remover/Paint:
    Code (CSharp):
    1. Width and height must be positive
    2. UnityEngine.Texture2D:GetPixels(Int32, Int32, Int32, Int32)
    3. StixGames.GrassShader.GrassPainter:ApplyBrush(Vector3) (at Assets/ExternalAssets/StixGames/GrassShader/Scripts/GrassPainter.cs:124)
    4. StixGames.GrassShader.GrassPainterWindow:DrawSceneGUI(SceneView) (at Assets/ExternalAssets/StixGames/GrassShader/Editor/GrassPainterWindow.cs:447)
    5. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
     

    Attached Files:

    Last edited: Mar 23, 2020
  2. sturentzler

    sturentzler

    Joined:
    Jan 8, 2017
    Posts:
    14
    Hi. Using 2019.3.0f6 whether using HDRP or URP the material turns pink when I: import Grass Flow asset, make a new material and assign any grass flow shaders. Help please. Thank you.
     
  3. Padilha

    Padilha

    Joined:
    Jun 6, 2016
    Posts:
    12
    I just discovered the problem, if I reduce the size of the terrain, which in my case went from 1000x1000 to 23x23 the grass will behave as described in my other posts.
     
  4. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    I don't think it has something to do with UV's, I think it's a problem with the density settings. The shader uses edge width as the base for its density, so it's possible that the steep areas are handled differently.

    Have you tried changing the falloff start/scale/power settings? Remember: The target density should be how dense you want the grass to be at it's maximum density, the other settings are for falloff.

    I explain them in around here in the shader tutorial:


    Did that fix your problem? If it still doesn't work, you should also try working with NatureMeshFilter's normalization and subdivision settings.
     
    Zyblade likes this.
  5. Mojo-Game-Studio

    Mojo-Game-Studio

    Joined:
    Sep 18, 2015
    Posts:
    111
    Any eta for a HDRP version?
     
  6. Zyblade

    Zyblade

    Joined:
    Jul 1, 2014
    Posts:
    140
    @Nonakesh
    Did I overlook it, or didn't you mention the URP support on the assetstore page? It's something I wouldn't omit.
     
  7. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    Right now it's on hold until there is more information for custom shaders in HDRP available. Last time I tried to support it, I landed in a bit of a dead end.

    Thanks for the idea, I actually didn't think about putting it in the description. I'll do that right now!
     
  8. superaldo666

    superaldo666

    Joined:
    Aug 30, 2013
    Posts:
    17
    Hi @Nonakesh, I just buy you shader and is great, could you let us try a beta version of the HDRP maybe?

    regards
     
  9. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    I think the HDRP version is actually already included? It's quite broken, so I don't think you'll be able to use it.
     
  10. bingofly

    bingofly

    Joined:
    Sep 15, 2018
    Posts:
    27
    Hi @Nonakesh

    Is it possible to set lighting normal mode while game is running?
    Could you please tell me how to do it?
     
  11. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    Yes, it's possible!

    First of all, you have to find the name of the important shader keywords, by opening the shader you're using, for example Grass.shader. Search for the lines with "#pragma shader_feature". The important line in your case is "
    #pragma shader_feature __ GRASS_HYBRID_NORMAL_LIGHTING GRASS_SURFACE_NORMAL_LIGHTING".

    You can set the shader keyword from a script, like this. Make sure you disable the other keywords first with this.
    For example, if you want to enable surface normal mode, disable GRASS_HYBRID_NORMAL_LIGHTING and enable GRASS_SURFACE_NORMAL_LIGHTING. If you want to enable regular normal mode, just disable the other two.

    Now the last part is to make sure that all shader variants are included with the build, by default all unused variants are stripped away. To do this, search all occurrences of "#pragma shader_feature __ GRASS_HYBRID_NORMAL_LIGHTING GRASS_SURFACE_NORMAL_LIGHTING" in the shader file you're using (GrassForward.shader, Grass.shader, or GrassURP.shader) and replace "shader_feature" with "multi_compile". Be careful, this line exists multiple times per file, once for each pass, all of them should be the same.

    Now you should be able to switch the mode at will during runtime!
     
  12. bingofly

    bingofly

    Joined:
    Sep 15, 2018
    Posts:
    27
    Thanks a lot, I'll try it :)
     
    Nonakesh likes this.
  13. AhmadMcreator

    AhmadMcreator

    Joined:
    Nov 20, 2019
    Posts:
    24
    Hello
    I was wondering if this is a bug or something I can remove? I get this in play mode, one for every cascade

     
    Last edited: Jun 3, 2020
  14. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    I haven't seen that problem before. Does it also happen with the unshaded lighting mode? Which Unity version are you on? I'm assuming you're using the builtin render pipeline?
     
  15. AhmadMcreator

    AhmadMcreator

    Joined:
    Nov 20, 2019
    Posts:
    24
    I'm on 2019.3.9f1 and using the built in URP but it seems to only happen when I am using shadow cascades (to get better shadows) like in the video. I don't know if these errors will help

    And yes it does happen with the unshaded lighting as well
     

    Attached Files:

  16. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,633
    Quick question about optimisation, when not looking at the grass is there still work going on? and also what is MatureMeshFilter for, can I turn it off?
     
  17. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    I'll look into it. Was this on other Unity versions as well, or is that the only one you've tried?

    No work should be going on when you're not looking. Both because of bounding volumes and because the shader discards any triangles out of sight, I think during the tessellation stage? So it's possible that each triangle is still generating one blade of grass, as long as a part of the area is visible, but it should be minor.

    The NatureMeshFilter component takes either a MeshFilter or a Unity terrain and provides it to the grass renderer. If you're using that workflow, you can't turn it off, but after the initial preprocessing (if you've turned it on) it shouldn't do any additional work.
     
    radiantboy likes this.
  18. tntfoz

    tntfoz

    Joined:
    Sep 29, 2016
    Posts:
    129
    Hi @Nonakesh have you (or anyone else here) been able to test if your grass works with Nintendo Switch?

    Also (separately) will it work with Vulkan (Windows)? Thanks!
     
  19. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    I know of at least one person who was able to use it on switch, but I believe that was with version 1.8 (which is still available on my website).

    Vulkan will very likely not work, but I haven't tested it in some time.

    Honestly, I'd just try it. If it doesn't work and you can't use the shader because of it, I will give you a refund.
     
    tntfoz likes this.
  20. tntfoz

    tntfoz

    Joined:
    Sep 29, 2016
    Posts:
    129
    Hey @Nonakesh no need for the refund, I've owned DX11 Grass for a few years now! :)

    I'm just enquiring how difficult it would be porting a game with this asset to other platforms (i.e. whether it supports them or not). Great that the previous version might work on Switch (I have the v1.8 asset downloaded already).

    Do you know if the dev who got it working on Switch needed to do anything special, or did the Switch just simply work with the DX11 shader? I wasn't even sure if Switch worked with DX11!

    Thanks!
     
  21. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    As far as I know they didn't have any custom changes. I'm not sure what each console supports exactly, I think it's mostly dependent on Unity's shader compiler. As I've said, I think you should just try the new and the old version and see if it works!
    I think I also remember somebody using the shader on PS4, but not sure about that one.
     
    tntfoz likes this.
  22. tntfoz

    tntfoz

    Joined:
    Sep 29, 2016
    Posts:
    129
    Thanks for your reply again @Nonakesh.

    One last question (and then I'll leave you in peace for a while :D ).

    My project is currently using the latest 1.8 release of DX11 grass and I've resisted upgrading to the 2.0 release as I don't need any of the newer features (e.g. the fallback shader).

    However, would there be any performance benefits if I upgrade to the 2.0 release? Has the shader been optimized beyond the 1.8 release so that the grass renders faster, or by using less resources, for example?

    The 1.8 release is doing what I need feature wise, but I'll certainly upgrade for performance benefits.

    Thanks.
     
  23. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    The new workflow is, if anything, a slight downgrade in performance for more usability. I'd personally say it's still worth it, you don't have to duplicate terrains any more and it can automatically fix weirdly shaped triangles in meshes. Also there are a few new lighting options on top of that. I think the interaction system became more powerful as well? Here it's also a bit slower, but it supports changing burn color on the fly, which is quite useful, for example for dynamically removing grass.

    If none of that is important for you, you should probably just stick with 1.8. Just look at the changelogs on the asset store, maybe something sticks out to you!

    Edit:
    Actually let me just post it here! I think the "texture atlas creator" could also be quite interesting.

     
    tntfoz likes this.
  24. tntfoz

    tntfoz

    Joined:
    Sep 29, 2016
    Posts:
    129
    Thanks @Nonakesh! If I do manage to target the Switch then raw performance is going to be important I suspect, so I'll keep 1.8 in place for now.

    However from your description it sounds like 2.0 shouldn't be too much of a downgrade perf wise (and if the texture atlas creator helps improve things then it might end up similar or better even) so I'll keep an upgrade in mind!

    Do you have a roadmap anywhere for future updates or do you prefer to keep that under wraps (perfectly okay if you do!)?

    DX11 grass is a great asset and really enhances the look and feel of my projects whereever I use it. Just a shame I haven't released anything yet that uses it! :)
     
  25. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    I'm really glad you like my asset! :)

    Honestly, at the moment I consider the shader more or less feature complete, so the only thing I'm "planning" is continued support and bug fixes. But some great things have come from requests in the past, so if you're missing something just ask me!

    That said, I'm quite busy working on a game project right now, after working on assets for years (one or two projects I gave up on down the line), so I'm quite hyped about that. In other words: I'll be happy to support the asset, but it might take a bit.
     
    tntfoz likes this.
  26. tntfoz

    tntfoz

    Joined:
    Sep 29, 2016
    Posts:
    129
    Good luck with your own game! If it uses your grass asset, post some clips in here to show us what can be done when a master uses it! :D
     
  27. malkere

    malkere

    Joined:
    Dec 6, 2013
    Posts:
    1,212
    Do you have any users that use this with procedural runtime generation, or know if that is possible? Most vegetation systems seems to have a heavy pre-process where they generate a cell structure and prepare instances, etc. I'm looking for something that I can start up repeatedly in runtime, with better performance than Unity's terrible built-in grass.
     
    PhoenixAdvanced likes this.
  28. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    Thanks! I'm working on a space game right now, so there will probably be no grass, but if I ever work on something, I'll post it here!

    At it's core the asset just uses a shader, so it will work quite well with procedural generation. I know some users that dynamically removed grass, but basically anything should be possible as long as you don't slowly move vertices.
    (The shader uses vertex position as seed for grass color/length/wind/etc.)

    The only pre processing that can happen is the grass renderers mesh normalization, which is completely optional.

    In short: if generate a mesh with UVs it should work perfectly.

    I'd be happy to answer more detailed questions, if you have any.
     
    tntfoz likes this.
  29. malkere

    malkere

    Joined:
    Dec 6, 2013
    Posts:
    1,212
    So there is a "manager" object that generates the grass via a sort of tesselation effect using a mesh as it's base? I don't need interaction, or every extremely thick grass, or very highly detailed control meshes evem, my terrains are 4m resolution (1024/256), I'm just trying to avoid the CPU spikes that Unity grass causes, though looking nice is always a plus =D

    I can definitely generate a mesh with UVs to feed to the manager if that helps, or probably just leave it up to the manager. Can I feed it parts at a time? I'm competent with C# if I can feed stuff directly to it, that would be great. I multi-thread generate 128m squared areas one at a time to keep the fps up, so would prefer to pass grass data in a similar fashion.
     
  30. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    I think the easiest way would be this: create your mesh, then simply add the NatureMeshFilter and GrassRenderer components with your chosen material. You don't even need the uv's if you don't need some of the features of the shader.

    You could also instantiate your mesh twice and add the grass material to the copy. You're using procedural generation, so I doubt you'd benefit from the components anyways (they are mostly for convenience).

    After that everything happens on the GPU, it uses hardware tessellation, no CPU spikes at all.
     
    malkere likes this.
  31. web553967152

    web553967152

    Joined:
    Mar 16, 2019
    Posts:
    6
    @Nonakesh
    Hello!
    Can I use it on Android platform?
     
  32. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    409
    Hey, how is HDRP version going? Did Unity release the info about HDRP you required?
     
    Mojo-Game-Studio likes this.
  33. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    As far as I'm aware the shader still can't be compiled for android. You could use the grass fallback option if you're already using the shader on other platforms though.

    I haven't really looked into it lately, but there's at least one fundamental problem with HDRP: It uses motion vectors quite extensively. Because of the nature of the shader it would be difficult and performance costly to generate motion vectors. In short it would require to do all wind, interaction, and position calculations twice, keep a copy of the interaction render texture. Not sure how good the performance would be after that.

    There also the problem that my shader as a somewhat stylized feel to it, at least in my opinion it works best for that. I'm not sure if it would even be possible to get the shader to look like it fits into HDRP.

    Maybe I'm overthinking the whole thing. I'm planning on making an update for the shader in the next few weeks (as I've said I'm quite busy with my own game project at the moment), but my priority will be to fix the shadow cascade problem in URP @AhmadMcreator posted. So no promises, but maybe I'll look into it again, if you the shader would work in HDRP. Just tell me if it's important for you, if not I'd rather not make the deep dive into that pipeline again, if I can help it! :D
     
    PhoenixAdvanced likes this.
  34. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    409
    Don't care - I have a top-down game.


    I'm using your shader in my photorealistic game to a great effect. I would even say that it's one of the features of the graphics that really makes the game stand out.
    upload_2020-6-30_11-13-48.png
    upload_2020-6-30_11-14-16.png

    It all depends on how you use it. I even used the shader to make bushes (I showed you screenshots in this topic few months ago).

    Conclusion: you are wrong - good universal shader.


    It's important for me so much that I will do it myself if you won't - I am moving my game to HDRP and I've already injected Advanced Folliage Shader into HDRP's Lit shader, so please do make your shader work with HDRP and please feel free to ask for help if you need it - cubrman@gmail.com
     
    Last edited: Jun 30, 2020
  35. Mojo-Game-Studio

    Mojo-Game-Studio

    Joined:
    Sep 18, 2015
    Posts:
    111
    I second what @cubrman says ;) You know you want to make a HDRP version really. You do, you so do, please grovel grovel
     
  36. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    409
    Now, make an HDRP version of the DX11 grass shader, would you kindly?

     
    Mojo-Game-Studio likes this.
  37. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    I guess I'm happy you think you're wrong :D

    If you have experience with porting shaders to HDRP maybe you could help me out! The last time I've tried implementing it in HDRP I was stuck here:

    It's probably something fairly small I've missed, but at the time I couldn't find the cause of the problem.

    But do I really?

    Well, I might as well.

    As I said, I'll probably have time in the next few weeks, but no promises yet! ;)
     
    PhoenixAdvanced likes this.
  38. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    409
    Like I said, I am happy to help, but I can't do it without the shader code. Gimme what you have and I will do what I can.

    Well, I injected Advanced Folliage shader vertex sway as well as my very own line-based dissolve shader code into the Lit shader without much problems. It works, what can I say?
     
  39. Mojo-Game-Studio

    Mojo-Game-Studio

    Joined:
    Sep 18, 2015
    Posts:
    111

    Yes you do really really want to, and your mum told you to :)
     
  40. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    Well, I'm not gonna do it now, mom! :mad:

    The HDRP code is already included with the asset. And what I was talking about is that the whole HDRP seems like it's been made with code generators in mind. Everything seems to be adaptable and changeable by the settings. Injecting a custom shader feels hacky at best, with lots of assumptions that might break with any changed setting.
     
  41. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    409
    Well, that's the fate of asset creators: release something and forever fix it with new version of Unity/new bug report :).

    Will be looking into the code now.
     
    Mojo-Game-Studio and Nonakesh like this.
  42. r3ndesigner

    r3ndesigner

    Joined:
    Mar 21, 2013
    Posts:
    143
    upload_2020-7-7_2-32-48.png
    Hello bro, i am trying to use you grass, but just now i realized that it wont work on mobile, do you think have any chance of use it in the most simple configurations? thanks ^^
     
  43. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    Honestly, I'd just try it. If you get any meaningful error messages post them here!

    Otherwise there's still the fallback system.
     
  44. Source-technology

    Source-technology

    Joined:
    Dec 2, 2016
    Posts:
    21
    @Nonakesh
    We use the asset DirectX 11 Grass Shader in our project (Unity 2018.4.22f1).
    Under Deferred pipeline (Not the Legacy Deferred), all grass is white (see pic1).
    Under Forward pipeline, the grass is normal green.
    Are there any solutions for that?
    https://imgur.com/a/vB7h15J
     
  45. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    I will look into the problem! For now I would recommend using the "Grass Forward Only" shader, which enforces forward mode, even in deferred rendering. Because of some missing lighting options (especially subsurface scattering) I'd recommend that one over deferred rendered grass anyways.
     
  46. macish

    macish

    Joined:
    Oct 29, 2018
    Posts:
    55
    what would be best practive regarding two topics

    Changing wind values dynamically. There is the grass interaction wind shaders that i can attach to a mesh. Issue is that mesh can only be so big. Attaching the mesh to the player itself and making it in size to cover the camera view does not work, since now when i move the hole grass spazzes out.

    Cutting grass that regrows. So i tought about using the trail render for that and only enable it while cutting but this does not work. Turning the script on/off makes the grass pop up fully restored.

    Any ideas or best practices here would be highly appreciated. Thnx.
     
  47. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    I think the interaction system is still the way to go! It really depends on what you are trying to do, but to create complex wind patterns I would experiment with layering multiple wind objects in your scene and changing their strength (with its material / shader property).
    For example you could have light wind and blend in stronger wind occasionally.

    Once again, you should try changing the materials strength property, to slowly make the removal weaker, instead of disabling the trail at once.

    Or you could use the trail itself: use the jump feature to deactivate the trail unless you want to cut grass away. Set up the trail so it gets weaker with time, then the grass will automatically regrow.
     
    macish likes this.
  48. macish

    macish

    Joined:
    Oct 29, 2018
    Posts:
    55
    Dynamic weather, the scene in general will be more or less open worldish,so big. I did not nailed this down yet but i try to be as independat of scene size as possible. Thats the reason i tought to move the interaction object with the player/camera but this does not work as intented.
    I think the basic idea is pretty simple as just increasing the wind values and tween the values to a certain strength that fits to the weather depicted.
    My problem is that the interaction system is bound to a mesh, that mesh if staticly placed i guess it would need to cover in worst case kilometres of space, or split that down to hundred of smaller interaction objects depending on world size.

    Jump is of course a good tip. Thnx i will try this out.
     
  49. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    A
    A single huge interaction plane should be quite efficient, I can't think of a reason why that wouldn't work. Just scale it up, if that works for you!
     
    macish likes this.
  50. reggie_sgs

    reggie_sgs

    Joined:
    Jun 29, 2014
    Posts:
    276
    I'm looking for a higher performance grass shader for use in games with a realistic style. Does your shader work with existing terrains or do you have to paint the grass using your system? Also, does it support grass prefabs or just textures?