I attempted Hardware Instancing by implementing grass foliage for the map.
How can I ensure the entire terrain plane is covered in grass foliage? I’m using the combination of a vertex shader / hardware instancing. The shader is applied to each plane spawned via hardware instancing to create the moving grass effect.
Also, what is the best way to go about placing on-demand entries spawned by players? The context of the game is a sandbox, there shouldn’t be a performance hit considering the amount of entities placed.
You could render a top down depth map of your terrain surface, pass it to the grass material shader and calculate the corresponding Y elevation for each position in the vertex shader.
You could use Ammo.js raycasts to sample positions on the terrain collider and get the required Y elevation. In my experience I found out that Ammo.js raycasts are very fast and you can sample thousand of positions without long wait times. But if that becomes a problem, another solution is to load Ammo.js in a web worker and do the sampling there.