Hey there!
My game infinitely generates tiles which the player travels along. I am struggling to solve this problem and would love ideas or a better approach.
I need a good solution for spawning grass and other vegetation which uses Shader Graph shaders for wind sway.
I have tried DrawMeshInstanced; the problem with this is that I don’t have a good way to control which Matrices to draw.
My current idea has been to associate grass matrices with the tile beforehand by raycasting and storing a List<Matrix4x4> on each tile. Then when the player enter’s the tile, they will instance every Matrix4x4 in the tile, as well as in the nearest adjacent tile.
This would work if I could figure out how to store the Matrices on each tile (Unity prefabs won’t do this by default).
Another problem with this approach is that the tiles can be very large and tank performance. Frustum and occlusion culling are basically out of the picture as far as I know because GPU culling is not supported with shader graphs, and the CPU frustum culling using culling groups and reconstructing the matrices is likely less efficient than just drawing all the matrices. Also, I would have to convert the matrices on each tile from local to world coordinates whenever they spawn in, and I’m not sure if that is efficient or even possible.
I have also tried creating a moving grid around the player that randomly spawns rows and columns of grass as the player travels, using a noise texture such that the randomness of the grass spawns is persistent, but the problem is the number of raycasts that have to be performed every frame.
Note: I have to raycast to place the grass because it uses the terrains vertex color as a spawn rule
Prefabs are terrible for performance too. And I honestly don’t want to store thousands of grass prefab transforms in my scene.
Here is a picture from my scene.
If I can avoid raycasting at runtime, I’d love to.
Does anyone know how its done in Rust, for instance?
