Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

[RELEASED] DirectX 11 Grass Shader

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

  1. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    512
    It works with existing terrain and custom meshes, by default the whole area is filled with grass, but you can use vertex colors or a density texture to change it. There is also a grass painting tool to simplify working with a texture!

    It only works with textures, because all geometry is generated on the GPU.
     
  2. reggie_sgs

    reggie_sgs

    Joined:
    Jun 29, 2014
    Posts:
    232
    Ok thanks. It sounds like we couldn't take a terrain that was made with multiple grass textures and prefabs and just have your shader render it We're looking for something that can take an existing terrain with grass prefabs and render it.
     
  3. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    512
    You could probably reuse the existing texture, but prefabs definitely won't be possible.
     
  4. Migueljb

    Migueljb

    Joined:
    Feb 27, 2008
    Posts:
    528
    Why do the older versions work in the deferred renderer and the new version only works correctly in forward renderer in standard pipeline?
     
  5. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    512
    To answer the why: These things happen. I haven't really found a way for automatically testing shaders, at least not one that would be worth the effort. The shader is quite stable at this point.

    I need a bit more information to do something about it, like Unity version, your workflow, etc.

    By the way, I'd recommend you use the "Grass Forward Only" shader, the deferred version is missing some lighting features that make it hard to work with, in my opinion.
     
  6. StudioEvil

    StudioEvil

    Joined:
    Aug 28, 2013
    Posts:
    62
    Hi @Nonakesh!

    I'm back with the implementation of the grass on our game.
    We previously (months ago) had the "white rendered grass in deferred mode" problem, with Unity 2019.1.

    https://forum.unity.com/threads/released-directx-11-grass-shader.348258/page-25#post-5338590

    I just tried again: Unity 2019.4.7f1, downloaded the plugin, imported, opened the GrassShowcase scene, switched the tiers to Deferred rendering path, closed and reopened Unity, the grass is still white (so the derred shader variant still does not compile i think).

    We need grass to be rendered in deferred mode because with have many dynamic lights on our game, so the question is simple: could you fix that? With a deferred only version of the shader maybe?
    If not, you should state on the store description that your (awesome) plugin does not render (sadly) in deferred mode on the standard pipeline.

    Thanks!
     
  7. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    512
    I'll look into it! I'm currently taking a (much needed) break from development, so probably sometimes in the week after the next. I don't expect the problem to be big, so you can expect a fix within the next 2 weeks (no promises though, there can always be unexpected complications).
     
  8. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    512
    I got back to the problem sooner than expected.

    Instead I had the following problem:
    upload_2020-8-28_9-10-43.png

    Which is caused by the shader variants not switching to the required ones (for deferred) until you open the material settings.

    As soon as I opened the settings, it looked as expected:
    upload_2020-8-28_9-11-31.png

    The problem with the example scene is almost as simple: The camera has HDR disabled.
    Once you set this:
    upload_2020-8-28_9-16-16.png

    It works as well. No shader problems at all, apparently. I'll still upload a patch to the asset store. There isn't anything I can do about the flicker problem (unless I add a script that checks every material every single editor update, which probably wouldn't be very performant), but at least the camera problem shouldn't happen.

    Just remember that when you switch to deferred rendering, you'll have to select each material, the editor will fix everything.
     
    Last edited: Aug 28, 2020
  9. StudioEvil

    StudioEvil

    Joined:
    Aug 28, 2013
    Posts:
    62
    Thanks! The HDR flag fixed the white grass problem!
     
  10. StudioEvil

    StudioEvil

    Joined:
    Aug 28, 2013
    Posts:
    62
    Hi @Nonakesh, i'm back again.

    Given that the trick of clicking the shader to be compiled, works 80% of the times, i have another problem.
    I have a scene with a terrain prefab only. The gress is setup correctly and i can see it if i temporary add a camera.

    I run the game. The game has a main scene with a camera and it loads additively the scene with the terrain.
    The grass appears broken:

    upload_2020-9-14_18-11-3.png

    So i stop Unity. I open the scene with the terrain again. And the grass is broken also here now. But now it renders only the shadows:

    upload_2020-9-14_18-14-29.png

    Seems that something brake the material.

    Even the GrassShowcase scene is broken:

    upload_2020-9-14_18-15-39.png

    So if i close and reopen Unity, i can see the grass again.

    We have had problems with shaders variant before, sometimes. Couldn't be the case to have a deferred only shader to bypass the variant problem?

    Thanks again
     
  11. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    512
    It's possible that you are missing some restrictions in the editor code, e.g. some variant changes cause other variants to change. You should try looking into the grass editor code and see how it's managing variants. On the other hand you could try setting up a material in the editor and only change it by hand. Don't change the variants via script, as it might break the materials.
     
  12. Abnormalia_

    Abnormalia_

    Joined:
    Jul 23, 2013
    Posts:
    61
    Is there way to make this work with "Single pass instanced" in VR? ATM with forwards renderer it renders only in right eye.
     
  13. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    512
    Single pass instanced rendering would require large changes in the shader, so at the moment I'm not planning to support it. Regular single pass rendering should work without problems!
     
  14. Abnormalia_

    Abnormalia_

    Joined:
    Jul 23, 2013
    Posts:
    61
    I see, I was always using this grass in my projects but unity removed single pass in 2020 XR manager. :(
     
  15. austinGENEreeve

    austinGENEreeve

    Joined:
    Mar 29, 2017
    Posts:
    2
    Density doesn't update with the "Grass URP" shader. am I missing something?
     
  16. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    512
    It's still in the documentation for 2020.1, so maybe it's missing because of a bug? Could also be that the documentation is not up to date :confused:

    It works just as expected for me. Are you sure you're changing the right material?
     
  17. Abnormalia_

    Abnormalia_

    Joined:
    Jul 23, 2013
    Posts:
    61
    Its only for PC VR, Quest and other do not support multipass anymore... Its slow anyway.
     
  18. Mojo-Game-Studio

    Mojo-Game-Studio

    Joined:
    Sep 18, 2015
    Posts:
    95
    I have a working HDRP version if you want the code @Nonakesh
     
  19. Mojo-Game-Studio

    Mojo-Game-Studio

    Joined:
    Sep 18, 2015
    Posts:
    95
    One issue I'm having, is at the edge of meshes, I've tried all the different density mode settings to no avail.

    upload_2020-10-14_18-23-47.png

    I also checked this happens in URP to.

    Here is the wireframe of the same screenshot:

    upload_2020-10-14_18-25-56.png
     
  20. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    512
    You do? Yes, I'd really appreciate it and I'm sure so would quite a few other people! :D
    Can you send the code via PM?
     
  21. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    512
    This problem occurs when you have very irregular meshes. The nature mesh filter supports fixing the problem by splitting up the triangles into more regular shapes. Look at the mesh normalization options. I think I also explained them in more detail in the video tutorial:
     
  22. Mojo-Game-Studio

    Mojo-Game-Studio

    Joined:
    Sep 18, 2015
    Posts:
    95

    Sent via PM, I can't remember if I edited anything other than the .hlsl code so I sent the whole package, I think it was only in grassfrag and the hdrp grass shader
     
  23. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    512
    Very nice! I'll look over it when I have the time and if everything works I can release an update soon! :)
     
    Mojo-Game-Studio likes this.
  24. Mojo-Game-Studio

    Mojo-Game-Studio

    Joined:
    Sep 18, 2015
    Posts:
    95

    Our meshes are too big to use the Nature Mesh Filter, it runs out of memory :)
     
unityunity