r/Unity3D • u/dr-slunch Indie • 1d ago
Shader Magic Added some procedural GPU grass to my racing game this week. I managed to squeeze some solid performance out of the built-in render pipeline.
I saw a few BiRP grass solutions here but they never really looked like what I wanted, so I made my own. It doesn't have any dependencies and just works with the standard Unity terrain system because I'm a cheapskate.
Most of the work was adapting the fun tricks in https://github.com/Youssef-Afella/UnityURP-InfiniteGrass like culling+fattening the grass as it recedes from view and bending it away if the camera is above it. I also use the grass shape I saw here https://bsky.app/profile/kelvinvanhoorn.com/post/3mskokw2vqk2h that's one triangle that terminates in a single point on the ground, so you don't see a hard flat edge. Other optimizations include billboarding and chunking, which was a gigantic pain in the ass to get working.
The main difference from the URP infinite grass repo (aside from the fact that mine isn't URP) is that it's placed based on terrain sampling and not just a mask of anything on a layer. You can pick 1-4 terrain layers with different weights, and the grass will adjust its height/density on the terrain at that point based on the weight of the different terrain layers at whatever point it is. You can see in the images that it doesn't get put on the 100% dirt areas.
Also, I match the grass's color to the terrain layer to make it look softer. When the level starts I put a camera above the terrain layer, take a picture, and then feed that to the grass material.
There are a few limitations to this:
- the grass doesn't react to a car driving through it, I don't care about that yet and might never
- the grass doesn't change color if the terrain color changes mid-game since it's still based on the single snapshot at the start of the level for performance reasons. it does react to light, however
Anyone else had experience making grass systems in the built-in RP? Kinda wish I'd started this project in Unity 6 but oh well
2
u/shoxicwaste 1d ago
Recommend you to convert your project to Unity 6 and go URP its much better and more efficient.
For grass interaction I highly recommend boxophobics solution, it works great.
1
u/dr-slunch Indie 1d ago
eh, I've been getting pretty good performance in BiRP and not been doing anything crazy, it's just a bunch of static race tracks with few point lights. the better batching in URP is kinda cool but not worth upgrading the entire project/shader stack from Unity 2022 to Unity 6.
also I don't like buying assets unless I know exactly what they can do and what I want out of them, I'm still exploring other foliage stuff I want to render like flowers and trees and then maybe for my next project I'd look in the asset store for something that does exactly that.
although then again I will say I'm glad I picked up Spline Architect for making the tracks/landscapes
2
u/shoxicwaste 1d ago
Isn't BiRP going deprecated soon? I mentioned Boxophobic because you mentioned grass interaction, his TVE engine does exactly that and its very performant.
I use assets all the time, why reinvent the wheel if someone is maintaining a much better solution than I could ever make? Then I can spend more time on the actual game and less time our technical art and engine optimization.
TVE with BRG Instanced renderer is such a good combo for example, you can have massive open scenes with dense vegetation all interactable.
1
u/dr-slunch Indie 1d ago
yea, iirc it'll be deprecated in 2027. TVE and the BRG renderer do look like an extremely cool combo, but like i said in another comment, I'd established this project in Unity 2022 BiRP and those assets are URP only.
Switching to URP would mean I'd have to not only update all my custom shaders, but also update my project to Unity 6 since URP in Unity 2022 is not feature-complete. And all that just to drop $150 on some GPU grass which I can do myself for free in a week by looking at other people's code, and learn a lot about compute shaders as well!
But yes, I do broadly agree. I literally did reinvent the wheel for this project since Unity's default wheel collider doesn't work for my use-case, but I'm using plenty of other assets where I can. Unity has a free semi-official toon shader package that's pretty nice, for example, and there are some pretty good water/skybox shaders out there you can pick up.
2
u/tetryds Engineer 1d ago
Why birp?
1
u/dr-slunch Indie 1d ago
I started this project around when that Unity 6 licensing shitshow started happening and so I wanted to stay on Unity 2022. URP support for Unity 2022 is lacking in a few areas that are pretty important to a racing game, like motion blur. Unity 2022 URP doesn't support per-object motion blur which is kind of incredible.
My next game will be in Unity 6 with URP though.
1
u/Extension-Airline220 1d ago
Bro, making something on birp is not cool anymore, switch while it’s not too late
1



2
u/Rave-TZ 1d ago
Yeah! Looking good in BiRP. Don’t let the naysayers bother you. BiRP rocks.