Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Procedural Generation, Vegitation Placement

Discussion in 'Scripting' started by Lorinthio, Aug 7, 2015.

  1. Lorinthio

    Lorinthio

    Joined:
    Aug 7, 2015
    Posts:
    39
    As a basis, So far my generation uses a port of LibNoise, That combines Ridged Multifractal noise (for mountain shapes), flattened Billow(for plains), and some Perlin noise to make the plains a bit more interesting.

    That is the gist of my generation basis, as a result it makes some interesting and (i think), pretty terrains.



    In terms of placing the texture, I run a Coroutine to iterate over each "Chunk"/terrain to check the slope/steepness and paint a grass texture if the slope is less than a limit. Following that iteration, I iterate over the terrain to place the trees and bushes in the green areas. This results in the stone mounds, and the green/flattened areas.

    THE ISSUE
    Steepness is the only thing I check in terms of placing grass details, and it causes the issues seen in this picture...


    My Question
    What would be another way to check for a smoother area of grass? Should I add a "Nearby" check (Check around within 2 units for other grass)?

    Or is there simply a better way to procedurally place these features other than relying on slope calculations?

    I would like the grass to end up near other vegitation, but feel like placing grass decal based on placed trees and bushes may be a bit overkill.(But may possibly be the solution.) Placing grass based on bushes/trees would look like this...




    So Unity Community! Your thoughts please!
     
  2. Lorinthio

    Lorinthio

    Joined:
    Aug 7, 2015
    Posts:
    39
    Casually inserting another picture for good fun, and as a side question.



    With the ridgees on the mountains they are green as well. My texture painting uses the following formulas...


    Code (CSharp):
    1.  
    2.             //[0] is Grass
    3.             //[1] is dirt
    4.             //[2] is stone
    5.                 splatWeights[0] = 4.0f - (Mathf.Max(steepness - 5f, 0f) / 8f);
    6.  
    7.                 //Texture[1] (dirt/grass), Grass will fade to dirt at higher altitudes
    8.                 splatWeights[1] = 4.0f - splatWeights[0];
    9.  
    10.                 if(splatWeights[1] > splatWeights[0]){
    11.                     splatWeights[1] += 0.5f;
    12.                 }
    13.                 // (Stone/Cliff) is stronger at higher altitudes, and steeper terrain
    14.                 // maxHeight-200 - height-200 / maxHeight-200, Gets fractional distance between
    15.                 //            200 and maxheight
    16.                 // multiply by strength of 5
    17.  
    18.                 if(height > 200){
    19.                     splatWeights[2] = 5.0f * ((height - 200) / (terrainData.size.y - 200));
    20.                 }
    I normalize the values at the end of computing the strengths. But my question is what would be a good way of removing the green on the mountains? Boosting the strength (5.0f)? A side effect is it turns my valleys more into a grey, which is undesirable
     
  3. Lorinthio

    Lorinthio

    Joined:
    Aug 7, 2015
    Posts:
    39
    So I may have answered my own initial question, "How to make grass placement 'prettier'". I think I'm just going to do a few passes of Cellular Automata after I place grass near other details. Cellular Automata is usually used to make more realistic cave shapes. So this should make for decent patches of grass and will bring in the shape towards the middle. This will remove the odd grass lines as well as make for nicer shapes of grass!

    As for the texture painting of grass, I tried boosting the strength of the Stone texture, and it made it look a bit better but not removing the issue entirely. Which is fine considering grass grows on cliffs sometimes. ;)


    SO, off to Cellular Automata!
     
  4. eisenpony

    eisenpony

    Joined:
    May 8, 2015
    Posts:
    971
    Not really my area of expertise but..

    I think picture 2 looks crappy with your strips of grass, while picture 3 looks great! I don't know what a cellular automata is but I'm not sure you need it.

    As for the grassy bits on the sides of mountains, I agree that any flat surface will tend to grow some vegetation but the type and amount is usually affected by altitude. Perhaps you could include an altitude in your vegetation placement algorithm.
     
  5. Lorinthio

    Lorinthio

    Joined:
    Aug 7, 2015
    Posts:
    39
    Yeah, I feel like Cellular will be a bit overkill, while creating steady results like picture 3, it would be another 4-5 iterations over the terrain simply to smooth grass patches out.

    But yeah picture 2 is the issue I'm aiming to remove, and relying on the slope of terrain causes that issue at points unfortunately.

    But thanks for leaving a comment on this!
     
  6. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    The cheapest solution to two is to simply add some random offset to each piece of grass.
     
  7. Lorinthio

    Lorinthio

    Joined:
    Aug 7, 2015
    Posts:
    39
    Ah so it would become patches instead of lines, that makes sense too. But I'd like to fully remove the lines or patches in general. Trying to peal back the tiny/ugly issues in the generation before I proceed and make more =D

    I'll post a picture when I got it ironed out
     
  8. Scrowneck

    Scrowneck

    Joined:
    Nov 18, 2018
    Posts:
    2
    I'm stiiiiiiiiiiiiiiiiiill waiting...