Search Unity

  1. New Unity Live Help updates. Check them out here!

    Dismiss Notice

Assets [RELEASED - FREE] Surreal PBR Grass Shader

Discussion in 'Works In Progress' started by LSUTiger85, May 11, 2018.

  1. LSUTiger85

    LSUTiger85

    Joined:
    Dec 29, 2015
    Posts:
    115
    Yes. Look at the GIT repository, a user committed an enhancement allowing Forward rendering. I haven't tried it, personally, but feel free to give it a swing.
     
    Lars-Steenhoff likes this.
  2. tntfoz

    tntfoz

    Joined:
    Sep 29, 2016
    Posts:
    95
    This looks great - thanks for sharing! Will you be adding distance LOD to the shader in the future - that will be especially important to manage performance on lesser hardware. I'm hoping to use the forward rendering shader for VR purposes, but with the framerates needing to be high, managing the distance/LOD of the shader will be key. Thanks!
     
  3. LSUTiger85

    LSUTiger85

    Joined:
    Dec 29, 2015
    Posts:
    115
    I will be using this shader in a game, however, I won't need LOD because I will probably have small patches of the grass instead of a large area. I will definitely need Forward rendering compatibility though, so I will officially add that. I do not know when I am going to do this. I am currently working on the gameplay for my game, so I might be some while before I get to the art, etc. I made this for you guys to be open source, so feel free to play around with it. I think changing the density at certain distances would actually perform better than LOD (maybe), or maybe both would be beneficial idk. With LOD, the GPU would still have to process each vertex input, which I think weighs more than the actual poligons themselves (I could be wrong on this). With varying densities, you wouldn't have this issue.
     
    tntfoz likes this.
  4. Marinarius

    Marinarius

    Joined:
    Feb 17, 2018
    Posts:
    2
    Hey @LSUTiger85 I've been messing around with your shader and I'm trying to make it into a placeable prefab but the rendered mesh doesn't save when I put the prefab in the scene. I can only generate and keep it within the scene.
    This is by far the best performing grass solution so I'd love to be able to use it for my purposes but I don't really know how to properly modify your script so it saves the mesh.
     
  5. LSUTiger85

    LSUTiger85

    Joined:
    Dec 29, 2015
    Posts:
    115
    You should be able to generate the mesh (which essentially creates a GameObject) and save the GameObject as a prefab. You've tried this and it doesn't work?
     
  6. LSUTiger85

    LSUTiger85

    Joined:
    Dec 29, 2015
    Posts:
    115
    the mesh is just a vertex cloud. You can create a vertex cloud in Blender and shape it however you like and import it and slap my shader on it and it should work. All the "Surreal Shader Tool" does is create a mesh for you, but you can create your own mesh. If you DO create your own mesh, make sure you do the following:

    1. make sure the vertex normals are facing the direction you want the grass to sprout.
    2. randomize the X and Y positions of the vertices so you don't get a uniform grid result.

    All the shader does is take the vertex cloud and renders a blade of grass at each vertex. The source of the vertex cloud can come from anywhere.
     
  7. LSUTiger85

    LSUTiger85

    Joined:
    Dec 29, 2015
    Posts:
    115
    Try this -

    (this is off the top of my head, I may be saying some of this inaccurately)
    - Go into blender and create a new plane (to the size you want)
    - Add a subdivision modifier and crank it up to an acceptable density for your grass.
    - Add a displace modifier and, using a noise texture, displace the vertices in the X direction - Apply Modifier
    - Do the same thing for the Y direction
    - Select all faces - delete all faces (FACES ONLY)
    - Select all edges - delete all edges (EDGES ONLY)

    Import this object into Unity and slap my shader on it.
     
  8. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    548
    Hey,
    really great system.

    1.
    Here a sources with advanced "LOD" techniques .
    See Crest Ocean renderer.
    It s an advanced lod technique for differnet tasks.

    see
    LOD data types
    https://github.com/huwb/crest-oceanrender/blob/master/USERGUIDE.md

    2.
    Here is another source with a nice breakdown for a offline rendered meadow scene
    https://cgtricks.com/making-meadow-darstellungsart/
    Do you think by converting splatmaps to black and white we could get close with your system?

    I will try.)

    Do you know an easy way to not only take black and white for point generation.?
    Instead some more "grey values" for density variation.




     
  9. GuitarBro

    GuitarBro

    Joined:
    Oct 9, 2014
    Posts:
    80
    Iirc there a line in the grass generator script that does something to the effect of "if(density > some value)". Replacing the value with a random range from 0 to 1 should allow it to be a softer falloff in density.
     
  10. LSUTiger85

    LSUTiger85

    Joined:
    Dec 29, 2015
    Posts:
    115
    I haven't verified this, but it is sounds correct. Your density map would have to have a "blend" between the black and white for this to work.
     
  11. LSUTiger85

    LSUTiger85

    Joined:
    Dec 29, 2015
    Posts:
    115
    By the way. Call of Duty: Blackout uses this same technique for their grass, however, they do not use a PBR texture. They just use a color gradient for each blade of grass and the source color is the color of the ground texture at that point. It would be cool to see one of you guys try to recreate that look.
     
  12. jaelove

    jaelove

    Joined:
    Jul 5, 2012
    Posts:
    302
    Does it only work with a perspective camera? When I change to ortho I don't see anything
     
  13. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    548
    Hi. I tryed the forward version from github but can t get directional light and reflection probe get to work with it.
    Do i do something wrong?
     
    Last edited: May 26, 2019
  14. LSUTiger85

    LSUTiger85

    Joined:
    Dec 29, 2015
    Posts:
    115
    I've actually never tried this.
     
  15. LSUTiger85

    LSUTiger85

    Joined:
    Dec 29, 2015
    Posts:
    115
    I didn't commit the Forward rendering changes and I haven't even tried it. You would have to change the shader code to get that to work.
     
  16. jaelove

    jaelove

    Joined:
    Jul 5, 2012
    Posts:
    302
    Yeah it doesnt seem to work with ortho camera settings
     
  17. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    548
    Thanks for the tip with the density map.
    I checked out both repositorys.
    Yours is working great on deferred.

    I made a heavy resesrch on gras last weeks an yours gave the best performance and visual results.

    The point cloud generation is great an even works on a sphere by generating a second half an rotating it 180 deg.

    However. The rest of the scene is heavily using 8xMSAA and TAA(CTAA) so i try to get it work with Forward Rendering in BuiltIn Pipeline.
     
    Last edited: May 26, 2019
  18. htrumo

    htrumo

    Joined:
    Mar 6, 2018
    Posts:
    5
    Hey there! Thank you so much for making this free. I've been looking for something like this for SO long.

    Would you know of a way to adjust the code so that the grass always faces the camera?
     
  19. LSUTiger85

    LSUTiger85

    Joined:
    Dec 29, 2015
    Posts:
    115
    I'm not sure how to do this, it would involve getting the screen normal which you can do from a shader. It would think it would be a little tricky. Do a search on youtube.
     
  20. GuitarBro

    GuitarBro

    Joined:
    Oct 9, 2014
    Posts:
    80
    I actually did something similar to this. Essentially you'd need to get the (negative) view normal (like LSUTiger mentioned) which could be obtained by subtracting the vertex position from the camera position in the vertex shader. The hard part is the actual alignment in the geometry shader since what the shader currently expects is the blade "up" vector in the normal property, not the blade forwards vector Iirc.
     
  21. htrumo

    htrumo

    Joined:
    Mar 6, 2018
    Posts:
    5
    I noticed that sometimes the grass would only cover half of a mesh I was using, however could fix this problem by centering the pivot point.

    I've recently come across a problem where I can't seem to get the grass to render at all. When I click Generate Grass Objects, it just creates an object in the hierarchy ending in _SGRenderer with no child objects. I understand that it's having difficulty rendering the grass somewhere, I'm just unsure of the reason as to why this is happening, because altering the pivot point is no longer fixing the problem. Any ideas?
     
  22. htrumo

    htrumo

    Joined:
    Mar 6, 2018
    Posts:
    5
    Realised the issue was due to my Target GameObject being too high on the Y-axis within the scene.
    When I moved the object closer to 0 on the Y-axis, the grass rendered perfectly!
     
  23. LSUTiger85

    LSUTiger85

    Joined:
    Dec 29, 2015
    Posts:
    115
    Yeah. The grass mesh creator works like rain fall and it starts high up on the Y axis (I can't remember the actual height), but if you need to, you can change this height in the code.
     
unityunity