Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Assets [RELEASED - FREE] Surreal PBR Grass Shader

Discussion in 'Works In Progress - Archive' started by TchPowDog85, May 11, 2018.

  1. TchPowDog85

    TchPowDog85

    Joined:
    Dec 29, 2015
    Posts:
    124
    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:
    129
    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. TchPowDog85

    TchPowDog85

    Joined:
    Dec 29, 2015
    Posts:
    124
    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. TchPowDog85

    TchPowDog85

    Joined:
    Dec 29, 2015
    Posts:
    124
    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. TchPowDog85

    TchPowDog85

    Joined:
    Dec 29, 2015
    Posts:
    124
    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. TchPowDog85

    TchPowDog85

    Joined:
    Dec 29, 2015
    Posts:
    124
    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:
    935
    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:
    179
    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. TchPowDog85

    TchPowDog85

    Joined:
    Dec 29, 2015
    Posts:
    124
    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. TchPowDog85

    TchPowDog85

    Joined:
    Dec 29, 2015
    Posts:
    124
    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:
    935
    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. TchPowDog85

    TchPowDog85

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

    TchPowDog85

    Joined:
    Dec 29, 2015
    Posts:
    124
    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:
    935
    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. TchPowDog85

    TchPowDog85

    Joined:
    Dec 29, 2015
    Posts:
    124
    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:
    179
    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. TchPowDog85

    TchPowDog85

    Joined:
    Dec 29, 2015
    Posts:
    124
    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.
     
  24. Ancient-Gen

    Ancient-Gen

    Joined:
    Oct 22, 2018
    Posts:
    4
    Is this useable in urp 2019.4.1f1?
    Tried it on all kinds of objects varying from terrain to plane to cube to sphere etc.
    On large terrains it just freezes unity, on smaller objects its done 'calculating' in mere seconds and creates an empty clone.

    Was really hyped to see something generous like this to work nowadays as well!

    edit: got it to work (partially)

    came back with:
    'EditorGUILayout.ObjectField(GUIContent, Object, Type, params GUILayoutOption[])' is obsolete: 'Check the docs for the usage of the new parameter 'allowSceneObjects'.' Assembly-CSharp C:\Users\***\Desktop\GrassTest\Assets\SurrealGrassShader\SurrealGrassCreator.cs 37 Active

    Result:https://www.imageupload.net/image/W2wAd
    Generated points stay on the sgrendered terrain and grass is not generated.
    It only shows the points where it shouldve spawned.


    Any ideas if this could be achievable?
     
    Last edited: Oct 28, 2020
  25. GuitarBro

    GuitarBro

    Joined:
    Oct 9, 2014
    Posts:
    179
    Unless someone else made a URP version, this will only work with the built-in pipeline. Shaders are not automatically upgradeable from built-in to the SRPs.
     
  26. Ancient-Gen

    Ancient-Gen

    Joined:
    Oct 22, 2018
    Posts:
    4
    Well I got the math working for the biggest part see > https://www.imageupload.net/image/W2wAd
    I am now just struggling with having the actual material visible/ geometry rendered.
    Do you reckon it could be done (i am not a scripter at all) ?
     
  27. GuitarBro

    GuitarBro

    Joined:
    Oct 9, 2014
    Posts:
    179
    That is the shader I'm referring to. It's likely possible, though I'm not too familiar with the details of URP/HDRP shaders as the APIs have been changing a lot and it's just not worth it for me to try and keep up right now. I would hope they support geometry shaders, but Idk for sure.
     
  28. Ancient-Gen

    Ancient-Gen

    Joined:
    Oct 22, 2018
    Posts:
    4
    I did have an URP extrude geometry shader on hand. But its definitively beyond my knowledge.
    This is as far as i could get it through said 'extrusions'. not even sure how the initial shader was approached saddly.
    https://www.imageupload.net/image/W2lgx

    IF somebody has got this to work in URP builds or can point me in a direction, much appreciated.
     
  29. GuitarBro

    GuitarBro

    Joined:
    Oct 9, 2014
    Posts:
    179
    Ah that's a good start. Looks like some of the vertex data is incorrect, but that definitely should be possible to get working.
     
  30. Ancient-Gen

    Ancient-Gen

    Joined:
    Oct 22, 2018
    Posts:
    4
    You were right about the vertex data. I needed to read into this tool a bit more.
    I looked over the 'raycasting' part. Apparently all i needed was to add an array to an existing shader.
    Its still very heavy on the FPS even though it shouldn't be so ill have to invest some extra time in it.

    But here is what a few hours of insanity got me into so far! :D
    https://www.imageupload.net/image/W2KtS
     
    Mark_01 and hopeful like this.
  31. GuitarBro

    GuitarBro

    Joined:
    Oct 9, 2014
    Posts:
    179
    Yeah that's getting there!