Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    Dismiss Notice

[RELEASED] DirectX 11 Grass Shader

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

  1. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    447
    Yeah, sure, I'll include that in the next update!

    That's an interesting use case! You could combine it with the new surface normal mode, to make the lighting smoother (unless you've already done that? It's a bit hard to see from a distance)

    Keep posting! I'm really happy to see your results.
     
    Zyblade likes this.
  2. pagnotmf

    pagnotmf

    Joined:
    May 20, 2016
    Posts:
    23
    Yes, I didn't want to post it here as I figured that might not be polite. It's up to Nonakesh. If he doesn't care, I'll post the link. It's specific to what we are doing on our golf courses but it shows you ideas for exporting meshes and setting up a 3 texture variant of the grass.
     
  3. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    447
    Oh, please go ahead! As long as something is related to my shader (e.g. not a different grass asset or something like that) I'm perfectly fine with it being posted here.
     
  4. pagnotmf

    pagnotmf

    Joined:
    May 20, 2016
    Posts:
    23
    There are several threads on the site that address the 3d grass using the Stix Games Shader. It encompasses about 1.5 months of hobby time experimentation for me.

    The tutorial for the community is in the thread - http://www.perfectparallel.com/topic/11290-3d-grass-tutorial/

    I think the most frustrating thing for my purpose is that my meshes are generated via a plugin and create non uniform triangles at edges. I tried using Blender and Instant Meshes to improve them but it wasn't a realistic process for the community. Additionally, the Unity vertices limit will automatically subdivide your meshes and create issues with performance.

    I am using the older version of the shader. Obviously, with the newer beta, many of these problems do not exist.

    Regardless, it's a joy to use and the 3d grass has been something our community has been waiting for years to have. With a Nvidia card, GTX 970 or greater, we are actually seeing an increase in performance over our non grass versions. It's like it brings the GPU to life.
     
    Stingreye and Nonakesh like this.
  5. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    447
    I just finished creating the trailer for the 2.0 update, so now I only have to upload everything to the asset store.

    Before that I'll try to get back that 5.2 compatibility ( @pagnotmf ), but I can't promise anything. I'll most likely upload the new version to the asset store tomorrow!

    Thanks to all of you who've tested the beta version, by the way! I was able to fix quite a few bugs because of you!
     
    keeponshading and Acissathar like this.
  6. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    404
    Wow. There is lot of valuable information and leassons learned. Thanks.

    Whats your problem with the non uiniform triangel generation at edges? Probably i can help.
     
  7. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    893
    Hi, where / when can we get the new version ? :)
     
  8. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    447
    You can get the lastest beta here: http://stixgames.com/grassshader/beta
    I'll probably upload the non beta version today, so waiting a few hours will give you a few bugfixes (I think?) and offline documentation.

    Well, I'll probably change the link then, to something like newest version... I'll just post the link once I'm done!
     
  9. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    447
    @pagnotmf I just checked 5.2 support and it looks like that Unity version doesn't support some fairly important changes I did at the beginning of the whole 2.0 development process. I'm sorry, but I don't think I can continue to support that version.

    I will however keep the legacy version on my website, so new buyers can still use the old version.

    I really hoped it would be an easy fix, but unfortunately it would be quite a lot of work and make the shader a lot harder to maintain. I guess there isn't much hope of contacting the games developer for an updated version, right?
     
    pagnotmf likes this.
  10. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    447
    You can download the release version 2.0.0 here!

    There is also a download for the legacy / Unity 5.0 version available here.
     
  11. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    191
    Hmm... weird... I was almost sure someone has done this before.

    No, 'Follow surface normal' breaks the illusion somehow. Dunno why.

    I wanted to ask about motion vectors. I know perfectly well that builtin Unity does not allow writing motion vectors. I've read somewhere in your thread that you aknowledge that it's a serious problem and that you are working on it. I wanted to ask if you ever considered taking the standard shader from the 'Builtin shaders' and injecting your grass code into it? The reason why it might be useful is because then you can change the mesh renderer into the skeletal mesh renderer and tick the 'skinned motion vectors' box that will compute the vectors for you. I am planning to do this for AFS (advanced folliage shader) as it struggles with TAA just as well.

    I haven't looked into your code yet and I haven't checked the 2.0 version yet. Please let me know if my suggestion is impossible in concept or (hopefully) obsolete.
     
  12. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    447
    The problem with the motion vectors isn't only getting unity to use them, but simply rendering them at all. Normally, you can simply use the changed position (from the CPU / memory) to create motion vectors for the whole object, but the grass shader includes movement in its code, so it would be necessary to calculate all positions, wind, interaction, etc. twice. That's not only performance costly, but also quite difficult to do.
     
  13. sasa42

    sasa42

    Joined:
    Jun 6, 2018
    Posts:
    16
    Last edited: Jul 1, 2019
  14. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    447
    Also I was talking about the surface normal lighting mode, maybe try combinations of both settings.
     
  15. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    447
  16. Barritico

    Barritico

    Joined:
    Jun 9, 2017
    Posts:
    197
    Hi.

    After update to 2.0 version:


    Assets\StixGames\GrassShader\Scripts\GrassFallbackProcessor.cs(736,29): error CS0103: The name 'GrassTextureUtility' does not exist in the current context


    Assets\StixGames\DirectX 11 Grass Shader\Editor\TerrainConverter.cs(109,17): error CS0103: The name 'GrassEditorUtility' does not exist in the current context


    Thanks!!!
     
  17. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    447
    Hey, I just imported the new version into an empty project myself, to make sure, and it looks like everything should work fine.
    Did you delete some folders? Or did you change the directory of the package? (If that's the case, I'll fix the problem, moving the package should be possible)
    Did you delete the old version before updating? Old files might have caused the problem.
    If even that doesn't work, can you try it in an empty project?
     
    Barritico likes this.
  18. sasa42

    sasa42

    Joined:
    Jun 6, 2018
    Posts:
    16
    That´s great. Then i will do an deep dive.
     
  19. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    191

    That is exactly what Unity does for skinned meshes (which include vertex motion in the shader) if you tick the 'skinned motion vectors' box. That is why I am trying to merge the Standard shader with the AFS shader. I will keep you posted on my results.
     
  20. sasa42

    sasa42

    Joined:
    Jun 6, 2018
    Posts:
    16
    some of my find out regarding surface lighting....

    you have a grass ground texture and a lightmap.... perfect combination is bring this both values to the grass color.
    Under trees, hedges and so on you get nice ground color toning and variation baked with your environment.

    and motion vectors....

    Forward renderering with 2x or 4x MSAA work great with TAA (PPV2 or better CTAA)
    Works good for wind movement without motion vectors. When you have in addition fast camera movements through your charakter or driving car motion vectors are really needed.

    Check Grass in HDRP Sherman Demo with fast camera movements.This grass is static and has 3 material HDRP Lit material variations. Lighting and fast cam movements are great. But its made out static splated quads on the tiles.

    Really great job with V2. We start integrating it tomorrow.
     
    Last edited: Jul 1, 2019
  21. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    191
    Ok i did the merge. The result visually is worse than before the merge. Damn.
     
  22. sasa42

    sasa42

    Joined:
    Jun 6, 2018
    Posts:
    16
    Do you have enabled MotionVector Debug Rendering to see if they are ok?
    I am pretty sure that standard shader implementation is not working for geometry shaders.
    You can find motion vector implementations and debug rendering for geometry shaders in keijiros repositorys on github.
     
  23. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    447

    Honestly, I can't really imagine where the motion vectors are supposed to get the additional information from? Are you sure you aren't missing some additional shader parameters Unity is using for skinned meshes?

    I mean, in case I'm missing something myself and there's an easy way of creating motion vectors in cases like this, that would be great!
     
  24. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    191

    I am quite a noobie in all this but my lizard brain is simply saying this: skinned characters are obviously animated in the shader. Skinned characters look good with TAA. Skinned mesh renderer has a dedicated checkbox for a "special case" motion vectors calculations. This seems to mean that Unity has a way of calculating motion vectors for moving objects but only if you use skinned mesh renderer and a compatible shader.

    I've just realized that my yesterday's test was wrong. I will continue testing later and keep you posted.
     
  25. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    191
    Sorry I am too lazy to dig this deep, I am an amature in shaders and all I want to do is to test a wild idea that skinned mesh renderer might produce good motion vectors even for shader animation cases. I will try to merge the two shaders (Standard and AFS) and see if the result looks better than before the merge. That is all.
     
  26. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    447
    I haven't looked into it myself, so it's possible they are using some kind of technique there, but I think it's more likely their skinned mesh shader has the option to generate motion vectors with additional information from the CPU. So the renderer tells the shader the animation state from last frame, which the shader uses to calculate the correct motion vectors.

    That would be my guess anyways. But keep us updated either way!
     
  27. francois_rizzo

    francois_rizzo

    Joined:
    Apr 4, 2017
    Posts:
    1
    Hi there,
    We're working in hdrp and the shader just appears black in the two demo scenes after switching to hdrp stix shader. Does someone succeeded to make it work in unity 2019.1.6f1 ?
     
  28. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    447
    HDRP is not yet supported. I couldn't get the lighting to work yet. I will likely fix this in a future update.
     
  29. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    191
    Well, I think I did everything properly this time and my results are absolutely unsatisfying: the tree (in the center of the screen) looks like a munched mess. Looks like we need to wait for SRP for any hope.

    1.jpg
     
  30. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    447
    Well, I guess you should stick with the settings you had before. I'm still surprised you can use my shader for a use case like this at all!
     
  31. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    871
    Just updated, what hapopened to all the nice example prefabs showing all the kinds of grass? I liked them
     
  32. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    447
    Honestly, there isn't really a reason why I removed it. I guess I wasn't a great fan of the scene any more, because I've been using it for too long.

    But I still have the files, so I think I'll include it again in the next version!
     
    radiantboy likes this.
  33. strongbox3d

    strongbox3d

    Joined:
    May 8, 2012
    Posts:
    759
    Please update it to work with HDRP! Please, please
     
  34. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    447
    That's definitely a goal for a future update, but I can't say exactly when I'll get to it.
     
  35. Zyblade

    Zyblade

    Joined:
    Jul 1, 2014
    Posts:
    100
    Small question, how did you created the tank bomb impact on the grass? It moved circular from inside to outside the impact area. Did you use wind areas in some way? I know I could just load up the project and have a look, so a rough quick answer is enough : P Thanks =)
     
  36. Migueljb

    Migueljb

    Joined:
    Feb 27, 2008
    Posts:
    453
    Does this work in VR with single pass rendering in latest unity 2019.2 or even 2018.3?
     
  37. oceanquigley

    oceanquigley

    Joined:
    Apr 20, 2018
    Posts:
    6
    Hi there,

    I'm trying to apply grass to a Unity 2019 terrain, but am getting this error (I am seeing a few blades of grass here and there, so something is happening).
    Any advice?

    ArgumentException: No valid grass type
    StixGames.GrassShader.GrassUtility.GetGrassTypeCount (UnityEngine.Material mat) (at Assets/StixGames/GrassShader/Scripts/Utility/GrassUtility.cs:135)
    StixGames.GrassShader.GrassUtility.GetMaxGrassHeight (UnityEngine.Material mat) (at Assets/StixGames/GrassShader/Scripts/Utility/GrassUtility.cs:283)
    StixGames.GrassShader.GrassRenderer.LateUpdate () (at Assets/StixGames/GrassShader/Scripts/GrassRenderer.cs:61)
     
  38. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    447
    I used a normal map with a plane and the normal displacment shader, then I animated it. It's quite a primitive effect honestly. The only restriction is that it can't be a particle effect yet, you have to animate it manually. If you need help with the basics of the interaction system, you could watch the tutorial http://stixgames.com/grassshader/documentation/interaction-system.

    You can look at the effect yourself, it's included in the Game scene. (Btw, left click anywhere while that scene is running, for debug explosions :D )

    Single pass VR should work in all supported versions. It doesn't support instanced single pass rendering though. (As it doesn't support instancing in general)

    Honestly, it looks like your grass material is broken somehow. I would recommend deleting it and creating a new material. If it still doesn't work, you could try deleting the StixGames folder and importing the asset again. If that doesn't help either, please tell me your operating system, GPU and Unity version. If the error only occurs after changing some settings, please tell me which ones.

    I believe that creating a new material should solve the problem though!
     
    oceanq and Zyblade like this.
  39. Stingreye

    Stingreye

    Joined:
    Mar 15, 2018
    Posts:
    1
    Ah too bad it can't work. Regardless, been using @pagnotmf 's tutorials for our golf game thats stuck in old unity and the results are promising. Great shader and really plays well with the Nvidia modern graphics cards.
     
  40. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    447
    I'm glad you like it! The old version can always be downloaded from my website, using the invoice number you got when buying the shader: http://stixgames.com/grassshader/legacy

    So even if you're stuck with the old version, you'll be able to continue using the shader!
     
  41. PhoenixAdvanced

    PhoenixAdvanced

    Joined:
    Sep 30, 2016
    Posts:
    162
    Hi,

    I am using this asset for my project, and it's working well, however I am having one issue with it.

    When using deferred rendering, (and not forward rendering) I get this issue:

    https://forum.unity.com/threads/sha...-with-deferred-rendering.733763/#post-4901900

    As that post states, I have modifed the shader, and I am also not using the current version (I haven't had a chance to port yet).

    Before I take the time to port the grass asset to the latest version, is there anyone that can shed any light on this issue? Is it a known issue, or is it fixed in the current version?

    Thanks.
     
  42. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    447
    The shader does support deferred shading since version 2.0 (or even before that? I'd have to look up the changelog myself). I'd recommend that you port to the new version, in my opinion the new version has quite a few changes that make the update worth the work.

    I've made a short guide for porting old scenes to the new version: http://stixgames.com/grassshader/documentation/upgrade-to-version-2
     
  43. PhoenixAdvanced

    PhoenixAdvanced

    Joined:
    Sep 30, 2016
    Posts:
    162
    Great, thank you, that's very encouraging. I've using a very old version, so I'm sure I just don't have the deferred lighting support.

    Thanks a lot!
     
    Nonakesh likes this.
  44. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    447
    I'm glad I could help! In case you're unsure, the deferred mode should be enabled automatically. There is also a separate shader type "Grass Forward Only" that forces forward rendering even in deferred mode, make sure you don't have that one enabled!
     
    PhoenixAdvanced likes this.
  45. amynox

    amynox

    Joined:
    Oct 23, 2016
    Posts:
    81
    Hello,

    I'm using Unity 2019.2.3f1 and the latest version of Grass Shader.

    When trying to Generate texture atlas (Grass fallback) i'm getting this error (4 time) :

    Code (CSharp):
    1. Selected texture format 'ARGB 32 bit' for platform 'DefaultTexturePlatform' is not valid with the current texture type 'Default'.
    2. UnityEditor.TextureImporter:SetPlatformTextureSettings(TextureImporterPlatformSettings)
    3. StixGames.GrassShader.GrassTextureUtility:SaveTextureToFile(String, Texture2D, Boolean, Boolean, Boolean) (at Assets/StixGames/GrassShader/Scripts/Utility/GrassTextureUtility.cs:23)
    And of corse nothing happen after (Grass fallback not working)

    Any help will be appreciated

    Thanks
     
  46. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    447
    Are you using the standalone build platform? If yes, Unity probably changed something in their texture format handling (again)... It should be a really easy fix.

    If you are using a different platform, switch to standalone, bake the texture, then switch back, that should solve the problem.
     
  47. amarillosebas

    amarillosebas

    Joined:
    Feb 28, 2013
    Posts:
    30
    How would you go about removing grass, or not having grass at some places?

    upload_2019-9-6_14-4-46.png

    My terrain is green. There's a brown plane which is not part of the terrain. Grass growing underneath clips through that plane. I've already tried with the interaction system, but since the plane continues below the terrain, it basically eliminates all grass above it.
     
  48. amynox

    amynox

    Joined:
    Oct 23, 2016
    Posts:
    81
    Hi,

    Yes, i'm using the standalone build platform.

    Should i wait for a fix from your side or there is any fix i can implement in your code ?

    Other question : how i can integrate Stix Grass with GPUI Instancer ? (on Unity terrain and other Gameobjects)

    Thank you and keep up the good work ;)
     
  49. PhoenixAdvanced

    PhoenixAdvanced

    Joined:
    Sep 30, 2016
    Posts:
    162
    Hi,

    I have been working on upgrading my Dx 11 grass to version 2 (I have a complex setup).

    However, I am seeing what I think is a problem in deferred rendering.

    In deferred rendering, the grass seems to be much darker than it should. This isn't a shadow issue, I have tried it with all shadows disabled.

    Changing the light direction does help, but only to an extent. Forward mode works perfectly.

    This image shows the issue:
    https://imgur.com/vZJDBDQ

    This is the same image in forward mode:
    https://imgur.com/4n7HYRo

    Here is an example with the light intensity set to a very high value:
    https://imgur.com/e1lLGxc

    It is clear that the grass is showing up as black, even though the sun light is very strong.

    Here it is in forward mode:
    https://imgur.com/fLdq870

    The grass is the same colour as the light, which is correct.

    What could be going on here? Is this expected behaviour, because the grass looks a lot better in forward then deferred with this lighting?
     
  50. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    447
    "
    So you don't want any grass where the brown plane is? In that case I'd recommend using the grass painter to remove the grass below the plane. If you want the grass to continue on the plane, you could add a second grass renderer component there! If you copy the material from the terrain and remove the density texture, you can have the same grass with different densities.

    I just found a fix, and it sould be future proof this time, as I'm just letting Unity handle the whole thing now:
    Got to the file GrassTextureUtility.cs, on line 25 change format to "format = TextureImporterFormat.Automatic".

    As a side note, I also found a bug where fallback rendering didn't work unless mesh normalization was enabled. I'll upload both to the asset store today!

    I've never used GPU Instancer, but if it creates objects with a mesh filter, you can add the components as usual, otherwise things could be a bit more complicated.

    Unfortunately that's expected behaviour. In deferred rendering mode, all lighting settings are disabled, as Unity is handling the rendering.
    There are two ways you could try to handle the problem:
    The easy way would be using the Forward Only version of the grass shader, so even in deferred mode the forward rendered version is used, but that way you won't have the performance advantages of deferred rendering.
    The other way would be creating additional lights to try to fill out the shadows of the grass, with some tinkering you should be able to get to a result that looks good.