Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

The Great Grass Dilemma

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

  1. SomeGuy22

    SomeGuy22

    Joined:
    Jun 3, 2011
    Posts:
    722
    Hi all, apologies for the long post but I want to get this discussion as complete as possible for the sake of being productive. For the past several days I've spent like 90% of my waking hours trying to nail down a solid approach to this issue but everything I try just seems to come with it's own set of problems and it's hard to see a clean way to accomplish what I want here. The problem is with grass.

    The Goal

    I've been working on this exterior environment for a fantasy/sci fi game that I'm building and I'm aiming for a somewhat realistic artstyle. My main point of reference was screenshots from Final Fantasy 15, specifically this image:



    So I started looking into grass. Quickly I realized that there were limitations within Unity's Terrain system which could hinder the look I wanted to get.

    Base Terrain

    After I prototyped the layout of my level, I added a terrain and started sculpting. The first results were horrendous because I only used a circle brush and made really smooth, ugly hills to act as mountains. But that's on me. I did more research and got the new 2018 Terrain tool extension thing from Unity which has hotkeys for brushes and mountain shapes, as well as erosion tools which really helped me get that mountainous feel. As of today, I'm working with a base terrain that looks like this:



    And here's the area I'll be showing later on that I'm trying to work on:



    I'm happy with the tools I have for sculpting, but I'm a little worried about the ground textures and mountain ranges not looking how I want them to. I have a feeling the texture really impacts how the ground looks with grass, but I've tried dozens of different textures from Textures.com and some of them just really don't look great when they're tiled on this scale--unfortunately they're not very high res so I can't scale them up much further, but regardless that's a somewhat different problem entirely. Just thought I'd mention it in case anyone thinks this is what I should focus on. In the meantime, I went to work on grass.

    Unity Terrain Grass

    My first approach was to use Unity's Terrain "Grass Texture" tool, which just asks for a texture and lets you paint on planes. So I made my own grass texture and placed it in. But then a problem appeared:



    The grass amount was coming in very sparse like this. There's no way I could match the coverage of something like FFXV if this was the shortest distance grass can come in. So I tried to trick it: I added another grass object which was actually the same texture, so that I could add more of it in the same area. And I got this:



    Clearly this wasn't going to cut it either. No pun intended.

    After adding a third grass texture I actually reached the limit of density for that area. So was that it? Did I just have to stick with individual obvious grass planes and hope that it'll work out when I flesh out the asset library? No - I had to increase the density. I looked into it and found the detail mesh options in the terrain settings. I turned "Detail Resolution" up to max and got something like this (just an approximation because it's hard to get my old settings back):





    Not enough for me. And considering that's still only grass, it would be impossible to add other small details like flowers or plants using this system. So I had to try another method.

    Everything is a Tree

    I came across this post which suggested a new method for painting grass on terrains--one that "looks better". I tried it out. The idea is to make a grass prefab patch and then use the tree editor to place it in. Surprisingly, it worked pretty well. I made a grass patch in Blender that looked like this:



    Then I added my own custom shader which gave it wind (trees don't use wind on the default shaders unless their vertex colors are set properly). I also added a ton of features during this process to improve the color of the grass, such as desaturation, overbright to make it lighter/ignore shadows, set the render order to avoid nasty AO artifacts, etc. I ended up with it looking like this, using that same texture from before:



    I added an LOD group (trees only get billboarded if they are made with tree creator, this is the SpeedTree approach which just uses Unity's LOD group to cull at a distance). Then I started painting, getting results like this:



    The difference was night and day--trees could be painted at much higher density, and adding more variations of grass actually allowed trees to be completely overlapped, with a custom density for each group that you paint in. So if you keep adding new tree duplicates you can have potentially infinite density of any combination of meshes you want. So great, problem solved, right?



    My performance has more than halfed, and that's just while standing still. With this method I lose about 30FPS for an area of this density, and that's only with grass, not even counting other vegetation types such as flowers or actual trees. Reducing the LOD distance helped a little but obviously I can't be reducing it too much or else it becomes an obvious fade. This is even after I disabled shadows and motion vectors for the prefab.

    And it makes sense why this would happen--each patch I made is being rendered individually with it's own LOD group. Unlike the Terrain grass, it's not combing patches into larger meshes that are easier to render, it's drawing each individual one and also doing LOD distance calculations for each patch, which must be hard on the processor. So with this method I can get the density and color customization that I want, but I'm losing performance because of that. I don't want to be limited by grass before I even add the rest of assets or have a solid grasp on enemy count per area etc. So this wasn't going to fly either.

    Back to Terrain Grass

    In order to get more grass density, I had to think about how the patches would behave. If my terrain were smaller then I might have more points of grass per patch, but I wasn't about to just throw away my terrain to rebuild it in chunks. Unity's neighbour tool is nice, but it only lets you add new terrains, not split an existing one into neighbours. So I looked up an Editor script online and ran it, splitting my terrain into 4 chunks of size 2000x2500 each. I set the grass resolution to max on all of them and I was actually able to increase density further. Now I was getting results like this:



    Okay, that's a lot more grass than before. But I had to make sacrifices: this is already 3 layers of the same type of grass, since an individual one still wasn't enough. If I go all out and push layers to the max I get this:



    I suppose that's a reasonable coverage but now I have to paint over 5+ times to achieve this. Also, there are problems with the way the grass is placed and rendered that bug me. All of the grass is sticking up the same way and is placed somewhat evenly apart, at least evenly enough that I can see the individual grass places. The color is also an issue, I don't have all the neat tricks my shader could provide so I get these green blobs, even tweaking the color to try and compensate it still just seems way too saturated and there's no way to adjust it. I also don't like how it looks at a distance, it should be a cutout texture yet the grass places look really square and blocky in the distance, as though the aliasing or something is just not making them less visible. Finally, the coverage is somewhat reasonable but for art's sake I'd at least like the option to add more density in certain areas if needbe--say for flowers or plants or something.

    So in the end, I'm back to where I started with no clue how to proceed with grass. Both methods have issues, and I can't see any good way to get the look I want.

    Thoughts

    This is more of a technical question, but ultimately the method I go with should be driven by how it looks in the end assuming it performs well. I'm well aware that other aspects of the ground such as rocks, trees, logs, etc will improve the look. I'm also aware that variations of grass height and other flowers will help as well, for instance I've tried adding variations with Unity's default terrain grass here:



    Certainly looks a lot better than that one grass texture, yet the same issues apply to each plane. If you look closely enough it still doesn't hold up for what I want - mostly because I can still see individual grass planes sticking out. Also, I can't rely on variations for the entirety of my terrain grass, in my view it really should hold up in an empty field with similar grass types and I'm not happy having to rely on this to hide the grass. It also suffers from lack of normal maps/desaturation etc.

    I'm also well aware that the quality of the grass texture itself can have an impact on how it looks in the terrain regardless of the method. And that's something I have to work on as well. But still, I expected to be happier with the results at this stage and I don't want to jump in and starting painting grass if the final result will have the same issues.

    So I'm really just hoping to find a workflow or better approach to all of this. Hopefully some ideas can get thrown around in this discussion and I'll continue to research a better way to do this. I'm just hesitant to spend more time on it and I'm considering just not having grass at all if I'm not going to be happy with any of these approaches. I should also clarify that I'm NOT saying Unity grass looks "bad" by any means, that will all be down to opinion and art style depending on the game, I'm sure the tool is great for many purposes. But as a matter of my own satisfaction and artistic intent, I'd like to do better.

    Summary of Issues
    • Density - how much grass I can put in one area
    • Performance - ideally I'd want it to run as fast as Unity's Terrain grass
    • Graphical features - normal mapping, wind settings, desaturation, overbright are all nice to have, but I can live without some of them if it means getting performant, dense patches
    • Aliasing/cutout method - The edges of how the grass is rendered and whether or not it appears "blocky" at distance
    • Distance - Either fading out, just disappearing, or shrinking in size, I'd like the LOD distance to be long enough to not be noticeable, ideally adjustable in realtime so I can add a graphics option for it
    • General look - I realize this is more artistic, but the color and placement of the grass in general for all of these methods just doesn't make me too happy. Again, I know that variations, better textures, etc. help, but it's hard to say what needs work and how I can actually go about making those textures. I've done plenty of art before, I know that looking at reference is key, but I just can't put my finger on what makes up the reference I have (like the FFXV image), and I can't clearly see what's going wrong. I know that's on me and with practice I'll get better, but it's worth mentioning in case someone can provide help there too.
    Potential Solutions
    1. Make some new performant grass method. I've heard about instanced grass and maybe that's a fast way to render custom meshes with as much coverage as possible. But it would be a huge time sink to develop that system and I'd want it to be linked to terrain. I want to be able to paint the same way I do trees, and I want the result to be dynamic if I ever go back and adjust the terrain height, it shouldn't be static. Instanced grass would need to dynamically follow the terrain and update in editor to be practical so I can view it. No clue if it'd actually slow down computers that have weak GPUs too.
    2. Replace the default terrain grass shader. I tried doing this with a shader from another post but I saw no difference. Maybe I just didn't do it right. It could help with the color but regardless it won't help the coverage or placement, and I'd still need to have multiple layers of the same texture to get the results I want.
    3. Custom LOD. I'm aware of Danny Weinbaum's forest optimization post. His solution was to make a custom LOD group that combines meshes in an area and does LOD for the whole hex. Smart, but he's also placing objects by hand without Unity's terrain. Again, it'd take a long time to make a system like this and I'd also want to paint objects on terrain without hand placing.
    4. Unless... I can use this custom LOD in conjunction with Unity's trees. The data for trees must exist somewhere on the terrain, so maybe it can be accessed and used to combine meshes. I have no idea how that would work, but it's an option. I'd really like something out of the box though, again it sounds like it'd take even longer to make that system than just hand placed custom LOD. Even if I could just group grass patch LODs I think it might help, but my guess is the combining is really what saves frames.
    5. Some plug-in for terrains that adds better grass options. I don't really want to spend money on this though, but if there's a free script that does this it's worth looking into.
    Perhaps as a goal I should say that I want to match something like this tutorial:



    That reference is probably close to what I imagine some of these areas should be. That grass is painted using that engine's tools and I believe he mentioned something about combining it so it didn't take a toll of the framerate. I wish something like that was possible with Unity trees for custom meshes. I'm aware part of it is the ground texture/grass texture quality, and perhaps that's something I should look into. Still, it's hard to really get a proper workflow/find the texture that matches what I want.

    Thanks for taking the time to look through it all. Any suggestions or ideas are appreciated since I'm completely stumped.

    EDIT: Unity Forums seems to have a hard time drawing one of the images, even after I replaced it with a new link. Perhaps I hit the limit. Regardless, you get the idea.
     
    Last edited: Jan 2, 2021
    swimswim, frarf, PutridEx and 3 others like this.
  2. SomeGuy22

    SomeGuy22

    Joined:
    Jun 3, 2011
    Posts:
    722
    I should also mention I'm using the Built-in Render Pipeline with Deferred Rendering on Unity 2019.2, which means I'm not using Shader Graph. In my research I've found that there is a treeInstances variable in the TerrainData class, which is a list of TreeInstance. So perhaps there is some way to combine the objects in editor, but again I'd need to preserve the original data so that I can repaint if necessary. Doing some sort of bake method sounds atrocious, and might hinder the painting workflow considering performance drops while the bake isn't active... unless I do partial baked data but that's just sounding even more insane to develop.
     
  3. jamespaterson

    jamespaterson

    Joined:
    Jun 19, 2018
    Posts:
    395
    There are a number of assets in the store which use techniques such as gpu instancing, unity jobs etc for rapid rendering of very dense amounts of foliage. My personal favourite is vegetation studio. I use the pro version but you might be able to get by with the regular version. Good luck!
     
  4. SomeGuy22

    SomeGuy22

    Joined:
    Jun 3, 2011
    Posts:
    722
    Looks like a neat tool, but I'm not keen on spending money for this, even for the standard version. I've been trying to read up on TerrainData and combining trees at runtime, this forum post has some good information. Seems like the TerrainData's TreeInstance has positions to render and an index which points back to the TreePrototype list of available trees. So I can picture an easy way to just spawn in the TreePrototype prefab at each Instance position and then combine groups of each mesh together. The problem becomes 1. I need to find the best grouping of objects to combine and 2. I need to dynamically create the LOD groups so that the groups fade out in the distance. It would be easiest to do this at runtime because then the TerrainData will be preserved when playmode stops, however it would add a huge overhead to the start of the scene (the loading time) because it'd have to combine everything at Start. Doing it in the editor would be faster for the player because the data is already baked, but problematic for me because I'd like to preserve the paint data per grass patch so that I can repaint if necessary. Either way, this still seems like a tough task that I wish could be solved through a more... built-in way. Even if I split my terrain again to get higher density there'd be an issue of the grass shader and concerns for the positions of individual grass planes.

    The other thing I've noticed while reading up is that I think detail meshes also use the same form of patching I described used by the Grass Texture method. However I could never get it to work properly--my painted objects never showed up. So I'm not sure what's going wrong there, I'll have to look into it some more. Painting on meshes which have groups of grass planes would be a really clean solution to this, as I can increase density infinitely by just changing my mesh. It'll also help the placement to be more in line with my tree grass, and it may look as good too if I'm able to keep the shader I had on the original tree grass prefab, though somehow I doubt that'll be possible.
     
  5. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,521
    aldoromao likes this.
  6. SomeGuy22

    SomeGuy22

    Joined:
    Jun 3, 2011
    Posts:
    722
    Looks great and fair priced too, but from what I can tell that's just a replacement shader for Unity's terrain grass. So it might improve the look of individual planes of grass for Unity's grass texture method, but it won't increase coverage or effect mesh placement/rotation as it is probably still limited by the terrain system's detail patch resolution. With the current size of my terrain I'd still have to paint over several times for each grass type to even get close to the desired density using Unity's grass texture system.
     
  7. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,521
  8. jamespaterson

    jamespaterson

    Joined:
    Jun 19, 2018
    Posts:
    395
    richardkettlewell likes this.
  9. konsic

    konsic

    Joined:
    Oct 19, 2015
    Posts:
    995
  10. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,521
  11. SomeGuy22

    SomeGuy22

    Joined:
    Jun 3, 2011
    Posts:
    722
    Okay well apparently there is an active bug in 2019.2 which causes painted grass density to be way lower than normal. Here is a forum post explaining the issue. The issue tracker says it is fixed in 2019.3 beta. Maybe when the official release is ready in January I'll be able to paint more grass using grass texture. Or maybe the limitation is merely that single patches don't fill up the whole patch and as a result I can still paint fully using multiple copies of the same texture, in which case the patch will only help in making less brush strokes but not increase the final density. I'll have to see.

    Seems like a good approach considering it uses splat maps on Terrain to draw the grass. I'm not sure about requiring DX11 though, might be fine but obviously could lower compatibility for older machines. I almost want to say it looks like overkill actually, I don't think I'm looking to draw 10s of thousands of individual grass blades and sacrificing compatibility for that may be worthless. If you look at the reference images they're not using any special shader tricks to fill grass with millions of blades, they're just cleverly combining meshes with decent cutout shaders to mix better with the ground. The coverage in the reference is good, but it's not full-field level, and more focus is on placement and clustering which is handled by the tree grass method but there's no control over it with texture grass. Thanks for the suggestion though, I'll look into it.

    I have seen use cases with that for grass, but from what I understand it only renders based on Bounds. So I'd need to write a complex solution in order to be able to paint and exclude areas from the instance zone. It also renders based on position so I'd need to incorporate the terrain heightmap data to match my terrain. Which I suppose is what some of those asset store packages do, but again I'm hoping there's a more straightforward way with the tools I have. I realize that may be asking for a lot but I think it's best to just see what's possible.

    I've done some experimenting and found that this is most definitely true. Detail meshes use the same patch system which means you don't get infinite density of individual meshes -- in fact if you paint too much in one patch it starts removing objects to save the vertex limit. However the meshes themselves can be stacked much further if they themselves contain planes for the grass texture.

    The reason my detail meshes weren't showing when I first tried was because my prefab had a root node and a child which contained the actual grass. I guess it doesn't like that so when I made the prefab just the mesh (filter + renderer) itself, it started to actually render. My grass plane was rotated incorrectly because Blender imports switch the Z and Y directions. I had to duplicate it and rotate it in Blender which is a pain (it really should preserve the rotation of your prefab) but I finally got it working.

    When I first tried it I ended up with patches like this:



    So my other assumption was true--they don't utilize whatever shader you have on them and will instead just get replaced by whatever the terrain system uses internally. My guess is the _MainTex field is used as some universal name and it just pulls whatever you have from there as input. Or maybe there's some detail mesh shaders that let you preview how it'll look when combined.

    Anyways, this clearly wasn't right. The problem was that I was using the "Vertex lit" type mesh, and changing it to grass got me this:



    That's a LOT of coverage, enough for what I need. And the color is customizable as well (my grass texture has a horrible green tint by default but it's easily adjusted). It also seems like the cutout quality is much higher than the grass texture method, if you look in the distance you'll see that I'm avoiding those big blocky chunks of grass when the mesh is smaller, it looks a lot more like a traditional cutout shader and it even receives shadows too. Performance is way better than tree grass as well:



    The texture needs work, and I'm still going to have to find a lot of variations to get the look I want. But so far this is looking like exactly what I needed from Unity--a builtin grass solution that uses custom meshes for placement, can be painted directly on terrain, clusters objects together for performance, potentially infinite density barring patch vertex limitations (can be adjusted by decreasing items per patch in the terrain settings) and with an adjustable, higher quality cutout shader that helps the look of the texture.

    It's not perfect though, here are some drawbacks:
    • Changing the shader means overriding the hidden default one
    • Grass meshes will not cast shadows, even with replacement shaders(?)
    • Small pain to set up in Blender since you have to work sideways
    • Detail meshes actually override grass textures if you paint over them, and I'd assume the same goes for other detail meshes. In other words, what I've painted above is max density and you can't add any other plants or grass variations to it. In practice I would lower the density and have as many different types of grass/flowers as possible, but there will be a limit at some point. There is a workaround though: If you do need the entirety of your detail patch to be grass, you can fill the rest with the tree grass method since it renders individual objects. So I can still have that density of detail mesh grass, but then substitute extra tree objects to improve the look. Performance will start to take a toll though since tree grass has it's own issues as described in the top post.
    Regardless, this is another tool in the shed, and I'm hoping it helps people looking for an alternate solution. I'll still be looking into alternate grass solutions and I'm sure that this system is far from perfect. I might hit another limitation in the future and end up having to yet more research into this, but I've caught a cold and it's the holidays now I'll have to trust it's good enough when I get back into it. Thanks to everyone who's given suggestions, I'm happy to hear your thoughts on more techniques or ways to actually improve the artistic quality of grass now that I might have a solid painting method!
     
  12. SomeGuy22

    SomeGuy22

    Joined:
    Jun 3, 2011
    Posts:
    722
    I just want to make a small follow-up on this. I'm pretty happy with the results from the detail mesh method -- using a custom sideways mesh from Blender as a "detail mesh" instead of a "grass texture", and using the "grass" shader option instead of "vertex lit". The coverage is really good so long as I stick to 2000x2000 terrains; from now on I will create neighbors using the terrain grouping instead of having one big terrain, which is a problem in itself for matching terrain textures but I'm assuming there are LOD advantages so it's best to stick with it for now. However, there's one annoying problem with this detail mesh method that requires some extra work:

    The default grass shader for detail meshes does not use the UV map for wind strength.

    By default all of your grass mesh will actually flow evenly with the wind settings on your terrain, meaning the roots of the grass will actually sway with the top--not very realistic. It's not noticeable at small wind settings but of course that limits the mood and ends up looking very static, so it would be nice if there was a way to add more wind without making the roots sway with the top. In fact, the "grass texture" method automatically does this by using your UV coordinates as the input for this wind strength, or more precisely, the prototype quad that is used for the grass texture has some extra info on it which defines the top as having wind bending 1 and the bottom as wind bending 0. So, what exactly is this extra info that the shader is using?

    It's really hard to find info on this for some reason, there's literally nothing in the docs that mentions it, but it turns out the terrain grass shader uses the Mesh's vertex colors for wind strength. Specifically, it uses the Alpha channel of the vertex color for it's strength. So, the solution is easy, right? We'll just paint on custom vertex colors in Blender to ground the roots.



    Well that's a problem. There's no Alpha channel available in Blender's Vertex Paint mode. Turns out, this is weird missing feature in most versions of Blender, only 1 version (2.79c) actually has it to some degree(?). And it's hard to find info about it, yet again. So we're kind of screwed unless we get that specific version and paint the alpha channel on. If only there was some way to convert one of our color channels into the alpha per vertex... Oh, there is.

    This forum post has a great discussion on this topic, one of the only ones I could actually find.

    Some code was posted there which takes advantage of the OnPostprocessModel method, which can literally override your meshes with modified info. I tried it and it didn't really work properly, so I modified it a bit to use my own string match and specifically turn one channel into alpha instead of some weird mixing of all the colors. Here's the code:

    Code (CSharp):
    1. // Author: Andreas Suter
    2. //
    3. // Copyright (C) 2012 by Edelweiss Interactive (http://www.edelweissinteractive.com)
    4. //
    5. // Permission is hereby granted, free of charge, to any person obtaining a copy
    6. // of this software and associated documentation files (the "Software"), to deal
    7. // in the Software without restriction, including without limitation the rights
    8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    9. // copies of the Software, and to permit persons to whom the Software is
    10. // furnished to do so, subject to the following conditions:
    11. //
    12. // The above copyright notice and this permission notice shall be included in
    13. // all copies or substantial portions of the Software.
    14. //
    15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    21. // THE SOFTWARE.
    22.  
    23. using UnityEngine;
    24. using UnityEditor;
    25. using System.Collections.Generic;
    26.  
    27. public class VertexColorToAlpha : AssetPostprocessor {
    28.  
    29.     private string myStartName = "TerrainGrassMeshes";
    30.  
    31.     private void OnPostprocessModel (GameObject a_GameObject) {
    32.  
    33.         if (a_GameObject.name.StartsWith(myStartName)) {
    34.             Debug.Log("Vertex Colors Modified on: " + a_GameObject.name);
    35.  
    36.             foreach (MeshRenderer l_MeshRenderer in a_GameObject.GetComponentsInChildren <MeshRenderer> ()) {
    37.                 MeshFilter l_MeshFilter = l_MeshRenderer.GetComponent <MeshFilter> ();
    38.                 if (l_MeshFilter != null && l_MeshFilter.sharedMesh != null) {
    39.                     Mesh l_Mesh = l_MeshFilter.sharedMesh;
    40.                     if (l_Mesh.colors != null) {
    41.                         Color[] l_Colors = l_Mesh.colors;
    42.                         for (int i = 0; i < l_Colors.Length; i = i + 1) {
    43.                             Color l_Color = l_Colors [i];
    44.                             l_Color.a = l_Color.r;
    45.                             l_Color.r = 1.0f;
    46.                             l_Color.g = 1.0f;
    47.                             l_Color.b = 1.0f;
    48.                             l_Colors [i] = l_Color;
    49.                         }
    50.                         l_Mesh.colors = l_Colors;
    51.                     }
    52.                 }
    53.             }
    54.         }
    55.     }
    56. }
    57.  
    EDIT: You need to stick this CS code into an Editor folder in your assets library. And of course, the name of the CS file probably has to match the class called VertexColorToAlpha.

    It's a little messy, but it works for me. I had to include the license because it said to but it's certainly free to use. All it does it take a peek into the meshes if the .blend file has myStartName at the beginning of it. In this case I went with "TerrainGrassMeshes" since my blend file is called "TerrainGrassMeshesSimple.blend". Then it just transforms the Color red channel into alpha and sets it back into the vertex colors. Really it should just copy the red channel and leave everything else but it's just a quick hack. You can modify it to work better or more cleanly.

    So painting in Blender means you just set everything you want to move with the wind to Red value 1, and everything rooted to Red value 0. That means the bottom will be blue:



    When you save the .blend in your Assets folder the code will run and you will get the debug statement. That means all the meshes in your .blend file have had their colors modified.

    Now we get properly rooted grass with any wind strength on the custom mesh :)



    I hope this helps people in the future. For all of the support that Unity offers online and in the docs, there are still so many topics that are confusing or not explained clearly, this vertex color thing being one of them. Here's hoping that everyone can document their experiments like this so that it causes less headache for others down the line. This grass method is looking to be the easiest to work with so far, barring the import override stuff, but it also gives pretty good results now. All that's left is to actually use it with proper textures and full levels for my game. Thanks to everyone that helped out!
     
    Last edited: Jan 2, 2020
  13. jamespaterson

    jamespaterson

    Joined:
    Jun 19, 2018
    Posts:
    395
    Great stuff! Fyi blender 2.8 supports alpha channel in vertex colours a lot better than 2.7, although the ui is tricky to use for painting.
     
    SomeGuy22 likes this.
  14. SomeGuy22

    SomeGuy22

    Joined:
    Jun 3, 2011
    Posts:
    722
    That's good to hear. Sadly I'm already pretty set with my workflow for asset creation and don't want to introduce potential new problems with an upgrade, I already learned my lesson the hard way with cloth being broken for the past few months now. Slightly off topic but I'm also somewhat "oldschool" when it comes to 3D modeling, I originally learned the 2.5x layout and concepts, so I find Blender's default shortcuts and UI ideas easier to grasp. 2.8 seems to have made some things more streamlined with other 3D modeling apps, but in doing so I think it unnecessarily complicates some aspects--layers being gone is an odd choice and it's harder to easily view multiple LODs of the same model for my workflow. The whole right-click select thing is gone, and I'm sure there's probably a way to change it but I don't like messing with the defaults too much in case I have to use someone else's install of a particular version. Internal Renderer being gone is also a little annoying since it was really easy to put together a scene with AO and no fancy lighting.

    Overall it's tough because I like some of the new features in 2.8 but I hate that versions of these programs can differ so much and the lack of compatibility between them can be troublesome. It'll never be an issue for my games if I only use 2.79 internally, but it becomes harder to collab with others if they are now used to 2.8. Again that's off topic but maybe worth mentioning for people interested in upgrading.

    I wanna follow up on this too. I did some experimentation and found that the vertex colors actually affect the diffuse color of the default grass shader for terrains. So if you paint your vertex colors on your grass to red it will actually tint the texture to be red when the grass is rendered. For some reason it only takes affect when you restart Unity. So really my code above is what it should be--after you sample the red channel just set everything back to 1.0 so the final color is white. Alpha does not affect this tint value which is probably why they used it to control the wind strength. This is the only way to maintain the color of your texture otherwise your grass roots will be tinted blue!
     
  15. SomeGuy22

    SomeGuy22

    Joined:
    Jun 3, 2011
    Posts:
    722
    It looks like I'm hitting another roadblock here and starting to get really frustrated with this whole process. Maybe it's just the fact that I'm having to spend so much time on it due to not having a team but it also seems like the entire solution for Unity vegetation/terrains is somewhat flimsy and locked down without being able to customize much. I'll try to document the problems I'm having and maybe some discussions about it can get some ideas going that I can pursue for a solution.

    The first problem is that I wasn't sure if the quality of my grass texture was good enough to get the look I wanted. I went into Blender and actually baked out custom grass blades in order to provide more gaps between edges, and was pretty happy with the bake. Yet when I plugged it into Unity (after a few saturation adjustments) I get this:



    Which is again pretty identical to the results I was getting before, at least at distance. Up close is a different story but since my game involves airborne movement I'd say it's pretty critical to get the look I want at this sort of altitude. My main problem with this look is that the grass is overall very blocky and patchy, and is very noticeably dark towards the fade out zone. It would be much better if it could actually blend into the ground a bit more, and perhaps hide the fade back into the flat terrain.

    My initial attempts at making the texture ended up horrifically dark at distance to my confusion. However, I found that the parts of the texture which were transparent were actually providing color for distant patches, probably because of repeated alpha cutouts and sampling. So I brightened up the "background" in Photoshop, but that ended up making the entire grass glow, even up close. I darkened it a bit to compensate, and this is where it's at now. However, it's not just the brightness I have an issue with, it's the saturation.

    I wanted to edit the grass shader so that I could add some custom features to it, perhaps a desaturation filter and an overbright option, which would help both these issues. But looking into it, it appears Unity 2019.2 does not allow you to override hidden shaders anymore. By override, I mean the trick mentioned in this question.

    Someone in this thread provided an editor script which is supposed to modify the Terrain asset JSON properties to allow for a custom shader. But unfortunately I couldn't get it to work. I wrote my error down on that thread in case someone can figure out what's wrong. Aside from that solution which seems pretty hacky/unstable (replacing your entire terrain data with a duplicate!) I can't think of how else to adjust the grass shader. No matter how much I adjust the color or the texture, nothing seems to match my ground. It's as though the cutout portion will always be obvious and is just colored/lit completely differently than the terrain.

    My second problem is best shown here:



    I'm already hitting the patch limit! Again! All I did was increase the density by a little bit, and I added some small rocks/grass details to the mix. Yet I'm getting holes in places which should be filled. In fact, they are filled if you get close enough, but at range Unity decides to drop them in favor of rendering closer blades. So even though I'm not even quite at full coverage here, I'm already hitting the max patch limit. That's going to make it tough to actually add more plant variations or ground details. Perhaps if I could lower the density I would have more room to add other details, but I don't see how it'll be possible without the patches looking spotted and inconsistent. It already doesn't look like a field of grass but more like a flat piece of land with grass painted on. I really could use a way to add more objects in these patches, even at max it's tough to see how I can fill it the way I want.

    I'm, again, well aware that with better art assets and more variety I could get closer to the look I want. However I'm still unsure about my terrain design and if this is really the best approach to use on my level. I could really use some help from an environment artist because it really feels like I'm stumbling around in the dark here. I know how to make art assets, but I'm not confident that any of them will actually pull these scene together until my grass is more consistent with the underlying terrain. Again, I will link to this tutorial. I'm not sure what kind of magic is going on to make those assets match so well with the terrain, but I'm really at a loss as to why I can't replicate it, even after following the steps as best possible within Unity. I imagine it has to do with the shader quality and shadows, but as just mentioned that's not possible with the grass detail method. I could switch to tree grass, but of course that would lead to horrible performance due to tree objects not combining.

    Overall I'm just feeling completely stuck. I need direction on the workflow here. Even after looking at references all day and trying to match my assets accordingly I can't get the look I want. Maybe I'm just not a good enough artist to accomplish it, but everything looks fine to me until I bring it into Unity's terrain. There must be something I'm missing here. I've been watching level design timelapses and all of them seem to handle grass/nature much better than this, I don't know what the difference is. Perhaps it's just the engine entirely at this point. Or perhaps their assets are just better because they already have a library of them. I just don't know. I'm going to do a deep dive into Final Fantasy yet again to study their grass methods. It just feels like a tremendous waste of time at this point and I'm at the end of my ropes here. I apologize for the rant, but I can't imagine this project continuing unless I can figure something out.
     
    PutridEx likes this.
  16. TchPowDog85

    TchPowDog85

    Joined:
    Dec 29, 2015
    Posts:
    124
    Getting grass to look good is more of an artistic challenge than a technical one. You have to make sure your grass texture is an extension of your ground texture. They have compliment each other. If you just want full, dense coverage, try a shader. I made this shader a while back to get the look I wanted. You can probably modify it to achieve the look you're after. Grass is not easy.

    https://forum.unity.com/threads/released-free-surreal-pbr-grass-shader.530919/
     
  17. SomeGuy22

    SomeGuy22

    Joined:
    Jun 3, 2011
    Posts:
    722
    Thanks for your reply. I've seen your asset before but didn't try it until now. First time I ran it I tried to do it on my terrain with a splatmap that came packaged with the terrain data. But the program halted and after about 10 minutes I figured it was broken so I stopped it. Perhaps my terrain was too big and also that I didn't realize your density map is actually inverted with black meaning draw and white meaning cull. So I tested it on a smaller and scale and got it to work:



    Seems like images are loading very slowly on the forums so me so if you can't see it embedded just right click and open it with a new tab.

    So I was able to get the results you promised in your post and with a customizable material and shader it seems like it would be much easier to blend into the ground and give higher quality results when it comes to shading and specularity (none such options exist on detail grass). However, I see several problems trying to use this for my kind of project:
    1. How would I paint the splatmap on a terrain using Unity's tools and export that to a file which can be read by your script? I could maybe make a dummy grass and delete it after painting but even so I'm not sure where that data is stored--splatmaps on terrains seem to be arbitrary and I'd have to do editing to invert and extract the colors I want. Not ideal if I want to constantly edit grass placement.
    2. It seems like it takes a while to bake on big terrains. Obviously with a proper splatmap I could restrict grass and that may help it run faster... but if it has to read the texture data anyways I'm not sure much better it'll be.
    3. Results are permanent--making changes means I need to re-run the program, which means I have to sit for potentially a long time just waiting for the generation. Terrain grass however is free to move as I update the terrain's height.
    4. Draw distance... Obviously for a terrain as big as mine I can't render all grass all the time. You mentioned that occlusion culling is supported but there doesn't seem to be an easy way to handle grass disappearing at distance. I'm able to add a LOD component but it has be done individually for each cell since it doesn't support multi-object editing. I could write a script to auto assign some values, but even then, cells disappear entirely--there is no fading and it's obvious when entire boxes just go missing. I'm also unsure about LOD performance considering the potential number of cells but I imagine it's at least better than each grass getting it's own component.
    I appreciate you sharing your work, and it does seem like a great tool simpler projects or just entire plain fields. But I'm not sure if I'll be able to utilize it properly for my game--considering the scale and guesswork involved with splatmap, and the sheer time it takes to bake/test/bake again could be a time sink. I realize there's not much more to be done from a script like yours, and maybe that's a just a limitation of Unity or a demonstration of how complicated this stuff can get which may take a much longer time to build. Building my own system is not going to be any better than this unless it's built specifically to cater to terrains and track every grass mesh which can move with the heightmap.... which I don't think I can do. I suppose don't know exactly what I want but I also don't think I need this extreme of a method for what I'm trying to solve right now.

    You're right that grass is more of an artistic problem than a technical one, I guess I just don't know where else to ask about this since I'm having a hard time with it. I've redone my grass texture many times now yet none of it appears to help the blocky look which appears at distance. As mentioned I probably need to consult an artist on this, I was just hoping my tools in Unity's workflow would allow for more artistic decisions to be made. But without shader editing on detail grass it seems like a no-go. There are other issues though and I take full responsibility for not being good enough at terrain design. It's just hard to find any sort of resources online which talk about this stuff.

    I went back into the game which inspired me in order to study how grass is done. I tried to pay attention to the ground and every individual mesh which was used to build the nature scenes. Here's a screen from Final Fantasy 15:



    If you really break down what's happening it seems like the ground texture is pulling most of the work here. Grass density is actually very sparse, and each grass object is huge. They don't use the classic "grass patch" either. They use this weird spikey thing with color variations and lots of variety with other bushes and rocks too. But really in this screenshot there are only 2 or 3 grass types at most.

    I will attempt this approach by revamping my ground textures and rebuilding grass yet again, but this time changing the final mesh used for painting as well as the texture. In the meantime, I would appreciate any artists who can give insight on this. It seems difficult to find tutorials online which talk about nature design--only timelapses which seem to just pull from pre-built assets and use existing scene references.
     
  18. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,492
    Look at old game, or to be precise news game on old machine, since it's weaker, it's easier to see the drastic solution they had to made.

    My personal pick is the wii game xenoblade (though I have to check the 3ds version too, which is even weaker)
    Grass still look pretty dense here


    They use big tuff, have a progressive fading out, have 2 grass relatively close visually but still break the pattern (flower and plain grass, flower fading in much more closely) a contrasting one (the heavy green bush) that is sparser but fade much later, etc ...
     
    Last edited: Feb 9, 2020
  19. TchPowDog85

    TchPowDog85

    Joined:
    Dec 29, 2015
    Posts:
    124
    Results are permanent--making changes means I need to re-run the program, which means I have to sit for potentially a long time just waiting for the generation
    There's a lot of this in game design.

    Draw distance...
    My shader is open source. You can pull down the code and edit it. Also, the technique I used was just-so-happened to be the technique used in Call of Duty on the battle royale Blackout map (I released my shader before that game came out :p). So it's definitely doable on big maps. Go play Blackout and look at it's grass. You can also do multiple passes with separate grass textures if you want. Then you can also add normal billboard terrain grass to thicken areas or places patches of a particular grass. My shader is just a base full-coverge grass that performs very well. Tip: to get your grass to look natural, make sure the root of the grass is the same color as the texture it lies on. Or at least very close.

    I don't know how big your terrain is, but remember, it takes a long time to work through these kinds of things. Designing a terrain is very involved. Some assets (like Gaia) allow you to do it faster but they're all limited in some way. To get detailed terrain painting, it's better to use splatmaps with many colors that are high resolution so you can have crisp transitions. From these splatmaps, you would create your mask for my shader.
     
  20. SomeGuy22

    SomeGuy22

    Joined:
    Jun 3, 2011
    Posts:
    722
    Yes, I suppose so. But aside from lightmapping I can't quite think of anything in my workflow which would have to take longer than 10 minutes. Then again, I'm not a AAA studio by any means so I wouldn't have a lot of tools like that anyways.



    Yeah, it's just that I haven't worked a whole lot with shaders and have only managed to add color features such as desat/overbright. Making a progressive fade across a single object that's performant sounds like a somewhat larger task, though you're right that's not impossible. I wasn't trying to say your tool wouldn't work here but in order to get it working properly within my workflow it would require a lot of time which I just don't have at this point. I was hoping to modify Unity detail grass instead of having to work directly with objects and build in features that already exist for terrains.

    Yes, well, that's sort of the problem. No matter how many colors I tried it seemed impossible to match the texture to the ground using Unity's detail grass. Seems like the underlying problem is in the textures as there's only so much tinting can do there.

    How would I make those splatmaps? Guess and check by painting in Photoshop? As I mentioned earlier it seems difficult to extract data consistently from Unity's terrain maps, I would need some external tool to paint data directly like that. The reason I need it is so that my paths can be devoid of grass while the fields have it filled. Matching it to the terrain texture is why I opted with Unity detail grass.

    That's a great reference, thank you!

    Yes, it appears you're right. I've been studying Final Fantasy grass all day and I've noticed a trend here with this sort of tradeoff method. So these kinds of games appear to have much larger details (as opposed to actual full fields of tiny grass) with various items to break up the patterns. That second part is something I already figured, but my problem was with how the grass looked by default. Since they use bigger details which are more sparse, they seem to rely more heavily on the underlying ground texture to do the work in terms of color. That means the vegetation seems to be more soft and light, as well as thin to allow you to see through it. As for multiple fade levels (bush and then grass and then flowers) that's not possible within the detail system. But it is possible to add bushes as trees with their own LOD components which fade at different times. So that'll be a good thing to keep in mind when I add more objects.

    Both of you are right about how important it is to match the color to the ground. In my work today I've actually redone the ground texture (higher resolution to reduce tiling) and recolored my grass. Using a PSD meant I had to actually color in the background with a fake layer at low opacity so that the remove matte option would pick up on the green tint instead of leaving it grey. I also brightened up all the textures and added more saturation to the post processing (a cheap trick, I know, but it's the best I can do for now). I switched the color of the grass to white as well, and really tweaked the PSD until it was bright enough to match the ground.

    Then I went in and added some of the spikey puffs seen in FFXV to break up the pattern. The end result was me spending another entire day (7+ hours) doing grass, but here's my results so far:



    Matches a lot better to the ground, and I'm much happier with this. It's not perfect, I've still got some more tweaks to go. But it's finally getting better and I feel like I have a more solid direction here. I'm planning on adding more plants to provide variation and I'll update here as I go to make sure I have a clear vision. Obviously there's a lot to be done in terms of other assets like rocks/cliffs/branches/tree types. But I'm on the right track. I'm still looking for any and all artistic tips when it comes to grass creation, I wonder if it really is just adding more variations at this point or if there's still further things I can do to improve the grass look. At this point without being able to edit the shader it seems hard, but I was able to get this far using my existing workflow so that should count for something.
     
    PutridEx and a436t4ataf like this.
  21. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,492
    I would say look also at the ground texture, it's generally a multitexture lightmap, but it's not just strict separation of various but obvious texture, in the xenoblade example they are pushing the hardware to have HUGE open field, so the texture is quite simple with obvious repetition, but here is final fantasy explorer:
    Around 5m


    You can see the ground has a flower texture that is intermittently blended with plain grass, look at how the grass mesh are strategically place as groups that contrast with group of flower, also in way to break the empty space into area, and how smaller group of grass is placed at edges and objects. The same technique are used with denser grass system. The point is to use the splat to blend the various ground texture in way that help merge with the spot of grass. You can see there is also bare ground strategically place visually around the map, and they use texture to simulate cloud, that give even more life. Pay attention at how they manage the horizon shapes too, the whole composition really help, even though you care only about grass, the whole impression is what give the cachet.



    Now when you look at that, you realize that's not so dense after all, there is a lot of line of sight management with tree blocking the horizon very often, more fuller bush (which are close), open sight are much sparser with shorter simpler element of grass and bush, and grass itself is extended by the ground texture, ie under the grass the texture tend to be close in color, and then it shift to another color, still close, but less saturated. So the whole composition help in managing the impression. Notice there is at least 3 tiers of height for solid mesh, from bush to small tree and big tree, and they come in 3 variation each even if just a slight color shift.
     
    SomeGuy22 likes this.
  22. TchPowDog85

    TchPowDog85

    Joined:
    Dec 29, 2015
    Posts:
    124
    How big is your terrain? Is it one terrain object or multiple terrain objects? I haven't used Unity in a while, but messing with terrains can be hella cumbersome. There are tools that make this easier, like CTS (Complete Terrain Shader). It will allow you to use PBR textures on your terrain and there are several blending options for each texture. You can also adjust the lightness/darkness, hue, etc of each texture. I would try this out.

    As I said, building a terrain can take a very long time. Like months if it's "large". There's a lot of tedious work involved. You should export your heighmap (which should be a built-in tool in Unity) and apply that heightmap as displacement to a plane in Blender (or your modeling tool of choice). Use that model and Photoshop (or Gimp) to create a splatmap for the terrain (this is the tedious part).

    There are other tools that can help you make splatmaps and terrains. Check out WorldMachine:
    https://www.world-machine.com/learn.php?page=workflow&workflow=wfunity


    Another Tip: If you want a "realistic" looking terrain, you're going to have to spend money on tools. OR it's going to take you quite a while to create a terrain will be a direct reflection of your artistic ability.
     
  23. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,924
    I'd like to point out that a lot of the examples people are giving of "AAA games do this badly, so don't expect too much" are considered *extremely bad* implementations in pro game studios. Just because some titles choose to have crappy graphics in this area doesn't mean it's acceptable (especially: not to players!). Most of the examples above are so bad they'd have been ridiculed even 10 years ago, let alone today. (I was working in a major FPS studio when TES 4 / Oblivion came out, and the first thing that happened was the graphics programmers laughing at how bad the grass rendering was. It's a fantastic game, but in the words of one of our graphics leads: "Bethesda has never bothered to learn - or spent the money to hire - anyone competent at terrain rendering, they focus their money on content-generation/quests/gameplay". I thought it was a bit rude, but had to admit it seemed accurate :)).

    @SomeGuy22 good work on persevering with this, and thanks for documenting your ups and downs. It's great to see where this is still difficult in Unity today, vs where different approaches are now easy, and how effective they each are.

    (I've been lurking on the thread for ages because I have a project in progress that's going to need some good grass sometime soon, and the few quick tests I've done using mainstream asset-store packages have been painfully bad, so I've been resigning myself to the probability I'll have to invest a few weeks hacking together a solution that doesn't suck. I've written basic geom/vertex grass solutions in the past, so I have a rough idea how to hopefully merge some of the techniques here, but I'm not looking forwards to it ... Seeing your trials and successes is a great help!)
     
    SomeGuy22 likes this.
  24. SomeGuy22

    SomeGuy22

    Joined:
    Jun 3, 2011
    Posts:
    722
    Those are some great tips, thank you so much!

    Line of sight blocking should indeed help hide the transition between grass and terrain, and bushes as you mentioned can also break up this pattern. When I get a chance to work again I'll try to add more of these types of plants and see how they flow with the scene. I also think tall rocks and cliffs could help the background and maybe make it feel more complete.

    For this level, I use 4 terrain objects which are neighbors, and each are about 2000x2500. All of my levels will need terrains of this size, and many of them have 4-8 actual terrain neighbor objects. They're not completely covered in grass, but it's still a lot considering I have that at least 5 levels which need this sort of treatment.

    I see... even if I do this though, I wouldn't have the texture data which is again stored arbitrarily as a splatmap based on what Unity decides is best. Arguably the texture data is even more important than height, it's to know which splat color correlates to which texture unless I do trial and error, and even that is prone to failure/change if Unity deems it necessary.

    Personally I'm not a fan of this mentality, I don't think any dev should ever "have" to purchase tools to get what they want out of their game. Of course, I think these kinds of tools are helpful and maybe it's true that some games can't be made without them. And yeah, there are limitations in Unity which need extension to deal with. But I'm not convinced that these limitations can truly set back a talented artist who has a clear design in mind. I'm obviously not good enough to really know how to push past these boundaries, but I'll at least attempt to work with what I have or find some custom workaround to these sorts of issues. Maybe for some people that's a waste of time, and that's perfectly okay. But I think this is a good exercise in understand design constraints and how to work with them to get the best possible product. And I'm sure devs appreciate finding workflows which don't require as much extension to work as close to Unity's provided package as possible.

    But as far as this problem goes I'm not against using external tools to get the job done. It's just that I feel like I'm most of the way there already with this method and I think it'd be better to just exercise better design/planning instead of breaking the bank.

    Yes that's kind of my worry here. As I was telling my friend before who urged me to work on something else, the end user doesn't care how many dozens of hours I spend on grass. Just because Unity limits shader rendering for grass doesn't mean the player will understand that limitation or accept that it's the best I can do. Unfortunately it's on me if the grass/nature assets aren't up to par, and when that negative review rolls in about grass quality it'd be my own fault for accepting a result I wasn't happy with. That's why I'm trying now to work with what I have and at least design the environment assets as best possible even with being stuck on this shader.

    Off topic a little but I actually wouldn't say that's a bad thing. When it comes to development sometimes studios have to make sacrifices which impact the final product. For the example TES I'd say back then content generation and quests might have been arguably more important for players than grass rendering. It all comes down to how the player perceives it, and I'm sure that a majority of players preferred that focus on quests above grass at the time.

    Thanks, I'm glad this thread is appreciated. As you can tell I tend to write a lot, but it's only because I like being thorough and I know more information is better for people that stumble across this in the future. I will continue to update here as I work on grass and share what I've learned. I'm confident at this point that 90% of "good grass" is just design and artistic prowess*, even with Unity's limitations it should be possible to make something I'm happy with. As the other user mentioned above, when it comes to working with "old" tech, look towards old solutions to the problem. Those older games are great references because they have figured out what works for them using tools potentially even worse than Unity's terrain. Obviously it won't fly for every project depending on style/target platform, but it's a good starting point. Every time I see a new Final Fantasy reference I end up kicking myself because the grass techniques seem easy to replicate--I just didn't have the vision or foresight to worry about it. I will study old games some more and see how I can improve the look of my scene.

    EDIT: Okay maybe more like 60-70%. It's hard to see the big picture until you have it running in your scene and some understanding of Unity's workflow is important to work with it. Different Engines may have better solutions for grass density, etc. But if I've learned anything from level design timelapses it's that you need good assets to make good levels. And beyond that, you need good placement and understanding of which assets to make to improve your scene. I really wish there were tutorials/timelapses out there which talk about how to make a level from scratch that don't just pull from some pre-built library of store bought objects.
     
    Last edited: Feb 10, 2020
  25. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,492
    Why do you expect him to run when he's struggling to walk, I personally choose very basic example so he can have some fundamental down, just like using contrast, placement, etc ... so he can develop a sensitivity to it. Once he master that, he can then open an actual landscape manual to improve the composition, or find better tech to improve the density.

    Also skyrim sold very well, so player might laugh, but so does bethesda's banker.

    AND if you find a better grass on wii level hardware (ie 3ds, gamecube or ps2) PLEASE SHOW ME so I can learn from it :p
     
  26. TchPowDog85

    TchPowDog85

    Joined:
    Dec 29, 2015
    Posts:
    124
    CTS handles all of this for you.

    Sounds like you're trying to make a big game, which I don't recommend. But if you DO try to make a big game, you're severely hurting yourself if you don't use 3rd party tools. Because it's just not practical for one person to develop a big game. Why? Because it takes too long.

    Modeling
    Texturing
    Animating
    Sound
    Gameplay
    Coding
    UI
    and the list goes on

    Its a time problem. This is why development studios have so many people.

    Regardless of the size game you're making, if there's a tool on the asset store that accomplishes a specific task you need, use it. That's what it's for. If not, THEN make it yourself (which is what I did for my grass shader). Also, if you're going to be a solo developer, you must learn how to write shaders. Shaders are the foundation of graphics.
     
    a436t4ataf and neoshaman like this.
  27. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,924
    Because what OP's demanding is very reasonable and fair to demand from a game engine in 2015, let alone in 2020. The fact that it's so difficult to get working in Unity today says a lot about how bad Unity's terrain rendering setup is right now (and they agree! Improving terrain for artists is one of Unity's big focuses right now! But grass isn't at the top of the list, there's worse problems they're solving first, so for now ... we have to self-help / help each other).
    In case it wasn't clear: the criticism of Bethesda's tech was on the assumption that everyone already knew it was selling / going to sell millions of copies - as gamedevs, we knew very well that sometimes choosing to make bad graphics is the right decision :). But it didn't change the fact that the world's best open-world terrain-based game had one of the world's worst (embarassingly bad) terrain rendering systems.

    Sorry, I missed the part where OP said they were targetting 20-years-old hardware (PS2 launched in the year 2000). If OP's trying to do that - sure, decent-looking grass is a waste of time, never going to happen.
     
    Ruslank100 and AbatureStudio like this.
  28. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,924
    I strongly agree on all this. But every pay-for grass solution I've tried from the asset store sucked donkey. The "classic" ones haven't had the rendering system updated in years, and look embarassingly out of date today (seriously: Unity itself has greatly improved their handling of instancing, geometry shaders are now supported nearly everywhere, etc - it's really sad to see these grass shaders using no new tech since 2013 or so).
     
  29. SomeGuy22

    SomeGuy22

    Joined:
    Jun 3, 2011
    Posts:
    722
    Maybe I just like to torture myself.

    Regardless, even if I had 3rd party tools, I still need to make the actual assets. It may look somewhat better in the end sure, but there's a cost vs. payoff management which you haven't considered. I haven't told you anything about the project so if I was making the game free and just wanted to work better within Unity's workflow I couldn't justify spending $50 on CTS. Or if this is just a hobby project I wouldn't care too much about expanding with complicated tools and would rather learn how to design as best possible with what I have. Of course, that's not the case here. But for those hobbyists out there who feel this idea matches their project, that is where this sort of studying comes in handy and is a good reference for those kinds of people. And I still stand by what I said earlier grass being mostly artistic prowess.

    I know as well as anyone that you can't expect to just buy an asset store plugin and make all your problems go away. You need to learn to work with the tools and make environments accordingly to actually get good results. I'm sure many veteran devs will tell you this. If I don't have a sense of what grass technique I want to go for then no amount of density or shader tricks will actually improve the look of my game, at least after a certain point.

    Sure, but there's a cost to it. And I'm not just talking about the monetary price. One would also need to learn how to use these tools which in all honestly could be days/weeks depending on the complexity of the asset. Any disruptions to workflow just add more time to development, which is totally fine for some. And then there's compatibility with your Unity version and support as Unity gets more updated--will your assets go out of date and become unsupported? Will they work for multiple projects or just one? Is the cost of the asset worth the value you get from it? Can you recoup that cost with the amount of players gained by using this tool? Maybe for a lot of people the answers are yes. But again, I personally feel like it's not necessary in this case, as I already have the tools I need, I just want to work better with them or find better tricks in using them.

    Well yes, I know how to write basic shaders. I know how to plug in maps and modify colors and surface parameters. I'm no expect so there's certainly more to learn here. But if you're talking about adding performant LOD to grass objects I'd say it's a little above what I normally do. I'm trying to be honest about my capabilities here, so yes I could probably do more research in that. But as you've already mentioned I have modeling, texturing, animating, sound, etc. to worry about. Learning more advanced shaders for this problem seems, again, like a time sink. I'd prefer to work with the workflow I've already started--the modifications to Unity's grass shader I have in mind seem far simpler to accomplish than slice-based culling at any angle. I'll do more research into shaders when I have less to worry about.

    Just to be clear, I don't think Unity's terrain rendering setup is all that awful. I've been using the Terrain Tools package and it's helped my workflow a ton. But you're right that there's definitely improvements to be made. It seems like normally we'd be able to edit the grass shaders but due to a change in 2019 that's no longer the case. Aside from that I was able to get density down, it just required using neighbor terrains which wasn't exactly clear. And I had to figure out wind and detail meshes, which again wasn't explained but the framework is all there. Really what I've learned is that Unity just needs more documentation and tutorials on these sorts of techniques for customizing grass and working with dense fields in large worlds. Aside from that it should be passable for my tastes so long as I can make the assets well enough and that my design is solid.

    Again I will stress that from those examples of old games that you don't need top of the line rendering features to make something that suits your project. It's really the design and art that pulls everything together. So long as your tools allow you to properly express your art. I wasn't feeling like that was the case due to shader lockdown but after modifying the texture a ton I'm starting to get better results. Sure it could be better. But it's not the end of the world, there are always alternate solutions, that's why I've tried to explore them in this thread.

    I'm not targeting old hardware, and I do think Xenoblade has mostly decent looking grass, even by today's standards. It's a more stylized approach which is why it seems to work in the game, at least imo. FFXV for sure has decent grass, again imo. That's been my biggest inspiration and as you can see they don't have giant full fields but rather carefully crafted grass with plenty of variations to fade well with the ground. That kind of stuff is actually achievable on old tech, and probably my best solution as it's easier to manage. Though I will try and mix it with my field ideas from earlier now that my grass is matching the floor a bit better. Again, design takes the stand here--I don't think hardware is the limit but rather the tools at my disposal and how I'm able to work with them.
     
  30. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,492
    @a436t4ataf I think we misread each other, I focused on artistic technique, no matter of tech will help you make something decent, only offer you a bigger palette. OP explicitly told about FFXV as an inspiration and if you followed the thread, he also struggle to make something artistically.

     
    SomeGuy22 likes this.
  31. TchPowDog85

    TchPowDog85

    Joined:
    Dec 29, 2015
    Posts:
    124
    I think you're missing the point here. My grass shader is the only shader I've ever written using shader code. Any other shader I made used the graph editor. It took me two days to write. I also spent weeks looking for the right grass solution for my application. Couldn't find it, so I wrote that shader to do exactly what I needed. Then I just gave it to the community to "give back". Writing shaders isn't hard to do, you just have to know exactly what you need. In your case, you need these grass patches to:
    1. Blend well with your ground texture
    2. Perform well on big terrains
    3. Have a draw distance

    You can do all of this with a shader. The examples you have shown from Final Fantasy probably use some sort of shader technique combined with billboard grass.

    Remember, billboard grass is heavy on the CPU - that's why instancing was created. Geometry shaders are all GPU - which is what the GPU is good for.

    Rule of thumb - if you have many many duplicated static objects, geometry shader is by far your best route.
     
  32. TchPowDog85

    TchPowDog85

    Joined:
    Dec 29, 2015
    Posts:
    124
    This might help you. This guy has a lot of terrain videos where he uses free assets and Unity's terrain builder. This might help you more than we can.

     
  33. SomeGuy22

    SomeGuy22

    Joined:
    Jun 3, 2011
    Posts:
    722
    Sure, but there are complications. For one, how would I get color information from other objects at a specific point? The shader as far as I know only understands it's own rendering properties and pixel info, so I'd need some way to pass extra information into it to work with the terrain. Making a shader "perform well" is... well complicated. And the reason I say it is because draw distance would normally be determined through some distance calculation in relation to the camera. If I have a lot of patches that could get very expensive. Again, I'm not saying it's impossible. I can do it if I take the time to research it. But as you can see from this thread I've spent an absurd amount of time on grass already so I'm hesitant to go deep into shaders for this sort of problem. I'm aware that understanding shaders is good for game programming, I'm just not confident that it can be written in a short amount of time.

    But as I already explained it's not just the shader which is stalling me from using this method, it's also the idea of having to rebake the ground every time I want to make an adjustment to grass. Even if it only takes 5 mins per bake, that still pales in comparison to the 5 seconds it takes to paint in a new patch of grass or remove it in Unity's detail tools, which makes iteration and testing much quicker. It also removes the guesswork because I can directly paint on the ground textures I know will be a certain color. Under your proposal if I make a change to the ground then I'd have to figure out a way to export that map to Blender, then repaint in blender, then export a splatmap with a custom tool, then probably modify it to work with your script. As you can imagine, even if I figure out a way to do this and work out all the tools I need to build to make it happen, it's still a long process.

    I've said this multiple times already but I'm already 90% of the way there with my current method. So apologies if it wasn't clear but right now I'm just looking for ways to improve the method I'm going with (working best with Unity detail grass) and how to design my level and assets accordingly to get what I want. It's more of an artistic/workflow approach at this point.

    Thanks for the reference. I've already seen it actually, but it's nice to review the basics. However, he doesn't really go into asset creation itself which I think is what was holding me back for a while. He's also using smaller terrains which means the grass plane method was dense enough in his scene. I use the grass detail method which are actual custom objects, and it seemed harder to match colors with that for some reason, possibly due to texture backgrounds/matte in PSD.

    I've been working on tweaking colors a bit and making some extra nature assets which help to make the scene more lively:



    One trick which I found to help was that I went into my grass textures and actually painted the bottom as black to give the illusion of shadowing at the base. Unity's grass shader recieves shadows (based on terrain darkness) but doesn't give them, so this was a good workaround that also is pretty performant.

    I think at this point it'll be all about placement and just more objects. I need a lot to get to the point I want to be at but at least now I have a clear direction. I talked with an artist on Twitter and he was able to give me a lot of suggestions to improve the fields and overall level direction.
     
  34. TchPowDog85

    TchPowDog85

    Joined:
    Dec 29, 2015
    Posts:
    124
    That's just how my setup tool works to make it easy to setup. It's not necessary once you understand how my shader works. My shader takes any point cloud you give it. You can export your terrain into an fbx object, import that into Blender, subdivide the model to make it dense, then delete all the points you DON'T want grass, save just the point cloud (remove lines and faces), then bring that back into Unity as a mesh and apply my shader to it. No splatmaps would be needed for this.

    All my setup tool does is create the point cloud for you while ignoring the black on a provided splatmap. But you can create this mesh yourself.

    You can create a car model and import it as a point cloud and still apply my shader to it. I'm not saying you should use my shader, I'm just pointing out the power of using shaders in general. Don't just toss out shaders as an option.
    This expensive task is what GPUs are built for and there are specific functions in shaders that help with "distance from camera" called ObjSpaceViewDir. If you want draw distance on your grass, there's no better place to do that than the GPU. If you do this with the CPU, you are severely hurting performance.
    Keep that. But also try adding an Ambient Occlusion Post Processing effect.
     
  35. SomeGuy22

    SomeGuy22

    Joined:
    Jun 3, 2011
    Posts:
    722
    Yes I understand, but even doing what you just described would require my terrain height to be final--if I ever need to redo a section or rework a part of level, say to direct a path in a different direction, or just shrink a certain space which already has grass, I'd need to go through the process of exporting, deleting faces, waiting for bake, etc. Perhaps in a AAA studio where everything is tested beforehand and designed with dozens of concept artists across multiple teams that would fly. But my process tends to be more iterative and rearranging level assets is a must for my working methodology. I'm not complaining here, just pointing out a limitation of pre-baking meshes without any sort of built-in paint tool. Obviously such a tool could be created for this purpose as an Editor extension, but again it's a big undertaking and probably not worth it here when I already have Unity's detail system.

    Thanks for the tips. I do have AO as a processing effect already, I just didn't want to mess with my settings and thought some extra shading on the grass would be less destructive to the rest of the scene. Not to mention if the user turns this effect off in the graphics options it'll still show through.
     
  36. SomeGuy22

    SomeGuy22

    Joined:
    Jun 3, 2011
    Posts:
    722
    I've encountered a pretty bad bug with grass currently and I don't know what's causing it. When I try to paint grass using the detail object method like I used to, it seems to be ignoring my target strength and just painting at max density all the time. Here are my settings: (If you still can't see images due to forum weirdness you can click on each one to bring up the link)



    And here's before I paint:



    After a single click I get this:



    Which doesn't look right considering I was supposed to paint at .06 density. For reference, my terrain still has my older paints where the density actually worked, and here's a few rocks which I believe were actually painting at a density higher than .06:



    The target strength slider also seems to be locked down to incremental values now instead of being pure float, which also seems wrong. The opacity slider seems to work which still lets me paint in smaller densities, but it becomes an issue removing grass because apparently the shift-remove option uses that same opacity. This means if I paint grass with low opacity I can only remove it with low opacity as well. Previously I could just set my opacity to max with a low target strength, allowing me to paint low amounts of grass but still remove them instantly. Now I have to wait for the removal since it factors in the opacity which I must use, unless I go in and adjust it every time I want to remove, but of course that destroys the whole convenience of the shift key in the first place. Regardless, whatever is happening here is clearly a bug or some feature removal or something, it's not right.

    There are two candidates: 1. I'm using the latest Terrain Tools package (version 3) which could've messed with the setting and 2. I'm on Unity 2019.3.4f1. Unfortunately I'm unable to determine which is causing it since I updated my Terrain Tools before painting any grass on this version of Unity.

    Perhaps @wyattt_ can weigh in on this, since I've been relying on Terrain Tools for all of my terrain editing and it's become necessary for my workflow. Maybe I could test if Terrain Tools is the issue by uninstalling it, but I'm concerned about what would happen to my project data as a result of that. I have Layer Palettes for multiple terrains in my assets folder, would they get ruined or interpreted incorrectly if I remove Terrain Tools? Is there any loss of data from my Terrain assets by doing this or can I safely reinstall Terrain Tools later? I know everything is just stored into splatmaps so I'm hoping I can do that but I'd like to be sure.

    If this target strength thing is a bug with Unity 2019 I can submit a bug report. Actually I just thought of a way to test this, I will try it out in a blank project that doesn't have the package installed and report back with my findings.

    This seems to be the opposite problem of the bug I listed earlier here. My hypothesis is that target strength becomes somehow tied to the patch density somehow in the terrain settings, because my terrain patches are at max. This may explain why some people have an issue of not enough grass while I have too much. Regardless, this is pretty horrible and somewhat scary. It's not the end of the world as I can still paint with low opacity at lower convenience, but having less control here will absolutely make terrain editing much more difficult as I rely a lot on having many detail objects and having specific strength values for each. I can't afford to wait months on a potential fix this time.
     
    marcospgp likes this.
  37. SomeGuy22

    SomeGuy22

    Joined:
    Jun 3, 2011
    Posts:
    722
    Okay, so it looks like Unity 2019.3.4f1 is the issue. I've discovered that the target strength is factored in to the paint operation, however the value appears to be scaled by a huge amount. To demonstrate, here is the result of painting at the lowest possible target strength (.0625) vs about half strength (.625):



    Brush size is 100 for both, and I'm using default patch settings. It seems that the patch resolution does indeed impact the paint as well, which I'm assuming is normal behavior. Here's what happens when I half the patch resolution and try the same experiment:



    I've also replicated the experiment in 2019.2.6 and confirmed that the target strength is working "correctly" with the exact same test:



    Now it seems like this shouldn't be a problem at first glance. If target strength is just getting multiplied by some weird value then I can just divide my paint target strength by the same value right? But that's no longer possible. In 2019.3 the target strength slider only works in steps, as mentioned above. .0625 is the absolute lowest it will go, even if you type into the slider field. That's a huge issue because it means we have lost granularity and precision that came with 2019.2. I have no clue why the target strength "multiplier" value changed in the first place.

    I realize I probably should've made a new thread for this, but I thought it was part of Terrain Tools so it would be a specific workflow problem that I could solve immediately. Sadly, that's not the case. I will still document it here and see about starting a separate discussion for this bug. Also sadly, I'll have to spend some time submitting a bug report which will halt development yet again. I will keep testing and providing updates as I try to get this issue fixed.
     
    marcospgp likes this.
  38. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,492
    File a bug
     
  39. SomeGuy22

    SomeGuy22

    Joined:
    Jun 3, 2011
    Posts:
    722
    I already did and got the automated email reply. The case number is 1227935. I will update here if I discover anything new or if they list an issue tracker for it.
     
  40. SomeGuy22

    SomeGuy22

    Joined:
    Jun 3, 2011
    Posts:
    722
    Quick update in case anyone runs across the same problem: Thanks to the direction of another user, I've managed to recreate the entire Terrain Detail tool using the Experimental Terrain API which exists in base Unity 2019.3. This replacement tool has a fully unlocked target strength value, allowing me to bypass the interval lock which exists in the current version. I've posted the code on this thread in case anyone wants it. After that headache, I'm finally able to resume painting at my desired densities as explained above with the detail mesh method.
     
    jamespaterson likes this.
  41. Kareeem

    Kareeem

    Joined:
    Mar 1, 2013
    Posts:
    37
    This thread is a very interesting read! Thanks for sharing and good luck with your project.
     
  42. forgefrequency

    forgefrequency

    Joined:
    Jan 23, 2020
    Posts:
    1
    So if I want to make cool grass with unity and render decent framerates im F***ed? or...?
     
  43. Mauri

    Mauri

    Joined:
    Dec 9, 2010
    Posts:
    2,663
    There's Nature Renderer, which is pretty cool.
     
  44. BrandyStarbrite

    BrandyStarbrite

    Joined:
    Aug 4, 2013
    Posts:
    2,074
    Wow! This is a really interesting topic. I'm glad someone bumped it up.

    I agree.
     
  45. marcb152

    marcb152

    Joined:
    Jun 20, 2019
    Posts:
    22
  46. Mauri

    Mauri

    Joined:
    Dec 9, 2010
    Posts:
    2,663
    Never heard of that, but it sounds interesting and may be worth a try.
     
  47. SomeGuy22

    SomeGuy22

    Joined:
    Jun 3, 2011
    Posts:
    722
    You can follow the workflow I've discovered and explained in my above posts. In summary: I found that the "tree" method for grass was too slow because there was no mesh combining, and each grass mesh required LOD calculations. Billboard grass looked too fake in its rendering, and did not have the correct densitites required even when maxing out the detail slider in the terrain settings.

    So my solution was to use the "detail mesh" system which is an option for terrains. That way I could make my own grass meshes, and each mesh could have more blade "billboards" within them to show much higher densities than previous. Detail meshes are also combined into patches, which massively improves performance, and you can customize the draw distance within the terrain options. The downside is you cannot modify the shader used and are stuck with what they give you. There are also little inconsistencies with how the painting tool works (if you make a change to a detail and paint over to another terrain it makes a duplicate of that detail even if it already existed on the other terrain... it becomes a mess really quickly because now they are "unlinked" and cannot be painted smoothly from one to the other). But the grass shader does support wind, you can get it working by painting the vertex colors and modifying them with a script using the methods I described above.

    There are other hiccups, such as the locked target strength slider in 2019.3. I managed to fix it by building my own painting tool which I posted above. Or the fact that if you put down rocks under the same system, the rock texture can sometimes leak into your grass due to the textures being atlased together internally. The solution I found was to make the rocks have an alpha channel in PS and set it to alpha 0, in order to stop the texture from appearing on random grass meshes elsewhere. Asides from this, the detail mesh system is well equipped to handle lots of vegetation that looks pretty good provided you follow the steps to make everything play nice. You won't have control over rendering though, so if you're unhappy with the features Unity provides you may want to look into a custom system. Be mindful though, that much of how your grass looks depends on the art assets and design you incorporate--getting a new system to render your grass may improve the look but it won't fundamentally change the quality of your vegetation assets. That's a big tip that I've learned from all this--it's crucial to tweak your ground textures and grass objects/textures until they match, and you can use extra tricks like painting the bottom with black for shadowing, or making extra vegetation inbetween for more variety, etc. The way you craft your grass meshes/textures is just as important, if not more, than the system you use to paint and render them, at least when it comes to looks, ignoring performance.

    Looks neat! I'll have to look into it for a future project, if it combines/instances meshes and renders nicely while also adhering to the terrain height dynamically, it would be great to have a system that can fade multiple grass types differently to hide the transition better. That's something that is definitely lacking from Unity's detail mesh system.

    Also just to show my progress, I've been finalizing the look of my game using everything I've learned from this thread. Here's a bit of how I got my terrain grass to look:

    https://i.imgur.com/NrFmcox.png

    https://i.imgur.com/7tEJUnA.png

    I'm pretty happy with this result. I'll definitely explore more for future projects but I've got a handle on my workflow for now. Thanks to everyone who has helped out and given suggestions, I've definitely put that knowledge to good use!
     
    Last edited: Aug 15, 2020
    swimswim and marcb152 like this.
  48. jraselinary

    jraselinary

    Joined:
    Oct 8, 2018
    Posts:
    1
    Hi, you can look at this grass gpu rendering :


    Gpu instancing
    Frustum Culling
    Grass have custom material : One Substance Material for Diffuse and normal, one perlin map for Wind Animation rendering, one color map for terrain blending, and one height map for noise variation and blending between two terrain texture. The grass is 6 CrossQuad for LOD0, 4 CrossQuad for LOD1 simple Cross for LOD2 and Billboard. Run on one Unity3D Terrain 500*500. Grass Deformation use simple per vertex modification
     
    PutridEx likes this.
  49. TerraUnity

    TerraUnity

    Joined:
    Aug 3, 2012
    Posts:
    1,247
    Here is our solution for dense grass rendering in Unity:

    Showcase


    Tutorial
     
    marcb152 likes this.
  50. StrategyTron

    StrategyTron

    Joined:
    Feb 20, 2019
    Posts:
    26
    I've just encountered The Great Grass Dilemma myself. I am making a city-builder game, so I have the additional issue of needing to know where vegetation is, and to cull it if a structure is placed by the player that overlaps the structure, and then to check if a structure has been removed, and "re-grow" the vegetation there, as to not leave large dead patches of land, if the player removed structures. I got either 4kmx4km or 8kmx8km of land to cover, so my grass isn't gonna be as dense, but needs to be "serviceable" for a city-builder.

    I'm still in the early phases of concepting/brainstorming ideas. I have one solution I came up with that may work out, and I'll be sure to post the outcome here, good or bad, and share it with this community effort in finding solutions to The Great Grass Dilemma.

    Also, thank you for making this post/thread, I know it's helped me out a lot, and I'm sure it's helped a lot of others.
     
    marcb152 and SomeGuy22 like this.