In Unity, is it possible to paint terrain details such as billboarded grass textures programmatically? (The kind that appear vertical and wave according to wind settings.)

What I know so far (or think I do):

  • Terrain.TerrainData.terrainLayers holds the textures (dirt/rock/grass/etc.) that can be painted “flat” onto the terrain
  • Terrain.TerrainData.detailPrototypes holds the billboard-able grass/vegetation textures that can be painted to appear vertical / waving in the wind
  • Terrain.TerrainData.treePrototypes holds the 3D tree models imported for placement
  • Terrain.TerrainData.treeInstances (I would guess) holds actual placements of trees on the terrain

What I don’t know:

  • MY MAIN GOAL: “Paint” billboarded grass details at specific positions on the terrain programmatically
  • Alphamaps (and splatmaps??) seem to figure into this somehow, but I don’t know how
  • Unity's example found here “blend[s] the two terrain textures according to the steepness of the slope at each point”, but that’s not exactly what I’m trying to do.

Hopefully this makes sense to someone willing to point me in the right direction.

  • 1
    \$\begingroup\$ Not able to answer all your questions, but I've previously generated both the terrain and splat maps externally, then imported them. The splat map is just a texture where each channel is used to represent "intensity of surface type x" in the final texture (if you have more than 4 types of surface, Unity uses multiple textures and renders in multiple passes, at least un URP). So it should be a case of finding the splat texture(s) backing the terrain and adding to one channel (whilst removing from others if you don't want blending) \$\endgroup\$
    – Basic
    Oct 25 at 14:37
  • 3
    \$\begingroup\$ With "Programmatically", do you mean in form of an editor script or while the game is running? (Full disclosure: I couldn't answer either question without doing some research. But I find it very likely that the approach would differ in these two cases) \$\endgroup\$
    – Philipp
    Oct 25 at 14:45
  • \$\begingroup\$ @Basic and Philipp -- Thank you both for your rapid responses. Philipp -- By "programmatically," I mean generating terrain data at runtime. Basic -- Regarding alpha/splatmaps, I've read more about these based on your very clear explanation. I'll need to examine an alphamap for an existing terrain ... mainly I want to see if I can distinguish the textures painted "flat" to the surface and those that are detail textures, billboarded like grass and vegetation. I'll examine when I get back to my Unity computer and then follow up here. \$\endgroup\$ Oct 26 at 17:26


You must log in to answer this question.

Browse other questions tagged .