I have a VFX graph used to make a flipbook grass particle system that I want to use on a terrain. I did some research and was pointed in the direction of using the TerrainType node in VFX graph, but Unity’s documentation on the node is very lacking and I can’t find much information anywhere else. How should I go about attaching my terrain to the VFX graph. As well, if it’s possible, how would I choose where to spawn the grass, based off of the painted textures on the terrain or a render texture?
Hi @Frybo4,
I believe the answer in this other thread should help.
@OrsonFavrel do you have any other suggestion regarding sampling the Terrain Layers?
Hello. The terrain type property allows you to get the Height map of the terrain. But the there’s no built-in solution for the particle distribution on the terrain. From what I can see, the Terrain Property type is pretty minimal in VFX Graph. It’s still useful to be used as a Struct that ties information together:
- Terrain Bounds.
- Terrain Height Map.
- Terrain Base Height.
To spawn grass on specific locations, you could extract information directly from the terrain textures. But this means that would still need to spawn particles on the whole terrain area and then perform a rejection sampling (scatter everywhere, sample the terrain’s textures and based on a mask or threshold keep/kill the particle with the alive attribute.) operation, which often isn’t ideal.
Instead, you could try an alternative method that implies baking the scattered location. There are multiples way of doing this. One of them is to use Point caches. They can be used directly in VFX Graph and can be generated inside Unity or in a DCC.
Or you can store those locations inside textures or even Triangles soup meshes thanks to your DCC application. If you want more information regarding the scattering workflows, the Demo team have made some breakdown relative to their last work in the Time Ghost Demo.
While they used ECS, the scattering workflow is similar, just a matter of storing the data to be used in VFX Graph.
Using the Terrain Height map Data:
- Create a Terrain Type property
- Bind it to your terrain thanks to a VFX Property binder
- Spawn your particles in a 0-1 grid fashion.
- Multiply the position by the Terrain Size.
- Use the 0-1 initial value (UVs) to sample the Terrain Height Map.
- Multiply this output by the Height Value.
- Use the Value for the Y component position, for example.
- Example: Discard particles based on their Y-position.
I hope this shed some light on the Terrain Property type and the scaterring workflow in general and how to make use out of them in VFX Graph. Finally, in this Github Repo, you’ll find one example that uses a terrain and some Point Caches to store information and spawn some grass. Wish you a wonderful day.
Thank you @FredMoreau @OrsonFavrel this is very in-depth and exactly what I needed.
I’m glad to know we were able to help. Good day to you