Sunday, May 26, 2019

Milestone: Procedural generation finished

The procedural generation is finished! Here comes a showcasing of the results.

Showcasing

LINK TO GITHUB REPO

Taking my poor Windows 10 to its absolute RAM limits, I increased the amount of grass blades from 50 000 to 100 000. This allowed for a denser, more realistic looking grass field. This is the result.




This implementation is a recreation of Markus R. Tillman's bachelor's thesis. In a number of ways, it is also an extension. The two most important ways ones are
  • Perlin noise determined color distribution
  • Grass blade variance
 See the below comparisons.




Most notably, the uniformity of the grass blades and their color has been broken, giving a much more realistic look to it.

Below is a compilation of what has been implemented.

 

The grass field
  1. has a Perlin noise map for ground height.
  2. has a Perlin noise map for color distribution.
  3. has a texture.
The grass blades
  1. have textures corresponding to the grass field pixel below it.
  2. vary in color depending on Perlin color map.
  3. simulate lighting.
  4. have randomized positionings.
  5. have normal distributed rotations, heights, widths and inclinations.

What has yet to be implemented: 

  1. Varying densities of grass.
  2. Simulated down-trodden paths through the grass field
  3. User interface
  4. Level of Detail optimizations
Currently, the only way of varying many of the parameters is to go directly into the code. It would be great to have a user interface for manipulating the most relevant and meaningful parameters. But due to time constraints, this will not be implemented.

Variation in grass height, width and inclination

Although the grass field does look great with merely variation in rotation, position and color, it is meaningful to add the possibility to vary in the height, width and inclination of the grass blades. Using normal distributions for all of these attributes (just like it has been done with the rotation), values giving good looking grass variations have been chosen. The grass field now resembles a much wilder field when looking closer.

Grass field with variations
Pictures of the variation in height. Difference in inclination can also be seen.

However, a problem was also discovered during this iterative cycle. Although it's very, very difficult to notice, some grass blades are sometimes levitating in the air because of their random positioning.

A couple of levitating grass blades
This problem is again barely noticeable when not hugging the ground, but it would be good to remedy it. The way the algorithm works at the moment is that it assigns the y-coordinate depending on which vertex of the field mesh it is currently at. The problem with this, naturally, is that when randomizing the position, you also need to have a corresponding change in the y-coordinate, since the field changes elevation depending on its x and z coordinates. The current implementation does not tackle this.

An approximative solution is to at least try to reduce the distance the grass blade has from the closest point on the field. An easy implementation is to look at how far away the randomization brought the grass blade, and then either let the grass blade's y-coordinate remain the same as its home vertex or let it become the average of two vertices. Long story short, in some cases the y-position will now be the average of two vertex positions, rather than always the y-coordinate of the vertex that is currently being iterated on.

Less drastic levitations

That's the final procedural parameter implemented.

Lighting

I've now successfully reimplemented the lighting model suggested in Markus R. Tillman's bachelor's thesis.

Lighting model, darker at the base, lighter at the tip

A simple explanation of how it works is as follows: The closer to the base of the grass, the darker it becomes. The darkness factor, so to speak, is linearly interpolated between the values of 0 and 1.5. This means that at the top of the grass blade, there will be a light color, and at the base there will be a black color.

A closer look

Colorization

Now both height and color is set properly using two Perlin noise maps.

Two Perlin noise maps to generate height and colour of grass blades

Now what's next is to implement a lighting model. One way of doing so is darkening the pixels closer to the base of the grass. I'll attempt that first.

After the crucial implementation of a lighting model, I will randomize the grass blades geometry (randomized height of blade, width and inclination).




Milestone: Height, Texture and Generation (Minimum Viable Product)

There we go. It is now possible to procedurally generate a grass field and populate it with grass blades.

Goal inspired by Markus R. Tillman's bachelor's thesis
Each grass blades texture is a randomized pixel of the field texture. It's a recreation of the methodology used by Markus R. Tillman in his bachelor's thesis. There are yet a couple of features to implement, most notably colorization and lighting.

Peace out.

Saturday, May 25, 2019

Grass generation

So I've managed to generate the grass blades at each vertex of the grass field mesh.

The grass blades are the purple dots everywhere

They are barebone though - they don't have any texture. Nevertheless, they do have a pretty decent mesh. The mesh for these grass strands are inspired by this picture from Markus R. Tillman's bachelor's thesis on DIVA (link here). The figure below is a screenshot of the illustration made by Per Axmark which my implementation attempts to recreate.


In my project, however, I only create the highest level of detail grass blade. There are three different ways the grass blade geometry can vary.

  1. The width of the grass blade.
  2. The height of the grass blade.
  3. The inclination of the grass blade.
The next step is to implement variability in the color, depending on lighting and the texture the grass stands on. This will be implemented in the coming posts.

Saturday, May 18, 2019

Project Title: "Procedurally Generation of Grass Fields in Unity"

So far, I've come up with this title:

Procedurally generating grass fields in Unity varying by density of grass, ground heights and grass color.

LINK TO GITHUB

I will work iteratively, meaning that whenever one parameter is finished (being able to vary the density of the grass) that is when the next parameter will be worked on. In that way, I'll always be working on a functioning product rather than trying to put it all together in one go. This is an early prototype of the ground. The grass will be added on top of the ground at the appropriate color and height.

Plane for the grass field in Unity. Grass will be added on top in the appropriate color and height.

Furthermore, I'll be working towards an important stretch goal. A more unique addition would be to include the "human factor" in this procedural generation. I was thinking first along the lines of having dirt on the ground, but figured it wouldn't be so different from some of the other attributes. Instead, I think it might be interesting to add in down-trodden paths. When people walk over the same line of grass a long time it creates a visible depression in the grass. I would like to let the user to pick a line and then have the program generate that path through the grass with procedural generation.

When the other goals are fulfilled, this will likely be the next one.