Using IsoSurface Grass and trees with standard terrain

Hello! This thread is for people who want to integrate IsoSurface style grass and trees into a standard JME3 terrain. Grass will only spawn on areas where the terrain alphamap has grass (Green channel).

So far, I have the IsoSurface demo compiling on 3.1 and I am trying to isolate the grass and trees from the isosurface.

So, lets start with the grassZone. How can I spawn the grass onto Jme3 terrain?

You may have to extract a lot of code as the ā€œZoneā€ stuff is all based on my open source paging library and has nothing to do with JMEā€™s terrain. So you may have to take the ā€˜iterate over the mesh and find places to put grassā€™ part out and use it somehow another way.

The pager library was meant to deal with this multi-level paging problem. I donā€™t think JMEā€™s terrain deals with it at all so you will somehow have to hook into it to load the grass when it loads the terrain. (Iā€™ve never used it before.)

Non-trivial, probably.

Haha good, I like a chalenge! A few questions:

  1. What does the grass do? I see that they are spawned with different rotations at different positions and that they react to player distance and ā€œwindā€. What else does it grass do?

  2. Why can you have so many grass blades? Is batching the only reason?

  3. What is multi-level paging ?

I think thatā€™s it.

Batching. Each blade of grass is one triangle in a mesh for the zone.

In this case, the grass canā€™t page in until the terrain is paged in because the grass needs to know where to plot. So there is a parent-child relationship between grid zones but all grid zones are built in the background and itā€™s taken care of by the pager. This also allows the parent zones to be larger and stuffā€¦ so you could have 128x128 size terrain tiles with 32x32 grass tiles or whatever to allow different LOD schemes for both. The pager makes sure that the grass zones donā€™t try to build until the parent terrain zone has built. It also makes sure that if a parent is canceled then the children are canceled, etcā€¦

Also note: my grass implementation resorts the grass in the zone the player is in as the player moves around. (Though that may be only in the game I was making, donā€™t know if I ported that back.)

Sorting the grass blades in the mesh is important for the semitransparent edges to look right. So the proper approach sorts the current zone as you walk around and sorts the neighbor zones once based on facing the current zone.

1 Like

Ok, thats good to know. I will try to pull out the bits and pieces I need and make it happen.

Let me get this strait:

Each blade of grass is one triangle in a mesh, a series of meshes is a zone, and the sum of zones is what we call grass.

The pager pages terrain and grass, so I need to make the grass pager page on terrain instead of isosurface. I also need the feed the alphamap info so that the grass knows where to plot.

This should be fun :smile:

A ā€œbladeā€ is technically a clump of blades because my texture atlas has little clumpsā€¦ and yes, itā€™s a triangle to save one vertex and require no index buffer.

A zone of grass is just one mesh, though. A zone is a cell in the grid. Terrain has its own grid of which the grass grid is a child.

re: pager, yeah, basically. If you didnā€™t care about editing terrain in the SDK this would be a lot easier as you could just make a heightmapped based terrain zone implementation pretty trivially.

I donā€™t know if it can help, but the OpenRTSā€™ Sower feature has a placing algorithm for grass and other assets on heightmapped terrain.

It is essencially a poisson-disc fast travelling, looking in a random way (Montecarlo) for best places to put an assets, accordingly to a set of user rules.

Itā€™s a WIP but may worth a look. Here is the code

1 Like