Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

[RELEASED] DirectX 11 Grass Shader

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

  1. Steamc0re

    Steamc0re

    Joined:
    Nov 24, 2014
    Posts:
    120
    I know you're busy, but I'm literally releasing the game tomorrow. Please help !!!
    I was getting the same two errors as above on compile. It turns out, it was due to the grass being hidden in a scene when I hit build. I don't know how any of this works, but goddamn this was annoying to figure out.

    Unity 2017.1.2p4
    Version 1.82
     
    HenryChinaski and Genebris like this.
  2. Dolzen

    Dolzen

    Joined:
    Mar 26, 2014
    Posts:
    82
    Will this asset support Vulkan instead of DirectX in the future?
     
  3. coen22

    coen22

    Joined:
    Aug 27, 2013
    Posts:
    26
  4. iemfi

    iemfi

    Joined:
    Jun 27, 2016
    Posts:
    4
    Directional light which is more than 90 degrees away from the grass normal (it's shining from below) causes NaN values, leading to artifacts with TAA. Any chance of having this fixed? Thanks.
     
  5. Ardinius

    Ardinius

    Joined:
    Oct 4, 2015
    Posts:
    47
    Hello,
    I was wondering if it is possible to render a projector or decal clearly over the actual grass mesh to show things like unit selection/range? I have experiemented with render queue and everything is just drawn either beneath the grass or the grass culls the decal.

    To put it another way does the shader render to the depthbuffer? (zwrite on)
     
    Last edited: Feb 27, 2018
  6. Genebris

    Genebris

    Joined:
    Mar 18, 2013
    Posts:
    22
    It turns out one scene with baked shadowmask lighting was causing these errors for me. It was the only scene with baked lighting in my project and it doesn't even have any grass in it.

    Is everyone else able to use shadowmask lighting and grass together in their project?
     
  7. Vassa91

    Vassa91

    Joined:
    Sep 19, 2017
    Posts:
    4
    Hi,
    i'm using this plugin to simulate a dense grass field under the player in a vr game, but i'm having some issues i cannot solve.
    It seems the grass have some zfighting problem, and it clip and flicker a lot upon close inspection (around 1 meter range).
    I'm on the last stable unity version (Unity 2017.3.1f1) with the last version of the shader.

    Someone could help?
    Thanks a lot!
     
  8. sipon

    sipon

    Joined:
    Feb 8, 2009
    Posts:
    134
    Same problem here !
     
    Genebris likes this.
  9. 265lutab

    265lutab

    Joined:
    Sep 15, 2014
    Posts:
    150
    I am currently optimizing the game I'm working on which is using this grass shader. In the quality settings I plan to allow the user to reduce the amount of grass that is shown by changing the max density on the shader at runtime. I wanted to check if this is a good way to handle a quality option for the grass or if there would be any known issues with changing the max density at runtime.
     
  10. Ranter1337

    Ranter1337

    Joined:
    Nov 4, 2015
    Posts:
    15
    Does this system currently work with deferred rendering?
     
    zeetu likes this.
  11. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    878
    Hi Nonakesh, sorry for not getting to this for a loooong time, been busy. Is it still ok to ask for help with this? In my project I still see the ghosting of the blobdisplacment, burn cutoff value change does not help. I also tried changing the mesh no help..
     
  12. H_Hazuki

    H_Hazuki

    Joined:
    Apr 4, 2013
    Posts:
    26
    Hi,

    Are you aware if this works within Nintendo Switch and if not, would you allow me to test it prior to purchasing?

    Thanks
     
  13. unisip

    unisip

    Joined:
    Sep 15, 2010
    Posts:
    269
    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

    Same error here. Build is VERY erratic. Sometimes it builds, sometimes it fails. I'm puzzled...
     
  14. Genebris

    Genebris

    Joined:
    Mar 18, 2013
    Posts:
    22
    Do you use baked lighting in your project?
     
  15. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    878
    Is this in a large project , maybe a shader limit has been reached?
     
  16. coen22

    coen22

    Joined:
    Aug 27, 2013
    Posts:
    26
    Last edited: Mar 29, 2018
  17. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    878
  18. coen22

    coen22

    Joined:
    Aug 27, 2013
    Posts:
    26
    @Nonakesh
    There seems to be an issue in OpenGL when using Unity 2018.1b13
    The grass blades don't catch shadows. Could you look into this?
     
  19. LSUTiger85

    LSUTiger85

    Joined:
    Dec 29, 2015
    Posts:
    108
    Would it be wise to set mesh as static and have it included in occlusion culling?? I did that and while running around the grass, it's flickering in and out. In other words, the OC is making it appear/disappear... a lot.
     
  20. LSUTiger85

    LSUTiger85

    Joined:
    Dec 29, 2015
    Posts:
    108
    bump.. ??

    I had another issue start happening. After baking lightmaps, the grass is flickering in and out darkto normal color. The plane which has the grass shader is not set to static. Also, the grass is not receiving shadows. This is happening when I move the camera.





     
    khos likes this.
  21. LSUTiger85

    LSUTiger85

    Joined:
    Dec 29, 2015
    Posts:
    108
    It has something to do with my lightmaps. I cleared my lighting cache and now the lighting on the grass is working as it should. I'm baking again to see if it happens again.
     
  22. LSUTiger85

    LSUTiger85

    Joined:
    Dec 29, 2015
    Posts:
    108
    I appears that setting the main directional light to "Mixed" causes the flickering of shadows. If it's set to realtime, this will not happen. But if you bake your lightmaps with the directional light set to mixed, the flickering will occur until you rebake with the directional light set to realtime.
     
  23. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    446
    Hey there, sorry for being gone for so long. I've had some health problems lately, nothing serious, but enough to stop me from doing basically anything work related.
    I'll go through all your problems and will try to help. Also I will start working on a CPU based Fallback system, which should partially solve all compatibility problems that exist with the shader. With the current plan, you'll still need a DirectX 11/Windows system for creating the offline materials (the scripts will use the shader to build a texture atlas), but after that is should even work on mobile.
    Of course I will also be reachable via email and private message again. Again sorry for not being reachable lately.
     
    Genebris and tntfoz like this.
  24. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    878

    I notice your mesh renderer does not cast shadows, if you turn that on does that help resolve the issue?
     
    Nonakesh likes this.
  25. LSUTiger85

    LSUTiger85

    Joined:
    Dec 29, 2015
    Posts:
    108
    No, I tried that. Thats the mesh that the grass shader is on. It doesn't need to cast shadows
     
  26. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    446
    Judging from the screenshots it looks like your directional light settings could be the problem. Can you post screenshots of the mesh renderer for the grass material and your light?
     
  27. LSUTiger85

    LSUTiger85

    Joined:
    Dec 29, 2015
    Posts:
    108
    It was the directional light. Setting the directional light to Mixed or Baked causes this to happen. Setting it to Realtime works.
     
  28. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    446
    Is the grass set to static? The grass is moving, so baked lights can't work with it. It must not be set to static.
     
  29. LSUTiger85

    LSUTiger85

    Joined:
    Dec 29, 2015
    Posts:
    108
    It is not set to static. See my image above of the inspector window for the plane.
     
  30. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    446
    That definitely sounds like a bug, I will look into the problem, but for now you should just avoid using baked lights. I think the shader should work with the real time global illumination baking, just not with the static one.
     
  31. iemfi

    iemfi

    Joined:
    Jun 27, 2016
    Posts:
    4
    Is there a way to get the grass density consistent when using the shader on a mesh with different sized quads? The density seems to be different depending on the width/length of each quad. The UVs are consistent, but the tessellation doesn't seem to take UVs into account.
     
    khos likes this.
  32. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    446
    As I've said before, the density is dependent on quad sizes because of how tessellation works on the GPU, so it's possible to normalize the density between all quads, but only by reducing the density of all smaller quads, you can't increase the density above the max. I'll look into this problem, maybe I can find a solution.
     
  33. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    446
    Hey, you shader looks good, but I would appreciate if you didn't post it in this thread. I have put a very large amount of work into this shader and while I appreciate open source, I think it's a bit... direct, to post a link to your project in the official post of another project that isn't open source.

    That said, here's what I think of your project: The point cloud technique is quite nice because you gain a lot of control, but I believe (and we've had another user in the forum who came to the same conclusion) that it is still missing the raw power of tessellation. That said, being able to do things on the CPU instead of the GPU should make it far easier to implement LOD and other techniques, but it will likely be hard, if not impossible to reach similar density as with my shader.
    Good luck with the project, I'd be happy to discuss it further with you in private messages!
     
    khos likes this.
  34. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    878
    Nonakesh likes this.
  35. iemfi

    iemfi

    Joined:
    Jun 27, 2016
    Posts:
    4
    I've tried solving it myself, but haven't had any luck so far. Which is strange, since it seems like it should be a fairly standard use of the tessellation.
     
  36. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    446
    Last time I tried to fix this problem I noticed that tessellation regulates mesh density without problems as long as the maximum density is not reached. But as soon as very large differences occur it can't handle it any more.

    I personally came to the conclusion that the best way of fixing will be a mesh preprocessor, that automatically splits triangles that are too large into smaller ones. The smaller differences will then be handled by the shader. I will look into this problem once I have finished the fallback system.
     
  37. dl290485

    dl290485

    Joined:
    Feb 4, 2018
    Posts:
    131
    I skimmed through the manual but I would just like to check; Does this only work with the unity terrain tool? Or can I use this as a material on a mesh?
     
  38. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    446
    This is probably the question that I get asked the most, apparently the FAQ isn't enough.. anyways, yes it does work with meshes, actually it probably works better with meshes than with Unity terrain, because Uniy terrain has it's own LOD system that interferes with the grass (not very noticeable, but still)

    If you have any other question, I'm happy to help!
     
  39. dl290485

    dl290485

    Joined:
    Feb 4, 2018
    Posts:
    131
    Thanks for the fast reply. However in regards to an FAQ, that may have been enough... if it was linked to in the store page :)
     
  40. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    446
    ... good point. Well, it's in the first post of the forum, but maybe I should really make a own section for it somewhere.
     
  41. Thermos

    Thermos

    Joined:
    Feb 23, 2015
    Posts:
    51
    Hi,

    I've noticed when playing under 4K screen resolution, the grass density is much higher if the base geometry's vertices are dense enough. How can I limit the max screen resolution parameter for the shader? Becuase I spend most of the time trying to adjust the density of different grass materials under 1080p resolution. I would like to see the density keeps the same when screen resolution scales up.

    Thanks.
     
  42. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    446
    I noticed that bug myself, while doing some updates. I have now fixed the density to be the same for all resolutions. The update that will contain this fix is still in progress, but I could post the one line that has to be changed, if you want (I'd do it right now, if I was on my PC).
     
  43. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    878
    PS after a loong time (of giving up due to other tasks) I re-visited this and discovered that my Ambient Occlusion was causing this effect.. I am currently working on moving the displacement mesh up higher than the camera view to avoid this, might be useful for others to know, if using AO.
     
    Nonakesh likes this.
  44. Squeyed

    Squeyed

    Joined:
    Aug 26, 2016
    Posts:
    27
    Would you mind posting the altered line please? I think I'm seeing the same issue.
     
  45. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    446
    Sure, here you go:

     
  46. Squeyed

    Squeyed

    Joined:
    Aug 26, 2016
    Posts:
    27
    Spot on Nonakesh! Thank you very much.
     
    Nonakesh likes this.
  47. Carterryan1990

    Carterryan1990

    Joined:
    Dec 29, 2016
    Posts:
    76
    Is it just me or when placing the grass the size brush doesnt work. It only works when the size of the brush is half way to the largest size.
     
  48. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    446
    I just tested it myself and it doesn't seem like it. Maybe your density texture is too small, so one pixel is larger than the brush size? Could you post a short gif of it?
     
  49. TCROC

    TCROC

    Joined:
    Aug 15, 2015
    Posts:
    119
    Hey @Nonakesh. I've been using your asset and it is great so far. I've encountered one problem though. The displacement system doesn't work on ground that isn't facing 90 degrees.

    Example:

    I am trying to run around on a cube. The displacement works correctly on the top face of the cube, but not any other face.

    Any help would be greatly appreciated!

    Thanks.
     
    Last edited: Aug 6, 2018
  50. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    446
    The displacement system work by using a camera that is pointed from the top downwards. In special situations like yours, where you want to run around a spherical planet, or a cube, this won't work. If you really need the displacement you could try creating a custom solution where you create the displacement texture directly and map it to the UV maps of your cube. Or you could rotate the cube instead, so the side with your player is always at the top.