Jun
23
2014

Grass Maker for Mesh Terrain (wip)

grass_mesh_generator_1

Trying to make some basic grass/plants generator for mesh terrain.. (not terrain object).
(This is part of Mesh Terrain/Splatmap Tool)


FEATURES

– Editor plugin: Generates grass billboard planes(quads) over mesh surface (using raycast..)
– Checks splatmap color, if its over certain threshold, then add grass here..
– Atlas texture support for grass

TODO
– Find: Better / realistic looking way to distribute grass/plants around terrain.. (Ideas: using splatmask? terrain surface angles? or just fill the whole scene randomly? or floodfill?)
– Fix: floating meshes (maybe can take raycast hit normal, then adjust border vertices using that..?)
– Add: position randomness
– Add: multiple grass/plant types (using atlas now)
– Add: grass options (scale, main color, variation, …)
– Add: billboard options (how many quad planes, what group shape: single, cross, …)
Add: take vertex color from terrain, use in shader : done
– Grass islands/patches should also have less/shorter grass on patch borders..if that looks nicer.
– Could add trees, rocks into this later also..
– Optimized Quad plane > Use single triangle instead?
– Lawnmover script, why not! (just move vertices down or change atlas image to cut grass)
– Bending grass near player (shader: move vertices by player distance)
– Add probability percentage option for each grass type (now there are too many white flowers..) *Random weighted selection..
– Optimize far away grass (hide it if too far, fade in or show when closer)
Distribution: less grass if lower mask threshold : Before: “if (maskC.g>0.75f)”, After: “if (Random.value>1-maskColor.g)”
– Fix shader: some problems with lights? (too dark in some areas/angles) : added custom surface shader lighting using this

PROBLEMS
Cannot use GetPixel() to get pixel color from that position, with raycast & hit.textureCoord, if the mesh texture material is set tiled? : Just had to multiply hit.textureCoord with tiling value.
– Webplayer demo build would be 44 megabytes! Have to check whats happening there..

IDEAS
– Raycast floodfill : Shoot raycast on terrain, if suitable mask color for grass, shoot more rays nearby and place grass (with scale based on original startpoint), until hit different mask color..

INSPIRATION
Grassy terrain/hill photo
Grass/sand terrain render
Outerra grass

RESOURCES
Nvidia grass (some quad shapes here)
Free skyboxes

Image#2: Problems > Floating meshes (since the quad centerpoint is taken from single raycast hit..)

grass_mesh_generator_2

AFTER (26.6.2014).. floating shadow still quite annoying here..
mesh_grass_generator_unity3d_b

Image#3-4-5: Trying to get quad aligned with surface, without distorting texture.. argh, why I didnt do my maths homework at school ><

mesh_align_surface_problem

Almost solved (by a friend with some mathemagic), now there are those color lines to indicate end vertex positions on surface.. not yet sure what happens to texture when quad is stretched over there..
align_to_surface_vectors mesh_align_surface_problem_unity_fix

Image#6: Added perlin noise to grass positions, looks ok from nearby:
mesh_grass_generator_unity3d_a

Image#7: Taking grass color/tint from current texture under it
mesh_grass_generator_unity3d_color_variation

Image#8: Using sprite shader, looks nice also (no shadows or waving though..and  forgot to set bottom vertex alpha to 1) *click images for full size
mesh_grass_generator_unity3d_sprite_shader

Image#9: Using texture atlas for grass (*btw. these plant textures are from : https://www.assetstore.unity3d.com/en/#!/content/6

mesh_grass_generator_atlas_texture_unity3d_view2

Image#10: 2 Sided lighting shader, added skybox and fog. (around 560 drawcalls, almost 2.5million tri’s)

mesh_grass_maker_unity3d_wip_terrain_1

Image#11: New random distribution probability threshold & height scale from mask color. It gives those random smaller grasses nearby the normal grass area

mesh_grass_maker_unity3d_wip_terrain_distribution_2

 

 


13 Comments + Add Comment

Leave a comment to mgear

Connect

Twitter View LinkedIn profile Youtube Youtube Join Discord Twitch

UnityLauncherPro

Get UnityLauncherPRO and work faster with Unity Projects!
*free unity hub alternative

@unitycoder_com

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.