Search Unity

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
    Well I can add that, if you need it. Just a small thought: wouldn't it be easier to rotate the planet, so the part you are on is always at the top? I mean you approach must be quite challenging when dealing with physics and even character controllers.

    You could send me your invoice number and I'll send you a modified script for that purpose, or you just edit it yourself:
    1. Add a vector property to the Grass.shader file (in the property section at the top), like this:
      _UpVector ("Up Vector", Vector) = (0,1,0,0)
    2. Add a upVector variable to the GrassDefinitionsAndFunctions.cginc file (or anywhere else really.. but it fits here), like this: fixed3 _UpVector;
    3. Set the up vector in the GrassGeom.cginc file to be equal to the newly created variable, like this (Line 68):
      fixed3 up = _UpVector;
     
  2. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    711
    @Nonakesh Hi there! I'm very interested in this asset and I was wondering if you would be willing to implement a certain feature: would it be possible to get a variant of the shader that would simply work with vertex alpha rather than height/density/displacement maps?

    In other words, height and density would be driven by the alpha vertex value of the mesh. Where a value of 1 would yield high and thick grass and a value of 0 no grass at all.

    The great things with using mesh vertex info like alpha is that it doesn't require new specific maps for each mesh; it's very flexible that way. Plus transitions/gradients are very smooth (or sharper if you use more vertices).

    (Of course to be perfect there would be a checkbox option to invert alpha value if needed)

    Is that something you would be willing to implement?
     
    ElectroMantis and eskovas like this.
  3. Project-Mysh

    Project-Mysh

    Joined:
    Nov 3, 2013
    Posts:
    223
    Hi Nonakesh,

    Why is this happening when using SSAO :
    DX11Grass_SSAO.jpg
    SSAO enabled----------------------------------------------------------------SSAO disabled

    And there is any way to reset the interacion with grass?
     
    Last edited: Aug 26, 2015
    JonDadley likes this.
  4. JonDadley

    JonDadley

    Joined:
    Sep 2, 2013
    Posts:
    139
    I've been noticing this same problem. I'd love to be able fix it!
     
  5. khos85

    khos85

    Joined:
    Jul 21, 2013
    Posts:
    541
    Thanks for your replies previously. I was just interested to try the displacement part, I have the script added to my player, but not sure how / what to do with the texture, can you explain that a bit , is there a video tutorial I can watch to understand this more?
     
  6. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,354
    We're being forced to return to Unity terrain for memory reasons so will use this for situational areas I guess.
     
    Last edited: Aug 27, 2015
  7. kzaurckichz

    kzaurckichz

    Joined:
    Nov 5, 2013
    Posts:
    52
    Thank you, it works perfecty.
    Just one problem, the Fade Start and Fade End doesn't seam to work.. no mather what value I set there, the grasse always seams to stop at the same distance (~100m).

    EDIT: Nevermind, I found out it was Density Falloff that I needed to set up right.
    Grass fade only seams to make a difference to the grass height according to the shader code... ?
     
    Last edited: Aug 26, 2015
  8. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    711
    That's unfortunately a common issue with Unity at this point. The solution is to create a replacement shader in the Camera-DepthNormal file.

    For more information please see here: http://forum.unity3d.com/threads/sessao-high-quality-ssao-w-color-bleed.323511/page-4#post-2200447
     
    hippocoder likes this.
  9. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    431
    If you can send me your invoice number (In a private message), I can look into it and send you the modified files, but that's a bit too specific to put it on the asset store... I don't want the shader to become too bloated to be useful.

    Yeah, I'm think that this is a problem with the SSAO script as well. My shader handles depth calculations quite well, as you can see at shadow casting and receiving, so the SSAO shader probably ignores it somehow.

    That's right. I think I explained that in the manual as well. Grass fade is just for visually blending the grass with the floor in the distance.

    Have you tried looking at the example scene in the new version? That could clear up a few things. If you still can't get it to work I can write a short guide here.

    That's unfortunate, but if you're willing to ignore the popping, you can still use the basic functionality. I just tried it out and it seems that it is possible to use height, color and density maps with the terrain after all, if you create them in an external program and add them like with a non-terrain mesh. You can't edit them with the terrain editor, of course.
     
  10. JonDadley

    JonDadley

    Joined:
    Sep 2, 2013
    Posts:
    139
    I'm pretty clueless when it comes to shaders, even after reading your link I'm not really sure what I need to do in my project to resolve the issue. Could you give any more specific advice?

    I'd love to get SSAO working well with this grass as it really helps it's appearance (especially when looking down at the grass immediately below the player - it helps fill in the gaps around the blades and blend them).
     
  11. khos85

    khos85

    Joined:
    Jul 21, 2013
    Posts:
    541
    Hi,


    I was just interested to try the displacement part, I have the script added to my player, but not sure how / what to do with the texture, can you explain that a bit , is there a video tutorial I can watch to understand this more?
    Have you tried looking at the example scene in the new version? That could clear up a few things. If you still can't get it to work I can write a short guide here.

    Yes I tried the sample scene, even took the sphere sample you made and put it into my scene but the grass does not displace on my scene.. Hopefully you could show/list a couple of steps to help out, many thanks if that is ok.
     
  12. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    431
    Have you followed all the steps from the manual?
    • The object with the grass material has to be on a layer you have selected in the layer mask.
    • The object with the grass material has to have a collider.
    • The object with the grass material must have a UV map. The displacement is based on a texture, so without one it will not work.
    • The displacing object does not need a collider. The displacement is done by raycasting. Of course you can add one if you need it otherwise, just don’t put the character collider on the grass layer.
    • The grass material has to have a editable displacement texture. It can be added with the Grass Texture Adder class.
    • The texture must be large enough for the area. Keep in mind that very large textures will significantly decrease performance. If you want to have displacement in a very large area, you could split it into smaller parts and use several small textures instead of one large one.
    If all off that is the case, it should work for you! I'm not sure about Unity terrain, but it should work there as well, as long as it's not too big.
     
  13. Project-Mysh

    Project-Mysh

    Joined:
    Nov 3, 2013
    Posts:
    223
    There is any way to reset the displacment effect after a few seconds the character passes trought the grass?
     
  14. khos85

    khos85

    Joined:
    Jul 21, 2013
    Posts:
    541
    Thanks, I did try the docs but thanks for the guide, I guess I am not too sure on what it all means(meaning I'm kind of dumb probably, or don't have the knowledge..), It might be that I moved your grass prefeb just slightly under my existing terrain (yeah I want to keep that for now) so the actual mesh won't show, only the grass and that could be preventing the collider from hitting the grass object.. I mean that is what I can think, I'll try moving the object into sight asap.
     
  15. Jean-Moreno

    Jean-Moreno

    Joined:
    Jul 23, 2012
    Posts:
    429
    Well, while the shader compiles fine and no error or warning is seen (either in Editor or on the console log), the shader still doesn't work on PS4 (can't see grass at all, the scene runs fine though).
    Tried both forward and deferred paths.

    Anyone would have any ideas about this?
     
  16. khos85

    khos85

    Joined:
    Jul 21, 2013
    Posts:
    541
    Does PS4 support DX11? not sure about that...maybe Xbox ;)
     
  17. Plutoman

    Plutoman

    Joined:
    May 24, 2013
    Posts:
    257
    Is there a particular reason you're sticking with forward over deferred?

    Just curious, because the deferred implementation seems to be working fine on mine, but I am not aware if there's any performance implications or anything. If I ever get the time to set it up (probably won't for such a minor feature, when I've got to start delving into animation/gameplay/pathing/ai), I wanted to set it up to work with Uber's translucency feature. Going to be quite expensive though especially as the geometry needs to be thick for that to work well. For screenshots, though, full shadow-casting on the grass, and translucency, with high density, high poly grass, would be quite beautiful.
     
  18. bartm4n

    bartm4n

    Joined:
    Jun 20, 2013
    Posts:
    57
    You are correct. DX11 is Microsoft technology. PS4 uses (modified?) OpenGL.
     
  19. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,354
    NDA means we can't speak about anything but you'd be surprised.
     
  20. bartm4n

    bartm4n

    Joined:
    Jun 20, 2013
    Posts:
    57
    Is this directed at the rendering API convo?
     
  21. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    431
    That shouldn't be a problem if the grass is on a different layer than the terrain. Of course then only the grass layer should be selected on the displacer script.

    I that question is directed at me: No there's not. I had a small bug in deferred, because I programmed the whole thing in forward, but now both of the modes should work equally.

    Absolutely no errors, but it still doesn't work? Well, that sounds quite strange, to be honest. Have you tried any other shaders with tessellation? Would be interesting to see if any of them works, because then there could still be a way to get it to work.
     
  22. borrowedLadder

    borrowedLadder

    Joined:
    Feb 11, 2015
    Posts:
    21
    Hey there,
    I picked up a copy from the store and tried to email you but my emails are just being returned - is something wrong with the support address?

    Anyway a small question, is there anyway with the grass to have it move out of the way as a character moves through it? I've seen some shaders with push bending for vegetation and it's something I'd really like to have if possible as your grass looks great! :)
     
  23. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    431
    Yes, I'm very sorry about that. My host is currently having some server trouble, which will hopefully be resolved soon, or I'll probably have to switch.

    Have you checked the example scene? I made a setup where you can move a sphere though the scene and the grass gets bent and pressed down. Is that what you are referring to?
     
  24. borrowedLadder

    borrowedLadder

    Joined:
    Feb 11, 2015
    Posts:
    21
    Aha! I hadn't seen the updated version with the examples :)

    The examples look great although they aren't 100% what I meant. With some other grass systems you can have the grass be pushes aside slightly as a collider moves through it, and then it will immediately spring back into place once the collider has left it.

    Would this kind of thing be possible?

    Looking at the examples the effect could be used in a way - would it be possible to have the displacement timed? For instance if I want the grass to be flattened down as I walk over it (as in the example) but after a delay you can set it would start to return to its original, non-squashed self?
     
  25. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    431
    I think I've been able to replicate something like that with some settings of the displacer. Try playing around with the settings, especially a low pressure threshold (that normally stops the displacer from affecting the grass).

    I've already created a small script that does that for somebody who requested it. I will probably add it in a future patch, but until then you could just take it from here! Just save it as GrassRegenerator.cs and put it on the grass object. Of course it's a bit basic, but you can use the regenerationSpeed variable to get it to look a bit better.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using StixGames;
    4. public class GrassRegenerator : MonoBehaviour
    5. {
    6.     public float regenerationSpeed = 1;
    7.     private Texture2D texture;
    8.     private readonly Color originalColor = new Color(0.5f, 0.5f,1,1);
    9.     void Update ()
    10.     {
    11.         if (texture == null)
    12.         {
    13.             texture = GrassManipulationUtility.GetGrassTexture(transform, false);
    14.         }
    15.         Color[] pixels = texture.GetPixels();
    16.         for (int i = 0; i < pixels.Length; i++)
    17.         {
    18.             pixels[i] = Color.Lerp(pixels[i], originalColor, regenerationSpeed * Time.deltaTime);
    19.         }
    20.         texture.SetPixels(pixels);
    21.         //Search for texture updater, which prevents multiply applys per frame (for multiple displacers)
    22.         TextureUpdater updater = GetComponent<TextureUpdater>();
    23.         if (updater == null)
    24.         {
    25.             updater = gameObject.AddComponent<TextureUpdater>();
    26.             updater.targetTexture = texture;
    27.         }
    28.         updater.RequestTextureUpdate();
    29.     }
    30. }
     
  26. Jean-Moreno

    Jean-Moreno

    Joined:
    Jul 23, 2012
    Posts:
    429
    After a quick test, it turns out that tessellation shaders do work in PS4, but not geometry shaders.
    I do not know if they are just not supported there, or if it is a syntax issue.
     
  27. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,354
    I can't see any reason they wouldn't work. Ask dev net what they think.
     
  28. Rico21745

    Rico21745

    Joined:
    Apr 25, 2012
    Posts:
    409
    I'm still watching this asset and hoping it eventually becomes compatible with default Unity terrain painting system or at least designating a splat texture that has the grass attached in the Unity terrain. As much as I'd love to dump the Unity terrain engine forever, there's just too many useful assets I have that are built on top of it :-/
     
  29. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    431
    Well, you can't use the terrain painting system, but you CAN use hand painted textures! Here's a (ugly) example of a grid texture used as a splat map on Unity terrain: http://imgur.com/vCgf8NV
     
  30. sakdeniz

    sakdeniz

    Joined:
    Jul 21, 2015
    Posts:
    7
    Hi Nonakesh,

    I think shader need improvements. I have poor fps with i5 cpu and ati radeon graphic card. My graphic detail level is best and anti aliasing set to enabled - force. It gives around 30 fps but i need 60 fps minimum for smooth gaming. My scene does not contain too much object. Just one ocean and 2 trees. After remove grasses from the scene fps going over 120. What is your advice for better fps without changing quality grass. I want to use it with default values. I dont want decrase grass detail settings. Is it possible improve shader code performance?
     
  31. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    431
    The grass shader is a very performance costly asset, but I wrote a whole section for improving the performance in the manual. If you've done all that is written there, there's really nothing else I could think of.

    You could still use it as a option that can be disabled. I personally don't need 60 FPS for gaming, I think 30 to 40 is still quite playable, so you could leave the choice to the player.
     
  32. khos85

    khos85

    Joined:
    Jul 21, 2013
    Posts:
    541
    I agree with you, maybe a ingame performance slider/tweak can be added by the developer so gamers can adjust the performace in game, eg best performance reduces grass fade end etc., but that is down to the dev.
    P.S. will this asset use CPU or GPU ? Do I think correctly: it does not matter what kind of Core i5 or i7 you have but more so the graphics cards, or am I correct?
     
  33. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    711
  34. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    431
    Yes, you are correct! The grass shader itself does exclusively use the GPU. The grass displacement (or more specific changing the grass displacement texture) on the other hand uses CPU power as well, so a different processor does matter in that case.
     
  35. Furry

    Furry

    Joined:
    Feb 28, 2013
    Posts:
    5
    Hi, asset looks great but do you have some demo(standalone for windows) in which I could walk and look at grass from different directions?
     
  36. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    431
    Currently I don't have one. I do plan to add a demo in the future, as soon as I can find the time to do it. Until then you could look at the trailer and screenshots or ask me any questions you might have!
     
  37. khos85

    khos85

    Joined:
    Jul 21, 2013
    Posts:
    541
    I'd recommend it, it really is good, from any angle!
     
    Nonakesh likes this.
  38. novello_io

    novello_io

    Joined:
    Nov 22, 2009
    Posts:
    287
    Really like this asset!

    Having a somewhat minor issue with the circular displacer when using multiple grass tiles.

    When crossing the border of one grass tile to another, I get these errors:



    This happens in the demo scene, but only between grasses of the same type. (I had to duplicate one)

    It also happens in my scene where I just have 5m grass tiles:


    Any insight as to what this might be?
     
  39. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    431
    That sounds like it's a bug in the displacer itself, I'll look into that as soon as possible! I'll send you a private message as soon as I have found something.
     
  40. sao

    sao

    Joined:
    Sep 2, 2014
    Posts:
    4
    Hi There,
    I just bought your asset and must admit it looks great.
    But I don't really understand one thing - there's the Simple shader mode with great looking and fast rendered grass blades. This isn't always sufficient as I need some diversification, flowers etc. But if I switch to Textures mode I won't be able to render the grass blades anymore.

    It would actually make sense to me to have the grass blades rendered in all shader modes and have the blades linked to one of the channels, say Red, for density etc. The texture limit would then decrease to 3 but that would still be just fine as the majority of terrain meshes will be covered by the simple grass blades anyway.

    Is it possible for you to modify the shader slightly?

    Also, it would be nice to have one another texture to cotrol grass heights for each channel separately. As I understand, currently it's done by alpha channel of the Color texture but for all grass types (in 4 Texture mode)?

    Thanks!
     
  41. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    431
    Unfortunately that would require some drastic changes to the shader. I have handled this problem by using a very simple rounded grass texture. I included it in the example scene, so feel free to use the same texture.

    Yes, grass height is controlled with the alpha channel of the color texture, but you can also change the height for each grass type separately (with the height settings below each grass texture).

    If you really require that much control for each texture, you could try using 4 different materials, all in 1 texture mode, and stacking them together. I haven't tested this though, so I don't know how the performance scales in this situation.
     
  42. sao

    sao

    Joined:
    Sep 2, 2014
    Posts:
    4
    Thank you for quick answer, I'll figure something out then.

    One another question - the textures are displayed as kind of camera facing billboards but strange thing is, they rotate around right corner instead of billboard middle producing this unnatural feeling. This becomes especially noticeable after setting the Width property to larger values.

    Any chance to fix that?
     
  43. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    431
    To be honest, I've never noticed that. The shader isn't really made with large widths in mind, as you could just use any other billboard shaders instead, but I will look into it in the next few days.
     
  44. jf3000

    jf3000

    Joined:
    Dec 31, 2013
    Posts:
    153
    There needs to be a tutorial on how to actually use this from a novice view, reading the pdf just gives a lot of information about the product but doesn't actually tell you the steps to using it.

    Even sent an email and nothing.
     
    Last edited: Sep 5, 2015
    DrewMedina likes this.
  45. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    431
    I am very sorry about that, my provider is having some serious trouble with their mail server, but I try to be as responsive as possible on the forums. I'm seriously thinking about changing the host because of this, but the rest of their service, including the price is incredible, so I'm still a bit reluctant...

    What exactly do you need a tutorial for? The grass shader, or the displacer? Both seem rather self explanatory to me, especially with the info from the manual, but if you could tell me what you have problems with, I could create a short tutorial to address them.
     
  46. jf3000

    jf3000

    Joined:
    Dec 31, 2013
    Posts:
    153
    Both seem explanatory to you because you created the asset. If I told you to hop in the seat and fly this 777 would you know what to do, of course not you'd crumble, the manual doesn't help because it won't tell you how to start the aircraft. That's the same as you and this, a mindset of thinking we all should know how to do this, whatever happened to showing the basics for the people who are just learning. I know I would be happy if there was a tutorial on a from the beginning to the end.

    1. Create a terrain
    2. Mould it
    3. Apply shader
    4. See result

    Some of us aren't that cluey when it comes to these sort of things.

    Thank you.
     
    hippocoder likes this.
  47. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    431
    Well, but there's the problem right there, the terrain doesn't perfectly work with the shader, which I have repeatedly written. It does mostly work, but there are some restrictions that I can't really change unfortunately.

    And I'm very sorry, but creating a terrain itself is really out of scope for my shader. There are a lot of tutorials on the internet for this topic, including ones by Unity itself.

    I'm happy to help you with any problems with the shader, but I can't give you personal training with Unity, there are other places that are better at that than I am.
     
    jf3000 likes this.
  48. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,354
    hopeful, Nonakesh and jf3000 like this.
  49. nicolasbulchak

    nicolasbulchak

    Joined:
    Aug 9, 2013
    Posts:
    37
    Purchased the plugin, LOVE IT! Are there any platforms that this will not work with. Does DirectX mean its made for windows only?
     
  50. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    431
    Yes, it only works on Windows right now. That is, until Unity supports tessellation on other platform. As soon as it does I will try to add support for other platforms as well.