Wednesday, February 19, 2014

Loading Terrain Heightmap Data Via C# Script in Unity

For my real-time strategy game Zyrtuul I need to be able to load different landscapes at run-time. A fundamental part of this is loading terrain heightmap data from script. I implemented this last night. I noticed that many people have been asking how to do this online, but I did not see any complete solutions presented. It turned out to be significantly easier than anticipated. This implementation allows you to save your heightmap using any image format (I assume it is saved in Assets/Resources/Heightmaps). Simply attach this script to your terrain object and it will load up the specified heightmap automatically.



Sunday, February 16, 2014

Experimental Art and Design Work for Zyrtuul.

Work has been busy at the moment and I was feeling a bit worn out, but I still felt like doing work on Zyrtuul. So I decided to take a break from programming for the weekend and focus on the artwork instead. I started off searching for source material and looking for inspiration online, in an effort to settle on an overall look for the user-interface, splash screens and overlays of Zyrtuul.

For a while I was attempting to take rendered images of various vehicles, super-impose them over a background and then modifying them in Photoshop to fake a hand-drawn / painted feel. I was initially happy with the results, but after comparing them to other games' splash screens I realized that, while they were okay, they weren't great.




After that I decided to stick with my original plan, using more generic spacey images, which are much easier to make (there is a lot of good source material out there that you can combine to get a unique-looking, visually appealing final image). The image below is still experimental and not final, but gives some indication of what I'm thinking the overall look and feel of the splash screen will be.



I had already designed the look of the mission select screen, but I wasn't 100% satisfied with its current state so I spent some time tweaking that as well. I still don't think it is perfect yet, but it will suffice for now. The current mission select screen can be seen in the image below. It may be too dark to see, but there is a square spot reserved for a top-down image of the map near the top right of the screen. I haven't implemented that yet though (the game is still in the rough early stages).




As the artwork starts to look more polished, elements that I previously liked no longer seem as good as they did. This was the case with the in-game overlays (which I put together sometime last year). These include the minimap border and the 'command panel' (that is, that panel where command buttons such as 'move', 'attack', 'stop' and 'patrol' would appear). In addition to that, I felt it was time to change the way resources are displayed (previously I just had placeholder text at the top-right of the screen). I have put all three in-game overlays into the image below to show what they currently look like.

At the top is the minimap border. The minimap would appear in the square black region. Below that is the resource display panel. When in-game, a number will be shown for each resource type. Below that is the command panel. When in-game, if a unit (that is, a vehicle or building) is selected, buttons will be displayed in the command panel. These allow you to issue commands to the unit.



I was happy with the way the terrain looked, but I felt that some textures looked better than others. I spent a few hours making new terrain textures yesterday. I wanted uber-high levels of detail, and so I composited various images together for the diffuse maps (I've had a lot of practice so I'm getting pretty good at it). I then manually constructed normal maps in Photoshop. Ordinarily, converting the diffuse maps to greyscale and then using that as a heightmap will, although a cheap hack, do the job when using it as input to construct a normal map. However, I wanted a very specific look, and so I instead (painstakingly) constructed the height and normal maps. It is difficult to clearly see the results from the screenshot, but they look very good when viewing the game at full size (especially when combat is occurring, due to the way weapon lights interact with the normal maps).



The final bit of work on Zyrtuul for the weekend was done this morning. I wanted to settle on the game factions and their banners / logos. This took surprisingly long (it took me many hours to do the banners). This is what I'm sitting with at the moment (the logos at the top-right of the image).


Deciding what the factions would be was difficult -- it often feels like most of the good ideas are taken already, and so coming up with something genuinely original seems impossible. They say that most stories are just variations on a few common themes, and so I consoled myself with that thought and decided to just settle on something.

The idea of an empire vs rebels is very cliched for obvious reasons, but Star Wars wasn't the inspiration for that (although now that I have made that connection, I'm wondering if I need to change this). Anyway, I may end up changing this, but the inspiration for this was actually Spartacus.

I thought the idea of designated slave planets would make for a good story -- entire planets whose populations are automatically born into slavery. Groups of slaves are periodically 'harvested' from these planets and brought to work on the elite planets. And, of course, such a situation would inevitably result in rebellion, which would then require those in power to quickly squash it to prevent other slave planets from joining in.

As for the Smugglers' Guild, well they have no interest in such conflicts but occasionally get involved when it profits them. The Smugglers' Guild is amoral and neutral, but if they can get away with attacking either side so as to benefit from the spoils of war, they will not hesitate to do so.

Tuesday, February 11, 2014

Implementing Fog of War

Last night I began implementing fog of war for Zyrtuul, and made some decent progress. Tonight I spent a few hours and got it working properly.

My implementation uses render-to-texture functionality, and involves the following steps:

- Create an orthographic camera that renders the scene from a top-down perspective. This camera does not render any of the usual objects. It will only render special objects called 'fog of war revealers'.

- Attach a quad to each unit in the game. This is simply a flat upward-facing rectangle positioned just above each vehicle or building. I call these 'fog of war revealers'.

- Map an image which will control the way fog of war is revealed for units. I initially used a simple black image with a blurred white circle in the middle, but then experimented and am currently using the image below (made it in Photoshop). This simply makes the fog of war boundaries more interesting. Basically, each unit will be surrounded by an area of 'transparency' with the following shape (completely arbitrarily chosen at the moment and definitely subject to change).


- Create a render texture. This is a surface that the fog of war camera will render to. That is, instead of rendering to the screen, it renders to a separate image in memory. Set the fog of war camera to render to this texture.

- The first time the camera renders it clears the image to black. It then disables its clearing behaviour so that for subsequent frames the image is not cleared. This allows the fog of war state to be permanent. If we wanted the fog of war to re-appear at locations where there are no longer any units we would skip this step and have the camera clear the render target to black every frame.

- Set the blend mode of the fog of war revealers to be 'additive'. This means that wherever the unit moves, the image above will be added to the black background. The following is a visualization of what the render texture might look like if there were four units in the scene.



- Render a large plane at the height of the terrain. This will cover the entire scene. This plane will render in both the main view and the minimap view.

- Map the render texture to this plane's material. What we are doing here is having the render texture control the alpha state of this plane. Thus, the white areas will be transparent but the black areas will be opaque.

- Set the depth buffering behaviour of this plane's material to 'no z-test' and 'no z-write'. This will make the plane always render on top of anything (so that we don't have to concern ourselves with situations where objects are above the plane). Also modify the render order of the plane so that it renders after all objects that must be obscured.

Below are some screenshots of the game with fog of war enabled. The turrets do not currently have fog of war revealers attached to them (so they can currently be obscured by fog of war, which I'll fix later).



Sunday, February 9, 2014

Zyrtuul Screenshots.

I put a lot of work into a new pet project toward the end of last year -- a real-time strategy game that is currently going by the name Zyrtuul. I took a break for a few months but recently decided to do some more work on it.

I've added various new vehicle types. At the moment I'm focusing on getting the art in and looking good rather than on implementing specific vehicle capabilities. I quite like the new harvester. As it gathers red suphur (visible in one of the screenshots, the red stuff on the ground) a heap of red sulphur gradually grows on the back of the vehicle, until it is full.

I'm experimenting with a darker, more grim sci-fi look. I've taken out the trees and water and have put in rocks and lava instead. I've also removed the grass terrain textures and replaced them with dark rock / dirt textures. The look I'm going for is that of a barren planet. To further promote that atmosphere, I've subdued the lighting and given it a bluish tinge. The vehicles themselves are quite detailed, and when combat happens there tends to be a lot happening on screen, so I thought it best to keep the terrain dark and unobtrusive.