Search Unity

[RELEASED] DirectX 11 Grass Shader

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

  1. m1735

    m1735

    Joined:
    Nov 28, 2013
    Posts:
    11
    This looks amazing on a PC, especially the self-shadowed grass.

    There are a few yellow "!" errors being thrown out on U5.6.0f3 upon the install of the asset:

    > 6x "due to inconsistent line endings"
    > 4x "Program uses geometry shaders, automatically setting target to 4.0"
    > 1x "warning CS0618: `UnityEditor.Handles.CircleCap(int, UnityEngine.Vector3, UnityEngine.Quaternion, float)' is obsolete: `Use CircleHandleCap instead'"

    After deleting the error-console and building to XboxOne, the warning CS0618 re-appears.

    Build (and Run) in PC looks great.

    Exporting via Visual Studio brings up no errors.

    Xbox One is purple-pink on the floor-meshes.
     
  2. Medto

    Medto

    Joined:
    Oct 28, 2015
    Posts:
    8
    Hello There I purchased the asset recently , and I tried also to make the displacer work without any success, is there a way to have that exemple scene. It's for my Vr project I wish when I dropped an object on the floor the grass will react to it. Thanks !!
     
  3. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    I've been having the same problem, to be honest. It's a bit hard to see why OpenGL Core is not working, but I've got some leads so I might be able to fix it in the future. If you're good with shaders and you have more time than I do, you could look at it yourself. I've found out that using Cloud Building results in a lot of very detailed error messages, this might be contain the error that prevent compilation for OpenGL Core. Otherwise I will get to it myself, once I have the time.

    It's in the Graphics settings, but for some reason, the Camera Depth Normal replacement is hidden now, so you have to right click the inspector tab and switch to debug before changing, I honestly don't understand why they did this.

    Is there a special Xbox One Log file you could look at? Without an error message it's a bit hard to even begin trying to fix this!

    I've been planning to create a new example scene, once I get the time, but until then you should look at the documentation that's included with the shader. There are a few short written tutorials in there. Having something react realistically isn't possible right now anyways. It's not technically impossible, but I believe that the performance cost would be too high to be worth it. You could instead use the displacement objects in the example scene to make it look like the grass is reacting. It's an approximation, but with a bit of work, it should be possible to make it look good.
     
  4. Medto

    Medto

    Joined:
    Oct 28, 2015
    Posts:
    8

    OK Thanks, I'm not looking for a crazy accuracy but enough to avoid interpenetration between grass and object, I'm going to look with the displacement object perhaps I chose the wrong way, thanks btw
     
  5. Martin-Baun

    Martin-Baun

    Joined:
    Apr 12, 2015
    Posts:
    7
    Hi
    Im' looking for a grass shader (I think that is what it is called) so I can place a little bit of "wasteland grass" (dry, yellow grass) here and there over a semi large Unity terrain (2000*2000 meters). So I'm not looking for a grass shader which makes a large grass field like a dui meadow or soccer field.
    Can this grass shader make that for me? :)
     
  6. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    1,487
    Hi, do you mean something like this, I'm using this grass shader for my dessert scene:
    camelsinstorm.jpg
     
  7. Martin-Baun

    Martin-Baun

    Joined:
    Apr 12, 2015
    Posts:
    7
    Yes! - But did you hand paint that or is it generated?

    I'm looking for a grass shader (script) so I don't have to hand paint the grass in a random pattern over a large area because it's very time consuming and it is not importend where the grass is exactly placed.
     
  8. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    The shader doesn't have random placement build in, but you could easily achieve this by creating a noise / clouds texture in Photoshop and putting it in the density texture slot of the shader. You could even use the grass painter to edit that random texture and refine the details.
     
  9. Martin-Baun

    Martin-Baun

    Joined:
    Apr 12, 2015
    Posts:
    7
    Hi again
    Could you point to a tutorial? I can't quite wrap my head around your solution.
     
  10. Unity4Life

    Unity4Life

    Joined:
    Apr 25, 2017
    Posts:
    5
    Hello !

    I'm getting really low FPS whenever I switch my duplicate terrain to use Custom material. Even if no material is set up, I'm dropping near 1-2 FPS. I've reduced the size of my terrain to 1024x1024, no grass, no trees in the terrain, only a handful of gameobjects.

    Here's a picture http://imgur.com/a/pGYd4

    I have GTX 1060 so I don't understand the sudden drop. Without the second terrain to "Custom" Material, I can be as high as 200+ FPS.

    Any Ideas ? Any workaround to use it differently on a terrain created by Gaia ? (I'm doing a RPG)

    Thanks a lot ! Great asset by the way :)
     
  11. jangomoose

    jangomoose

    Joined:
    Feb 17, 2016
    Posts:
    40


    I have the same issue, will be interested to see what the problem is. Useing a Gaia terrain also.
     
  12. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    I'm sure there are better ways for this, but something like this: https://gamedev.stackexchange.com/questions/35724/how-can-i-easily-create-cloud-texture-maps

    Change your grass material to a grass type that uses a density texture (e.g. Simple with Density, or any of the textured modes) and put the texture you generated into the density texture slot.
    If you change the texture to Read/Write enabled in the importer, you could even use the grass painter to modify it from there.

    I believe there is a bug with Unity terrain, or maybe something we're all missing, but apparently when you're duplicating the terrain in the scene, this can lead to extreme performance drops. Duplicating the terrain asset, in the assets folder and putting that at the same position as the original terrain doesn't cause this. It's a bit annoying, as you'll have to manually sync the two terrains, but you could even write a script for that.

    I've never used Gaia myself though, so there might be another reason for this problem. If it doesn't fix the problem, can you look at the profiler where the performance loss is happening?
     
    jangomoose likes this.
  13. Abnormalia_

    Abnormalia_

    Joined:
    Jul 23, 2013
    Posts:
    128
    Few more screens from "VRZ : Torment", looks and feels really smooth in our VR game:


     
    turboscalpeur and Nonakesh like this.
  14. Da-Luk

    Da-Luk

    Joined:
    Apr 25, 2017
    Posts:
    53
    Hey ;),
    i'm too getting really low fps drops from one to another moment which i dont understand. Everything works fine with 60 fps and suddenly drops to 2-6 fps for about 5 seconds. (on AMD Radeon R9 Fury X)

    Above all i try to get the shader working on animated objects without success.
    I tried the following lines of code from the GrassVertex.shader but it's still pink.

    ...

    v.vertex = mul(unity_ObjectToWorld, v.vertex);
    v.uv = TRANSFORM_TEX(v.uv, _Density);

    #ifdef GRASS_OBJECT_MODE
    v.objectSpacePos = v.uv; // <- Line 14
    #endif

    ...
    Unity Error Report:
    Shader error in 'Stix Games/Grass': cannot implicitly convert from 'float2' to 'float3' at Assets/StixGames/DirectX 11 Grass Shader/GrassVertex.cginc(14) (on d3d11)

    Can you please help me getting the right solution?
    Thanks
     
  15. Unity4Life

    Unity4Life

    Joined:
    Apr 25, 2017
    Posts:
    5
    Thank you so much !! Duplicating it in the asset folder instead of the inspector fixed it and now I have much better FPS. Still tweaking some details here and there but here are some screen shots :

    Before StixGames implementation (made with Gaia details spawner, I suck at it and it's my first game) lol.png

    After StixGames implementation :
    yay.png

    Can I say I love you ?
     
    Nonakesh likes this.
  16. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    Have you duplicated the terrain in the assets folder instead of in the scene? That's the only reason for extreme frame drops I know.
    What do you mean with animated objects? A moving platform with grass? Is that line modified or in the original shader, because that looks a bit weird... using the "Object space mode" setting on the grass material should make it possible to use the shader on moving platforms, without any changes!
     
  17. Da-Luk

    Da-Luk

    Joined:
    Apr 25, 2017
    Posts:
    53
    Yes i modified that line a little but without success.
    I tested the "Object space mode" and it works on moving objects but i want a blender imported animated model covered with grass like a fur.
    Everything is fine "Object space mode activated" but if the Animation starts, the grass position fluctuates wildly. It's like a fast wind changing direction. Looks very weird but in my case wind is deactivated. So i think the shader isn't expecting vertices to move and can't handle it.

    You know what i mean?

    If you get that running well, i think you can use it as a nice fur shader for animated characters like animals or pets.
    You could appeal to an absolutely new target group.
     
  18. nbac

    nbac

    Joined:
    Jul 7, 2015
    Posts:
    267
    if i do use the unity post processing stack with bloom enabled and my direct light intensity is 0 i get a really bright artifact
    unity 5.6.0f3
     
  19. Unity4Life

    Unity4Life

    Joined:
    Apr 25, 2017
    Posts:
    5
    Hello !

    I'm having trouble with the Grass Painter tool. I have my Unity terrain selected and opened the painter and it shows my terrain as being selected, however how do we paint and add/remove stuff ? The brush does not appear in the Scene View. Is there something I am missing here ?

    Thanks,
     
  20. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    Sorry, but I won't support using the shader as fur, there is quite a bit of code that would prevent the grass shader from working like that. Honestly, I would have to remake large parts of the shader and even then I'm not sure it would be possible to work for animated models at all.

    I'll look into it. Until then you could try to disable the light once it reaches 0 intensity. (That's less performance costly anyways)

    Are you selecting a terrain with a grass material? As long as it has a regular material you can't paint grass. You will also have to create a density texture, but you can do that from inside the grass painter interface.
     
  21. Unity4Life

    Unity4Life

    Joined:
    Apr 25, 2017
    Posts:
    5
    Yes I am using a terrain with a grass material (the default one for now which is named GrassMaterial). I have clicked "Create a texture" with the default 512 size and once that's done, all the grass disappears from the terrain and I can see under the GrassMaterial that it changed the "Grass Density 1" to a black image.

    I'm still not sure what to do next or how everything works. I still don't have the brush appearing and I'm using the default GrassMaterial with default texture. Would you care explain how the tool works ? I've went through the documentation already.

    Thanks !
     
  22. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    First you need a terrain with a grass material, the material should use a grass type with density (basically everything except Simple Grass, Simple Grass with Density is fine, of course).
    Then you open the grass painter and select the terrain with the grass material, not the one with the floor.
    Your material already has a Density texture, so this should be fine too.
    The only thing missing is, well, moving the mouse over the terrain in the scene view and painting. If that doesn't work, can you send me your project via private message?
     
  23. Unity4Life

    Unity4Life

    Joined:
    Apr 25, 2017
    Posts:
    5
    Fixed it ! In fact, it was only due to the fact that I removed the collider from my terrain with the grass material (I had removed it because my original terrain already had a collider). For some reasons, once I added it back, I could now paint on everything :)

    I noticed that once I was using the "remove" button on the paint tool, it also removed whatever texture the terrain had on this particular part.so let's say I removed grass from my mountains, than the texture of that mountain would now be white. Although there might be a more elegant way to make it work, I fixed this by slightly lowering my grass terrain to -0.01 so now I get the best of both worlds :)

    Thanks again for this awesome asset.
    Cheers
     
  24. Gnimmel

    Gnimmel

    Joined:
    Apr 21, 2010
    Posts:
    358
    I was wondering what the best practice is for painting grass density in a world that is made up of multiple instances of the same object?

    I have a level where the ground is made up of multiple tiles which is all the same object. This means when I paint grass all the objects get the same density map. I thought vertex painting might work better, but I had the same result as it seems the vertex color is stored once for all the same objects.

    I was going to make a few extra ground objects with different grass density's to get around this, but I thought I'd ask in here first in case I was missing something obvious?
     
  25. nbac

    nbac

    Joined:
    Jul 7, 2015
    Posts:
    267
    Last edited: May 3, 2017
  26. nbac

    nbac

    Joined:
    Jul 7, 2015
    Posts:
    267
     
    Nonakesh likes this.
  27. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    This depends on how you set up the project. If you are generating the tiles via script, you can set the vertex density during the generation, that's probably the easiest way of doing things, if you don't require more detail.
    Another possibility for procedural generation would be using a texture, but setting the texture coordinates for each tile, so they simulate being on a large plane (each tile is a small part on the texture), then you could either generate the texture, or use the grass painter for it.
    If you don't generate the tiles, you'll probably have to create a new material per tile and change the settings individually.

    Really nice scene, thanks for sharing. I'll look into the post processing bug. As I've said before, just deactivate the directional light when it reaches 0, but you've already done that as it seems.
     
  28. Deleted User

    Deleted User

    Guest

    I Got this problems. Bad mesh.
     
  29. nbac

    nbac

    Joined:
    Jul 7, 2015
    Posts:
    267
    disable object space mode in grass shader?!
     
  30. Deleted User

    Deleted User

    Guest

  31. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    This problem is actually described in the manual, it's because the grass shader uses tessellation to generate grass, it is dependent on the shape of its mesh. The mesh you use for the grass shader should always be a regular grid.

    You could solve this by creating a grid mesh and putting it where the grass is in the scene right now, it looks rectangular, so that shouldn't be a problem.
     
  32. kritoa

    kritoa

    Joined:
    Apr 21, 2017
    Posts:
    60
    I just purchased this asset yesterday and it works really well in my project. I had a question about the lighting - I wanted to get a little more directional lighting so I turned off the contribution of the global illumination so that it's only paying attention to point/directional lights, and I'm using only a single directional light coming in at a very low angle (like sunset/sunrise), and despite this, the grass seems pretty evenly lit in all directions except from a specular hit when looking at the sun and what looks like a color change/glow at 90 degrees perpendicular to the sun direction. Switching from Inverted PBR to PBR of course just flipped the specular highlight to the other side, but in both cases the grass looks very evenly lit in all directions.

    Do you know how I can get grass to look significantly darker on one side versus the other? I'd love to, for example, be able to modify the lighting response so that when I look towards the sun I get very dark diffuse but bright specular, etc..

    I am ok with modifying shaders myself (and even wrote my own grass shader a few weeks ago), but yours is a little more... advanced :) ... than I'm used to - I'm wondering if you can just point me to the right place where I can start poking around and dropping in a straight up dot(normalDir, lightDir) and work my way up from there.
     
    Nonakesh likes this.
  33. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    This is a bit of a difficult topic, the lighting in the shader has a lot of approximations and hacks to make the lighting actually look good on it. If you want to dive into it, you should look into the GrassFrag.cginc file, that's where most of the lighting is.
    I will look into this myself too, I think the shader would gain a lot from this.
     
    kritoa likes this.
  34. mattis89

    mattis89

    Joined:
    Jan 10, 2017
    Posts:
    1,151
    Hello! So lm using Gaia. Is this asset compatible with that?

    This shader look extremly good, easy to use?

    Thanks ! :)

    Mattis
     
  35. Kojote

    Kojote

    Joined:
    May 6, 2017
    Posts:
    200
    Hello!

    Unfortunately, I have a problem with the asset. In an empty project, where the asset is exclusively, I have a terrain of a size 1000 x 1000. As soon as I test the game, I still have a frame number of 2!

    Do you have an explanation for this?
     
  36. kritoa

    kritoa

    Joined:
    Apr 21, 2017
    Posts:
    60
    Aha I see: the major part of my not being able to get more directional lighting is in the definitionsandfunctions file where you do

    fixed3 grassSegmentRight = cross(dir, lightDir);
    lightingNormal = normalize(cross(grassSegmentRight, dir));

    So all the lighting normals point generally towards the light. When I replaced grassSegmentRight with the regular groundRight vector in the second calculation I was able to get it to look directional (though I lost the nice specular highlight when looking into the sun). When going that route, however, it looks like significant shader work is required to get it to look good. I feel like your current "hacky" approximations look really, really nice as is. I was able to get a pretty interesting look by fading between different pre-rendered grass textures with different lighting directions (I rendered 4 images of a blade of grass with front light, left light, back light, right light, and fade between them depending on grass normal and light dir), but it was a little too heavy for VR.
     
  37. mattis89

    mattis89

    Joined:
    Jan 10, 2017
    Posts:
    1,151
    ? Anyone now
     
  38. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    I have never used Gaia myself, but I believe they should work together without problems. I'd recommend you buy the shader and try it out, then post the results here. If it turns out that there is an incompatibility, you can post it here too, I'll try to fix the problem, if that isn't possible I can give you a refund. :)

    There is a problem with Unity terrain, where a huge performance loss is caused by duplicating it. You can solve this by duplicating the terrain asset (in the Project view) instead of duplicating the terrain in the scene.
    Personally I would recommend not using Unity terrain at all, it's pretty horrible anyways...

    Can you post screenshots of this? It sounds like a interesting approach.
    As I said, I've looked into this myself too. Instead of trying to improve the hacky approach, I tried to make the grass slightly more realistic. As you noticed, right now all the blades of grass are rotated towards the camera, while the normals are oriented towards the light.
    This time I tried to rotate the blades of grass randomly, like they would in real life. The disadvantage is, that this requires to render both front and back faces of the grass, so it will cost some performance. On the other hand this grass mode should also work in deferred rendering mode! It is still missing some subsurface scattering, right now it looks very dark towards the sun, but I will definitely continue working on this.

    upload_2017-5-14_15-27-35.png
     
  39. kritoa

    kritoa

    Joined:
    Apr 21, 2017
    Posts:
    60
    Sure, but don't judge me :D This was a tech test, so it looks like crap.

    This is grass blades oriented towards camera, normals also oriented towards camera, blending between 4 textures depending on orientation of light dir to normals:

    awayFromSun00.png

    intoSun00.png

    And then this is the same thing, but with the normals oriented towards camera and then offset randomly by up to 45 degrees to make the a little less perfectly regular:

    intoSun01.png

    I'm not sure how good this could be made to look (and I stopped trying because this approach is slightly too heavy for my needs), but right now the textures I'm using are black and white, and I'm coloring with the primary and secondary colors in your shader, so everything is very monochromatic. If I have some time to play around with it, it would be interesting rendering the textures in color (in which case I could get a more saturated subsurface/backlight color)
     
  40. Dolzen

    Dolzen

    Joined:
    Mar 26, 2014
    Posts:
    90
    Nonakesh can you give me some tips on how to change the shadow color in unshaded lighting? I would like to increase the shadow brightness since it's too dark (The shadow that is being cast on the grass)

    I will appreciate any help, thanks!
     
  41. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    I will try recreating similar results with shader code, having a large amount of texture accesses like this is probably too expensive. I'll post any results here.

    The color of the shadow isn't dependent on the shader, it's mostly based on the ambient light in the scene. You should try changing the skybox and the scene's lighting settings.
     
  42. Dolzen

    Dolzen

    Joined:
    Mar 26, 2014
    Posts:
    90
    Ok thanks!

    Do you know a way to remove ambient ligth from Unshaded Lighting mode?
     
  43. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    If you don't want to have ambient lighting in your scene, you should probably change this in the scenes Lighting settings. Just set ambient intensity to 0, the grass will use this as well.

    If you really want the grass to be the only thing ignoring the setting, go to the GrassLighting.cginc file, and replace line 7:
    Code (Shader):
    1. return half4(s.Albedo * (gi.light.color + gi.indirect.diffuse), 1);
    with this:
    Code (Shader):
    1. return half4(s.Albedo * (gi.light.color), 1);
     
  44. Tarball

    Tarball

    Joined:
    Oct 16, 2016
    Posts:
    166
    Looks great, but I'm lucky if I get 10 FPS with LOD start set to 20 m. I'm using Gaia (Unity) terrain though, as tons of other people do. How can I get this to work with Gaia?
     
  45. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    LOD Start and End improve performance, but not by much. You should try changing Density Falloff and Max Density instead, they are the main factors for performance.
    Also I have never used Gaia before, but if it is based on Unity terrain, you should try to duplicate the terrain asset (in the project view) instead of the terrain scene object, having duplicated terrain scene objects seems to cause huge performance losses in Unity for some reason.
     
  46. Nonakesh

    Nonakesh

    Joined:
    Aug 27, 2011
    Posts:
    576
    I just uploaded a new patch, quite a large one this time:

    1.7.0:
    • Adds a new grass mode, where the grass is not always oriented towards the camera, but in random directions. This can be used for realistic art styles or to reduce the billboard effect in VR.
    • Adds a new wind displacement shader, which can be used for wind zones or weather effects.
    • Makes the shader internal wind optional (you may have to re-enable the wind manually for your old materials)
    • Adds a new example material that shows how texture atlases and the new grass mode can be used for a realistic art style.
    • Expands the example scene.
    • Fixes a bug where the grass painter only updated the view while painting.
    The update should be available over the asset store in a week, but if you want it right now, send me your invoice number per PM or mail and I can give you the update directly.
     
    mattis89 and turboscalpeur like this.
  47. mindless2831

    mindless2831

    Joined:
    May 15, 2017
    Posts:
    17
    Multiple questions here, first of which I am sure is easy: Where do I find my invoice number so I can PM you and get the update?

    Secondly, Adam Goodrich posted on here about 7 months ago and asked if you guys could talk about making this compatible with Gaia ( he's the creator ) through GX ( Gaia Extension ), have you ever contacted him or have you any interest in ever doing this? I think a lot of us would benefit from that direct integration because it would allow grass propagation through Gaia's fitness model for Terrain and reduce the need for a custom Density Mask... It would be amazing if the is something you would consider!

    Third, and probably the most complex of the issues, is there anyway to make the grass calculations happen on another thread/coroutine? I am developing on outdoor game for the Vive on 4km x 4km terrain, and I can not get acceptable frame rates using this shader with anything other than Simple Grass. Even if I add with Density it shoots processing time up all the way to 38ms in some instances which is far above the 11ms threshold acceptable for VR... I love this shader so freaking much and would love to be able to use it, but my project simply will not run good enough currently with its implementation. I thought about getting ThreadNinja so that I could maybe break up the processing for grass calculations so that it won't bottleneck the CPU, but I wouldn't know how to use this with your shader. Where are the calculations performed? I have used the Profiler and have found that GPU calculations are happening in the 0.43ms to 1.5ms range which is absolutely ok ( I have a 1080 ), but 36ms on the CPU which completely kills performance ( I have a i5-6600k @ 4.5ghz ). Any suggestions if multithreading/coroutines won't work with your code? I am desperate as I have not found another grass asset that looks half a good in VR other than using prefabs made for Unreal ( which of course are ungoldly expensive ).

    Thank you for your time, I really really hope you can help, because as of right now I am at a loss.
     
    mattis89 likes this.
  48. Censureret

    Censureret

    Joined:
    Jan 3, 2017
    Posts:
    363
    Is it possible that you could add more support for terrains and terrains plugins such as Gaia?
     
    mindless2831 and mattis89 like this.
  49. mkgame

    mkgame

    Joined:
    Feb 24, 2014
    Posts:
    592
    I bought this asset and testing it under Unity 5.5.1f1. I loaded your test scene and tried to add/remove grass from terrain and meshes, but no effect with your grass painter tool. I read your doc, maybe i missed something.

    Just for clarification, we can have on a mesh or on a terrain just max. 4 different grass types based on the shader?

    Duplicating terrain, what if I have trees and details on map? I guess there would be better a meshcollider, which could be updated by reading the height map of the terrain. That would be clean I guess.
     
    mindless2831 likes this.
  50. mindless2831

    mindless2831

    Joined:
    May 15, 2017
    Posts:
    17
    I also am not able to get the grass painter to work. Everything is selected properly as in the tutorial but when I actually paint nothing at all happens. And yes, I created a new density mask texture with the tool as well which removed all the grass by adding a black texture to the shader density mask field, but it simply isn't modifiable with the painter tool.
     
    MarkusGod likes this.