Search Unity

[RELEASED] DirectX 11 Grass Shader

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

  1. PhoenixAdvanced

    PhoenixAdvanced

    Joined:
    Sep 30, 2016
    Posts:
    171
    Hi, thanks for your reply.

    Using the forward only version of the shader is exactly what I have decided to do, and it seems to work well. I'm not too concerned about the performance issues, since I am targeting high-end systems (and I am quite some time from release).

    Are there any other disadvantages to using forward only? Would deferred rendering look better visually, if I used the second approach?

    I am quite happy with the look of the grass now, so I'm not too worried, but I am just trying to decide if I *should* be using deferred rendering or not?
     
  2. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    461
    The only advantage of deferred rendering is better performance with many lights. With forward rendering the grass material has to be rendered for each light source, which can be quite performance costly for a high end shader like this. In deferred the grass is rendered into a texture once, then the lighting is calculated with that information.

    Deferred makes it impossible to use custom lighting effects, that's why the grass looks so dark, it's treated like a solid material, instead of thin blades of grass.
     
  3. Sam512

    Sam512

    Joined:
    Jan 13, 2019
    Posts:
    178
    Hi. I can't seem to to do anything with grass painter
     
  4. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    461
  5. indieDoroid

    indieDoroid

    Joined:
    Jan 25, 2016
    Posts:
    239
    hi @Nonakesh

    May I ask if this works for LWRP or Forward rendering? :)

    Thank you!
     
  6. pagnotmf

    pagnotmf

    Joined:
    May 20, 2016
    Posts:
    25
    Nonakesh,

    I am still very much enjoying your shader. (Legacy version) I have made small advances monthly and it keeps looking better and better. I have an issue that I am having trouble solving. I am seeing dark flashing along my grass textures in game. It happens with shadows ON and OFF on the mesh. It is more obvious with certain textures.

    I am using a PSD file as a texture atlas with a proper alpha, defringing, and have tested wrap modes "Clamp" and "Repeat" with no change in results. I feel that this is not a texture related issue. I am thinking this is either a Unity problem or something with the shader modes?

    Any suggestions would be appreciated. Video of flashing issue is below. Starts with material settings in case you might notice an issue.
     
    Last edited: Sep 24, 2019
  7. ILoveMyDada

    ILoveMyDada

    Joined:
    Apr 30, 2014
    Posts:
    2
    Whenever I go to the Material, it shows it as pink. And your shader gets filed under Not Supported. Is there something I'm doing wrong? Any help would be great.
     
  8. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    461
    It doesn't support LWRP yet, but it does support forward rendering! I will add support for the different render pipelines in a future version.

    It looks like there are multiple textures in the same position. This could be a problem I fixed during development of the 2.0 update. Can you try using the new version? Make a backup first, of course. I've created a short upgrade guide here: http://stixgames.com/grassshader/documentation/upgrade-to-version-2

    Which version and platform are you on? Are you sure that you deleted any old versions before importing? Have you tried reimporting the asset, or import it into an empty project?
     
    indieDoroid likes this.
  9. webjeff

    webjeff

    Joined:
    Mar 11, 2015
    Posts:
    35
    Any ETA on a LWRP (URP) version? Would love to see that, this is the only thing holding my project from going to URP at the moment.

    Thanks!
     
  10. macish

    macish

    Joined:
    Oct 29, 2018
    Posts:
    33
    @Nonakesh hi, i updated from an old build (1.x something i don't recall) to the latest version.
    I splittet my terrain into a mesh by using the now deprecated tool (previously it was not). Now i have the issue that i can't use the grass painter at all.. it say to select a grass object but when i select a SubTerrain object it just deselect its right away. Any ideas?

    EDIT: Never mind, apparently the setup changed, while it still rendered the "old" setup just fine, it just did not recognized the grass elements without all components.

    BTW i love this grass.. by faar the best grass solution i tried yet
     
    Last edited: Oct 11, 2019
  11. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    461
    I've been working on another asset lately, which is in its final stage of development, but in that case I will try to look into it sometime next week. Let's hope there aren't any major problems while porting.

    I can't make any promises though, last time I tried to port it to the HDRP it looked like it would require a fairly intense journey through their shader code...

    Yes, it's necessary to switch to the new workflow, which helped me clean up the code a lot. I think it's both more useable and less error prone now. If you still need some help porting, I've written a really short guide: https://stixgames.com/grassshader/documentation/upgrade-to-version-2

    Also I'm happy you like my asset! If you have any other problems with using it, you can always post here!
     
    macish and webjeff like this.
  12. Sam512

    Sam512

    Joined:
    Jan 13, 2019
    Posts:
    178
    Hey,
    can you integrate your shader with Vegetation Studio?
     
  13. macish

    macish

    Joined:
    Oct 29, 2018
    Posts:
    33
    @Nonakesh

    What is the other asset you are working on?

    Can u tell me if burned grass could recover similar to the trail? So that "destroyed" potions of the grass regrow after some time?
     
  14. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    461
    I've never used it myself, so I don't know. It mostly depends on the developer of Vegetation Studio, but I'd be happy to help with supporting my shader in other assets, if I can.

    Right now I'm in the final stages of a Wave Function Collapse asset. If you've never heard of the technique, it basically let's you take a set of tiles (e.g. individual parts of a building, spaceship, or whatever you can imagine), create constraints for each tile (basically defining which tiles can neighbor each other), after that the algorithm will create a working model. In other words, you create a few tiles and it automatically generates maps, buildings, vehicles, weapons, or basically anything else that fits into a grid.

    I've been working mostly on an editor that makes this as easy as possible, but I'm not sure yet how long it will take. Once the documentation is finished I'll probably make a beta test.
     
  15. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    461
    I'm currently uploading an update with very basic URP support. Only randomized orientation grass and no special lighting modes, but it should be possible to work with it if you really want to switch to URP.
     
    webjeff likes this.
  16. Sam512

    Sam512

    Joined:
    Jan 13, 2019
    Posts:
    178
    I remember when I import your asset with VS in my project.. There was some conflict code in console and had to delete your shader. When I have time I will show you
     
  17. macish

    macish

    Joined:
    Oct 29, 2018
    Posts:
    33
    Something like this ?
    , that sounds interesting!

    Could you still answere my previous question regarding regrow of burned parts?
    "Can u tell me if burned grass could recover similar to the trail? So that "destroyed" portions of the grass regrow after some time?"
     
  18. webjeff

    webjeff

    Joined:
    Mar 11, 2015
    Posts:
    35
    Wow, I was sure this was going to take a long time! I'm going to test this as soon as I see the update. Thank you for working on this!
     
  19. wayego

    wayego

    Joined:
    Aug 6, 2018
    Posts:
    9
    Hey
    I'm unable to use the grasspainter because everytime I open it and select a grass object it instantly deselects it and gives me this console error. (See attachment)

    Any idea what might be wrong?
     

    Attached Files:

  20. NathanJeeves

    NathanJeeves

    Joined:
    Jul 6, 2015
    Posts:
    8
    Hey Stix,

    I am using your shader in unity 2019.2,

    For some reason im getting this horrible darkening effect, do you have any idea what could be causing it?

    I literally copied this 'crop' material from your example file.

    Cheers
     

    Attached Files:

  21. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    461
    Yes, exactly! I really love the technique, but in it's raw form it's far from usable for artists / non-programmers, so I've been trying to create editor tools that make it easier to use. I've you're interested, I've been posting some screenshots on twitter, although I'm not really very active there: https://twitter.com/simon_stix

    Sorry about that, looks like I missed the question. Yes, that's definitely possible. You could for example animate the burn strength property, decreasing it with time, then delete the object once it's 0.

    I'm honestly quite happy about the new pipelines. They seem well designed and documented. I only wish my own code wasn't dependent on parts of the old pipeline, but it was possible to fix that with some semi ugly code. If you need any specific features, tell me and I'll try to add them as well. As you might guess it would be a lot of work to port everything at once.

    It looks like the problem is caused by a TransformReset script? That doesn't seem to be a part of my asset.

    I'm guessing that your sun in rotated fairly straight from above? If that's the case you can fix the problem by using the subsurface scattering feature for your grass material: https://stixgames.com/grassshader/documentation/general#subsurface-scattering

    If you're using deferred rendering, I'd recommend adding a fill light to brighten the grass.
     
  22. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    2,364
    Will this work on standard renderpipline with metal? as metal does not support geometry shaders.
     
  23. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    461
    If it doesn't support geometry shaders, then the DX11 shader won't work. The grass fallback should work as expected.
     
  24. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    485
    Hi. Our integration from DX11 Gras Shader is finally done.
    But now Winter comes. Do you have any idea for snow?
    Slightly and full covered?
     
  25. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    461
    I mean realistically, I would remove the grass using the interaction system. You could also change the color of each grass type to white, but snow doesn't really work like that in real life.

    If you want to be as close to reality as possible, I'd leave the grass as it is for light snow, slowly recolor it to brown (using the burn feature of the interaction system), then with heavier snow you could move the grass towards the ground and remove it after some time.
     
  26. Migueljb

    Migueljb

    Joined:
    Feb 27, 2008
    Posts:
    472
    Will this work in HDRP and unity 2019.2 and above?
     
  27. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    485
    Would be great if Nonakesh could bring his gras knowledge and workflows to HDRP VFX Graph.
    I think technically HDRP 7.1.6 is ready and stabil enough in Unity 2019.3.0f1.
    Plus proper lighting and motion vectors who should be work out of the box in HDRP.
     
  28. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    461
    It works for Unity 2019.2 and above, but HDRP support is still experimental. If you need any specific features, I can look into supporting them.

    I don't really see how the shader could be compatible with the VFX graph?

    Lighting I agree, but motion vectors would be extremely complicated to implement. I'm fairly sure that HDRP doesn't change that. The problem is that all of the geometry is rendered on the GPU, so having motion vectors would basically require having to calculate all vertex positions twice. And for that you'd need to save the previous frame of the interaction system, so in practice it would probably be quite performance costly and extremely time intensive to implement.
     
  29. sasa42

    sasa42

    Joined:
    Jun 6, 2018
    Posts:
    17
    Have a look on gemoetry shader grass implementation
    Sample #04 – Grass Wind
    from
    https://blogs.unity3d.com/2019/03/06/visual-effect-graph-samples/

    Motion Vectors should work. They work in the other demos. The Grass example i didn t check.

    See Page 16
    https://www.slideshare.net/unity3d/creating-explosive-realtime-visuals-with-the-visual-effect-graph-unite-copenhagen-20

    Unbenannt.JPG
     
    Last edited: Dec 9, 2019
  30. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    461
    I honestly think that the new visual effects graph looks great. I haven't had time to look into it but I'm sure it has great potential uses. The problem still remains, that this would require reimplementing the whole shader in a different tool. And it also wouldn't fix the problem with the interaction renderer, unless they are using some other trick to calculate motion vectors I haven't thought of.
     
  31. OrbitalImageStudios

    OrbitalImageStudios

    Joined:
    Jul 8, 2013
    Posts:
    3
    Hi I'm not totally sure how the Mesh subdivision works on terrains. As you can see in my screen shots, leaving it as mesh subdivision 1 is working fine, but in screenshot 2, you can see the grass is rendering in weird places when i set the mesh subdivision to 2 or higher. what am i doing wrong?

    Screenshot 1 with mesh subdivision set to default 1


    Screenshot 2 with mesh subdivision set to 2

     
  32. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    461
    This looks like a bug. Is there anything special about your mesh? Like did you scale it differently, or did you use any additional scripts? Also which Unity version are you using?
     
  33. PhoenixAdvanced

    PhoenixAdvanced

    Joined:
    Sep 30, 2016
    Posts:
    171
    This is excellent! I am currently looking at porting my project to the HDRP, and the grass shader is one of the stumbling blocks that I was worried about.

    How would I test the grass shader in the HDRP?

    I have started a new project in 2019.3, imported the grass shader, and changed the shader on the grass material to "grassURP", but nothing shows up, I just get grey distortion on the mesh.

    Is there a specific way to setup grass for the HDRP?

    Thanks!
     
    keeponshading likes this.
  34. OrbitalImageStudios

    OrbitalImageStudios

    Joined:
    Jul 8, 2013
    Posts:
    3
    Hi, is there anyway to use the deferred rendering with the unshaded grass? or somehow to get a similar look? since you cant change to unshaded if you use the deferred render grass. I'm going for a specific look, and want the performance of the deferred rendering.
    Thanks!
     
  35. OrbitalImageStudios

    OrbitalImageStudios

    Joined:
    Jul 8, 2013
    Posts:
    3
    Hi, sorry for late reply, forgot I had posted in here. I think it was using Gaia Asset, but I can't remember if it did the same on the default unity terrain, but i think it did. I will try it out when i get the chance again.

    I'm using the latest build (Not Beta) i will check specific version when i can get to my computer again
     
  36. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    461
    There should be a special material for the HDRP, be aware that I haven't actually gotten around to implementing it yet.

    My current plan is that I'll do that in the next few days, I've already started fixing the lighting for URP and will continue with reimplementing all the lighting features from builtin.

    Yes, you can get the best of both worlds, if you use the "Grass Forward Only" material. That way the shader is forced to use forward mode, while the rest of your scene is rendered in deferred mode. Other than that you could modify the deferred renderer, but that's not really something I'd recommend, because it would probably require a lot of work.


    I've already fixed the problem, it was simply a bug in the terrain converter. Honestly, I think I originally forgot to test terrain conversion with hills and only tested if textures scaled correctly...
     
  37. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    461
    I'm currently in the process of uploading a new update:

    DirectX 11 Grass Shader Version 2.2.0:
    • Adds full support for Universal Render Pipeline. All features, including different lighting should work as expected.
    • Fixes a bug in terrain preprocessing, where changing the subdivision level caused grass flying above the terrain.
    In other words, you can use the shader in URP with all its features. The update should be on the asset store in the next few days (probably a bit longer because of the holidays). If you can't wait that long, answer to this post and I'll upload the file on my website, so you can download it with your invoice number.
     
  38. PhoenixAdvanced

    PhoenixAdvanced

    Joined:
    Sep 30, 2016
    Posts:
    171
    That's excellent, thank you for your work on this!

    Looking forward to experimenting with the new version!
     
    Nonakesh likes this.
  39. SNicolas

    SNicolas

    Joined:
    Apr 6, 2013
    Posts:
    11
    This looks great! I will wait for HDRP support and definitely will buy this asset :)
     
  40. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    461
    I've tried to fix the shader for HDRP again, which went quite well at the start, but once I got to the actual rendering I've hit a bit of a roadblock. The shader is rendering with some extreme artifacts and I have no idea where they are coming from:

    upload_2019-12-29_12-28-23.png

    Honestly while working with the HDRP, it looked like it wasn't made to work with custom shaders at all. I think they're using code generators all over the place, so fitting something into it that doesn't use ShaderGraph or the visual effects graph is, well, not really possible, I'm afraid.
     
  41. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    485
    remembers me on this
    https://forum.unity.com/threads/hdrp-weird-pixelated-lighting-bug.705785/
     
  42. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    461
    It does look kind of similar. Honestly, I wish there were some more documentation on the whole pipeline, but I don't think it's meant for custom shader, at all. Hopefully the additional tools, like Shader Graph become mature enough to make complex shaders possible again.
     
  43. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    485
  44. PhoenixAdvanced

    PhoenixAdvanced

    Joined:
    Sep 30, 2016
    Posts:
    171
    I was just about to post about some lighting issues that I discovered, I am not sure if I am talking about the same issue:

    https://i.imgur.com/hwJWFRm.png

    Can this not be fixed?
     
    Last edited: Dec 31, 2019
  45. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    461
    I'm not the biggest fan of that approach, honestly. Now don't get me wrong, if they modeled the different shader stages in their editor in a simple way, I think it would be a great way of reducing the complexity of writing shaders, but they just seems to be mixing everything together in a fairly non-transparent way. Well, I mean tessellation and geometry shaders aren't supported at all, but the one time I used ShaderGraph for vertex shaders it was quite bad in my opinion.

    I wish they would support regular custom shaders too, shaders are far more robust than any custom tool after all. They have been around much longer.

    I'm quite sure it's possible to fix it, but I'm not sure what's causing the problem, so it's a bit difficult to try to solve it.
     
  46. StudioEvil

    StudioEvil

    Joined:
    Aug 28, 2013
    Posts:
    52
    Hi @Nonakesh !
    Just bought your plugin and it's awesome, but i have a problem.

    Unity 2019.1.14f1, standard pipeline, deferred rendering, DX11, linear color space, Windows 10.

    "Grass Forward Only" shader renders fine in deferred mode. but if i use the plain "grass" shader, all the grass is renderer total white. If i switch the rendering to forward, grass is rendered correctly. No errors in the console or in the shaders. Why?



    upload_2020-1-3_17-44-47.png
     
    Last edited: Jan 3, 2020
  47. pagnotmf

    pagnotmf

    Joined:
    May 20, 2016
    Posts:
    25
    @Nonakesh, I had to return to once again to thank you so much for your work. The power of your shader is unbelievable. I learn something new every month and continue getting more and more realistic results with FPS improvements as well. The biggest improvements have come from little tweaks - I am now able to shade my grass with a match to my mesh diffuse color. Additionally, I am using the masks for my colors to create my heightmap for grass length. Our really embarrassingly small golf community thanks you!

    I return to show results only to encourage others using your shader to keep tweaking and experimenting.


     
    Nonakesh, keeponshading and Zyblade like this.
  48. Zyblade

    Zyblade

    Joined:
    Jul 1, 2014
    Posts:
    102
    That looks really good : o
     
  49. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    461
    I just tried it myself, and it looks like for some reason that Unity version ignores the forced shader variant changed for deferred rendering. You can manually set the material to "Randomize grass direction", then it should work (I hope), but I'd recommend you update to Unity 2019.3 or something like that, where it worked as expected, at least for me.

    This looks really great! I'm really happy to see what your community accomplishes with my shader!

    Keep up the great work!
     
  50. PhoenixAdvanced

    PhoenixAdvanced

    Joined:
    Sep 30, 2016
    Posts:
    171
    Oh, so you're still interested in working on the issue?

    Hopefully Unity will release support for custom shaders for the HDRP, a lot of devs have asked for them, and as a very beginner shader writer, I can see the advantages of that type of system.
     
unityunity