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. nicolasbulchak

    nicolasbulchak

    Joined:
    Aug 9, 2013
    Posts:
    37
    Ok so this was working great on my system with Windows 7, however I now have windows 10 with DirectX 11.1
    And the grass does not show up in unity. Any thoughts?
     
  2. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    446
    Maybe your editor switch to Non-DirectX 11 mode? Or maybe your driver was corrupted from the update. I use Windows 10 myself, so I am sure it works there!
     
  3. bocs

    bocs

    Joined:
    May 9, 2009
    Posts:
    335
    getting a hitch every now and then...not too bad, but maybe something you could look into?



    maybe i'm using some bad values..but works how I want, at least until I hit the edge of the mesh then the error/hitch.
     
    Last edited: Sep 14, 2015
  4. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    446
    The performance hit is probably coming from the error. I was able to find the cause of it, with help from @JesseAlexander, so that should be fixed in the next patch. I think I'll be able to finish it up at the beginning of next month. The patch will probably also include a new displacement system. It will be a bit different to use but should have better performance.
     
    hopeful likes this.
  5. bocs

    bocs

    Joined:
    May 9, 2009
    Posts:
    335
    obviously an issue with RoundDisplacement, logging the values show the problem.

    Do you have a quick fix? if not i'll figure it out after I get some sleep.



     
  6. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    446
    Unfortunately I don't have a quick fix, but I was able to find when exactly the error occurs, so it shouldn't take too long to fix it. I don't really have time to work on it today, but as soon as I fix it I'll post it here. It shouldn't take longer than a few days if you can live with the error until then.
     
  7. daville

    daville

    Joined:
    Aug 5, 2012
    Posts:
    267
    Hi... I'm interested in getting this... but I couldn't find any documentation (I guess the docs are included on the package when you buy it).

    could you explain the workflow to use it?... or make the documentation public?... or are there any workflow video tutorials out there to get an idea of how to implement this?

    Thanks.
     
  8. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    446
    I did make a Documentation, but it doesn't really have a tutorial yet (I'll add a small one in the next patch).

    The workflow is really simple though:
    1. Create a mesh for the grass. (There are some rules to that, I explained them in the Documentation)
    2. Create a material (or use one of the example materials as a starting point)
    3. Apply the grass shader to the material
    4. Add the material to your mesh. (Just drag and drop the material on the mesh, or look at the renderer component)
    5. Well, that's about it. You can play around with the settings so the visuals fit your style.
    If you have any other questions, I'd be happy to answer them!
     
  9. ijoaum

    ijoaum

    Joined:
    Mar 4, 2015
    Posts:
    9
    Can someone post some screenshots o video with implementation of this on Unity Terrain? I use a procedurally generated terrain with a lot of chunks at the same time, so it's really big. I just want to know if I can use it with the limitations we have for Unity Terrain.

    Thanks
     
  10. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    446
    On screenshots you don't see any difference at all. The trailer itself is actually done with Unity terrain, the terrain problems aren't really visible there though, but they aren't too severe anyways. The main problem is that, when you're using Unity terrain, the grass can sometime just pop into existence instead of slowly fading in.

    Another problem is that you can't use the terrain painting tools, but the grass can still be controlled with textures (like height, density and so on).

    There are no restrictions on how far the grass is rendered, or how it is rendered in general. Oh, and grass displacement (like when a character is walking trough the grass) is, at the moment, not working with Unity terrain at all. At least it is impossible with very large terrains. I will fix this in the near future though.
     
  11. daville

    daville

    Joined:
    Aug 5, 2012
    Posts:
    267
    Hi thanks for answer, My main concern is about, how do I have control over on wich places of the mesh I want the grass?
    and if I want different grasses on the same mesh.

    for the workflow it is basically a material right? So if I have my mesh with Material IDs, I can have half of the mesh with grass and the other half using other random material.

    but... What I don't get is like.. will there be grass all over the place?

    I'm guessing that if I add it to a sphere it will look something like this


    But... Sorry for asking a lot but I still don't get it on how to have control on wich places to have grass and wich don't.
     
  12. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    446
    Doing it with the material id's, or completely different meshes would be the most efficient way (performance wise), but you can also use a texture to set exactly how dense the grass should be at a position. So if the density texture is black, there will be no grass, if it is white there will be the maximum amount of grass.

    Also putting it on a sphere like that wouldn't be possible, because right now the grass is always going upwards. That said, it wouldn't be impossible to add support for something like this, if you'd need it.

    If you have any other questions, I'd be happy to answer them (Tomorrow, that is, it's already 11pm in my timezone).
     
    daville likes this.
  13. ijoaum

    ijoaum

    Joined:
    Mar 4, 2015
    Posts:
    9
    Thanks Nonakesh! I will buy and test for myself. This is the most beautiful grass I ever seen.
     
    Nonakesh likes this.
  14. UrgeT

    UrgeT

    Joined:
    Mar 2, 2013
    Posts:
    10
    Best performance of any grass I have tried, getting 80-90+ fps with this, with standard grass I got down in 20-30 with much less grass:



    Sow far have the the grass plane slightly below the terrain plane and seems to work well that way.
     
    Nonakesh likes this.
  15. FromLions

    FromLions

    Joined:
    Jul 18, 2015
    Posts:
    3
  16. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    446
    Looks lovely!

    I only have a tablet and not the bay Internet for about a week right now, so I'll answer a bit later (and shorter. I hate tablet keyboards), but if you want to use the displacement you should look at the manual or my forum posts. The current system doesn't work very well with unity terrain, but I'll release a new displacement system, probably some time before mid next month.
     
  17. Poupi

    Poupi

    Joined:
    Jan 11, 2012
    Posts:
    104
    Hi Nonakesh !
    First all of, congratulations for your package, performances and quality are great !
    We're working on Xbox One, and unfortunately we have some errors when trying to build the shader.
    Here's a screenshot of the console showing the errors :

    grass_shader_xboxone.png

    Do you have any idea why this is happening ? Tell me if I can help you to debug these errors.

    Thanks in advance,
    Robin
     
  18. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    446
    Well, why it's happening is probably that the Shader compiler works differently for Xbox One than for PC, what exactly the problem is, I don't really know, it could be a missing feature, or some syntax error.

    Maybe you could send me the expanded versions of all the errors? (The info on the bottom of the console when you have selected a error)
     
  19. bansheesoft

    bansheesoft

    Joined:
    Oct 3, 2014
    Posts:
    50
    When built the shader shows as pink as in stand alone. In the editor it works great. What am I doing wrong?

    The below is the error log.

    WARNING: Shader Unsupported: 'Stix Games/Grass' - Pass 'FORWARD' has no vertex shader
    WARNING: Shader Unsupported: 'Stix Games/Grass' - Pass 'FORWARD' has no vertex shader
    WARNING: Shader Unsupported: 'Stix Games/Grass' - Pass 'SHADOWCASTER' has no vertex shader
    WARNING: Shader Unsupported: 'Stix Games/Grass' - All passes removed
    WARNING: Shader Unsupported: 'Stix Games/Grass' - Setting to default shader.
     
  20. tobeychaos

    tobeychaos

    Joined:
    Jul 22, 2015
    Posts:
    1
    Wonderful Asset! I managed to get it working with the Unity Terrain where it follows the mesh of the terrain BUT I can't quite figure any workaround when wanting to remove the grass in certain patches, for example.. where I would want to put roads/buildings/other assets.

    Anyone have a workaround within the Unnity editor?
     
  21. Poupi

    Poupi

    Joined:
    Jan 11, 2012
    Posts:
    104
    Unfortunately the other errors don't help that much (only the third one differs) : /

     
  22. khos85

    khos85

    Joined:
    Jul 21, 2013
    Posts:
    541
    I'm using your DirectX 11 Grass Shader on Unity 5 very nicely but I have a project which is on Unity 4.6, when I try to download and then import from the asset store the import fails, it says in console:
    Error while importing package: Package has unknown format
    UnityEditor.AssetStoreContext:OpenPackage(String)

    Is this package compatible with Unity 4.6?
     
  23. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    446
    The grass shader uses Unity 5's PBR lighting, so it doesn't support Unity 4. You might be able to get the unlit mode working, if you copy the files from a newer project (I guess that Unity 4 just can't unpack newer packages?), but I think that there still might be problems with the shader structure. Unity 5 simplified some things with shadow and deferred rendering, so they probably aren't compatible even then.
     
  24. khos85

    khos85

    Joined:
    Jul 21, 2013
    Posts:
    541
    Ok, no worries, thanks for the info.
     
  25. DrBlort

    DrBlort

    Joined:
    Nov 14, 2012
    Posts:
    69
    Is there any chance of an executable demo scene to see how it looks in VR, with some basic camera position controller? (Mainly, height).
    That would be my target platform, and I'd like to know what kind of performance to expect.
     
  26. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    446
    To be honest, I don't really know how to develop a demo for something I don't own myself. I might be able to get access to a Oculus sometimes next month and even if that doesn't work out, I'll probably get a VR set myself at the end of the year, at least if the consumer versions are really released by then. Then I'll be able to support that platform better!
     
  27. JonDadley

    JonDadley

    Joined:
    Sep 2, 2013
    Posts:
    139
    I've used this asset in two VR games now. It looks extremely good in VR - far better than other grass solutions I've tried.

    However, it's very hard to hit 75fps and also get lush, thick grass. Unless your scene is very simple (or you have an extremely powerful PC) you'll most likely need to make the grass quite sparse.

    You can cover sparse grass up to some degree with heavy use of SSAO (although SSAO can look bad in VR) but as me and other have noted, this grass has some artifacts when used with SSAO (objects buried in the grass still receive SSAO and become visible 'through' the grass).

    tl;dr this is the best looking grass in VR I've experienced however it's a bit too performance hungry to be completely practical for VR just yet.
     
  28. DrBlort

    DrBlort

    Joined:
    Nov 14, 2012
    Posts:
    69
    Thanks for the replies!

    @Nonakesh: I think that activating the Player setting "Virtual Reality Supported" would be enough for a quick test, although I understand that without a HMD it would be hard to make a quality demo for the general public. EDIT: Plus, making a GUI is not that straightforward, has to be 3D.

    @JonDadley: Good to know! As I'm still testing ideas I'm not sure of how much grass I would need. I was planning to make certain areas in the level to indicate stealth (as in covered by tall grass, think cornfield in movies).
    I guess that I'll have to be closer to finish my assets first to have a more realistic vision of performance.
     
  29. Misciagno

    Misciagno

    Joined:
    Jul 27, 2013
    Posts:
    88
    Looks good but without heightmap support I can't use it for my game :/. Will be watching the thread just in case.
     
  30. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    446
    What do you mean with heightmap support? Depending on what you mean, it does support it! (Setting the grass map with a texture and applying the texture to a terrain, which uses a heightmap. Both works, but the latter has some smaller disadvantages)
     
  31. Misciagno

    Misciagno

    Joined:
    Jul 27, 2013
    Posts:
    88
    @Nonakesh I'm a little confused. In your asset store description it says "Height maps, density maps and displacement maps do not work with Unity terrain." I first interpreted that as it wont work on terrains that are generated with the import heightfield option. Are you saying I can set up a texture to place this grass on terrains that use a heightmap that I generate from a program like world machine?
     
  32. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    446
    Yeah, the description is a bit confusing, I will fix that with the next patch. The grass doesn't change the heightmap at all. Actually the shader doesn't even have access to that. The height map I was talking about it the texture that changes the actual grass height, like it's half a meter high at one point and 2 meters at another.

    And I also found out that those maps do work with Unity terrain after all (I just remembered it wrongly after working on other stuff for too long). It's just the terrain editor (the texture part of it. Height map editing still works. That's completely independent from the shader) can't be used for the grass, you have to create the textures externally, or with another asset.

    I'm getting confused myself now, so in short: The only thing that doesn't work is using the terrain editor to set where grass is growing and where not. And there is some slight popping when using Unity terrain. Everything else works as always.
     
  33. Misciagno

    Misciagno

    Joined:
    Jul 27, 2013
    Posts:
    88
    Ok that's good to hear, I'll definitely check it out soon :)
     
  34. Pecek

    Pecek

    Joined:
    May 27, 2013
    Posts:
    127
    I like this so far, but I don't get something. Looks like the max density variable is rounded down, its only changing anything when it's near a whole number(~1.99 looks exactly the same as 1.0), is this intended? If so, why?
    Also is there any chance to support transluency in let's say a few months?
     
  35. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    446
    Sorry for being a bit slow to answer this time, I've been sick (and still am), which is also why the update I talked about is a bit delayed.

    So, the reason why it is always rounded down, is because the max density (or more accurate max tessellation) value is a integer value. As to why the slider is in float.. uh, well, probably because I looked over it while programming it. Or I'm forgetting some weird Shader inspector limitation. Anyways, I'll probably change it in the next patch!

    To keep it short: no, unfortunately it won't be possible.
    The main problem for that is transparent depth sorting. You've probably already seen that problem at times, for example when you have many particles, or multiple particle emitters intersecting each other and some of the particles that should be further away are drawn in front of the closer ones.

    That happens because the renderer doesn't know what polygons are actually closer to the camera. With particles it's kind of easy, you just sort the particles themselves (the point that represents the particle, not the triangles of the billboard that is actually rendered), so you have to sort a few thousand vectors by distance.
    When you want to have multiple transparent models it gets more difficult, you'd have to sort every polygon within a model to get acceptable results, which can be millions. That's already kind of impossible. As far as I know there are a few tricks to get around that problem, for example using bubble sort in a shader to order the pixels. (That sounds horrible, but as you have only few pixels that overlay each other, it's not too bad)
    Now to the real issue: Imagine the same thing with my grass shader. Every single blade of grass is made of up to 12 triangles, so there are several millions of them on the screen. And even worse, at times there are probably thousands of layers above each other, so the pixel sorting thing couldn't work either.

    Now, let me think of some ways of faking the whole thing... Those are just guesses and may be long shots, but maybe that could still help you!
    Now the easiest way of solving the issue would be to just accept that you can't get translucency and use the cutout alpha maps that are already implemented. Yeah, great tip, I know.
    Another thing I could think of is using something like dithering on the texture. It isn't really transparent, but it could look like it! Unity itself is using that approach for their transparent shadows (which has the same problem, as you might imagine)
    Another idea would be to quickly switch the texture on and off, to create something that appears like it's transparent, although that would probably only work when you have a extremely good and constant framerate, otherwise it could flicker.
    Maybe the best approach would be to combine the two above. Use dithering, but change the dithering pattern every frame. I'm just afraid that it wouldn't really look good, even when using that last approach, so the best idea is probably the disappointingly simple first approach.

    I hope I could explain the problem. If you have any other questions or wishes, please go ahead! (I might still be a bit slow to answer though)
     
  36. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    446
    I just uploaded the new version of the shader here's a short changelog:
    • Adds a new displacement model that is more flexible, easier to use and should have better performance.
    • Adds several tutorials to the manual.
    • Fixes a bug that can cause some errors with the old displacement model.
    I probably forgot some things here, but the first one is biggest change anyways! I also added a demo to the first post, as well as the new manual.

    It will probably take a few days until the changes are approved by Unity, so if you can't wait, just send me your invoice number per private message and I will send you a link with the updated package!
     
    Zyblade and Chman like this.
  37. Zyblade

    Zyblade

    Joined:
    Jul 1, 2014
    Posts:
    93
    Really appreciated. A comprehensive manual now, very detailed. Well done, thanks for the update.
     
    Nonakesh likes this.
  38. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    446
    The update was just accepted by Unity. You should be able to download it from the asset store now.

    As always, if you have any problems just post them here or send me a private message and I'll try to help as soon as possible!
     
  39. sbLora

    sbLora

    Joined:
    Nov 8, 2015
    Posts:
    4
    TLDR: Thanks.
    I just wanted to say thank you for making this. I spent 2 days searching the internet for this exact thing and it didn't even dawn on me to search the asset store. I'm new at this, and my project is still in the planning stages, but your shader is written down in my gamedoc and bookmarked in the browser and on YouTube and I am definitely coming back here to buy in the next few weeks.

    Even if I somehow spend dozens of hours playing with this to get it to look just how I want for my game (because I'm a stupid perfectionist) it will still save me a tremendous amount of work. The interactive bending is exactly what I need for a crucial gameplay element.

    Quick question: Does the grass currently respond to external wind? If not, could the turbulence be adjusted on the fly from a script during some event, or would this break things? (This is not a feature request or tutorial request, just asking for some quick insight, as in "yeah that's pretty doable," or "that will probably be difficult")

    Sorry to do this AGAIN but seriously, thank you! Maybe I'm just delirious after sifting through the internet late at night, but I'm so happy to have found this. You're awesome, you put a ton of work into this, you're doing a great job supporting it, don't ever get discouraged because you seriously rock. I didn't think I could get this happy in the asset store.
     
  40. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    446
    Thanks for the huge praise!

    With the internal (hard programmed) wind you see in the trailer changing the wind or turbulence isn't possible and making it changeable by script would be hard at best.
    Now before you get discouraged by this, let me say that there's a solution for this since the last update: You could use the displacement rendering (which changes the grass when you walk through it) and render the wind there! In other words, completely turn off the wind on the Shader and input the real wind from outside. This could be done simply be creating a wind texture (with a wave like normal map) putting it on a plane and moving it around, but it could also go as far as calculating fluid dynamics in a compute Shader and having actually calculated wind in the scene. Of course the latter would be a lot of work, I'm just saying that it's quite flexible in that regard.

    So in short again: it's possible, but it might take a bit of work.

    If you have any other questions, I'd be happy to answer them. And thanks again for all the praise!
     
  41. sbLora

    sbLora

    Joined:
    Nov 8, 2015
    Posts:
    4
    Thanks for the reply, and for the ideas! Never thought I'd study fluid dynamics for a video game but I might just take a crack at it! :) I'm sure I can at least come up with some jerry-rigged solution to increase the wind on command that won't look half bad.
     
  42. Fodalichking

    Fodalichking

    Joined:
    Mar 18, 2015
    Posts:
    12
    Hello @Nonakesh,
    Is it possible to create grass only over a certain splatmap? I really need this feature since I allow the player do some painting in the unity terrain at runtime.
     
  43. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    446
    You could probably get the same thing with particle effects, but if you have the performance to do it with fluid dynamics, I sure won't stop you. To be honest I'd like to see that myself. I have some ideas how it could work, if you're really going to look into it.

    Yes, splatmaps are supported! As long as you don't use the "Simple" grass type (without density), the material has a slot for a grass density texture, which is just a splatmap for up to 4 different grass textures.
     
  44. mrlinds

    mrlinds

    Joined:
    May 15, 2014
    Posts:
    4
    Have you tried running this with the unity 5.3 GL support (or thinking to support it)? I tried setting '#pragma target gl4.1' which is fine, but I get :
    GLSL compilation failed:
    ERROR: 0:243: Swizzle of non-vector primitive float
    &
    GLSL compilation failed:
    ERROR: 0:113: Declared size (3) of input array in the tessellation evaluation shader is incompatible with earlier declarations (expected 32)
    ERROR: 0:153: Use of undeclared identifier 'hs_TEXCOORD1'
    ERROR: 0:153: Use of undeclared identifier 'hs_TEXCOORD1'
    ERROR: 0:154: Use of undeclared identifier 'hs_TEXCOORD1'
    which doesn't really say much about where the error is, and I assume it has something to do with unity's compilation. I've gone and tinkered a bit with the shader, so it might have been something that I've set. Am looking into possibilities (Like GS_OUTPUT defines texIndex or lightDir with TEXCOORD1 ??? shot in the dark)

    Haven't figured out a whole lot with geometry shaders, so if you've got a better clue, that'd be super cool.
     
  45. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    446
    Oh, interesting! I didn't realize that the GL mode was useable already. I'm really busy right now, but as soon as I have the time for it I'll look into it! Thanks for the info.
     
  46. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    446
    I just submitted a small patch. I haven't looked into OpenGL support yet, I'll have to get Linux for that first, or at least install it. Nothing fancy, but if you want it right now, just send me your invoice number per PM and I'll send you the patch.

    Here's the changelog:
    • Fixes the shader for Unity 5.3 (They changed something in their cginclude files which broke the shader)
    • Adds option that improves viewing grass from above, but might look strange in some situations.
     
    JonDadley and ThunderTruck like this.
  47. Kabendji

    Kabendji

    Joined:
    Feb 9, 2013
    Posts:
    24
    Hello,

    First Thanks for this really great asset.
    I just wanted to know, if there is a way to make it work on IOS?
     
  48. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    446
    Unfortunately that a quite definite no. At least in the next few years. At least until mobile supports tessellation and geometry shaders.

    Except I'm underestimating mobile GPUs.
     
  49. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,832
    latest iPhone probably can once metal compute shaders are added (Unity is doing all kinds of magic so this will be sooner, not a few years). But it still would be a bit of a slow technique - you really need the transistors and cores from a big fat brick of a modern GPU to run this stuff well. It's one thing to have support and another thing for a tiny power saving device to deal with it quick enough :D

    One of my cards - a 460 - deals with this OK but the 780 doesn't bat an eyelid and its not a thing that one worries about. The difference between the cards is pretty much down to how well they do geometry shaders and fill rate.

    /random thoughts
     
  50. elbows

    elbows

    Joined:
    Nov 28, 2009
    Posts:
    2,396
    Unity have been working on the new openGL stuff for a number of versions of 5.x now, and they started that work on Windows first. So I don't think you need to get Linux to see what the OpenGL Unity stuff is like these days, you can get the editor to run in that mode on Windows as per the following instruction. (taken from the long blog post about DX11 features coming to Mobile in Unity 5.1. http://blogs.unity3d.com/2015/05/26/dx11-features-on-mobile/ )

    • “-force-glcore” Force best available OpenGL mode
    So run the unity editor with the -force-glcore command line argument and you should be able to get in on the OpenGL action.