August 2012

Battlefield terrains (and some technical stuff)

As you might have noticed from pretty much all battlefield-related screenshots I’ve posted over the last months (or even years), the battlefield was always surrounded by water (and earlier on by some kind of bowl), and I was never really happy with it. Especially when fighting in a desert scenario, surrounding it with water looked pretty odd, and adding a sandshader didn’t make things any better. But just having the battlefield floating in the air didn’t look good either, so I recently sat down and finally decided to add real 3D terrain surrounding the battlefields, with different terrains depending on the setting you’re fighting in.

Since this involved some technical stuff that could be interesting to some other (game) developers out there, this posting dwelves a bit deeper into the technical backgrounds than usual, so (work-in-progress) screenshots first and technical stuff after the break (in case you’re interested) :

And now on to the technical stuff…

Creating and rendering the terrain itself is pretty basic and forward. I used my own TerrainTextureGenerator to create different terrain textures for each of the battlefield settings, and also made a heightmap for it, with the center part being flat and some surrounding mountains. When a setting is loaded, the texture assigned to it is loaded and a display list for the terrain is created.

Now you might think it’s enough to just render the battlefield at the floor level ot the terrain at it’s center, right? Sadly it isn’t that easy. The problem is that I want the base height of the hex tiles to be the same height as the floor level of the terrain, and since hex tiles can be lower than the base height (e.g. water hex tiles), the terrain’s floor plane would shine through in those spots, making those lowered hextiles invisible and giving an odd look.

So to fix this I (once again) used the stencil buffer, an OpenGL buffer that allows you to mask out certain parts of the framebuffer, allowing for a lot of different effects. So when creating the display list for the hex fields I also create a (simplified) version of them for stencil rendering. Now before rendering the terrain, I render these simplified hex fields into the stencil buffer without touching any other buffers (color, depth or alpha) :
glColorMask(False, False, False, False);
glStencilFunc(GL_ALWAYS, 1, 1);
glCallList(HexBattleField.StencilListID);[/delphi] After this, the stencil is set for all fragments covered by the stencil displaylist for the hextiles of the battlefield. The next step is to setup a stencil compare function that’ll only render where the stencil doesn’t equal 1 when rendering the terrain :
[delphi]glColorMask(True, True, True, True);
glStencilFunc(GL_NOTEQUAL, 1, 1);
[/delphi] Now rendering the terrain will spare out all fragements with a stencil value of one, resulting in a cutout where the hextiles have been drawn into the stencil buffer :

As you can see the terrain’s base height is aligned with the floor height of the terrain and rendering hex tiles below floor level works as expected, and no terrain will shine through. The final step (see the right screenshot) now was to add bordering hexes that fade into the surrounding terrain texture to get a nice and (mostly) seamless look :

And although the terrain isn’t overly detailled or using any fancy shaders this looks already much more realistic and atmospheric than the old version with the surrounding water plane.

Oh, and I btw. noticed the my very own glCapsViewer was mentioned in the OpenGL 4.3 Overview-BOF at SIGGRAPH’12. Pretty nice…

Delphi / Pascal header for OpenGL 4.3

Just a quick heads-up to let you know that I’ve updated our “official” OpenGL-Headers for Delphi / Free Pascal to the recently release version of OpenGL 4.3. So if you’re developing cutting-edge 3D stuff with Delphi or Free Pascal you can now use the latest features available, as long as you’ve got the hardware and your vendor released new drivers (I can’t wait for the first OpenGL 4.3 report to be uploaded to the glCapsViewer database Update : Thanks to end, who has uploaded the first OpenGL 4.3 report to the database!).

Some of the new features are compute shaders (along with shader buffers to feed them with data and to retrieve it from them), new texture compression formats, and some new vendor extensions (like NV_Path for pathrendering, e.g. scalable fonts).

Since I’m on an ATI (AMD) GPU and only NVidia has released OpenGL 4.3 drivers I wasn’t able to test out the new features. As usual the header should work with windows (32- and 64-bit), Mac OSX (at least in FPC, haven’t tested with XE2) and Linux (naturally FPC only). So if you got the hardware, the driver and want to test one of the new 4.3 features with Delphi / FPC, go ahead and get our new header on the official wiki page.

And if you find any bugs with the new features (or old ones too), please let me know.

“Phase 2” – Jungle warfare

Some live footage from the battleground :

Somehow I could hardly resist not to call this post “Welcome to the jungle”, cause that’s exactly what I thought when playing around on the game’s manual battlefield in the “jungle”-setting. I did a lot of postings about the new manual battles for “Phase 2”, and in several of those I mentioned that there is a lot of content that needs to be created for the different settings of the battlefield.

In “Phase 2”, every region of the globe has a setting assigned for when you attack it and enter the manual battle-mode. These settings are changed in the game’s data editor (called WeltEdit), and range from arctic, lushgreen, dry over to desert and jungles (there have been many more during development, but I had to reduce the number. And depending on the selected setting for the region you’re about to attack, the game loads different maps, models, textures. And every setting needs its own content, at least in terms of textures, trees, roads and all those things that change from setting to setting. You can’t e.g. use a jungle tree in an arctic or desert setting, cause that’d look pretty awkward, though on the other hand you can use e.g. the tank barriers in any environment. This results in a lot of content-creating work that has to be done for this specific part of the game.

So from time to time I sit down and (try) to create models (and content) for one of those battlefield settings. And this weekend I finally got around creating some models for the jungle setting. Mostly a half-way decent looking tree, something that’s used pretty often and has to look at least decent. And all of you that create 3D models themselves known that it’s pretty hard creating organic objects that don’t look bad (especially if you need to keep the poly-count in mind), so the jungle tree that you can see in those screenshots was a lot of work and is not the first iteration. I don’t know exactly, but I think I threw away at least half-a-dozen different jungle tree designs. And that has been the case for many of the 3D models I created, so over the last few years there have been dozens (or maybe even up tp a hundred) 3D models I created that were never shown to the public, though I’m pretty sure that this new model will make it into the finally game. And in the second shot you’ll clearly see that there’s still a lot of stuff missing, like buildings and other 3D models that’ll fit into a jungle setting.