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. Join us on Thursday, June 8, for a Q&A with Unity's Content Pipeline group here on the forum, and on the Unity Discord, and discuss topics around Content Build, Import Workflows, Asset Database, and Addressables!
    Dismiss Notice

The Great Grass Dilemma

Discussion in 'General Graphics' started by SomeGuy22, Dec 21, 2019.

  1. marcospgp

    marcospgp

    Joined:
    Jun 11, 2018
    Posts:
    153
    I am encountering the bug mentioned above with the weird brush strengths. Can we get it fixed?

    Using Unity v2020.2.1f1
     
  2. SomeGuy22

    SomeGuy22

    Joined:
    Jun 3, 2011
    Posts:
    717
    It's not a bug, I got a response to my bug report and it turns out the brush strength is like that on purpose. See here:



    So they have intentionally clamped the slider to specific values and supposedly also upped the base strength when it comes to detail painting. There's a few reasons why it worked better the old way, here's what I wrote in response as thoughts on the matter:

    But I don't claim to know anything behind the curtain as to what the Unity devs may want here, probably just a way to streamline the tool and make it more accessible somehow? Regardless, it's not up to us sadly and that's the change they went for so it is what it is for now.

    There is a workaround though, I posted it earlier up in the thread. To solve this issue, I was able to recreate the entire detail paint tool using the Experimental Terrain API, and with it an unclamped target strength value to paint at lower densities. I posted the code publicly on this thread which also documents the detail paint issue. Just put the script into an Editor folder and you should be able to use the tool as listed underneath the "paint" options for terrain. Be aware of the drawbacks though. Hope that helps!
     
  3. marcospgp

    marcospgp

    Joined:
    Jun 11, 2018
    Posts:
    153
    Reducing detail resolution on the terrain settings also seems to help when the minimum brush target is still too strong:

    upload_2021-1-2_17-30-38.png
     
  4. SomeGuy22

    SomeGuy22

    Joined:
    Jun 3, 2011
    Posts:
    717
    That's true, however it would limit the maximum amount of details to be placed down and you'd end up with sparse grass placement even if you were trying to fill it with multiple variants. If you wanted a high number of objects while still being able to paint at precise lower densities, you'd have to utilize opacity or use the script I linked above.
     
    marcospgp likes this.
  5. marcospgp

    marcospgp

    Joined:
    Jun 11, 2018
    Posts:
    153
    @SomeGuy22 Unfortunately for me opacity is a no go as I like to paint details by holding the mouse down and moving the cursor around, which even at the minimum opacity quickly reaches the maximum.
     
  6. Aleiiixx

    Aleiiixx

    Joined:
    Feb 12, 2021
    Posts:
    1
     
  7. Arqae

    Arqae

    Joined:
    Nov 15, 2018
    Posts:
    4
    A bit out in the future.
    But based on my experience you may be looking at the wrong aspect your grass dilemma. Your grass mesh doesn't look bad at all in my opinion, but you may rather look into grass shadows and other graphical adjustments. When I changed to HDRP I realized how big of a deal something like Ambient occlusion and also as one of thing you pointed out, the background(Surface texture in this case) also changes how your grass fit to the ground and will look less harsh on the edges. These adjustment might be what you're looking for, but can't make any promises :)

    I also used a few techniques while working with my grass which seems to help with density issues like overlapping multiple grass planes and texturing the fade the bottom part to a darker texture
    while not as realistic rotating the grass slightly to cover more of the surface also seem to give a more dense feeling

    Hope you find any of this helpful if you haven't already found your solution :D
     
  8. SomeGuy22

    SomeGuy22

    Joined:
    Jun 3, 2011
    Posts:
    717
    Thank you for the suggestions! But actually as you said I already incorporated all of those ideas about halfway through my grass journey. Ambient occlusion was always on for all of those screenshots though I'm not sure if Unity's detail mesh grass shader is actually compatible with that post processing so I'm not sure what difference it made. But regardless, for my project I found that I actually didn't want to shadow the bottom too much as it looked more pleasing to have it match the terrain closely. I guess it really depends on the style and level of realism but to me it seemed to matter that the grass matches the terrain in hue/saturation/brightness more than anything else.

    Adjusting the grass patch to cover more ground with "flattened" planes is a great way to cover more surface as you mentioned! I've seen it done in several tutorials in my research and I think it's a big part of making the grass varied. Using Unity's default grass option unfortunately leaves you with individual squares which is why I discovered that I had more control with patches using the detail system.

    If you want to see the final result of my efforts you can check out Iron Reckoning on Steam! The vegetation was extremely important for the look of my levels and I show it off a bit in the trailers and screenshots.


     
    Arqae, neoshaman and marcb152 like this.
  9. nikoggbg

    nikoggbg

    Joined:
    Aug 20, 2018
    Posts:
    15
    GPU instancer works perfect for us.
     
  10. Seedersj

    Seedersj

    Joined:
    Apr 22, 2016
    Posts:
    18
    I'm not sure if you've considered it or not, but you could break your terrain up in to multiple 'tiles', which could individually have the same 'detail resolution' you are using now, but it would be much denser since your tiles are smaller.

    My terrain tiles are only 100x100, and i dont need much resolution at all to get very high amounts of grass:





    My batches are still pretty high with this amount of grass because I havent found a way to share the same material with the grass and the rest of my stuff yet. I dont even really want this much, and just turned the resolution up to 512 for this screenshot. I could go even higher...

    Here's 2048... but i can't even tell a difference

    upload_2022-8-23_21-46-19.png


    And this is the material problem manifested:

    upload_2022-8-23_21-47-44.png

    Here I have 2 different grass types rendering on screen (dark in foreground, lighter in bg), so the batches are even worse because its an additional material.

    If I could just get a shared material with instanced shader properties working between different detail mesh prototypes, I would have no batching problems at all, and could have as many types of grasses/flowers/rocks as I wanted essentially.

    I might end up just generating my own meshes at runtime for each detail layer and uv map the textures on to the quads manually.

    And there are still ways to render far away terrain, even though you are using tiles for nearby terrain:

     
    Last edited: Aug 24, 2022
  11. SomeGuy22

    SomeGuy22

    Joined:
    Jun 3, 2011
    Posts:
    717
    Wanted to share another neat trick I've found as I continue improving the look of my vegetation for new projects. In Shinogi Chess Club, I opted for transparent grass as I figured it would fit the anime/stylized look of the game and offered a soft approach to adding detail. It ended up looking something like this:



    So that's a pretty non-traditional approach I opted to take, and I'm satisfied as a first attempt. But there are several drawbacks. One is the lack of shading between areas covered in shadow and those in light. With this technique my grass tends to just glow evenly across the field at night and while it does give a neat look, it's somewhat limiting as I can't truly contrast the shaded areas of my field completely. The only contrast I get from this is via the floor bleeding through the transparent grass which still worked in the game, but was very limiting. Another is the sorting issues that pop up if I wanted to make the grass more opaque and noticeable:



    Obviously the use of a transparent shader will result in these issues. So I tried going back to a traditional cutout approach for the sequel game. This worked to make the "shaded" parts of the grass become darker when shadows cast on them, however it resulted in the backfaces of grass becoming shaded even in normal daylight. This makes sense because that side isn't facing the sun, however as far as "soft vegetation" goes this really ruined the style for me:



    So if the backface shading was ruining the style of the grass, and I still wanted to use a cutout approach to get them to match the lighting in shadow... how could I control the shading of the mesh more precisely?

    That's when I realized the solution was something I had already been using in a different aspect of the game. One trick I learned from making anime characters is to manually edit the normal direction to create softer shading. i.e. even when a character's hair has "fluff" details that extrude out from the head, you can force it to shade like a sphere by using the "normal edit" modifier in Blender. Turns out this can totally be used in the environment too, and it works to make objects appear much softer when shaded!

    By modifying the grass mesh normals to always point up, it allows both sides of the grass to be shaded by the same amount regardless of where the sun is. Shadows that are cast unto the field still plunge the grass into darkness because they hit the "upwards" direction that the grass is supposed to shade from. Imagine it as a plane which is facing up. Even though the grass is facing other directions, they are shaded as though they are a plane. They essentially face the same direction as the field itself. Much like how the hair extrudes get shaded more softly when their normals point to the "flatter" shape, the grass will get shaded more softly when their normals match the object they are meant to blend with. The results are really impressive to me:



    And it works well up close too:



    I accomplished this by using the "normal edit" modifier in Blender and set a target to above my grass mesh. That way, the grass normals all point upwards. To create this look I also took into account what I learned making hair and grass in previous games:
    • Allow a lot of negative space between the blades to create the see-through effect
    • Curve the grass mesh itself to add shape rather than the bland "straight-up" quads you may be familiar with
    • Since these are non-terrain grass meshes, I use the static option to ensure they are baked together on build
    • I used a custom ShaderGraph to animate the vertices allowing them to flow in the wind
    • Most importantly: do a lot of trial and error to match the color of the grass blades to the ground beneath. This soft shading approach works best when the color is near identical to the ground since it looks a lot more like a natural extension of the floor rather than objects pasted on top.
    • Make the grass bright enough so that SSAO can kick in and handle the cast shadows. This effect still looks really cool and is much more performant than using actual shadows on the grass blades. I actually disabled the cast shadows via the renderer options on these blades. I'm also using an asset store package to allow for higher quality SSAO that can really get between the blades. Not sure how it compares with the default SSAO but it was the only thing available for URP at the time
    And that's it. I really love the look of this grass but it took a lot of practice to understand what steps provide the biggest wins here. I will definitely use this normal trick going forward in all my grass. Hopefully if I transition back to Unity terrains in the future I will be able to use custom shaders or something like that too to get the detail method looking similar to this. Hope that helps and I'll always try to update here if I find anything interesting to share!
     
  12. BrandyStarbrite

    BrandyStarbrite

    Joined:
    Aug 4, 2013
    Posts:
    2,061
    @SomeGuy22
    That is alot of interesting info. Good read bro.
     
    SomeGuy22 likes this.
  13. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,373
    It's actually a common and standard technique, you can also extend it to Bush by hacking the normal not I the up directions but in a circle or any blobby shape you need.
     
    BrandyStarbrite and SomeGuy22 like this.