Skip to content

Youssef-Afella/UnityURP-InfiniteGrass

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

UnityURP-InfiniteGrass

Fully Procedural and Dynamic Grass for Unity URP.

It meant to be a fast to implement grass system that doesn't need any baking or having any static environemnt.
Just enable it, give it the LayerMask of the objects where you want it to be, and everything gets drawn procedurally.

Preview Video

Tested on RTX 3060: https://youtu.be/NwVtPIxUuCY

How to Use

Just drag the "InfiniteGrass" folder to your project then go to your URP settings and add the "GrassDataRendererFeature" to it.
From there choose the LayerMask of your Terrain mesh.
Assign the Material and the ComputeShader (Included in the folder).

image

Next, in your scene, make an empty object and add the "InfiniteGrassRenderer" script to it.
Assign the Grass Material (Included in the folder) and play with the settings until you get what you want.

image

Features

Fully Procedural:

You don't need to have a HeightMap or use the Unity Terrain, you can put grass on anything just by changing the LayerMask of it.
Also it doesn't require generating a big buffer of positions of the whole world, it generates just the necessary amout of positions around the camera so the Memory isn't a big concern.

Image Sequence_002_0000

Frustum Culling and Density Decreases over Distance:

It allows you to draw for far distances with less performance cost.

image

Dynamic Color Modifier:

It allows you to modify the color of the grass blades using any object or texture you want.
To make you own color modifier, create a new material from "InfiniteGrass/Modifiers/GrassColoringShader", give the material a texture and a color.
Finally, add a quad mesh to your scene and apply the material to it, you can then place the object wherever you want with any scale or rotation like a Decal.
There is no problem also in using Particle Systems with that shader like the waves in the preview video.

Image Sequence_003_0000

Dynamic Mask and Density:

Just like the color modifier, just make a material from "InfiniteGrass/Modifiers/GrassMaskShader" and apply it to a quad or any other mesh.
Just note that the usual meaning of "mask" here isn't what it's used, White means the grass will fully be cutout, Black means full density.
You can also instead of fully cutting out the grass make the density decrease by making the material "Opacity" property lower.
(The Red Channel of the VertexColor of your meshes also occludes the grass).

Image Sequence_004_0000

Dynamic Slope:

By "Slope" I mean the inclination of the grass blade.
It's just a simple modifier like others, just make a material and apply it to a quad, but this time the color will describe the direction where the grass blade will be directed to.
Red controls how much the grass is inclined to the X axis (0: it will go to the -x, 1: it will go to the x, 0.5: it will stay upward).
Green controls how much the grass is inclined to the Z axis (0: it will go to the -z, 1: it will go to the z, 0.5: it will stay upward).
There is no need to use the blue channel cause the grass can't be inclined to the Y axis (it just mean it's upward).
This is usefull if you want to make Custom Wind effects, Explosions, Stepping on grass ...
There is an example of each of these in the Sample Scene.

Untitled-2
Untitled-3

Wind System:

Wind from texture, similar to the "Dynamic Slope" but just applied to the whole grass field.

image

Stylized Billboard Grass:

The grass blades are always (atleast trying) to look to the camera from all angles.
The material includes a lot of parameters to customize the look.

image

Performance

With: Spacing = 0.1 | DrawDistance = 300 | Full Density Distance = 40 | Grass Subdivision = 2 In 1080p, I get an average fps of 200 in my RTX 3060.

It's around 20M position tested and 800K visible grass blades rendered every frame.

To be Added

  • We are testing more that 20M position and adding to the buffer only 800K, so maybe we could lower the size of the compute dispatch by implementing Chunking (Somehow, not sure if that's possible in this setup)
  • LOD cause we are always drawing the same subdivided grass blade even in far distances.

References

About

Fully Procedural and Dynamic Grass for Unity URP

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published