Development Pt.4 – Environment
Let’s focus on environment for a bit. First thing that comes to my mind when talking about environment is nice and neat visuals, . But I would say that there are 2 main elements that create vide game environment, which I would say is visual aspect, and functional aspect as well. Everybody knows what visual aspect is, so I’m going to focus more on second one, functional aspect of the video game envrioment. It could include simple functionality like environmental story telling, arranging objects to tell a story of great battle, or ambush in a forest, a story which is communicated through the visual representation only, without a need of extra description in form of audio narrative or text. Secondly, it could include aspects that can directly affect game functionality/mechanics, like finding specific creatures or resources on some parts of the map only (crocodiles in tropical parts of the map, mammoth in arctic areas of the map…etc.) , or during the specific time of day (i.e. vampires during a night time, werewolves during a full moon only…etc.). Or we can even combine time of the day with a location. Let’s say you need “thick werewolf skin” to craft piece of armor. We know that we need to look for werewolves during a full moon only, but where to look for werewolf with a “thick” skin? Probably not in tropical areas, but rather in freezing, winter environment, where they have adapted to harsh winter conditions by developing a thicker skin that protects them from freezing temperatures. So this type of creature could be found in snowy forests during a full moon phase only. We could also include environmental story telling, to allow player find werewolf faster by placing some werewolf footprints leading to his den…etc. It would help to avoid frustration from spending great amount of time by looking for this specific enemy. Ok, enough talking, let’s jump on development part.
Environment – Visual Aspect
For a change, let’s focus on visuals a bit. Taking into consideration game setting, which is fantasy world with a bit of realism, I imagine dense forests, castles and ruins, remains of ancient civilizations…etc. So let’s start with the forest and floiage. First time I started thinking about creating a game ready tree, I thought “nah, easy, it’s just a trunk and branches with alpha cut-out”. Well, in theory, yes. But in practice, hell no. Making nice and believable realistic foliage that can run in real time is very complex process. Especially because it includes transparency, which is very expensive thing to calculate in real time, and as far as I know, it can’t be done using deffered rendering method, but only by using more expensive forward rendering. Ok, let’s get back to the trees topic. Let’s define first what makes trees and foliage believable. At first, it’s light scattering. A nice effect created by light rays passing through leaves, which is created using additional textures. Secondly, it’s movement (branches and leaves sway…etc.), which is created mostly through the shaders, using WPO (World Position Offset). At this point, knowing complexity and time needed to create enough foliage assets in high enought quality, I’ve decided to pay for a Speedtree license, which is very afordable for indie developers and would save me plenty of time. But, it wouldn’t let me sleep if I wouldn’t explore possibilities how to create such an effects.
Foliage and wind sway
As mentioned before, this is usually done through the shaders, by moving vertices. Let’s approach it as modelling or texturing process, primary detail first (offsetting a whole tree), then secondary (offsetting branches and twigs independently from tree trunk) and tertiary (offsetting twigs independently from branches). So first, i want to get wind direction, which we can store as Vector3 variable (but I’m going to use only first 2 vectors, disregarding Z vector). This variable tells me which direction wind blows on world X and Y axis, and will be used to define direction of vertex offset, and I’m also going to use another variable, wind strength, which defines amount of vertex offset. First thing I want to do is bend a whole tree depending on wind direction.
So everything works as expected, tree is bending, branches and twigs are swaying independently from tree trunk, and wind has limited effect on branches that are in cover, behind a tree. But, as I meantioned at the start of this topic, I’m going to use Speedtree, since I really don’t have a time to create rich variety of tree models. But it was nice to explore this topic and learn something new.
Small note regarding performance and optimization. Since this method is using multiple UVs, we can simply create simplified versions of the material, and assign them to the different LODs respectively.
- LOD0 – Highest detail, using 3 UVs. Tree trunk, branches and twigs are animated.
- LOD1 – Medium detail, using 2 UVs. Tree trunk and brnahces are animated.
- LOD2 – Low detail, using 1 UV. Only tree trunk is animated.
- LOD3 – Static mesh, no vertex animation.
Leave a Reply