Vegetation - Part 1

  *to be updated


Introduction

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


   Method 1

The first approach is to setup the position in 3ds max or your 3d software, then export big chunks of vegetation at once. I recommend it to fill the "out of bounds" areas as it may not look convincing enough during a closer inspection.


   Advantages

  • Less time consuming, less work and tweaking. Is possible to adjust large amounts of vegetation quickly, 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 exactly preview of how it would look like in-game before repacking.
  • SMD have fewer entries, things are less polluted and easier for editing.
  • Works better with casted light sources (Type 2 Subtype 4) as it requires less entries.
  • May work better with BLK as it requires less entries.
  • Low Spec Friendly, especially when the model uses a single mesh.


   Disadvantages

  • The pop-in is huge, and we have FPS spikes as the chunks load and unload, it is not something smooth but very inconsistent and choppy.
  • Due to the big .obj, the SMD file will increase in size making the game take a while to load, uses more memory.
  • Poor modularity, in case we decide to change something in the future, as the vegetation will be joined together like one big piece (unless we export it with multiple meshes, see the end of the post link).
  • Can't be used for dynamic vegetation, the more vegetation in one model, the more unnatural it looks when working with SMX because it has only one axis to swing. 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 produces the most convincing vegetation. 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 requires 1000 small grass models to fill it, we will have to add these 1000 entries in the file, each one with a different coordinate.


   Advantages

  • Pop-in 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 appearance modularity, in case we want to remove part of the model for performance reasons, or even change the appearance, 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, using a single mesh.
  • 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, much more convincing.
  • SMD is smaller in size, uses less memory, loading times may be shorter.


   Disadvantages

  • Very time consuming, depending on the size of the area.
  • Poor repositioning modularity. When importing a model.obj from a extracted SMD, it might be hard to identify which entry is which model. May require manual selection and detachment, centralization of the object pivot, in order to find it by the coordinates. or lower the idx count to find it by trial and error. I recommend having a saved project in the 3d Software with numbered layers by entry, this can make life much easier. 
  • SMD gets a lot of entries, making things confusing if not carefully edited.
  • May cause overload with casted light sources (Type 2 Subtype 4).
  • Adds extra overhead to the engine and may trigger the Locked Camera Issue.
  • Performance may be worse when compared to the same poly count using Method 1, especially if in that Method the model is "Single Mesh".
  • May not work well with BLK if the overload is already present, like when we have hundreds of entries, some of them may not spawn when entering the BLK triggerzone. *tested
  • We don't have a preview of how it will look in the 3d Software like the Method 1, requiring to restart checkpoint to check in-game for each model.
  • Not Low Spec friendly, requires a beefier CPU.


   SMX

One simple tip is to create the first SMX entry, and then duplicate it. After that just invert the swing values using a minus symbol, this will make it move the opposite way. Now is just a matter of intercalating the entries in the SMD. Set one SMD entry using SMX entry 1, and 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. Adding null entries with scale 0 can be useful as padding, but may add extra overhead and trigger the Locked Camera issue if the area is already close to the limit.

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 vegetation. 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, it doesn't work very well with single-sided models though.

There's also a very common issue which is transparency. The vegetation 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 (Color_A = 0x4), it's a little more aggressive then default 0, but gets rid of most of the aura issues. It disables the blending of the model, at cost of some aliasing. 


Color_A = 0x0

Color_A = 0x4

Color_A = 0x0

Color_A = 0x4


The Offset[8..11]  is useful to tweak models that uses transparency map_d it can fix the edges, not recommended for shadows as it will break the softness of the edges. For example: Offset[8..11] = 0x8 is good for vegetation. 


Offset[8..11] = 0x8


Offset[8..11] = 0x0


Offset[8..11] = 0x0


Offset[8..11] = 0x8


Sometimes even with the right setting some artifacts can persist, it happens when a model is on top of another with lower hierarchy. This can be fixed by adjusting the hierarchy of the transparent model to be higher than the diffuse one.


Watchtower with lower hierarchy than Tree (Fixed)


Watchtower with high hierarchy than Tree


About the EFF 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 conflicting with EFF, so I don't know a way of adjusting it yet. 

One possible solution is to replicate the EFF billboards with SMD. They will not follow the camera like the EFF does, and may look fake from some angles but at least it's better then having this issues. The billboards usually produce artifacts with other effects like fog and the baked shadows. For the baked shadows is possible to see a small line artifact over the ground. 

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

More info can be read here.