Jump to content
  • Advertisement
Sign in to follow this  
GuyWithBeard

3D Distribute points onto height field according to density

Recommended Posts

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!

Share this post


Link to post
Share on other sites
Advertisement

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.

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!