Search Unity

DirectX 11 Grass Shader

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

  1. WildStyle69

    WildStyle69

    Joined:
    Jul 20, 2016
    Posts:
    225
    Hi @Nonakesh -- was wondering about the performance hit / curve for using more than one grass type. i.e. is it double for each additional grass texture type or just a bit more, not sure if you know?
     
  2. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    836
    Hope it is ok to share, I finally got grass removing working at runtime, I am happy :)
     
  3. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    439
    You can have up to 4 grass types per material, in the trailer they were all mixed randomly, but you can use a texture to define where you want which type of grass. You can actually use a texture update now, so you could define one texture atlas for a flower field area, another for a desert field, etc.

    To be honest I'm not exactly sure. The performance cost does increase, but I'm sure it doesn't double. I would guess that it is a insignificant performance loss.

    Nice work! I always appreciate videos of the shader in action! :)
     
    WildStyle69 likes this.
  4. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,015
    so... can i get my existing unity terrain with its grass and convert to this one automatically? or i have to start from scratch? because my existing terrain is huge and it has tons of details that i added through months manually.
     
  5. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    836
    Now that would be a cool feature, get the DX 11 asset to check where Unity grass is and replace it with it's own lovely variant! Probably quite difficult to do...
     
  6. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,015
    it's actually not hard to do, i've done it myself several times to place other items but i don't want to have to study the code of someone else to be able to do it
     
  7. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    836
    Just convert the terrain to mesh, then use the DX11 grass material on that mesh, job done.
     
  8. alice_funo

    alice_funo

    Joined:
    Mar 9, 2016
    Posts:
    14
    I've just stumbled upon the same problem and used the hidden DepthNormals shader -- however, it means the game won't build (at least, not for 12 hours or so!) because the shader is included in the "always include shader" pipeline and all variants are calculated! I'm trying to figure out a way to reduce the number of variants to exactly the ones that we use.

    I've tried the build process on multiple platforms so it's not limited to any one...
     
  9. alice_funo

    alice_funo

    Joined:
    Mar 9, 2016
    Posts:
    14
    Btw my fix is to look at the grass material we use (we have one right now), and bake in the actual variants flags we used, either by just doing #define directly, or leave fewer options on the #pragma line if we need a few. This seems like something that can only be done on a per project basis, so perhaps it's worth a place in the documentation.
     
  10. Ardinius

    Ardinius

    Joined:
    Oct 4, 2015
    Posts:
    46
    Just purchased it, amazing asset.
     
    Last edited: Nov 9, 2017
    Nonakesh likes this.
  11. mattis89

    mattis89

    Joined:
    Jan 10, 2017
    Posts:
    1,052
    Sadly this was unusable for me .. I cant change terrain material..because other asset is using already custom material..
     
  12. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    836
    Hi,
    I am using your asset nicely :)
    I would like to ask about two points:

    1. BlopDisplacement objects / burn map to hide grass in certain areas, I noticed that there is a slight "ghosting" of the Displacement mesh is shown ingame, see screenshots below, the yellow highlight shows the problem:
    1.JPG 2.JPG 3.JPG
    How can I remove this effect? Eg change the mesh to quad?

    2. Is there anyway I can increase the denity more than the sliders allow me too? I have some very large meshes and the spacing is to big, can I change the shader for this?
     
  13. Ardinius

    Ardinius

    Joined:
    Oct 4, 2015
    Posts:
    46
    As this is a directx11 shader, when we build projects to Mac what happens to the client?
    Will the build work and they just wont see the grass? Or will a fallback shader need to be in place?
     
  14. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    836
    Isn't this working with Open GL also? That would work on MAC I'm sure...
     
  15. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    2,100
    Metal supported in osx?
     
  16. Emperor

    Emperor

    Joined:
    Feb 13, 2014
    Posts:
    23
    Hey, I'm getting this weird bug:
    upload_2017-11-18_11-19-56.png

    upload_2017-11-18_11-20-29.png

    Any ideas? Looks like some kind of light/reflection problem; not sure.
     
  17. nbac

    nbac

    Joined:
    Jul 7, 2015
    Posts:
    239
    looks like the same thing i had in conjunction with the postprocessing stack
     
  18. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    439
    Yes, you can reduce the shader variants by going to the Grass.shader file and replacing the #pragma with #define macros.

    The new patch (sometime this week) will include changes that may add support for Mac. OpenGL Core works on my PC, but I can't promise anything for other platforms.
    1. I added a new BurnCutoff setting, so this can be adjusted in the shader.
    2. Density is dependent on the terrain polygon density, so once the shader is set to its maximum, you will have to increase the terrain density.
     
  19. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    439
    What are your post processing settings? Also your light and grass settings (especially the light mode)? This looks like the grass is creating infinite brightness and your post process stack is trying to blur it reasonably.
     
  20. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    439
    That shouldn't be a problem, the grass doesn't render the floor by itself, so you have to duplicate your terrain or floor mesh and put the grass there. Look at the example scene for a short tutorial.
     
  21. mattis89

    mattis89

    Joined:
    Jan 10, 2017
    Posts:
    1,052
    Yes. But that woule be still too heavy because my terrain is so large and my ram is suffering already..
     
  22. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    439
    If you convert the terrain to a mesh and duplicate that it shouldn't have any memory overhead. Of course the performance cost would be higher in total. I guess the best/only way to handle this problem would be to use another terrain engine, or write your own. That way you could create the mesh and duplicate it, so it uses the same data.
     
  23. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    439
    Here's the changelog for the new version, it should be accepted in about a week, if you want it earlier than that, you can send me a PM with your invoice number and I'll send it to you directly. By the way, sorry for not being very responsive lately, I'll try to improve that again!

    Here are a few cool features as a small apology:

    1.8.0:
    • Adds support for OpenGL Core (This has not been tested well yet)
    • Adds a new tool that can convert Unity terrain to a mesh.
    • The grass painter can now also paint the color and height map.
    • Adds a burn cutoff, so the small grass stumps can be prevented.
    • Edit, as I forgot that one in the asset store: The example scene shouldn't crash any more, I've converted the terrain there with the new tool!
      Edit2: Nevermind that.. the crash still happens.. but I also found out how to fix it. Drag the example prefabs into an empty scene one by one, so the materials can be loaded. Then open the example scene. It's a bit ridiculous, but apparently that's necessary. I'll report this to Unity once again.
    If you have some problems or would like to have a feature in the future, post it here, or send me a PM or email!
     
    Last edited: Nov 22, 2017
    WildStyle69 likes this.
  24. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,015
    question.... your tool to convert unity terrain to mesh does it also handle the grass density? like i have 7 type of grass all over my unity terrain and the main thing stopping me from using your system right now is that if i have to manually redraw everything and reposition everything i would lose days of work
     
  25. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    439
    I figured out how to do this and added it as a feature to the Terrain Converter. I'll update the patch today, but if you want it right now, you can send me you invoice number and I'll send you the new version directly.
     
  26. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    439
    Here's the changelog:

    1.8.1:
    • The Terrain Converter can now extract detail textures, so you can reuse your existing grass textures.
     
    WildStyle69 and Lars-Steenhoff like this.
  27. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    836
    Hi Nonakesh, lots up good news from you :)
    I'm very interested in this Terrain Converter option, would I be able to give the new version a try?
    Also, maybe this is a request, can the terrain converter change the density of the mesh, that would be pretty cool, to control grass density?
    You added a new BurnCutoff setting, so this can be adjusted in the shader, I have tested this slider/value but it does not seem to help with the slight "ghosting" of the Displacement mesh . Maybe I am not using it correctly, would you be able to provide a screenshot of the setting of how it should be set to remove the ghosting effect, then I can try it?
     
  28. SilverStorm

    SilverStorm

    Joined:
    Aug 25, 2011
    Posts:
    555
    Just bought this asset because I needed nice dense grass with a negligible performance impact and out of the box the demo scenes run at 20 fps for me and 35 without shadows.

    There was a reviewer I saw who said that they run at 1200fps so I wanna know what that guy was smoking.
     
  29. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    439
    You can send me your invoice number and I'll send you the Unity package directly (tomorrow, probably).
    I will also check everything again, it's always possible I broke something before submitting...

    There is a bug in Unity terrain that can cause extreme performance cost, if you duplicate the terrain directly in your scene. Look at the example scene, close to the terrain there's a tutorial box with some information. If that's not the problem, can you post a screenshot of your scene?
     
  30. SilverStorm

    SilverStorm

    Joined:
    Aug 25, 2011
    Posts:
    555
    I just imported the project in and opened the default scenes.Here's what shows up on my performance:
    There's definitely something weird going on. The shadows are disabled in that screen grab and it shows 600K verts which isn't that much to be giving such low fps.

    I haven't edited any settings or done any optimizations but I doubt it would be that slow out of the box.
     

    Attached Files:

  31. Genebris

    Genebris

    Joined:
    Mar 18, 2013
    Posts:
    22
    I still get two errors when building. Version 1.8.
    Shader error in 'Stix Games/Grass': invalid subscript '_ShadowCoord' at Assets/StixGames/DirectX 11 Grass Shader/GrassFrag.cginc(36) (on d3d11)

    Compiling Vertex program with DIRECTIONAL SHADOWS_SHADOWMASK GRASS_CALC_GLOBAL_WIND GRASS_USE_TEXTURE_ATLAS GRASS_WIDTH_SMOOTHING THREE_GRASS_TYPES
    Platform defines: UNITY_ENABLE_REFLECTION_BUFFERS UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING UNITY_ENABLE_DETAIL_NORMALMAP SHADER_API_DESKTOP UNITY_LIGHT_PROBE_PROXY_VOLUME
    Shader error in 'Stix Games/Grass': invalid subscript '_ShadowCoord' at Assets/StixGames/DirectX 11 Grass Shader/GrassFrag.cginc(119) (on d3d11)

    Compiling Vertex program with POINT SHADOWS_SHADOWMASK SIMPLE_GRASS
    Platform defines: UNITY_ENABLE_REFLECTION_BUFFERS UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING UNITY_ENABLE_DETAIL_NORMALMAP SHADER_API_DESKTOP UNITY_LIGHT_PROBE_PROXY_VOLUME
     
  32. SilverStorm

    SilverStorm

    Joined:
    Aug 25, 2011
    Posts:
    555
    I have an update to this post that part of the lag does come from a Unity bug which happens when play mode is maximized which affects a lot of plugins but I am not sure what to do right now because that bug was posted a year ago with no fix even for Unity 2017.
     
  33. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,015
    Is there any performance or comparison between this asset and Critias Foliage system? I'm undecided which one to purchase.
     
  34. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    439
    If it happens when maximizing the play mode, it could just be actual performance cost. I'm sure the in-editor play mode window isn't the most efficient thing. Have you tried in a real build? Is the performance much better there?
    I would personally recommend lowering the grass density in edit mode and later increasing it for the final build. What GPU do you have?

    When exactly does this error occur? Only when building?
     
  35. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    439
    Both assets have a rather different goal, to be honest, as the creator of the other asset wrote himself, his foliage system is CPU based and optimizes objects in your scene, as far as I've understood it. In one of his first posts he mentioned that my shader could be used inside his system. My shader is 100% GPU based, so I am certain that it will be faster (It's possible to render a dense field of grass with individual blades of grass, which would be impossible with CPU based renderers)

    If you just want good looking grass you should probably get my shader, but I'm biased of course!
     
  36. SilverStorm

    SilverStorm

    Joined:
    Aug 25, 2011
    Posts:
    555
    Hi there I have a Radeon 5750 series which got a 3Dmark test of 1500 where as the GTX960 for example got 6000.

    Now I am talking about getting 20 fps in the default scenes that come with this asset so what are you and other users getting and are you using relatively new features that might only be supported on newer cards?

    *Update
    There's only one scene in the update you just published and that just happens to be the one that crashes Unity 2017....For now I am using the one that comes with 4 tests and am working on the plane demo. By default it's 20 fps but I disabled all the other planes except the grass one and disabled the pointlight and get about 70 fps + 10 when shadows disabled so that's not too bad.
    I am sure to find more optimizations soon.

    I know it's a silly question but does the demo scene grass use gpu instancing?
     
    Last edited: Dec 5, 2017
  37. Genebris

    Genebris

    Joined:
    Mar 18, 2013
    Posts:
    22
    It happens only when building and doesn't fail the build in editor but does in Cloud Build. Also, it seems not to happen if I build only a few scenes, but no particular scene seems to cause this.
     
  38. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,015
    ok so i bought it and it looks nice on my pc with NVidia 1080ti... but my MacBook pro displays a nice pink grass. I know it's not supported, but any hope to get it to run on MacBook?
     
  39. Nijiem_Arhi

    Nijiem_Arhi

    Joined:
    Oct 4, 2017
    Posts:
    15
    Hey @Nonakesh

    I'm running into some hitches regarding lighting the grass from the shader.

    I'm working in a scene that is using baked lighting and have found that the DX11 Grass does not work properly with it (renders black). In scenes were the grass is receiving realtime cast shadows it interacts as expected.

    In the screenshot below, I am attempting to use light probes to have the grass interact with light appropriately (grass not set to static, 1 directional light set to baked) but the result is the the grass rendering as black, as well.

    upload_2017-12-6_14-58-56.png
    (White spheres are debug objects to test if the light probes are working properly)
    Additional information:
    • I'm using a mesh with the DX11 Grass Shader on it in the scene above.
    • I've tried light baking using a terrain (mesh used in screenshot) with the shader on it and had the same outcome (grass is black).
    • As a side note this is for a VR project, but there's no evidence I've found that seems like this is a problem related to that.
    • This project is in 2017.1.1p2

    It appears that all scenarios where the grass is receiving any type of baked lighting information (lightmap, or light probes) results in the grass appearing black. Do you have insights to the issue occurring here? Maybe I'm missing something obvious?

    Edit: Upon closer inspection it looks like the grass is not rendering full black, but it is being darkened to near black when receiving baked lighting information.
     
    Last edited: Dec 7, 2017
  40. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    439
    I will upload the split up scenes again, I thought replacing the terrain with regular meshes would fix the crash, which was apparently wrong... I really hope Unity fixes this problem. And for performance optimization you should try to change the Max Density and Density Falloff setting, those are the ones that impact it the most. With your GPU it might by a performance problem, honestly I think it's not that you are missing any features just the raw performance.

    I'm afraid cloud building just doesn't like complicated shaders for some reasons... I would stick with regular builds for now.

    Have you tried the newest version of the shader? On windows it works with OpenGL Core, well kind of anyways, the compiler still bugs out at times, or takes very long. I was still hoping that the shader might work on Mac too, with OpenGL Core...

    Can you send me this example scene via PM? I'm basically using Unity's standard lighting, but it could be that I made some errors with the lighting, so your scene would be nice for testing.
     
  41. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,015
    well, i have the latest version on the asset store... it doesn't run on mac, but mac by default is working on metal, no clue if that uses opengl core internally
     
  42. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    439
    You can change it in Edit->Project Settings->Player, then in the inspector go to Other Settings, deselect Auto Graphics API for Mac and now you should see a list where you should be able to change to OpenGL Core.
     
  43. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,015
    tried, didn't work. does it work on your mac?
     
  44. Gruguir

    Gruguir

    Joined:
    Nov 30, 2010
    Posts:
    311
    I can't get it to work along with vertex colors (vertex density mode) - Ut 2017.2.0f3.
    I set vertex colors at runtime by script on procedural meshes, i tried various settings as this is not really documented.
    Did someone tried that before ? @Nonakesh i sent you an email
     
  45. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,015
    I can't get it to work. This is my unity terrain without directx grass and changing the material to use directx grass. The terrain textures then are gone and the grass looks horrible. I've tried playing with all the settings and read the documentation from page to page... nothing works. Any ideas?

    grass1.JPG

    grass2.JPG
     
  46. Gruguir

    Gruguir

    Joined:
    Nov 30, 2010
    Posts:
    311
    If you are replacing terrain material with the grass one, i guess that this is the intended result. I'm not sure about the way to use it with terrain, but it should be explained in the documentation.
    Edit : look like you have to use another mesh for the grass on top of your terrain
     
    Last edited: Dec 10, 2017
  47. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,015
    yeah but from the doc what it seems is that it needs to duplicate the mesh, so you have to render twice the same mesh, which for a terrain is HUGE
    I'm sure that's not what was intended, so i must be missing something.
     
  48. coen22

    coen22

    Joined:
    Aug 27, 2013
    Posts:
    26
    I have the same error, it always occurs in the latest version 1.8.1 in editor and I don't get further.
    It seems that in GL for some feature options the grass is missing _shadowCord. However this is not the issue that prevents it from showing any grass. I was able to get rid of the error. But it still doesn't show the shader as it should. Which is strange because I'm only getting warnings now. Even after reimporting.
     
    Last edited: Dec 11, 2017
  49. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,015
    nobody replying? the asset is basically not usable right now if it doesn't render the terrain and the grass or I have to duplicate every terrain mesh to render both...
     
  50. Slaghton

    Slaghton

    Joined:
    Sep 9, 2013
    Posts:
    129
    (switching to forward rendering fixed it I think. Shouldv been set already with vr settings I thought)
    edit2: Some grass blades are working but some are still borked. odd

    Hmm, i'm getting what looks like z fighting in version 5.6.1f1. In an older project 5.4.03f it works great. It did say something about changing shader models to 4.0 or something as a warning.
     

    Attached Files:

    Last edited: Dec 14, 2017