Unity | I made an even better Interactive Grass Shader + Tool

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone welcome to this third cross system video in the first video I introduced my grass painting tool which at the time used a geometry Shader and in the second video I talked about converting it to a computator and adding more improvements and now I'm back with a new version with even more features and improvements so what's new in this version the tool is no longer a monobehavior but an editor window with new settings the most requested feature from the previous video was generating graphs on terrain and objects automatically so that's possible now too and there's options to block graphs on certain terrain layers or vertex colors I added chunk calling so only the grass that's in camera view gets rendered the performance is also better here's a test scene with almost 1.4 million Grouse blades running well on the steam deck here's a quick overview of all the features in paint edit mode you can use a brush to paint new grass remove grass edit the length and width and the colors and reproject positions after making changes to the floor in flood mode you can set the color and length width for all of the grass at once generate lets you select terrains and meshes to generate grass points on based on this density slider here you can also set it to fade the height of the grass with vertex colors and terrain layers or block the generation completely on specific vertex colors and terrain layers there's also a collision check layer mask so no grass gets placed on the rocks for example the general settings holds the min max allowed length and width random height offsets the blade shape settings allowed segments and Blades per Point placed wind tinting calling settings and finally interaction strength and shadows option these settings are all saved in the grass setting scriptable object which is used by the grass compute script additionally there is also blending with terrain textures and interactivity okay so how does all this work by painting or generating the graph system will add data to a list this data is a custom struct called grass data and holds four entries the position of the graphs the normal of the floor or object the point is at the length or width of the grass from the editor window the color of the grass from the editor window and this cross data list is then sent over to the compute Shader in a buffer which will use this data in additional settings to create the triangles for the grass here's a simplified example showing how a blade of grass gets made out of triangles say we want to make a grass blade with three segments we need to place a bunch of points and draw triangles using those points so we start by placing one vertex vertex 0 then we take the width of the Cross we want and use that offset to place our second vertex vertex 1. now we need to go up by the total height we want divided by the segments we have and then we can place the third vertex vertex 2. now repeat the process by offsetting the width and segment height and for the last segment to create the tapered end we only place one vertex same segment height but only half the width offset so it ends up in the middle this has created seven vertices zero to six now I just need to use these vertices to make triangles a quick connect the dot shows that we need five triangles here a triangle needs three points so for the first one it's easy just zero one and two but we want to do this automatically in a loop for that Loop over the amount of triangles we need to make five in our case and every time grab the current index we are on plus the next two points so for the first Loop we get zero zero plus one and zero plus two and these points make up our triangle and for the next Loop we do one one plus one and one plus two so our second triangle is on one two and three and now just do this three more times and we have a blade of cross if we do the same thing but add a few more settings like a curve smaller bottom width more segments we get something like this then with a radius offset and more blades you get a nice little clump of grass finally with even more settings like color random offsets and wind you get this nice stylized cross look all the geometry info for the graphs is created by the compute Shader but this doesn't actually render it it just sends it to a buffer this buffer is read by this custom node in the Shader graph which turns it into visible triangles the chunk culling works by creating a giant bound around all of the Cross splitting this up into smaller bounds and assigning the ID of the Cross points to these child bounds the system then checks if the camera view overlaps with any of these bounds and Returns the grass IDs inside of it to a list which is sent to the compute Shader the computrader will then only process a gross point if it's in this list the terrain blending is done by taking a snapshot of the meshes and terrain you want to blend with this snapshot is made by a camera with an orthographic top-down view that will only look at specific layers the final Shader will take this snapshot texture and blend the bottom of the grass with it if blending is enabled interactivity takes World positions of objects with the Shader interactor component and Compares it to the Cross vertex positions using distance calculations it then bends the grass based on the radius specified in the components there are pre-made packages available for my bright Giant star patrons but all the files are public so let's go over how to set it up go to the link in the description scroll down to the bottom and grab all the C sharp files and the compute Shader then for shaders grab the one that is right for your random pipeline for built in this is the grass surface Shader for urp it's both the Shader graph and the hlsl file import all of these files into your projects you'll need to move the grass painter window scripts to your assets editor folder or make one if you don't have it yet otherwise you cannot make a build this editor specific code will get stripped out when it's in this folder the Grouse window tool will try to save settings in the settings folder if you don't have this one yet create it before opening the tool window or you will get errors you can also change it to a different folder if you go to the init function in the Grass painter Windows script and change these lines you can now open the garage tool window from tools grass tool click the button to create a new graph system object it will tell you you have to create a graph settings file from utility graph settings in this cross settings file add the compute Shader and make a graph material if the Shader graph gives you errors you will need to open up the graph and set the cross hlso file into two custom nodes now create a material out of this Shader and assign it in the cross settings file you can now paint and generate grass to get the blending to work create an empty game object and a child camera set the camera to orthographic and 90x rotation so it looks down add the render Terrain map scripts to The Empty parents drag the meshes and terrains you want to blend with into the slots and disable enable the components if you now turn on blending in the cross material it should blend with the floor for interactivity you just need to add a Shader interactor component to your interactive objects hit manual update in the Crosstour window and it should work right away some things to note if you're editing the grass material you need to hit manual update to actually see the differences unless you turn on auto update in the grass compute script but auto update can get very slow because it keeps recreating all the data just keep that in mind if you're seeing flickering or stretch vertices there is just too much grass on screen at once reduce the number of total grass or the max plates per point and finally the grass is set up so you can easily add additional buffers using the grass IDs for example to cut grass or burn it if there's interest in a guide on this let me know in the comments so there we have it the newest version of my growl system I hope you find it useful if you want more resources and tutorials they're on my GitHub page linked in the description a big thank you to my patrons for supporting my tutorial making thanks for watching and see you next time [Music] foreign
Info
Channel: MinionsArt
Views: 38,491
Rating: undefined out of 5
Keywords: grass, unity, grass shader, interactive grass, minionsart
Id: 2OA9sicjj7E
Channel Id: undefined
Length: 11min 30sec (690 seconds)
Published: Fri Jul 28 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.