Detail-Mesh Generator

Hello everyone!

I’m working on a detail-mesh generator for my games to efficiently cover wide landscapes with small meshes.

Here’s the list of features currently implemented:

  • General:

  • Generates meshes using scattermaps and uniform distribution method and combines them.

  • Ability to select of a scattermap color channel (ex: to generate grass using green channel and rocks using red etc.).

  • Ability to define offset and scale of the scattermap (in case you need only part of the image for generation).

  • LayerMasks to determine where to generate detail-meshes and which layers to discard from generation with offset value (ex: to generate some grass in shallow water).

  • Generator itself:

  • Terrain alignment.

  • Random selection from mesh arrays.

  • Scattermap channel strength scale multiplier.

  • Base rotation offset (in case you didn’t fix pivots before exporting your meshes to Unity).

  • Random rotation offset.

  • Normals generation (keep original, user defined, terrain aligned, spherical) - for better lighting.

  • Other:

  • Caching and storing uniform scattering points as assets (in case of very large maps).

  • Capturing and saving a snapshot of the area below generator (which you can use to draw a scattermap).

  • Ability to write custom data modifiers and override any vertex data before uploading it into the mesh.

  • World-space position storing in uv modifier.

  • Push vertices along terrain normal modifier.

  • Simple LODing shader.

  • Ability to uniformly divide the generation area (in case of very large maps - for better culling).

  • Ability to generate uv2 for lightmapping.

Future features:

  • Ability to override other stuff with custom scripts (like uniform points distribution).


This is how generated mesh looks with terrain-aligned normals:


And with original normals:

Uniform mesh division:
HospitableUnlinedAbyssiniancat

LOD shader in effect:
UniformInsidiousAfricanelephant

Other tricks possible with the world-position stored in uv3:
HardRelievedKite

Generation without scattermap:
ClumsyPleasedAmericanmarten

3 Likes

Looks really nice! Would to see this asset on Asset Store. Useful stuff

Added ability to write custom modifiers to change any vertex data before uploading it into the combined mesh.
It’s just a matter of writing a simple script and attaching it to the generator’s gameObject.

public class MR_PositionToUVModifier : MR_DetailGeneratorModifier {

    public int savePositionUvChannel = 2;

    public override void ModifyDataPerSubMesh( int subMeshId, float scattermapValue, Vector3 localSubMeshPos, Vector3 terrainNormal, Transform rootTransform,
                                                List<Vector3> vertices, List<Vector3> normals, List<Vector4>[] uvs, List<Color> colors ) {
        for ( int i = 0; i < vertices.Count; i++ ) {
            Vector3 pos = rootTransform.position + rootTransform.rotation * localSubMeshPos;
            if ( uvs[savePositionUvChannel].Count < vertices.Count ) {
                uvs[savePositionUvChannel].Add( new Vector4( pos.x, pos.y, pos.z, 0f ) );
            } else {
                uvs[savePositionUvChannel][i] = ( new Vector4( pos.x, pos.y, pos.z, uvs[savePositionUvChannel][i].w ) );
            }
        }
    }
}

Added ability to divide a generated mesh into several GameObjects for better occlusion\frustum culling.
Added ability to select desired Layer for output mesh.
Improved UI a bit.

HospitableUnlinedAbyssiniancat

Added ability to generate uv2.
Added new vertex modifier - push vertices along terrain normal.

Added a Quickstart guide and documentation. Preparing the package for Asset Store.

Today my package was rejected, so I had more time to improve some things.
Here’s new stuff:

  • Added support for Unity 5.6 and newer
  • Inspector windows multi-selection
  • Simple mode with just Generate button
  • Ability to change length of preview distribution points
  • Scattermap projection
  • Ability to use prefabs containing several meshes as a single instance for generator
  • Lightmap/Occludee Static options
  • Shadow Casting options
  • Generator now casts rays along it’s down vector instead of arbitrary Vector3.down
  • Working area bounds are now scaled with generator’s scale

WelllitUncomfortableAntarcticgiantpetrel

Added grass dynamics - bending by a pseudo-wind, stomping and burning.

Have you tried submitting this to the Asset Store again?

Yes, I added support for Unity 5.6 and submited pack again… and never heard anything from Unity since

Assuming nothing happened with this in the end? Massive shame. This would be incredibly useful for us individual developers.

I’ve been attempting to do something very similar but with limited results at present for an extensive underwater game and as you can imagine, filling all that space and having it look as good as you’ve demonstrated is extremely difficult if you’re using your own custom detail meshes.

I found out that using Houdini might provide even better results for scattering, baking and generating other stuff.
This mesh-generator became obsolete very quickly.