pingpoli.de



GameDev 2019 Week 36: New Desert Map

Distant Terrain, Models, Desert Map Timelapse

16.10.2019 - 20:52
Distant Terrain

For quite some time I wanted to make a desert map, but my editor only had support for ocean at the edges. I could have made a desert island, but when I think of deserts I don't really think of islands. So instead I added a new feature to my map editor - distant terrain - terrain that starts at the edges of the playable map and goes into the distance until it disappears in the fog and the sky.
I started with a simple flat colored terrain. But flat terrain is way too boring so I added hills to it next. I added a window to the editor for the distant terrain settings. It is possible to set the distance for both flat and hilly terrain and only for the hills the elevation, the number of subdivisions and the distance where the hills start are also customizable.

Far Plane Distance and Shadows

When I was working with the distant terrain I realized that my hardcoded far plane distance wouldn't really work for it, so I had to change the code to add support for a variable far plane distance and added a setting for it in the editor. Changing the far plane distance also alters the sky quad accordingly. In addition to this I was using the far plane distance as the distance for the largest shadow cascade, but when increasing the distance everything outside of that distance was rendered in shadow or had very blurry shadows when increasing the size of the largest shadow cascade with the far place distance. The fix for this was very simple, just keep the size of the largest shadow cascade constant and render everything outside of it without shadows (it will be very far in the distance so it is hardly noticable that there are no shadows). I have no idea why I had everything outside in shadow before, probably to see where the shadow cascade ends, but it makes so much more sense to have everything outside in sunlight. I actually decreased the size of the largest shadow cascade a bit, so the shadows in the distance are a little bit more detailed.

Better Hills

The hills were looking a bit boring still so I added more details. First I added a random devation in the x and z direction so not all peaks are on an exact grid. The probability of a grid position to be a hill is now greater the further in the distance a hill is, the terrain in general has a slight elevation increase towards the distance and hills further back are a little bit taller than ones closer to the playable map. This makes the hills look a lot more interesting than just random elevations. Additionally, if the hills look a bit weird, just press the create button again and they are going to look different and hopefully better.

Colors

Next I worked on the color of the distant terrain. I realized that my implementation wasn't optimal and I changed a few things so the color of the terrain could be changed without changing the terrain itself. I added a color selection button to the options window and also allowed the vertex colors to have small variations from the selected color to make the terrain look a little bit more interesting.

Texture

Most of the maps however are going to use textures, so I added support for textured distant terrain as well. The tile size of the distant terrain tiles is a lot bigger than the tile size of the playable map, so just having one texture tile per terrain tile would look very coarse and weird. Instead I used a nice trick, when the texture wrap setting is on repeat the uvs of the vertices can go beyond 1.0 and the texture is scaled down and repated. With this I could add a texture scale to the options window that controls how zoomed in the texture is. I found that having the distant terrain texture a little bit coarser than the playable terrain looks the best.

Models

Now that there is hilly terrain with a texture, it also needs some models to look more realistic. First, I needed a function that can calculate the elevation at every position. Because the terrain is made out of triangles this is the intersection between a vertical line at the x|z position and the triangle responsible for that position. The distant terrain is mostly decoration in the distance there is no need to manually place models there, so I only added a script that can mass place models on the distant terrain.

Water

At first I didn't add the distant terrain to the water reflection shader, because I though they were mutually exclusive. But in reality there are a lot of arguments to have an ocean and some land at the horizon or maybe an island in a lake. So I added the distant terrain to the water reflection shader and it looked really good.



Saving & Loading

The next thing and always one of the more annoying tasks is to make sure that everything is saved properly to the editor project file and can be loaded correctly again. To get it to save and load I had to refactor some aspects of the distant terrain code once more and split them properly into a data and a renderer class. I also found a small optimization for the renderer. After the refactoring the saving and loading was fairly straight forward to implement and worked soon thereafter.

Game Export

At this point it was finally time to add the distant terrain to the binary exporter that exports the map so the game can import it quickly. When I exported a test map and loaded it into the game the distant terrain was exported and imported correctly, but I noticed a massive bug. The ambient and diffuse lighting values were never saved in the exported maps. The other maps used the default values so I didn't notice it, but I made the desert very bright and it was obvious that the map was a lot darker in the game, but it was very easy to fix. Importing maps with a different far plane value didn't work at first, I had to change some of the game rendering code to make it work.

Ludum Dare Weekend

2 minutes before midnight on Friday I realized that this weekend was Ludum Dare and decided to participate again very spontaneously, so I took a few days break from working on my normal game to make another one. I also wrote a Post Mortem blog post for my ludum dare game.

Models

To get back into my normal game I made a western house in Blender as a highlight piece for the desert map. Actually the week before I made a few more smaller models here and there, 2 more rocks, a prickly pear cactus, a dead bush and a joshua tree.



Cleanup

Before making the desert map and moving on to something else, I figured I should tie up a few loose ends. While working on the distant terrain I mostly focused on the hills, because that's the type I am going to use a lot more often than flat distant terrain. Therefore the flat distant terrain was missing a few features that were working on the hills, most notably there was no way to apply textures to it. I was using a different rendering system for flat terrain, because I could render it with fewer quads that way, but that way couldn't support textures. But in all reality the performance cost of a few more quads is basically zero, so I changed the flat terrain creation and rendering to use the same system as the hilly terrain, only with an elevation of zero at every tile.

Editor Improvments

While using the editor a little bit for testing I also wrote down a few updates it needed. Firstly, I changed the terrain editing brush completely and added different types of terrain editing: increase elevation, decrease elevation, flatten and set. Previously there was only the set option, which was very annoying to use. I also added a quick little shortcut: when the brush is in either increase or decrease elevation mode, holding shift while clicking will do the opposite, with this the terrain can be edited very efficiently without having to move the mouse down every time to change the brush mode.
Additionally I added a button to the numeric layer window to hide the numeric layers again.
And finally I created the option for the texture brush to place a texture tile only with a certain chance. This makes it easier to mix textures.

Blender is stupid

I wanted to make a water tower in Blender, but after 2 hours or so I gave, because I couldn't create a good steel framework under construction for it. Basically all I wanted to do was take a bunch of lines and make them 3D, but there is not good way to do it in Blender. Neither the skin modifier nor the curve bezel produce good looking results without any artifacts. However, the math for this is quite easy: take the direction of the line as a vector, take the up vector, calculate their cross product, take that result and calculate the cross product between it and the line direction and you have the coordinate axes of the line and you can create a cuboid from there.
So I had to make my own program to do this: export the lines from Blender, import the file to my program and it converts the lines to cuboids and exports it as an OBJ file again, which can then be imported into Blender again and you can continue from there.
With that program I was able to make a nice water tower and a desert windmill.



Desert Map

And finally, after all of this, I could make my desert map:






by Christian - 16.10.2019 - 20:52


Comments

555
by dwUQQUrL - 31.08.2022 - 00:32
Social Media:  © pingpoli.de 2020 All rights reservedCookiesImpressum generated in 10 ms