Archive 17/01/2023.

Render grass blades on specific part of terrain texture?

suppagam

Does anyone know how rendering grass blades on specific parts of a terrain texture would work in Urho?

I imagine it would need a mask texture, of course, but how do I read the mask and instantiate the objects on those areas? Is there a SetDetailLayer equivalent for Urho’s terrain object?

guk_alex

I can imagine that it could be done via particles with the grass intensity being described as some sort of heat-map.

JTippetts

You could use your weight map texture for a mask. The TerrainBlend texture uses a weight map to describe how to splat the terrain textures, so you could just load a copy of that texture CPU-side, and query pixels directly to determine where to instance your grass.

suppagam

Thanks! But how do you read the mask black vs. white pixels in Urho? And what object do I instantiate? Do I have to create my own object with quads, or is there a built-in way of doing grass efficiently?

JTippetts1

There is no built in way of doing grass, outside of the usual static meshes and mesh groups. You can go off into the weeds with shell/fur rendering, volume rendering, etc… but that will all take a bit of custom development and probably a few hours spent reading theses and siggraph papers. I did a brief experiment with a scheme that uses a static mesh of billboards constantly centered on the player (thread: Grass/vegetation mapping repo: https://github.com/JTippetts/Urho3DGrassTest ) with mixed results. With a bit of artistic finesse it could maybe be made to work.

As far as querying the weight map, that is a simple matter of loading the map into an image and sampling a pixel directly. The map will have one color component mapped to your grass base texture, so you can just test that component vs some threshold and enable/disable grass at that spot depending on the result.

suppagam

Oh, I’m not really looking into fancy modern ways of doing grass with shaders and stuff. I just thought there was a built-in efficient way of slapping tons of billboard quads with a texture on my terrains as a layer. Like this: http://docs.garagegames.com/torque-3d/official/content/documentation/World%20Editor/Tutorials/CreatingFoliage.html

Thanks for the link, I’ll definitely learn from your implementation. Thank you!

As for the sampling, I think I have to phrase my question a little better: With Urho, once I read the mask and know what is closer to 0 or 1 and therefore how much grass I want, how do I get the transform (X, Y, Z) where to create my quad?

Lumak

I think this is what you’re looking for – Vector3 Terrain::HeightMapToWorld(const IntVector2& pixelPosition) const

suppagam

Thank you! Super useful.

jmiller

Over the years we have also accumulated a variety of threads with still valid advice and samples related to vegetation, grass, and such.