Search Unity

[RELEASED] DirectX 11 Grass Shader

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

  1. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,527
    I have one error on Mac with the latest version in URP

     
  2. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    I got the shader working up to a point where everything should work as expected, except for the pixellation problem, so if there's a fix, I'd be happy to use it. I don't really have the time to dig deep enough into the HDRP to find the problem, unfortunately.

    And yes, I think supporting custom shaders would be quite important, but I'm not sure if it's even possible with the code generation they appear to be using. On the other hand I found the URP very nice to use for custom shaders. Quite an improvement over the built-in pipeline.
     
  3. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    I can't really think of a reason why there would be a C# error on Mac that doesn't exist on Windows? Are you sure you have the right C# version selected (I think there was an reduced subset or something?)

    I'd recomment reimporting the shader.
     
  4. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,527
    Ok I made new test project ad the error seems to be gone
    But I have one problem I'm using URP but the shader is pink, and it says its not supported on my GPU , ( radeon vII )
    Screenshot 2020-01-06 at 11.26.08.png

    Screenshot 2020-01-06 at 11.25.27.png

    Screenshot 2020-01-06 at 11.17.38.png
     
    Last edited: Jan 6, 2020
  5. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    That's in Unity 2019.3, right? I'm honestly not sure, are there any errors in the inspector when you select the GrassURP.shader file? Also do you have a machine with an Nvidia card, to test if that's the problem? I honestly don't think it is, but you never know with shaders...
     
  6. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,527
    Unity 2019.3 0f4.

    My build platform is iOS, It seems the shader is not supported

    I don't have an Nvidia card to try, but I think it won't make a difference

    Screenshot 2020-01-06 at 19.20.53.png
     
  7. PhoenixAdvanced

    PhoenixAdvanced

    Joined:
    Sep 30, 2016
    Posts:
    316
    That's good. It worked on my system except for, as you said, the pixellation issue. Maybe when 2019.3 comes out officially the pixellation issue will be solved?

    I have heard there are some bugs with 2019.3, the pixellation issue may not be due to your shader at all?
     
  8. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    Yes, the full shader isn't supported on iOS, I'm quite sure that mobile GPUs don't have the necessary shader features, but without meaningful error messages, it's hard to say.

    Grass fallback should be possible with a ShaderGraph shader. If you need that feature, I could look into it.

    Well, let's hope so, but I personally think that I'm missing something in the pipeline. It looks a bit like the pipeline blocks rendering my shader, or at least reduces the resolution while rendering it.
     
  9. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    937
    This variation looks fantastic.
    Can i ask how many different and what kind of grass textures?
     
  10. pagnotmf

    pagnotmf

    Joined:
    May 20, 2016
    Posts:
    26
    Easier solution than appears on the shader end. But, a bit of Blender work to get the vertex density I need and unwrap correct.

    I am using the 1 texture "grass type" with Default PBR shading. I use a modified version of the default supplied grass texture. (It's a lighter gradient at the base) I then use a satellite image for the grass texture color.

    Part of the program we use in Unity to develop golf courses (it's a spline based mesh maker) has a method that you can use a satellite overlay for the diffuse color of the mesh. I then export this mesh and unwrap in Blender so that my unwrap perfectly aligns on my satellite overlay, as this will color the grass.

    This allows me to tweak the satellite image in Photoshop and the grass color result will match.

    I have a tutorial posted on our golf forum - http://www.perfectparallel.com/topic/11536-3d-grass-tutorial-updated-method/#entry176097
     
    keeponshading likes this.
  11. AhmadMcreator

    AhmadMcreator

    Joined:
    Nov 20, 2019
    Posts:
    24
    Hi

    I recently bought this asset and tried it with enviro and the grass turns black when using cloud shadows. I tried the random grass orientation but I don't like the way it looks so I'm wondering if there is a solution for this problem?
     
    Last edited: Jan 19, 2020
  12. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    937
    Last edited: Jan 16, 2020
  13. iichiversii

    iichiversii

    Joined:
    Nov 23, 2011
    Posts:
    139
    I have not purchased this asset as of yet, however, I am very interested in it, before I decide on a purchase is there any video clips of this asset used in VR and with performance, I would really appreciate if you could point me in the right direction
     
  14. AhmadMcreator

    AhmadMcreator

    Joined:
    Nov 20, 2019
    Posts:
    24
    since I'm using randomize grass orientation I get this shiny yellowish effect which is really ugly. Is there a way to get rid of this as it would solve the black grass I get when using enviro
     

    Attached Files:

  15. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    What kind of cloud shadows are you using? The shader should support light cookies and Unity's shadow caster.

    I'm actually using Halton sampling for grass fallback, but in shader code these things are a bit more complicated. I think random sampling works quite nice with lots of small blades of grass!

    I'm not sure about video clips, but visually it should work without problems in VR. Performance is quite scalable with the shader, I also created a guide for optimization: https://stixgames.com/grassshader/documentation/performance-optimization.

    Also you could always ask here for advice. And if it really doesn't work out for your project, you could send me a PM with your invoice number and I can give you a refund.

    It's a bit hard to say, but I would guess one of the following is the problem:
    • You have a light angled in a very strange direction, which causes the highlight
    • Your skybox is bright at the bottom. You could fix this by enabling "Ignore specular global illumination"
    • You grass floor color is set to white, causing the strange artifacts. Set it to the color of your floor material instead.
     
  16. AhmadMcreator

    AhmadMcreator

    Joined:
    Nov 20, 2019
    Posts:
    24
    I've tried these solutions but the problem is the shadow cookie. when I turn it off the shiny blades render normally. I really like your asset and hope there is a way to solve it. This is what the enviro maker said.

     
    Last edited: Jan 21, 2020
  17. Goldrake

    Goldrake

    Joined:
    Feb 6, 2010
    Posts:
    148
    does it work with HDRP?
     
  18. AhmadMcreator

    AhmadMcreator

    Joined:
    Nov 20, 2019
    Posts:
    24
    so I was implementing the grass interactive system and it worked perfectly until I updated some other assets and had to recreate it again but this error kept coming up flattening the grass.

    "
    ArgumentNullException: Value cannot be null.
    Parameter name: material
    UnityEngine.Rendering.CommandBuffer.DrawMesh (UnityEngine.Mesh mesh, UnityEngine.Matrix4x4 matrix, UnityEngine.Material material, System.Int32 submeshIndex, System.Int32 shaderPass, UnityEngine.MaterialPropertyBlock properties) (at <7559bf9767e74ff5906f18401f66cd57>:0)
    UnityEngine.Rendering.CommandBuffer.DrawMesh (UnityEngine.Mesh mesh, UnityEngine.Matrix4x4 matrix, UnityEngine.Material material, System.Int32 submeshIndex, System.Int32 shaderPass) (at <7559bf9767e74ff5906f18401f66cd57>:0)
    UnityEngine.Rendering.CommandBuffer.DrawMesh (UnityEngine.Mesh mesh, UnityEngine.Matrix4x4 matrix, UnityEngine.Material material, System.Int32 submeshIndex) (at <7559bf9767e74ff5906f18401f66cd57>:0)
    UnityEngine.Rendering.CommandBuffer.DrawMesh (UnityEngine.Mesh mesh, UnityEngine.Matrix4x4 matrix, UnityEngine.Material material) (at <7559bf9767e74ff5906f18401f66cd57>:0)
    StixGames.GrassShader.RenderTextureInteraction.RenderInteractionTextures () (at Assets/StixGames/GrassShader/Scripts/RenderTextureInteraction.cs:182)
    StixGames.GrassShader.RenderTextureInteraction.LateUpdate () (at Assets/StixGames/GrassShader/Scripts/RenderTextureInteraction.cs:123)
    "

    edit: nevermind I created a new scene and re did most things.
     
    Last edited: Jan 24, 2020
  19. PhoenixAdvanced

    PhoenixAdvanced

    Joined:
    Sep 30, 2016
    Posts:
    316
    Hi,

    I just created a very simple test project in the new Unity 2019.3 final version.

    I used the HDRP template, and imported the latest release of the grass asset.

    I tried several of the demo's, and I simply changed the existing shaders to use the Stix Games "HDRP" version of the Shader.

    I didn't try the URP shader or the URP template.

    It seems that the issues regarding strange box-shaped distortion are still present, particularly when the grass density is increased, as in this image:

    https://imgur.com/d7cPGyG
     
  20. Zyblade

    Zyblade

    Joined:
    Jul 1, 2014
    Posts:
    141
    Could it be, there's a bug when using a probuilder mesh with the painter? It says: "Width and height must be positive". They were like -3000. Not a big deal for now, but maybe you can reproduce it, trying to paint on a probuilder created plane. Position of the plane isn't important. The bug appears on position 0 and other big numbers.

    Almost forgot, Windows 10, Unity 2019.3.0f3.
     
  21. AhmadMcreator

    AhmadMcreator

    Joined:
    Nov 20, 2019
    Posts:
    24
    still getting the black grass after play testing a scene without using cloud cookies. it happens during the night sometimes and other times not

    Windows 10, Unity 2019.3.0f6
     
  22. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    I just tried it myself and regular shadow cookies work fine with the shader. As far as I remember, that part of the lighting is handled by Unity's shader code, not mine.

    The problem might be in the interplay between the cloud shadows and custom shaders.

    Unfortunately it doesn't, I wasn't able to fix the weird graphics glitches I've posted before.

    So you could work out the problem?

    Yes, that's exactly the problem I wasn't able to solve. The shader should work perfectly in URP, but HDRP doesn't work.

    That sounds like there's something wrong with the lighting in general. Is it possible that the problem has something to do with baked lights? Those aren't supported with my shader (I mean the grass is quite dynamic, so baked lighting doesn't really make sense anyways)

    I tried it myself and it looks like the problem is, that ProBuilder uses UV's to tile the texture. I think. Either way, even with the fixed editor, once I tried painting the area, the whole plane was affected at once.

    I'd recommend using ProBuilder for prototyping and using another tool (like blender) for the final scene, where you can add the grass. You could also "fake" the density by using the interaction system, that way you don't need a (correctly) unwrapped mesh.
     
  23. Zyblade

    Zyblade

    Joined:
    Jul 1, 2014
    Posts:
    141
    Thanks Nona. I'll do my editing in photoshop anyways, for layered non-destructive workflow. I just wanted to mention it, in case someone else stumbles over this error message^^
     
  24. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    Thanks for the report! Honestly, I think I need to look over that part of code again, sometimes, it's really quite convoluted. At least it works for regular meshes...
     
    Zyblade likes this.
  25. PhoenixAdvanced

    PhoenixAdvanced

    Joined:
    Sep 30, 2016
    Posts:
    316
    Oh really? I assumed it didn't work for any of the SRP's.

    That's really strange that it works for the URP, but not HDRP, since they are both "scriptable render pipelines"! Hopefully it is a unity bug that will get fixed in future versions!

    Have you mentioned it to Unity?
     
  26. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    The main point of the scriptable render pipelines is that they are extremely customizable, not that they are all compatible with each other.

    I was hoping for the same thing, but it turns out that URP and HDRP are extremely different. URP is somewhat similar to the old builtin pipeline, only that it's better designed. HDRP looks (at least to me) like a very complex combination of code generation and dynamic systems. The goal is probably that lots of fundamental things can be changed via GUI, but I found it extremely difficult to extend. I think it might not be meant to be extended at all, except for ShaderGraph.
     
  27. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    Are you sure you are in the right thread? This one is for the StixGames DirectX 11 Grass Shader.
     
  28. Zyblade

    Zyblade

    Joined:
    Jul 1, 2014
    Posts:
    141
    @Nonakesh when I use Surface mode and use a point light, the floor with specular pbr setup doesn't match perfectly like with the directional light. Do you know which lines in the shader need to be adjusted? Would be nice, if it lightens the grass, like the directional light so the grass keeps being seamless with the floor (smooth transition between grass and floor)
     
    Last edited: Feb 8, 2020
  29. PhoenixAdvanced

    PhoenixAdvanced

    Joined:
    Sep 30, 2016
    Posts:
    316
    Hi,

    Is there an easy way to modify the grass shader to reduce the strength of the shadows?

    Both the forward and deferred rendering shaders have very strong shadows, which doesn't look good in my project. I can reduce the shadow strength on my sun light, but then the shadows on the trees, player, etc, are too weak.

    Ideally, I would like to reduce the shadow strength on the grass only, is this possible?

    Thanks.
     
  30. Zyblade

    Zyblade

    Joined:
    Jul 1, 2014
    Posts:
    141
    @Nonakesh I tried quite a few things, but I couldn't manage to get point lights working properly in surface mode. Most of the grass blades are too bright. Some of them are brighter than the other ones, just a few ones evenly spread. And another few ones, also evenly spread, are perfect smooth. I don't know if this has something to do with normals.

    Maybe you find the reason.
     
  31. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    Sorry for taking so long to answer, I've been sick for over a week.

    I think the problem is probably that point lights change based on direction and position, unlike directional lights, where only direction / normal is important. I'm not sure if its even possible to match them perfectly.

    Do you have a screenshot of the problem? Maybe I can think of something from there.

    You could try increasing the subsurface scattering strength per grass type, other than that the shader uses Unity's lighting, so you could try changing the ambient lighting.
     
  32. PhoenixAdvanced

    PhoenixAdvanced

    Joined:
    Sep 30, 2016
    Posts:
    316
    Thanks for your reply, sorry to hear that you have been sick!

    The subsurface scattering didn't seem to make too much difference to the strength of the shadows on the grass. I am using one directional light for the sun, and changing that will affect all shadows. How would I change the ambient lighting by itself?

    I am not using baked lighting, etc.

    Thanks!
     
  33. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    You should look into the lighting settings of your scene. Play around with the "Environment Lighting" settings, either boost the lighting of your skybox, or try using a single color ambient light.
     
  34. PhoenixAdvanced

    PhoenixAdvanced

    Joined:
    Sep 30, 2016
    Posts:
    316
    Thanks a lot, I have looked into that. I am using the Skybox lighting mode, so I can't adjust it from there, but changing to "color" does seem to help a bit.

    I will keep playing with it, thanks for your advice!

    EDIT:

    Would something like this work:

    https://forum.unity.com/threads/diferent-shadow-strength.225640/

     
    Last edited: Feb 23, 2020
  35. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    If you really want to make the shadows weaker there's an easier way to do it, just be careful, this also changes how the shader reacts to lights.

    Go to GrassFrag.hlsl and add this additional line anywhere you can find UNITY_LIGHT_ATTENUATION, so it looks like this:

    Code (CSharp):
    1. UNITY_LIGHT_ATTENUATION(atten, i, worldPos);
    2. atten = max(atten, half3(0.8, 0.8, 0.8));
    Change the numbers to make the shadows weaker or stronger, 1 is no shadows at all, 0 changes everything back to normal.
     
  36. PhoenixAdvanced

    PhoenixAdvanced

    Joined:
    Sep 30, 2016
    Posts:
    316
    Hi,

    I made those changes, but I couldn't see any changes to the shadows at all. I tried with the basic unmodified grass shader (in forward mode) and the demo scene.

    I made the change in two places in GrassFrag.hlsl, around line 52, and around line 120.

    Did I miss somewhere? I couldn't find anywhere else where UNITY_LIGHT_ATTENUATION was defined.

    Thanks for your help!
     
  37. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    Are you using the builtin pipeline? If yes, can you try the same thing, but replacing 0.8 with 0.9 or 1.0?
    Also which lighting mode are you using?

    If you're using URP you'd need to change another file.
     
  38. PhoenixAdvanced

    PhoenixAdvanced

    Joined:
    Sep 30, 2016
    Posts:
    316
    I'm using the Built-in RP. I have my scene settings set to deferred lighting, but I am using the forward shader for the grass.
    I have tried various values, from 0 to 1, with no effect.

    I've tried simple grass, and the other grass types (1 texture, 2 texture, etc) and the shadows dont seem to change on any of them, even though the grass itself works.
     
  39. Zyblade

    Zyblade

    Joined:
    Jul 1, 2014
    Posts:
    141
    @Nonakesh

    Here 2 example screenshots. You can see, some blades are very bright, some are just a little too bright and some rare ones match perfectly. You have to look a little closer to reckognize those perfect ones. In the screenshot without pointlight, everything is perfect (no hard floor transition, everything is smooth).
     

    Attached Files:

  40. Migueljb

    Migueljb

    Joined:
    Feb 27, 2008
    Posts:
    562
    Why is it when I switch the camera to deferred the rendering looks really bad and not right gets really dark? I used to use the old version in deferred and never ran into this problem I just upgraded to latest any info would be great or maybe something I'm missing etc to check for deferred.
     
  41. PhoenixAdvanced

    PhoenixAdvanced

    Joined:
    Sep 30, 2016
    Posts:
    316
    I think that's the same problem that I had. It's to do with the unity lighting. Eventually I had to stick with the forward shader, it looks a lot better.

    I am currently trying to find a way to reduce the shadow strength on the grass, which I think could help as well.
     
  42. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    Honestly I'm at a bit of a loss, it worked perfectly on my end. Maybe the shadows in deferred rendering are handled differently?

    I'm not sure, but it's possible this is fixable. I'll look into it.

    Exactly, I'm afraid the deferred renderer is missing some lighting features to make things like grass look good. It could be possible with some additional lights, but the easiest way is definitely to switch the grass to forward only.
     
    Zyblade likes this.
  43. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    I tried fixing this problem and it turns out that point light rendering is slightly broken in general. I tried comparing my rendering code with Unity's standard shader and it looks like I'm doing exactly the same things. Honestly, I have no idea what's going wrong.

    I do have an idea how to solve your problem, but it's really not much of a solution at all... Have you considered switching to URP? I just tried it myself and the lighting looks like it perfectly matches there. Honestly, the whole renderer looks better in my opinion, but I'm not sure if the switch is worth it for you. Sorry I couldn't be of more help.
     
  44. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    By the way, I created a support Discord server: https://discord.gg/jvBFhQA

    I think that may be a good way for smaller questions! I'm not sure how it'll work, as I'm a bit obsessive with Discord and still want to keep some measure of work-life balance, but worst case I'll check it semi-regularly depending on how much other stuff is going on in my life, as usual. :D

    Also, I've just submitted my new asset Tile Composer to the asset store: https://forum.unity.com/threads/tile-composer-code-free-procedural-generation.849637/
     
  45. Zyblade

    Zyblade

    Joined:
    Jul 1, 2014
    Posts:
    141
    No problem. At least, it's one way to solve it. Well, beside one asset, my project could work on URP. I will decide later how to solve it, thanks for the hint.
     
    Nonakesh likes this.
  46. Padilha

    Padilha

    Joined:
    Jun 6, 2016
    Posts:
    12
    I bought your asset today and did some testing with plans, just like you did in your video tutorial. Everything worked perfectly, but when I put the material on the terrain, the grass only appeared in some places. Maybe I lost some basic configuration or something.

    Unity version : 2019.3.0f6;

    On the left is the terrain and on the right is the material placed on a plane:
     

    Attached Files:

    Last edited: Mar 23, 2020
  47. PhoenixAdvanced

    PhoenixAdvanced

    Joined:
    Sep 30, 2016
    Posts:
    316
    Have you tried adjusting the settings on the grass shader?
     
  48. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    Are you using NatureMeshFilter and GrassRenderer for your terrain? You've applied your material directly to the plane.

    Can you post a screenshot of the settings you are using, e.g. NatureMeshFilter and GrassRenderer.
     
  49. Padilha

    Padilha

    Joined:
    Jun 6, 2016
    Posts:
    12
    I'm using the NatureMeshFilter and GrassRender. If I decrease the density, the grass appears but it would be unviable.
     

    Attached Files:

    Last edited: Mar 23, 2020
  50. Zyblade

    Zyblade

    Joined:
    Jul 1, 2014
    Posts:
    141
    Maybe weird UVs (density/height map?) or wrong vertice density. But it seems it's more related to UV/Texture things. I would try another mesh and look, if that happens there too.