Search Unity

[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:
    576
    Yes, that is a new feature since the last version of the shader! Just select "Randomize grass orientation" at the top of the shader settings.
     
    frbrz likes this.
  2. liero116

    liero116

    Joined:
    May 22, 2012
    Posts:
    72
    Wow perfect!

    I guess I haven't updated in a while.

    Thanks!
     
  3. Jeremy-Borton

    Jeremy-Borton

    Joined:
    Oct 21, 2015
    Posts:
    63
    So I just recently purchased, and I'm looking at the documentation, (which is great but), but for what I was looking for.
    It start with discussing how to use on unity terrain. I have a mesh terrain. I guess I just have to experiment? You should include getting started with a mesh terrain as well in the documentation.

    I'm having no luck so far placing on a mesh terrain. The setup is unbelievably hard (at least for me) If things don't work out soon, I might have to ask for a refund.

    Thanks,
    Jeremy
     
    Last edited: Jul 29, 2017
  4. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    A mesh terrain? Like, a terrain that's just a mesh from a 3d modelling program? Sorry, I didn't include a tutorial for that, because it is very straight forward to use with those... You just put the material on the mesh, like with any other material.
    You could also look at the example scene, there are a few (small, but size doesn't change how it works) examples with meshes in it.

    The only problem that could come from using a mesh terrain, is that grass density is dependent on the polygon density, so if your mesh is not uniform, you might have difficulties. This is also described in the documentation, a bit further down, in a section called visual problems, or something like that.
     
  5. Ramulos

    Ramulos

    Joined:
    Feb 19, 2017
    Posts:
    57
    Hello, Im also interested in the VR situation of the application and want to know how itll perform. Could you confirm the issues with VR were solved? is there any screenshot that can show how many frames/ms the grass would use?

    Sorry if this is repetitive. Thank You.
     
  6. Jeremy-Borton

    Jeremy-Borton

    Joined:
    Oct 21, 2015
    Posts:
    63
    So I clicked window, stix games, place grass, and It says I have to select an object in the hierarchy, and I do, but It doesn't recognize anything, not even terrain. So I started a new project. Same thing...
    So I looked at the tutorial. I create the material. I drag it onto my mesh terrain. It covers the whole entire thing with grass!!! I don't want only grass, and the whole thing grass! I want to be able to paint grass where I want it.
    Anyway I can get a refund? It's just not working out for me. I'll message you my invoice number.

    Thanks,
    Jeremy
     
  7. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    1,490
    Hi there, just some input if I may: Have you tried using the Grass Painter tool?
     
  8. Jeremy-Borton

    Jeremy-Borton

    Joined:
    Oct 21, 2015
    Posts:
    63
    I tried removing the grass component from a object, and I can't. The only options are : Reset, Select Shader, Edit Shader. It's getting real annoying trying to work with this tool.
    I tried using the tool after applying the material to a plane cube. it didn't work. After I clicked a few times a red circle appeared which indicated where to add or remove grass, but it didn't work. Nothing changed.
    I can't stand dealing with these things. Maybe it works for another, but don't blame me, I really tried to get it working. I use plenty of other assets that have all worked. Please refund.
     
  9. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    I think this depends on your scene mostly, can you send me a few screenshots so I can try to help you optimize the shader for your project? I may not be able to answer soon, I am currently outside my country, so please be patient!

    Honestly that sounds like you are using the wrong tools. It could also be a bug in the grass painter, in that case, can you tell me the Unity version you are using? Also are you using the newest version of the grass shader?
    Also in case this has not been clear: You have to put a grass material on the object, then open the grass painter, then select the object with the grass material, then you'll get instructions right in the grass painter. It shouldn't be difficult, but it could be that the painter is not intuitive enough yet.
     
  10. Black_Raptor

    Black_Raptor

    Joined:
    Nov 3, 2014
    Posts:
    181
    Grass painter doesn't work for me, someone could make an tutorial please ? I dont understand the documentation ( I use unity 5.6.0 )
     
  11. elettrozero

    elettrozero

    Joined:
    Jun 19, 2016
    Posts:
    216
    Grass painter paints on a mesh/terrain that has grass material (of course) and a collider.
     
  12. elettrozero

    elettrozero

    Joined:
    Jun 19, 2016
    Posts:
    216
    Error in shader (not always) :

    Shader error in 'Stix Games/Grass': invalid subscript '_ShadowCoord' at Assets/StixGames/DirectX 11 Grass Shader/GrassFrag.cginc(36) (on d3d11)
    Compiling Vertex program with DIRECTIONAL SHADOWS_SHADOWMASK GRASS_CALC_GLOBAL_WIND TWO_GRASS_TYPES
    Platform defines: UNITY_ENABLE_REFLECTION_BUFFERS UNITY_NO_CUBEMAP_ARRAY UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING UNITY_ENABLE_DETAIL_NORMALMAP SHADER_API_DESKTOP UNITY_HARDWARE_TIER3 UNITY_LIGHT_PROBE_PROXY_VOLUME

    This seem to be related to Deferred shading...
     
    Last edited: Aug 14, 2017
  13. Black_Raptor

    Black_Raptor

    Joined:
    Nov 3, 2014
    Posts:
    181
    Yes, but when i paint, a small windows appears en select my mesh but when i paint i see nothing ...
     
  14. elettrozero

    elettrozero

    Joined:
    Jun 19, 2016
    Posts:
    216
    Make sure the windows says 'Current object: [object with grass material on it]'
    The object has proper collider and proper material
    You should see red circle appear.
    Eventually check the brush size on the window (which is Grass Painter)
     
    Nonakesh likes this.
  15. Aminator

    Aminator

    Joined:
    May 8, 2015
    Posts:
    4
    I was trying displacement through the displacment trail renderer and displacement camera on a spherical planet today with the grass following the surface normals. When my character is walking around the planet (and is also surface aligned) the trail renderer doesn't work on the underside. So I tried having the displacement camera follow my character a specific height away from it using its transform.up. As that didn't help much, I also set the rotation of the displacment camera to the one of my character and added a 90 degree rotation to the x angle but it still didn't work right even after trying a number of different rotations.

    Does anyone have a solution to this problem or am I simply misunderstanding the concept?
     
  16. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    I don't really understand your setup from your description, but have you looked at the example scene? It has a working setup of the trail renderer and the displacement camera. You could simply copy it into your scene.
    You could also post some screenshots of your setup so I can see if there's anything obviously wrong with it.
     
  17. elettrozero

    elettrozero

    Joined:
    Jun 19, 2016
    Posts:
    216
    Nonakesh, do you aknowledge the issue of grass with deferred rendering?
     
  18. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    Yes, I'll look into it. Are there any other infos you can give me about it? Like which Unity version are you using, which shader settings cause the error, etc.
     
  19. Aminator

    Aminator

    Joined:
    May 8, 2015
    Posts:
    4
    Yeah, I have used the setup from the example scene and on a relatively flat surface it works. My problem is that I also want the trail render to take effect on a planet-like mesh where objects may also be on the underside of it like here:
     
  20. elettrozero

    elettrozero

    Joined:
    Jun 19, 2016
    Posts:
    216
    Sure, ask me anything :)
    Unity 2017.1.0f3 (not beta).
    Cameras are controlled by Cinemachine (but I don't think that's matter).
    The problems occurs when Render Path is Forward too (out of the sudden).
     
  21. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    1,490
    Does this relates to how the collider is setup perhaps, just a thought to share. Have you tried the same with a standard sphere, does that work?
     
  22. Aminator

    Aminator

    Joined:
    May 8, 2015
    Posts:
    4
    Yes, I have tried it, but that doesn't make a difference. But I could try the circular displacement, the one without the displacement camera and see it works with that.
     
  23. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    I'm afraid this is a much larger problem. The displacement renderer is hardcoded to work with flat surfaces. I think the system could be adapted for a round planet, but it will always be problematic, as the displacement would always only work on one side of the planet, where the displacement camera is currently looking at.

    You could try the old system, which changes the displacement texture via raycasting and scripting. It's a lot slower and harder to work with, in my opinion, but it should be possible to remove this restriction.
     
  24. Aminator

    Aminator

    Joined:
    May 8, 2015
    Posts:
    4
    I am trying out the old system but matching the ray with the direction of the player always gives me an out of bounds exception for the texture rectangle. And yeah, the games becomes really slow, especially with a bigger displacement radius. I might have to come up with different idea but for now at least visually it works perfectly.
     
  25. SharpeDesigns

    SharpeDesigns

    Joined:
    Mar 4, 2015
    Posts:
    4
    Any news on potential OpenGL Core support? Sounds promising from some of the posts here! :)
     
  26. BlackThunder4

    BlackThunder4

    Joined:
    Apr 29, 2017
    Posts:
    1
    Hi,
    Your shader looks really beautiful and works great (the money was worth it ;)).
    I finally got the displacement working, but I've got three questions:
    1. Do you really need the cone (DisplacementMesh), because for me it just works when I place the DisplacementTrailRenderer on my Player?
    2. Shouldn't the DisplacementCamera follow the player instead of the MainCamera? My camera can be very distant from the player.
    3. In the GameView, the player leaves behind a trail (pink, blue and white), thats probably the DisplacementTrail. How can I disable it, so that it doesn't show anmore (but the Displacement still works)?
    Thanks in advance,
    Sebastian
     
  27. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    I didn't get to look into it yet, but I will definitely post about any results here!

    1. The cone pushes the grass in front of the character away, but sure, if you don't need it go ahead and delete it!
    2. Whatever works best for your scene honestly, but if the displacementCamera follows the character, your main camera could fly outside of its reach, so no displacement would be visible any more, until you go back to your main character, of course.
    3. All displacement objects have to be on a special layer, the displacement is working in your scene, so I guess you are already doing this. You can disable this trail on your main camera in the inspector and in the editor with the dropdown menu at the top right of the editor.
     
  28. elettrozero

    elettrozero

    Joined:
    Jun 19, 2016
    Posts:
    216
    Shader error in 'Stix Games/Grass': invalid subscript '_ShadowCoord' at Assets/StixGames/DirectX 11 Grass Shader/GrassFrag.cginc(36) (on d3d11)
    Compiling Vertex program with DIRECTIONAL SHADOWS_SHADOWMASK FOUR_GRASS_TYPES GRASS_CALC_GLOBAL_WIND GRASS_IGNORE_GI_SPECULAR GRASS_UNSHADED_LIGHTING GRASS_USE_TEXTURE_ATLAS GRASS_RENDERTEXTURE_DISPLACEMENT
    Platform defines: UNITY_ENABLE_REFLECTION_BUFFERS UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING UNITY_ENABLE_DETAIL_NORMALMAP SHADER_API_DESKTOP UNITY_LIGHT_PROBE_PROXY_VOLUME

    Hope this helps to understand where the problem is.
     
  29. elettrozero

    elettrozero

    Joined:
    Jun 19, 2016
    Posts:
    216
    Am I the only one who has this problem?
     
  30. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    1,490
    What where you trying to do when the error shows?
     
  31. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    Sorry, I didn't get to look into your problem yet, mainly because I wanted to do the OpenGL Core fixes first, because they may add/remove a variety of other problems.

    Speaking of which:
    Is anybody here interested in beta-testing the OpenGL Core version of the shader?
    If yes, please send me your invoice number per PM and I will send you the new version. I will not upload it to the asset store yet, I'm afraid it could have broken a few things...
    @SharpeDesigns you seemed interested, want to try it?
     
  32. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    1,490
    Hi, does this mean it could be used on platforms like android?
     
  33. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    I'm not sure because of the performance cost, but in theory it should be possible!
     
  34. malkere

    malkere

    Joined:
    Dec 6, 2013
    Posts:
    1,212
    Has anyone used this with MapMagic? Or any sort of runtime generation? My game is fully procedural and the grass is ugly!
     
  35. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    I've never used map magic, but the shader can take a texture as density input, so it should work with any procedural system.
     
  36. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    Also I am still looking for beta testers for the OpenGL Core version! In theory this should work with any platform. If you are interested, send me your invoice number and I'll send you this version!
     
  37. malkere

    malkere

    Joined:
    Dec 6, 2013
    Posts:
    1,212
    Hmm, looking through the documentation.. The normal flow would be to plug this into the material for a terrain? That would make it impossible to use any of the assets designed specifically for terrain texturing like RTP or MegaSplat. Is there another workflow option?
     
  38. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    Oh no, I actually think Unity terrain is horrible and you shouldn't use it at all!
    The shader can be used on any mesh, it's just a material. There are a few restrictions of course, for example the mesh should have very uniform polygon density, as the grass density is dependent on polygon density.
     
  39. malkere

    malkere

    Joined:
    Dec 6, 2013
    Posts:
    1,212
    Interesting... this is an advanced form of tessellation?
    My game is all about distance (max 48km view), so the LOD'ing and wide array of tools built for runtime terrain generation make their continued use a big plus. Would be great if Unity spent a few weeks making them a lot faster though =[

    I could certainly create a mesh copy of the terrain, slice it, and use the splatmap data to generate density maps for the shader. The two main goals of course being visual quality and increased performance. What do you think about trying something like that? Would the grass layer worry about the z-buffer or would it be fine at the same coordinates? I think a single pass over a 128x128 mesh would still be much less CPU intensive than a thick patch of native unity grass, no?
     
  40. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    Yes, the shader is based on tessellation and geometry shaders!
    I think generating slices of the terrain could work very well, performance wise. Also I'm not sure how my shader compares to unity grass performance wise, but it definitely looks far better, in my opinion.
    The z-buffer shouldn't be relevant to the grass.
     
    malkere likes this.
  41. Genebris

    Genebris

    Joined:
    Mar 18, 2013
    Posts:
    144
    Is everyone able to use Cloud Build with this shader? It was working fine for many months but a week or two ago all builds started to fail. I didn't even change anything related to this shader when this started. I have only these two errors in my last build log:
    706: [Unity] Shader error in 'Stix Games/Grass': invalid subscript '_ShadowCoord' at Assets/Code assets/StixGames - DirectX 11 Grass Shader/GrassFrag.cginc(30) (on d3d11)
    707: [Unity] Shader error in 'Stix Games/Grass': invalid subscript '_ShadowCoord' at Assets/Code assets/StixGames - DirectX 11 Grass Shader/GrassFrag.cginc(124) (on d3d11)

    I have tried reimporting and updating the shader and changing cloud build settings. It also seems to not happen when I select only a few scenes in build settings. And of course, editor builds flawlesly, it's just Cloud Build.
    Unity 2017.1.0f3.
     
  42. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    Cloud build never really seemed to work, but maybe it will be better once the OpenGL Core support is working.. I'll look into the problem (probably next week) and keep you updated on it!
     
  43. WildStyle69

    WildStyle69

    Joined:
    Jul 20, 2016
    Posts:
    318
    @Nonakesh -- great asset man, looks so nice!

    I'm working in VR -- for performance reasons I've duplicated the terrain, then turned it into a mesh, which I then sliced.

    Benefit of this is that I can use distance based occlusion on the mesh pieces that have grass. This works great so far, however I just wondering the best way to paint grass in this scenario? All the grass terrain pieces are sharing the same material.

    Also by batching the material across mesh instances, that will help performance too still right?
     
  44. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    I think this is a great way of improving performance, actually. The easiest way of painting the grass, is probably to use the same material on a terrain, painting the density map there and later using the density map on the slices.

    I'm not sure about performance and batching, maybe you can test it and write the results here?
     
    WildStyle69 likes this.
  45. WildStyle69

    WildStyle69

    Joined:
    Jul 20, 2016
    Posts:
    318
    Awesome, thanks man! Good to know the painting should still work that way. I'll get back to you with my findings once done. :)
     
    Nonakesh likes this.
  46. Been_Maya

    Been_Maya

    Joined:
    Aug 12, 2017
    Posts:
    20
  47. Been_Maya

    Been_Maya

    Joined:
    Aug 12, 2017
    Posts:
    20
    Your WebPlayer demo doesn't work correctly for me because F3, F4 and F5 trigger some actions in Internet Explorer, so the scene aren't loaded.
    Also in Internet Explorer, WASDQE don't do anything.
     
  48. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,633
    This is not working for me in Unity5, I just see flat planes, anyone know how to fix it ?
     
  49. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    It does have a basic form of SSS and cutout transparency, but I think actual translucency would be impossible, considering how many individual blades of grass would have to be depth sorted for it to work.

    The webplayer is horribly outdated, to be honest.. The demo was made in version 1.0 or something like that.

    When you select the Grass.shader file, is there an error in the inspector? What exact version do you use? And what operating system are you on?
     
  50. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,756
    I can't find anything about this: does it allow several type of grass? All demos seem to display only one type. I want different grass on a hill, on flat areas, on mountain, near water, etc... does it do it? got any video or demo mixing them and changing density of each type?