Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

DirectX 11 Grass Shader

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

  1. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    431
    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:
    22
    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:
    431
    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:
    22
    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.
     
    Nonakesh likes this.
  5. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    431
    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:
    313
    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:
    823
    Hi, where / when can we get the new version ? :)
     
  8. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    431
    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:
    431
    @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:
    431
    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:
    178
    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:
    431
    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:
    11
    Last edited: Jul 1, 2019
  14. Nonakesh

    Nonakesh

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

    Nonakesh

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

    Barritico

    Joined:
    Jun 9, 2017
    Posts:
    181
    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:
    431
    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:
    11
    That´s great. Then i will do an deep dive.
     
  19. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    178

    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:
    11
    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:
    178
    Ok i did the merge. The result visually is worse than before the merge. Damn.
     
  22. sasa42

    sasa42

    Joined:
    Jun 6, 2018
    Posts:
    11
    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:
    431

    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:
    178

    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:
    178
    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:
    431
    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:
    431
    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:
    178
    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:
    431
    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:
    841
    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:
    431
    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:
    665
    Please update it to work with HDRP! Please, please
     
  34. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    431
    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:
    89
    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:
    436
    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:
    5
    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:
    431
    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.