Vegetation

  *to be updated

 There's two main ways of adding vegetation, each one has its own pros and cons.


   Method 1

   The first approach (not preferable) is to setup the position in 3ds max or your 3d software, then export big chunks of vegetation at once.


   Advantages

   • Is fast this way, less work and tweaking. Is possible to quickly add large amounts of grass by using a plugin like "Move to surface" by Miled Rizk, it will auto adjust to the surface just requiring a little polishment.

   • We have a perfect preview of how it would look like in-game before repacking.

   • SMD gets less entries than the method 2.

   • Works well with casted light sources (Type 2 Subtype 4).


   Disadvantages

    The performance hit is huge, and we have FPS spikes as the chunks load and unload, it isn't something smooth but rather very inconsistent.

    Due to the complex model, the SMD file will increase in size making the game take a while to load.

   • Poor modularity, in case we decide to change something in the future,as the grass will be joined together like one big piece.

    Can't be used for dynamic vegetation, the more vegetation in one model, the more unnatural it looks when working with SMX. If we want wind movement we must add each model one by one, which bring us to the next approach:


   Method 2

This is the preferable way although not the fastest and easier. It will use a single model, with coordinates xyz set to 0 in the 3d application. Then the position will be determined by the entries in the SMD file, one by one. That means if the area is big and require 1000 small grass models to fill it, we will have to add these 1000 entries in the file, each one with a diffent coordinate.


   Advantages

    Performance is better, as we move the vegetation gradually appears and disappears based on the draw distance. Because the model is small it fades well when entering the not rendered zone.

    Less FPS Spikes, performance is more consistent without peaks and valleys like the first method.

    Good modularity, in case we want to remove part of the model for performance reasons, or even change the appearance of the grass, we can easily edit that single model responsible for it, and the changes will be reflected for all those entries. That also means if the model has issues or is not optimized properly, it will directly affect the visuals and performance. So the main model should be made the best way possible.

    It works well with wind movement, using SMX is possible to add all sorts of animations that combined feels like the vegetation is alive, moving as the wind blows.

    SMD is smaller in size, thus loading tones are shorter.


   Disadvantages

    Very time consuming, depending on the size of the area.

   • When importing a model.obj from a extracted SMD, might be hard to identify which entry is which model. May require to centralize the pivot to the object, to find it by the coordinates.

   • SMD gets a lot of entries, making things confusing if not carefully edited.

   • May cause overload with casted light sources (Type 2 Subtype 4).


   SMX

One little tip is to create the first SMX entry, and then duplicate it. After that just invert the swing values using a minus simbol, this will make it move the oposite way. Now is just a matter of intercalating the entries, one SMD entry using SMX entry 1, the next using SMX entry 2, then SMX 1 and so on. In the SMD place them side by side to fill the area needed, and add a null entry with scale 0 as padding, then clone and use a offset to the values, moving it in the direction required by the terrain to speed up things.

In r108 I 've used only 2 SMX entries for the graveyard vegetation, but is possible to create more complex SMX setups to add variation. Using the cloning/offset tricky can result in a repetitive pattern, that will look unnatural. This can be solved by manually editing Y axis to add some random look to the grass. You can try to prevent this effect, by not align perfectly the models side by side, with non linear spacing.

Is very common when cloning to have the vegetation somewhere we don't want it, missing in some regions, or the edges looking squared like a step ladder. To fix this the models near the edge can be rotated in the Z axis to minimize this effect.

There's also a very common issue which is transparency. The grass is usually 2d using some alpha texture that hides part of the model, acting as a mask. The problem is that sometimes end up creating a aura artifact. This gets more visible the more vegetation overlap each other. I like to use SMX alpha value of 4, it's a little more aggressive then default 0, but gets rid of most of the aura issues. 

About the Billboard trees issue with shadow layers, I still don't now how to make it work without getting rid of the shadow layer. The problem is that these layers usually use ARGB alpha, or have SMX hierarchy 4 ~ 5, when the EFF has 3 I belive. So I don't know a way of adjusting it yet. With this layer getting higher priority, is possible to see a small line over the terrain.

One possible solution is to add billboards in the SMD. They will not follow the camera like the EFF does, and may look flat from some angles but at least it's better then having this issues. The EFF Tress usually are the last thing before the skybox, so the ideal order would be:


   Skybox

   SMD Shadow layer

   EFF vegetation

   SMD vegetation

But anything other than 4 or 5 make the shadow layer look strange.


I think the best way of dealing with this is to decrease the Z axis of the layer, to get it the close as possible to the main terrain. There are situations where the EFF billboard trees overlapping each other, produces the same aura on the edges. Using intensity = 0x400ff fix the edges, but the effect become dark and transparent so it's not a fix, as it creates other problems.