Advertisement

Distribute points onto height field according to density

Started by September 09, 2019 10:32 AM
2 comments, last by GuyWithBeard 5 years ago

Hi,

I have a heigh tfield terrain which I want to "paint" grass and other foliage meshes onto using a density map. For example, let's say I have a RGBA texture which is stretched onto the terrain. This would give me the ability to paint 4 different kinds of foliage meshes onto the terrain, each using the value in one channel to represent the density.

I have some (probably bad and/or slow) ideas on how to calculate the world space points for each grass blade mesh, but I figured I should check here if there are any standard ways of doing this. My terrains are fairly large and I need to calculate thousands of world-space points for blades of grass. The terrains are static though, so I can potentially do this offline in my editor if doing it at runtime turns out to be too slow.

How is this normally done? Also, is it feasible to do it on the GPU using only the height field and distribution map as input or should I pre-generate the points (or do them on the CPU at runtime)?

Thanks!

What you want is known as "importance sampling". A simple way to implement it is to interpret the densities as probabilities in the range [0,1]. Then, until your grass budget (e.g. number of instances) is met, pick a random 2D point on the surface. Generate an additional random number in the range [0,1], if that number is less than the density at that point, keep the point as a grass instance. Otherwise, discard that point and generate a new one.

Advertisement

That is actually surprisingly close to what I had in mind, but I did not know the term "importance sampling". Should make it easier to do additional research if needed. Thanks!

This topic is closed to new replies.

Advertisement