Grass Maker for Mesh Terrain (wip)


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


– 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

– 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

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..

– 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..

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

Nvidia grass (some quad shapes here)
Free skyboxes

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


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

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


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:

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

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

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


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


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




12 Comments + Add Comment

Leave a comment


Subscribe to Blog via Email

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