Sunday, April 29, 2012

Making of Radar demo #6: The Byteplumber

So far we covered mostly creative-production aspects of this demo. Making ideas, 3D modeling rooms, doing objects, and so on. So, what was my task as a programmer? Just hanging around a bit?

Well, as you know, the Tower22 engine isn't exactly finished. I can't recall the exact things that had to be done for this demo, but the listing was quite long... endless really. Once we decided to decorate the place with a snowy theme, one of the main new features that had to be implemented was stuff to make it look cold. Ice and falling snow particles for example. Furthermore, we needed water, And while doing so, I thought having water-ripples caused by the falling snow/drip particles would look nice too. Some more visual effects were:
- Lightshafts
- Snowdust particles
- (Compressed) DDS textures
- Gas particles
- Sharper looking graphics / improved specular
- Parallax Offset Mapping
- Waterpool decals
- FXAA (Post screen Anti Aliasing for smoothing the edges a bit)
- Heat-haze sprites
- Monster morphing animation (the "breathing")
And probably I forgot a few things. But if you thought that would be all, you're wrong. Most of the time being spend on "programming the engine", happens on invisible, magical things. And fixing bugs. Many of the points above have already been implemented once, but using old clunky code. More than often it happens I discard the old module, and replace it with modern techniques. The particles for example. Making a bunch of snowflakes falling down softly isn't the most difficult since unsliced bread. However, after looking some tasty modern-particle demo's, I decided we needed a GPU approach too. Which means the graphics-card will update the particle positions/physics instead of the CPU.

Let's not forget that games require more than just graphics, although this Tech-Demo was merely a compilation of rooms and effects, supported by spooky tunes. Spooky tunes... I still had to finish some unfinished business with FMOD, a third-party sound engine. And the camera-flight through those rooms needed some help as well. Portal-culling had to be improved and cleansed from some nasty disappearance-bugs, and while trying to capture a movie, I realized having a recording-playback tool would be nice too. The movie has been recorder quite a lot times, but the camera path had to be the same each time. Impossible to manually do that, so instead a camera-position logger has been added.

Usually adding a new feature ends up in a lot more work in order to integrate it nicely into the engine, and to prepare it for eventual other usage as well. That particle system for example is not only dealing with falling snow of course. Before even starting, the imagination flooded with fires, smoke, clouds, stinky flies around corpses, 80ies laser-Tron effects, green gasses, fog fields, rain, tornado's, mushroomcloud-laying-motherfuckers, and who knows what. So, I didn't just make a particle generator for snow, I made an all-round particle generator. And the extra effort paid off later on with the waterdrops, gasses and snowdust in the same demo. If you need to add or change something, do it well.
The ice required a new pass in the engine, as it uses a simple sort of sub-surface-scattering. First the the surface will get litten normally, then it gets rendered again, scattering its own light and the background contents.

Between adding features, I also had to support the modelers. Not just by giving instructions and feedback, but also by providing their tools of course. An engine is not just a library that can be used to render/drive a game. It includes the editors, tools, documents, and so on. After all, your artists rely on that. If I want them to make a rotating fan or animated screens on a computer, the editor needs functions to create those.

The Fly is Dead, yeah
Another thing that takes a (too) big portion, is bug-solving. Bugless programming is as realistic as having a relation and never arguing. Fixing things is part of the job. However, the engine sometimes feels like a Jenga Tower(22). Instead of removing blocks, we are inserting blocks. But at the same time, something else gets pushed out of the tower. Some typical bugs like "#$% barrel object doesn't cast shadows anymore" have been fixed dozens of times.

Sniff, smells like bad design? Maybe, although I would like to call it "lack of manpower". The engine has hundred-thousands code-lines, stuffed in unfinished sub-modules. In a real game-company, -you know, where they have more than one programmer-, each programmer(team) is assigned to a specific module, and will deliver something documented, tested, finished. At least, that's what they should do. But here at... erh, we don't even have a name, I'm programming everything. So, there is little to no time to finish modules, let alone document things. Instead, I work "on demand". Whenever artist X needs a certain effect, or if the game needs a new mechanic, I'll implement it. Of course, the modules have been designed with all possible functionality in mind so it's not that I have to hack in future add-ons, like stuffing a body in too small garbage bag. But since I work in small fragments on each module, the chance on bugs increases as some code-parts are left unfinished, untested, or if I forget a couple of conditions when adding a new feature months later.

Yes, it would be better to finish a module completely rather than stopping somewhere halfway. Then again, there is little time, and its often pretty meaningless to work on something that won't be needed yet. For example, I could renew the whole animation-module. But as long as there is no playermodel with a proper stand-walk-run animation-set, its not very motivating to start on it. In fact, it probably only makes bad code, as it can't be tested right away. I call this "blind coding". You make something, but you have no idea if it really works and fits the needs yet. Coding in advance only works if the goals are very clear, and with some test-subjects. Otherwise -> a waste of time.

Last but not least, I would hate to spend weeks/months on the same dull module. It's a relief to switch over from graphics to physics, or from sound to gameplay once in a while. Hey, I'm not spending so much unpaid hours of free time to torture myself! In the end, having fun in what you do might be the biggest key to success. Although I got to admit fixing bugs is goddamn annoying. Progress is the things that really rewards, not spending a couple of nights on the same old bug again. It's like the police catching the same toothless alcoholic prostitute every weekend.
Sometimes bugs can turn out pretty cool through. Forgot what the hell went wrong here, but it looks kinda angry.

Don’t worry, we’ll get there. Bit by bit. Each time when a new room or object is finished, the tools, engine, shaders and other related modules get bigger, faster, richer, tested, and better oiled. It might not happen in a truly professional way, but as said, programming is a story without an ending anyway. Do you really think the programmers at Valve or Crytek stopped one day during development, as their part was completely finished? Of course not. There are always glitches, bugs, missing features, non-optimized code. And otherwise modern-technology passes by with merciless speed, forcing you to upgrade or even rebuild certain parts again. And again. Unlike making a 3D model, a programming task is never really finished. That can be frustrating sometimes. Honestly, it makes me “restless”. Ever since I started programming and wanted to make a game ~13 years ago, I can’t just play take a pause, watch a movie, play a videogame or chill out with a fishing rod anymore. Because the programming is never finished, there is always that urgent feeling that something needs to be done. Not spending time on “the job” makes me feel useless. I’ll go to bed with it, and wake up with it.

Sure, I still have time left for my work, family, and drinking beer with the guys. But I need to be careful this hobby won’t become a sick obsession. Then again, we all have obsessions, don’t we? Some spend years on fixing old crappy cars. Some are obsessed by sixpack-abs and visit the gym every day. Others are obsessed by sixpacks of beer, and your mother is obsessed by cleaning the house and will fight the lost battle against dust. It’s this drive that makes us good at things. And what does it gives us at the end? Hell, I don’t know. The sports-guy will get old and fat eventually, mom has to dust the house again one day later, the car-lover doesn’t give a shit about cars that work again, he will start on another piece of junk. As for Tower22...? It will be my 5 minutes of fame when it gets finished ;)

Wednesday, April 18, 2012

Scrooge McDuck

One of the charms of this project, is that it's being made with very limited resources. Not that Tower22 is anywhere near finished, but it feels a little bit like making the impossible possible. The Tower22 headquarters is my couch and bed. We work with Commodore 64's, ancient programming languages (Delphi 7), and a handful of cowboys doing this in the spare hours. Programming is done while sleeping, models are sculpted on the toilet, sound is recorded while feeding our kids. And neither do we have a budget or art-subsidies. I pay with "good job!" emails, or ok, constructive feedback if you will. Hey, recently one of our guys got a (paid) job in the games industry and thanked for the stuff he learned with Tower22. That gives little tingles, like a proud grandpa.

Some hint me about funding websites like "Kickstarter". Now I'm not an expert, but as far as I know, these are websites that help (Indie)projects with a (small) budget. Not to buy private jets and E3-booth with robot-babes. You know, just a budget to buy a new videocard, a CD with sound effects, or maybe even to allow one or two persons to exchange some working days without their families starving. Not sure where the money comes from, probably from individuals who like to see a game happen and donate. Or maybe with good old magic. So Rick, why not grab some cash, say your boss he can stick those harvesting machines in his @ss, and chill out on the sofa with Tower22?

Well, first of all I like my jobs, I'm a loyal slave. But moreover, I'm dead scared of funders and George Washington papers. My momma always said "Nothing for free in this world boy", with a lovely black lady Chicken-Tonight voice. No she didn't say that, but they did raise me with common sense. No-one on this planet gives money just because they like you. They want something in return. Something that sells, generates more money. If EA Games knocks on the non-existent Tower office-door, with a bag of money, they expect us to finish a selling game within X years. And as soon I say "sure thing doc", they got me at the balls with a rusty vice. If our little (not so experienced) team fails to deliver, they will take my baby. A bit like how Duke Nukem Forever got finished(rushed) by another team in the end.

Every room gets multiple sketches. Tons of work, but every detail should be done with love. This one was done by newcomer Pablo btw.

But... nothing wrong with that right? Of course people expect something in return, We're not living in a yippie-hippie world. And even there people would expect services in return. Trade a cow for a donkey, publish Tower22 in return for your wife, et cetera. If I give money to a painter I don't expect him to fix the sink either, paint the damn house. Yet, there are still some problems. A publisher invests, then wants to make money. And as we all know, games play on safe. Not a miracle, because these days games aren't produces by 2 programmers in a basement anymore. Shit no, we're talking about armies of artists, expensive engines and studios, Bill Clinton and Mr. Ed the Talking Horse doing the voiceovers, complete American football teams, and very large basements of programmers. And not to forget all the marketing of course. Millions of dollars are invested, so publishers are very reserved with experimental ideas.

But I can already tell you that the Tower22 game ideas are not founded on typical selling-bombs like slow-mo bullet modus, chattering gasmasked alien soldiers, and auto-save every 5 meters that makes the game accessible for the whole family(= sellable), including your Labrador. Man, my generation was raised with impossible Super Mario jumps, no-save at all in NES games, and extremely annoying games that made the joypads fly around. Hardcore gamers (in nerd-jargon), and that's what you can expect from Tower22 as well (imagine a Gomer Pyle face now). But with a publisher on the buttons and money, a game like this will likely result in something we didn't exactly want.

But wait a minute. We were talking about small funding. To buy coffee and a new mouse and stuff. Yet, that still makes me nervous. My momma always said "Son, thou shall not steal", with a mother Theresa voice on her deathbed. No, she didn't said that, and she is still alive. But they did raise me with decency. If Billy donates 2 dollars to Tower22, then I want to make sure Billy can get a copy of this game sooner or later. No matter how small his donation was, he has faith in us, so we owe him. And honestly, at this point there is no guarantee Tower22 will be there soon, or even will be finished some day at all.

Last but not least, my momma always said "Money poisons, my dear.", with flowers and braids in her hair, barefeet, and hairy armpits. No, she didn't said that, and I don't know how her armpits look. But they did raise me non-materialistic. We make Tower22 because we are passionate. Not to get rich. Sure, a budget increases the chances. In fact, it might be the difference between a hardcopy on the shelves or keep-on-dreaming. But if someone offers help, I want to make sure he/she is doing it because he/she really loves drawing/modeling/composing/programming, and likes to see Tower22 happening. As soon as there is money, people may get greedy. Pay me more, or I'll walk away to another company with your ideas. And who is getting what with a small budget? Ten- thousand dollars sounds like a lot, but divide it through 10 people. The remainder is not even enough to pay my house two for months. Pay-per-service sounds more fair, but how to judge what a 3D cardboard-box model is worth anyway?

More corridor, this time from Borja, another newcomer doing concept art. Yes, I'm happy we finally have 2 guys doing environment sketches!

Is funding out of the question then? No, it is not, and my momma didn't say not to do it either. But before taking that step, whether grabbing 2 dollar from Billy’s pocket, or receiving big money bags + cans of helpers by a big publisher, I want to make sure we are heading the right way first. With that I mean the team must be talented, motivated and big enough to produce a substantial part of the game. That also includes some self-reflection. My part, the game-idea + engine, must work too. If first testplays turn out to be damn boring, or if the engine is as stable as a North Korean rocket, we need to change plans. The engine is in a too early stage, and the amount of content-production manhours is still too little/fluctuating to make a good planning & hard guarantees.

Hmmm... that doesn't sound very hopeful! But hold on. The team doubled the last few months. Not that more people automatically leads to more and better results -don't forget each of them also needs to be guided properly-, but in this case its certainly a step forward. I'll introduce them in a next post. Anyway, let's say if we can make a bunch of good looking / SCARY, *playable*, floors, I may look again at Kickstart or the likes. Because at that point, we proved for ourselves we are able to do it, plus we can estimate how long it takes a bit.

And let me reveal something else then. Finishing the entire game in this setup is indeed impossible, unless you are patient and play Tower22 on a classic PC in future times where we fly with cars and make love with holograms. The target for now, asides attracting some more artists with 1 or more future demo movies, is to make the first ~40% of the game, and release it (for an Indie price). Yeah that's right, a game. To play. But not the complete thing. Although I must say the game storyline is perfectly suitable to split in two, I'm not a big fan of the "Episode" approach. But in our case we have little choice. If part1 is a success, getting funds and more horsepower to realize an even better second part will be much easier. And if it fails, we'd better return to our Magic cards collections and kitchen gardens. My momma always said "A man has gotta know when to stop." ;)

Monday, April 9, 2012

Making of Radar demo #5: Objects

Ever bought or rent a new empty house? Then you must be familiar with the “that looks smaller than I thought” symptom. It only takes a few steps to cross the room. But you may have also seen TV programs about people who “collect”, those who managed to stuff their house with million boxes, cats, old junk that might become handy some day, and a wife somewhere between the trash piles. That suddenly gives a whole new dimension to the space.

In games, the dimensions of a room can look misleading easily. Nowadays we can use 2048x2048 textures, entrophy, many decals, and secondary detail(normal)Maps to enhance the detail, but older games had to improvise with a handful of blurry, stretched textures. But even high quality textures still don’t contain the amount of detail a real surface has, and a wrong scaling of the texture makes the room look smaller or bigger than it should. On top, there is the 3D camera view that doesn’t match a real life eye view. In other words, we need filling for the rooms to clarify the dimensions of a room. A door, washing machine or couch gives a better idea of what a virtual metre is.

Contents gone, floor and left wall textures stretched x2

And of course, it also takes objects to define the purpose of a room. Place some metal bunkbeds and Bob Hope girl posters and you have a Vietnam barrack. Paint it pink and replace the poster with Justin Bieber and you have a girls room. Put down some pee-stained mattresses, needles and pipes, and you have a crackhouse. There is a lot you can do with a floor, 6 walls and a ceiling. So, grab an IKEA catalog, argue with your girlfriend and start filling the rooms. Three Björn chairs here, the green Aslög sink there, a mahogany Helga toilet pot over there. Oh wait… we were doing a (“Soviet”) Radar Station…

The rooms had been defined, though not all of them had a purpose yet. So I took a (imaginary) snapshot of each and made a simple sketch of what & where could be placed. Then each room would result in a list of assets to-do for Sergi, who did most of the objects for the Radar Station. But what the hell would the Russians need in a Radar Station? Well, you can find a lot of answers on websites like The Russians made a good habit of photographing old forgotten hospitals, schools and rocket silo’s. Too bad we realized this a little bit too late, so most of the contents we’re wild guesses. A military Radar Station, let’s see. Computers, charts, documents. A place to sleep and brush teeth for the soldiers. Facilities to lay bricks. And lot’s of storage space for… No idea what a radar crew would store. Explosive barrels? Not really, but barrels are fun nevertheless. Boxes with documents, spare computer parts, canned dogfood.

Come to think of it, we forgot some entertainment for a bunch of bored soldiers, waiting forever on the nuclear threat. Maybe a billiard would have been nice. Then again, we’re talking about a Soviet army base here, not an American one. Not that I served the red army and have experience, but pictures like THESE
THESE tell me there wasn’t much luxery for those poor bastards. For that reason: place empty vodka bottles, cigarettes, and books. Too bad we didn’t have time to make all those. Sergi did 1 or 2 objects per week, and we had about 11 weeks so do the math. I ordered all the required assets on priority, so pencil drawn hairy women pocket sexbooks were low on the list. Big important stuff first. But the point is, do your homework to make things authentic. Again, Tower22 has nothing to do with Stalin, iron curtains or Russia. Yet we chose the decayed buildings from that era as a design guideline, so googling for Russian factories, North Korean apartments or old-tech technology from that time is part of the job. Just mixing everything without thinking is like an orange 70ies flower wallpaper with a modern Ivar dinertable. Disgusting. Although just mixing up everything is pretty Soviet style actually…

You can imagine its pretty hard to get everyone turned up when showing your ideas with horrible pics like these.

Anyway, to the 3D Batmobile then. Sergi had 1 or 2 objects to make each week, using 3DS Max btw. The program doesn’t matter much though, some use Maya or Blender as well, just as long it can export OBJ files. Usually we would search for a few photo’s to make sure our minds were on the same track. Then a game model was made. Wanna to know polycounts? Depends on the object, how big it is, how important it is, and how many times it will be used. The monster, nitrogen-tanks and big computer terminal take more than 6 to even 10 thousand triangles (when close to the camera), other stuff varies from a few hundred to a few thousand triangles. A modern GPU can easily shit out hundredthousands of triangles. Yet that still doesn’t mean you shouldn’t care. Spending thousands of triangles on small details such as ashtrays, wall sockets or a piece of cloth is overdone. A large, dominant object like the big computer terminal in the Radar Station on the other hand, will be in the spotlights and deserves some extra triangular love.

Quantities also matter of course. GPU’s generally don’t like to get interrupted, so always try to batch and do much stuff with as little calls as possible. Group/order on object, share the same textures if possible, and maybe use modern techniques like instancing in case the same objects appear in real big number. A dense Crysis jungle for example. Hundreds of trees and plants need to be rendered somehow, so it’s wise to use instancing, use the same textures to reduce texture toggling, and to keep the polycount relative low on those. In the case of Tower22, it’s not likely the same objects will appear in dense clusters though. It’s not that a dusty apartment contains twenty computer desks. The limited view distance allows to give some more triangles, though we still need to think about exceptional cases where we can actually see a lot.

A pretty simple trick to reduce the load is Level-of-Detail (LOD). Ever saw lantarnpoles suddenly (diss)appearing in GTA? Noticed the sinks being thrown at your head getting more detailed in a Halflife2 deathmatch game? It’s the LOD doing its magic. Hopefully you didn’t see it happen in the T22 demo movies, but it happens all the time. The big computerterminal for example has about 12k triangles in its “highest” detail. But after a couple of meters, all those little screws, buttons, and potmeters aren’t needed anymore, as you barely can see them anymore. So why waste thousands of triangles on invisible details?

Guess the 6.126 differences and win fantastic prizes.

Smaller objects like a trashcan or small pieces of debris won’t even have a Low(est) LOD, making them disappear. It’s also possible to switch over to a simple sprite / impostor for distant objects. Not sure about Crysis, but that’s how Farcry for example managed to render its jungle covered islands. Anyway, each object in Tower22 gets a couple of lower detailed meshes, usually by deleting some details by hand, and/or simplifying the mesh with a plugin in your favourite 3D modeling application.

Material sharing
A bigger performance problem is the variety of textures and different “materials”. In Tower22, a material is a collection of shaders (vertex, fragment and sometimes a geometry shader), shader parameters (colors, factors) and textures (diffuseMap, specularMap, normalMap, whateverMap). Before an object is rendered, first its material should be applied. Apply “stinkyLeatherCouch” material, then render the stinkyLeatherCouch 3D model. That way the GPU knows how to draw that thing. Switching to another material (= passing other parameters, toggling active shaders, binding other textures) takes time though. Not much, but yet the performance gets a serious kick if you do it hundreds of times. That’s why the engine sorts everything on material. In case there are 10 stinky leather couches, we only have to apply the corresponding material first and then render the 10 models. Saves a headache, but as mentioned before, Tower22 typically does not use a lot of the same objects at once. That doesn’t mean there are little objects neither, they just vary a lot.

Take a look in your own livingroom. Couch, chair, saloontable, carpet, vase, another vase, plant, cabinet, TV, DVD stash, wall socket, painting,… do I need to continue? Ok, clock, remote control, ugly decorations you didn’t buy yourself, candles, more stupid vases, junk from the kids, a book or two… enough. In 3D world, those are all different models basically. Unless you combine them to one. For example, the cabinet with the TV and DVD stash could be modeled as 1 bigger object, using just one material as well. But what if you want to shoot the TV of the cabinet? If you want to play with destructive physics, you still need to separate the objects… but that doesn’t mean they can’t share the same texture anymore! It’s not uncommon to share the same textures, shader and parameters amongst multiple objects that have (nearly) the same rendering characteristics and are likely to appear together in the same rooms. A bunch of books, kitchen pots and pans, debris blocks, cardboard boxes, plants, trees, or the IKEA Stömpekopf (ok this is the last time) furniture set that comes with a 1 seat, 2 seats, 3 seats couch and saloon table. The warehouse racks in the movie have up to 6 different cardboard boxes, but all using the same material. Thus only 1 material switch instead of 6. Winning.

Quite a lot decals we're used, but many of them using this single texture.

Physics and hitzones
What else can be said about objects in Tower22? Oh yes, maybe that an object is more than just a 3D model and a texture. Some objects require animations, but I'll save that for another time. Furthermore, models -if desired- can be kicked around with the laws of Newton. Physics and (bullet) collision detection requires some additional info though. First, we need a collision “hull”. To ease the computations, one or more simplified meshes are used to define the collision shape of an object. Each hull has its own info too, a physical material and hitzone ID. A car for example could be made of metal, rubber(tires), and glass parts. Each with different sounds and effects when they get hit. A special gastank hitzone could trigger an explosion when being hit by bullets. Very useful for making weak or armored spots on a tank or boss character. But also useful for making interfaces with objects. For example, point & click the cursor at the drawer of a desk to open it.

The yellow lines show the physical hull variants of the screen objects (and map geometry). Usually those are simple box or cylinder shaped primitives.

Object attachments
Asides defining physical properties, it’s also possible to attach other (sub) objects and sprites to a host object. For example, the computer screens on the big computer we’re animated sprites. And the rotating fan was made of two objects; a metal frame, and the rotating blades. The connection between the objects is either a static one, a simple motor that makes the child object shake, move or rotate, or a physical joint. A physical joint is well… based on “real” physics. Or at least simulated physics, such as a ball & socket or hinge joint. Useful for ropes, chains, cowboy saloon doors, tires, corkscrew motions, lamps swinging on the ceiling, ragdolls breaking their necks, et cetera. Making connections is useful for adding optional components to your model, such as a helmet on your ugly head, or putting various weapons in the players hands. And of course it's useful to rip apart sub-objects again once things get blasted.

Apart from regular objects, we can also attach more advanced entities such as (shadow casting) lights (car headlights, helmet lamps, gun lasers, ...), particle generators (smoke exhausts, smoking cigarettes, fire barrels) and invisible fields that can alter gravity, teleport other entities, heal or harm, act like a magnet or triggers boyancy which means the player starts swimming once nearby this object. Absolutely useless, but fun nevertheless.

In case you are thinking “how the heck are these awesome dudes stuffing all that data in a3DS Max or Lightwave file?!”: we don’t. We save LWO or OBJ files, containing raw mesh data. A bunch of vertices and texcoords is all we need. Like explained for the maps previous times, these files are imported in the T22 “Object Editor”. Then these files are interpreted either as LOD’s or physical hull meshes (in the case of a lightwave file we look at the material name so everything can be imported at once). All additional data and properties such as normals, tangents, names, mass kilograms or attachments with other entities are then defined inside this editor. And once the collection is complete, we can test the object inside… the Radar Station. Remember, we made that map as a playground for testing your new IKEA (oops did it again) Smêgma barstool in various circumstances. Dark rooms, bright rooms, skylight, water buyoancy, throw it down the stairs, let it slide on ice, and so on. Once we’re happy fonzies, the workspace gets exported to our own internal object format, which then we can place wherever we like in our maps. Finally.