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 www.englishrussia.com. 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.

LOD
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.



Editor
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.

Tuesday, March 27, 2012

UBO Wan Kenobi


Nothing to do with this entry, but some of the current programming progress: Screw up the repeating patterns by (vertex)painting details on your textures!

I thought it would be nice to have some nerd-talk between all those "Making of" posts. Tonight’s special guest: UBO's. No, UBO's are not a new shoe brand or Unidentified-Blowjob-Objects. Though "Uniform Buffer Objects" kinda sounds the same. If you make extensive use of shaders -and any modern game engine does- you may have noticed you are passing quite a lot of parameters to these shaders. For example, pretty much all shaders that involve lighting or reflections somehow, need to know the camera position and/or light properties such as color, falloff, position or its projection matrix in case of spotlights.

Tower22 has a few hundred different shader programs (build from ubershaders based on selected options). And the number is growing as the amount of options grows. Normally, I would need to pass parameters such as the camera position or light props again for each shader. Feels like a waste of time, since those values are the same for all shaders. Or how about shaders that need a large array of parameters? For example, you may want to do all lights at once in a single shader program. And “Vertex Skinning” (animating via the GPU) is also a technique that requires to know a big number of matrices (or quaternions) somehow. It's perfectly fine to pass all those parameters one by one before the rendering starts, but it's not the fastest way. Too bad a shader can't grab data from a fixed location somewhere in the videocard memory... Or can they...

If those issues sound familiar, UBO's can be your angel in darkness, the spray can in a stinky toilet. Not only they may give a (slight) performance boost, it also allows programming in a more natural way with structs and stuff. Instead of passing all those parameters individually, you make a data buffer. Which is basically just a block of vectors(float4) stored somewhere in the videocard memory. Pretty much the same idea as texture buffers or Vertex buffers:

1- Make a buffer
2- Fill it with data (once, or at the start of each renderCycle, or whenever an update is needed)
3- Define the same buffer in your shadercode. As an array or struct for example.
4- At creation, get the buffer-parameter from your shader and link it with the block you made earlier

In other words, the parameters have been moved from the CPU/RAM to the GPU/Videomem so we don't have to pass (and slowdown the pipeline) all the values anymore. Down below you can find a simple implementation, using OpenGL and Cg. When using GLSL, it works almost the same though. Probably even simpler.



Preparations
Before hitting your coding typewriter, make sure your drivers are prepared though. First of all, if you are using Cg (like me), download Cg 3.1 or higher. And if you are in love with OpenGL, make sure you are using OpenGL 2.x at least. AND, you may need to update your videocard drivers as well!! I tried and I tried, but making a buffer the pure OpenGL way caused crashes. Then I realized the laptop videocard comes from 2009. UBO's weren't even born back then, or at least still pooping their diapers. A videocard driver update did the magical fix in my case.

Unless you are using up-to-date headers, you may need to define some new OpenGL functions first. Well, I'm using Delphi so don't count on up-to-date functions. Ditto for the Cg libraries. Luckily adding new functions is pretty simple. If you can’t find a particular function, just search for it and the OpenGL docs tells you exactly how the function works, what it returns, what parameters to give, et cetera. Also good to know, the nVidia OpenGL10 SDK has some examples as well.



Example: lighting with structs
---------------------------------
Now let's make a practical example. Lights. Our space-ice-hockey game uses a number of simple pointlights, let's say 128 at max. Several shaders such as the environment and character shaders need those lights. We could define all lights as follow:

struct PointLight
{
float3 position;
float range; // Falloff distance
float3 diffuseColor;
};
// ! Don't use this code! There is a problem with the layout, I'll explain below

struct SceneLights
{
int lightCount;
PointLight[128] light;
} _sceneLights;

With such a struct, we could do the lighting inside a shader as follow:

for (int i=0; i < _sceneLights.lightCount; i++)
{
PointLight light = _sceneLights[i];

float attenuation = getAttenuation( pixelPos, light.position, light.range );
float3 diffuse = saturate( dot( pixelNormal,
normalize(light.position - pixelPos) ) );
diffuse *= light.diffuseColor.rgb * attenuation;
totalDiffuse.rgb += diffuse;
} // for i

And chaps, don't forget you can also still pass traditional parameters as lookup indices. This can be useful when rendering lots of stuff in a single breath, when using instancing for example.

... uniform int myID )
{
MyData d = dataArray[ myID ];


1 Making the buffer:
---------------------------------
Pretty cool huh? Step1 is to make a buffer. Simple stuff:

{ Create an empty buffer }
glGenBuffersARB( 1, @ubo.glHandle );
glBindBufferARB( GL_UNIFORM_BUFFER, ubo.glHandle );
err := glGetError;
if err <> 0 then
ubo.glHandle := 0; // Arh! Check your drivers matey

{ Size & Fill it (or pass NULL if you don't want to fill it yet) }
if isDynamic then
glBufferDataARB( GL_UNIFORM_BUFFER, byteSize, dataPtr , GL_DYNAMIC_DRAW_ARB )
else
glBufferDataARB( GL_UNIFORM_BUFFER, byteSize, dataPtr , GL_STATIC_DRAW_ARB );

glBindBufferARB( GL_UNIFORM_BUFFER, 0 ); // Detach
{ Make a Cg Buffer }
ubo.cgHandle := cgGLCreateBufferFromObject( cgContext, ubo.glHandle, CG_FALSE );


Some notes. First, you can define how your buffer will be used with the GL_DYNAMIC_DRAW_ARB parameters. I showed 2 variations, but there are more tastes, check the OpenGL documentation. Basically you need to decide how often the buffer will get updated? Only once? Each cycle? Even more?
* Another note, at the bottom I'm making a Cg specific variant of this buffer to use it with Cg shaders. If you use GLSL or something else, you can skip that line. Another note to self, Need to buy milk for tomo... wait, nevermind.


2 Filling the buffer & Layout:
---------------------------------
We already saw glBufferDataARB being used to fill the buffer. In this case it would be a pointer to struct(s) I showed earlier. You can update (sub)contents with

// GLSL
glBindBufferARB( GL_UNIFORM_BUFFER, ubo.glHandle );
glBufferDataARB( GL_UNIFORM_BUFFER, byteSize, dataPointer, );
glBufferSubDataARB( GL_UNIFORM_BUFFER, byteOffset, byteSize, dataPointer );
// Cg
cgSetBufferData( ubo.cgHandle, byteSize, dataPointer );
cgSetBufferSubData( ubo.cgHandle, byteOffset, byteSize, dataPointer );

There are some catches though. First of all, you can't just mix datatypes like I did (float3, float, int, ...). If you do, you may get weird results. Correct me if I'm wrong, but by default OpenGL expects the datablock to use the std140 layout for formatting. There are documents out there describing this. But if you take the lazy path like me, just make sure everything is using float4 (or float4x4 for matrices) or int4 types:

struct PointLight
{
float4 positionRange; // XYZ W = Falloff distance
float4 diffuseColor; // RGB A = not used
}; // 2 x 16 = 32 bytes

struct SceneLights
{
int4 lightCount; // X = pointlight count
PointLight[128] light;
} _sceneLights;
// 16 + 128 * 32 = 4.112 bytes


Yes, that may give some overhead (unused fields on the color and count variable). You don't have to use this way of formatting, but filling the buffer get's a whole lot more difficult then, as you need to know the offsets for each variable in that case. OpenGL and Cg have functions to calculate those btw.

Second rule, be aware there is a maximum size. For now, 4096 float4's to be more precise. That means I could define up to 2047 lights (don't forget the in4 lightCount variable) in the example above, as each pointlight takes 2 float4's. If that is not enough for you, you can bind multiple UBO's at the same time. You could make one UBO with all pointlights, another one with all spotlights, and so on.
* Oh, and Delphi boys, don't forget to pack your records ( TPointLight = packed record )!

3 Defining the structs in your shader
---------------------------------
Depends on the language you use, but it's pretty much the same as you did in C++, Delphi, or whatever it is you are using. Below a Cg example. The "BUFFER[x]" is an optional addition that tells Cg on which fixed "slot" the buffer is bound. Like textures, you can bind up to 32 (I think) UBO's at the same time. If you don’t care about the specific index, just type “: BUFFER;”.


4 Final step, connect shader parameters with the UBO's
---------------------------------
Not sure how it's done with GLSL, but with Cg you need to find the UBO parameter first, and pass the cgHandle we got before with cgGLCreateBufferFromObject(). For each program that uses UBO's:

var uboParamHandle : CGParameter;
begin
uboName := 'SceneLights';
uboParamHandle:= cgGetNamedProgramUniformBuffer( programHandle, pchar(uboName) );

I bet there are more ways to wire up the whole thing, but this is at least one of them. Anyway, now that we have the parameterHandle, we can pass the UBO:
cgSetUniformBufferParameter( uboParamHandle, cgBufferHandle );

As said, use the bufferHandle we got via cgGLCreateBufferFromObject(), thus not the one we got from OpenGL with glGenBuffers(). Unless you have crazy ideas, you only have to pass this value once by the way. So typically that would be at the start. Some final important notes (and maybe I'm doing something wrong):

* When defining large arrays in your shader, the compile time can get a LOT longer. It seems the entire array gets unwrapped.
* That's why I suggest to pre-compile the shaders and load those as long as you didn't make changes.
* Too bad cgGetNamedProgramUniformBuffer() does not seem to work with pre-compiled shaders... I think this is a bug in the Cg3.1 library, so I asked on the nVidia forums... with no result yet.

May the UBO be with you

Wednesday, March 21, 2012

Making of Radar demo #4: Gameland Immigration services


Off-topic, but nice to show nevertheless, some first-concepts for one of the many corridors...

Not too long after making a bunch of ideas, the first maps rolled out. And with a map I mean an empty room/corridor. Like buying a new house, you still have to argue where to place the sofa, and whether to use pink paint or clown wallpaper. But that's for later concern. First, a new map has to pass the Engine22 immigration services.

A finished model does not yet make a suitable game-map. This is because a "freestyle" 3D package like Max, ZBrush, Lightwave or Blender, does not have to follow any rules. Where games have to deal with physics/collisions, closed worlds, size boundaries, portals, spatial sorting and all other kinds of optimizations, a 3D package does not have to worry about performance, memory usage, or how the model will be used. Hence we're talking about making environments, but you could just as well model flying spaghetti.

That's why we have border watch; an importing tool that tests if the supplied model meets the requirements, scraps shit, and eventually adds additional data. This is common for pretty much every engine or game-tool. Though the bigger professional engines like UDK or Source often come with their own map-editors that force you into a certain way of modelling. Sorry if I bother you with ancient terms, but let's take Quark as an example. A long time ago, when the Halflife1-Saurus still wandered our planet, I used Quark to make some custom maps, just for fun. It can be a bit compared to Hammer, or the Unreal Editor.

Quark. 3 closed rooms, hollow primitive shapes -> Brushes.

Polycount
------------------------------------
In Quark, you couldn't just throw triangles wherever you pleased to do. No, you had to work with "brushes", sort of big hollow Lego blocks. Although I don't know the indepth details, using those blocks for rooms made sense, as they assured your world to:
- have a floor to walk on
- being closed (walls, floor, ceiling (or skybox))
- having a definition of "rooms" / "sectors". And this would help splitting up the world in logical sections, used for lightMaps, AI calculations, physics, culling, collision trees, and whatever was needed.

The downside however was that those blocks were a bit sturdy. It was hard, if not impossible sometimes, to make a complex (organic) shapes. If you needed small or complex details, you had to insert "props". Boxes, furniture, barrels, but also doors, lamps, pipes and railings are examples of props. That doesn't sound very handy, but keeping the maps as simple as possible makes sense, especially for older hardware. In many (older) games, props follow a bit different rules than the static world that carries them. Props don't reserve space in a lightMap, but use (simplified) lighting. Props use none or simplified collision hulls (resulting in slight less accurate but faster collision tests). Props can fade out and be hidden after X meters, or toggle to a lower-detailed version to win some polygons and speed. Props can be moved around, while static parts of the world such as the streets, buildings or walls can't. The player can be inside a room. but not inside a prop (unless it's a vehicle or something). Making a strict line between the static world and props is done in pretty much any game, although modern games manage to get things more flexible. No lightmaps for the static world, destructable worlds, accurate collision detection with props so you can climb and enter them, et cetera.

The maps (= static environment), using relative simple cube-like meshes like those Quark brushes, have a low polycount. Props on the other hand have a very high polycount compared to them. For example, the monster in the Radar Station demo uses almost more polygons than all radar station walls/floors/ceilings/pillars together. A computer model takes about 1.200 triangles in T22. A simple room with a window and a door only needs 400 triangles or so. Having a low polycount for the environments is useful for various reasons. First of all, the less polygons, the faster things render. You can fade-out a 1.2k triangle computer object after 30 meters or so. But you can't fade out the Empire State Building in a GTA-like game. Even not after a few thousand meters. Using a low-poly model for this (background) model is a solution.

Another reason to watch your polys, is collision testing. When you fire a bullet, the engine needs to check where it intersects a wall, or head. or... The most stupid thing you can do is looping through ALL triangles in the world, then for each check if the bullet intersects. You don't have to be a programmer to understand that testing this for thousands, maybe millions, of triangles is not such a good idea. For that reason, games often split up their worlds in invisible cubes (or another type of spatial grouping). With octrees for example: Imagine 1 huge cube around the entire world. Then you can split that cube into 8 sub-cubes. If your bullet flies somewhere in the upper-left-front cube, you can already skip thousands of triangles that are not (partially) inside this cube. Each cube can be divided again in 8 sub-sub-cubes, and so on. How many times you subdivide depends on you. You could for example keep dividing until either the cube-size is less than 1.0 M3, or when there is only 2 or less polygons intersecting. The idea is minimize the amount of triangle checks. Ray-versus-triangle checks are expensive, while sorting out in which sub-sub-(...)cube your bullet is, is cheap. So with the help of an octree, BSP, quadtree, or whatever, you can dive to the deepest level for a certain position in your world. Then test collisions with the triangles that are inside or intersect that octree-node.

Now, worlds that use a relative low number of big polygons, will have simple, thus easy-to-access, octrees as well. A lot of (small) triangles on the other hand will still require many checks, and/or an octree with many subdivisions (taking up some performance, but also memory).

One more very good reason to keep the worlds relative simple and to separate props, are lightMaps. Now Tower22 doesn't use LightMaps (though they might return). But many games did, and still do. When using lightMaps, each polygon needs it's own spot reserved somewhere in an image so you can store it's own incoming light values on those pixels. Images are not infinite though. A 512x512 image for example has "only" a quarter million pixels. The amount of space you need depends on the polygon size (large walls need more pixels than tiny stuff), but also on the polycount. If each polygon needs at least 1 pixel, you can't store lightdata for more than a quarter million polygons in a 512x512 image. For simple walls that are made of just a few triangles, this is not a problem. But a stupid sphere shaped doorknob, no matter how small, may already use 40 triangles. So you already need 40 pixels, or at least 6 if you pack them together based on the XYZ axis direction they're facing. A better idea would be to kick out that doorknob and use another (simplified) lighting method on it. Who will notice the difference anyway?


Importing maps in T22
------------------------------------
Back on topic. Although we do have a Map Editor, it's not suitable for actually constructing the mesh. We use the Map Editor to insert props, paint walls, hang-up the lamps, attach sounds, write scripts. And eventually do some small cosmetic surgion such as welding vertices, shifting the UV coordinates, or removing a polygon. The modeling itself still happens in another 3D program. Why reinvent the wheel?

You can't expect me to make an equal or even better modeling tool within a few months while the 3D Max or Blender boys are working years and years on it. No, way too little time. Instead the artist models the worlds (and props) in his/her favourite program, then exports it to OBJ files, an old simple industry standard. When importing these files for the first time (thus when adding a whole new map to the game), the OBJ first has to pass border watch though. And that's me & my loyal sidekick Birdman, uhrm, Lightwave.

Like explained before, a 3D modeling program or OBJ files, have to follow any rules. An OBJ file is not much more than a listing of coordinates (vertexdata) and the relation between them (polygons made of X vertices). But we need to know a bit more to make it suitable for a Tower22 map though. A map is more than a bunch of visual geometry. For example, we also need to define collision shapes, and eventual special trigger zones (water, lava, ladders, teleporters). That's why I supply the model with some more layers in Lightwave. One nifty feature in Lightwave is to work in layers, each containing its own data. That makes it easier to separate things while importing. Here an idea what a map is made of in Tower22:
1- LOD's (the visual geometry in several variants, from full to low detail)
2- Collision Geometry
3- Sound occlusion geomeetry
4- Reverbs
5- Triggers
6- Portals (to see other neighbor rooms defined in another map)
7- Cloth
8- Rails
9- ...Probably more to come...



1- LOD's
-----------
In the LOD's we basically the model as you see them in the game. But talking about levels-of-detail(LOD), ever noticed buildings to become suddenly more detailed when approaching them in a game like GTA? That's because they used multiple versions of each map-area. When looking on a distance, a simple textured cube for a flat could be sufficient. You don't see the small details such as normalMaps, antenna's, ornaments, signs or other architectonic quirks anyway. Same principle of Tower22. Each map has a HIGH, MEDIUM, LOW and ULTRALOW(optional) mesh. Depending on the distance, but also if you can see it or not (T22 = mainly indoor this lot's of occlusion), a version is picked for rendering.

Not only the geometry uses less triangles, the surfaces can also use simplified materials where all the special shader tricks such as normalMapping, parallax or entropy are disabled. This also helps loading the sectors smoothly in the background. First load the simple mesh, than the medium, et cetera. You can actually see this happening in GTA San Andreas when you drive faster than the world could load. Eventually ending up in a weird void with flying cars and pieces of pavement here and there.

Notice the PC version being more detailed (dig that XBox boys!)? That's most probably because the lower LOD variants fade-in earlier on the XBox to gain some speed.

2- Collision Geometry
-----------
Normally what you see is also what you can touch. But not always in gameland. Sometimes games define invisible walls to ensure the player-idiot not falling of a roof. Or vice-versa, they remove the collision for a piece of wall so you can jump through a painting like Super Mario 64 did. Very useful for ghost stuff or making secrets hallways. If your player has problems with stair-climbing physics, and believe me, climbing stairs is difficult, then it may help to make a crippled-friendly invisible variant of the stair. But mostly, the collision geometry is exactly the same as the Highest LOD in our case.


3- Sound occlusion geomeetry
-----------
With all the visual violence, we often forget our ears. But to make things sound realistic in an indoor game, sound needs to follow some physical rules as well... Like getting absorbed when travelling through a thick wall. Luckily FMOD allows you to define a 3D world, where you tell the occlusion factors for each polygon. So what I do is making a copy of the LOW LOD mesh (no need to let small crap block sound), and define their materials. A "medium concrete wall" for example may occlude 60% of the volume.

4- Reverbs
-----------
Here we define spherical zones that contain a "Reverbs", another cool sound feature. Reverbs are basically sound modifiers. Here is an experiment:

produce a fart in A:the bathroom B:a concert hall C:a cave D:under water
E:(optional) next to your girlfriend in the livingroom.

Maybe you didn't smell the difference, but you should have heard the difference. Due acoustics, each room sounds different. Reverbs add echoes, and do all kinds of crazy math I have no idea about. But it sounds cool. In Tower22, you can define such an effect for each room. But if needed, you can also do it more local. If a corner of the room has airduct metal around it, place a "airduct" reverb there. The Occlusion volume will not only block sound, but also the effect or reverbs by the way.


5- Triggers
-----------
Ever since the Atari, game worlds have special zones that give you bonus points, kill you, or warp you to a next level. Whenever the player (or something else) enters a zone, something happens. A practical example would be a water-volume or hazardous zone. If your player intersects a water volume, he has to toggle to swimming (or drowning) modus. In the map, I can define zones (which do not have to be cubes btw) and name them with a specific identifier + parameters in some cases. "GRAVITY 0 -9,8 0", "LADDER +Y", "TRIGGER eventX", et cetera. Basically these volumes help you driving the player state-machine.

6- Portals
-----------
I could tell a whole lot, or just refer you to portal culling. In short, we split up the entire Tower22 in sectors, which are typically rooms or corridor(pieces). So 1 lightwave file contains 1 sector. Usually rooms are connected via doors, holes, or windows. In this layer we define those portals via simple quads. The engine will figure out which neighbour sector is connected via this shape and link them up. If it fails to find anything, you can also do that manually. Or you can play Valve Portal / Prey tricks with it, by defining an entire different sector behind a portal.

7- Cloth
-----------
A special kind of geometry are surfaces that use cloth physics. Think about flags, sheets, curtains or Batman capes. You can hang a (highly) sub-divided shape, and define which vertices are attaced, and which are free to move (by gravity / wind / collisions).


8- Rails
-----------
A set of 2D lines to set out paths for camera's, animated sequences or nodes for AI routing. This way, you could for example make all possible routes a car could drive through your city, then pick a rail and let the car (globally) follow the nodes. Or use it for a Tour of Duty patrol.




Oops, forgot a triangle. Now what?
----------------------
That's quite a lot ey mate? Well, most maps only define the LOD's, physics, sounds and portals initially, which are mostly extracted parts or copies of the High mesh. Extra stuff like triggers or cloth can be imported later on. Once the Lightwave file has the required layers filled, it can be imported into the game via our own map-editor. This editor will then save it to our own map file format, which contains additional data such as ambient info, script, props, and other T22 specific stuff. From now on, we work with the T22 map file...

However, what to do if the artist wants to make a last-minute change? Forgot a polygon, move a vertex, resize a bit... Yeah we programmers don't expect such things to happen, but it does. The big downside of using importers/exporters or any other kind of extra steps in between, is the extra work the artist has to do in order to get his model working. Boring work, and bigger chances the artist forgot a certain step. If your importer does not catch those flaws, it could result in weird bugs, not working maps, frustration, and flying keyboards.

To reduce the chance on that, the Map Editor itself has a few tools to make simple adjustments. UV-maps can be remapped, textures can be changed, vertices can be weld, polygons can be removed. For operations that require to re-import the model anyway, it can be done locally. With that I mean you don't have to throw away and rebuild the entire map. A specific component of the map, such as the UV-coordinates for a few polygons, or the collision mesh, can be reloaded on their own, while preserving the rest of the map.

It's still not as user-friendly as Hammer, Quark, UDK Editor or a Crysis Sandbox, but hey, you got to make some compromises with a 0$ 1 man programming team. And that's why I import all the maps instead of the artist, protecting them from frustrations. Plus the urge of fixing something is bigger when you are confronted with the bugs yourself, rather than getting complain-mail ;) Next time: Making Props.

And there you have your map imported...burp. I'm always dissapointed after working X hours, then seeing an ugly (faulty) mesh like this. But hey, don't let the first impressions take you down! New born babies are ugly too ;)

Wednesday, March 7, 2012

Making of Radar demo #3: Planning and 3D Maps

Seems quite a lot new people joined the T22 blog past months! That's great, because my goal is not to make a cool game, but to beat Perez Hilton's blog of course. Nah, it's nice to have you here. And don't underestimate your own role on this; the more attention this project gets, the bigger the chance it succeeds.


Asset planning
---------------------------------------
Are you familiar with that phenomenon, lot's of ideas and discussion, but little productivity? Whether you make a game, or have a meeting at work about implementing X, people are enthusiast in making ideas and good in chatting generally. But as soon as you really need to pick up the worktools...

Not familiar with that? Good, that means you are a "worker" :) So we had ideas, floorplans and a few shitty sketches ready for this Radar Station. Now we just had to... build the whole damn thing. Talent and enthusiasm all over the place or not, the team needs to be instructed. If you expect all your "employees" to take initiative and fill your mailbox with finished goodies every day, you'll be disappointed. If you are in charge of a project, it's your duty to push, stimulate, feedback, and make clear goals. Artists are often ready and happy to do something, but they need your confirmation. Like a sniper needs a “fire” signal. Like the red telephone needs to ring before launching the missile.

Ok, so what I did were 2 things:
- Make a simple asset listing in a Notepad file
- Made an Asset Database where details, progression and author info could be stored per task in a database.


Making a global list is simple, but important. I knew which rooms we had to make, and had a rough idea of the room-contents. So for each room I made a list of sub-assets. Floor textures, wall concrete, dirt decals, a rusty bed model, a metal rack with stinky boxes, and so on. Asides visual assets, there were also audio assets. For example the sound of a computer or airvent. And of course programming tasks. If we want snow falling in, it also requires particle generators and shaders in the engine. For each week, I assigned a couple of assets to the team members. PersonA does a concrete and pavement texture, personB makes a barrel object, personC records goat sounds, and so on. And so I planned the next 10 weeks forwards.

Asset, but in a database. Properly managing a database takes extra effort and discipline though, so a simple textfile might be best to start with after all.


The magical factor of a successful planning is the feasibility. If you load too much on personA, you can redo his planning 2 weeks later on, because he already got behind. If you plan tasks for personB he doesn't like, the same will likely happen. If you leave no room for people being busy (work, sick, family, abducted...), same story. And don't forget more assets will automatically pop-up on the go. Unless you can look in the future, it's near to impossible to foresee each possible (sub)task. Be aware the amount of tasks will grow. If the planning is way off realism, people will discard it, and it has become a worthless piece of paper…

The easiest way to prevent this, is planning very little. But hey, that's not very stimulating either, and it will delay the release of course. It's ok to push people, as long as there is time to breath. Plan the unforeseen. What I did is making a "deadline" end November, though I already knew we most probably would need entire December as well. I also planned 1 empty week halfway, just to catch up things. On top, I "sinused" the weeks. 1 busy week with 3 assets for example, 1 easy week with only 1 asset, then a busy a week again, et cetera. if personA would be busy fighting with his girlfriend in week3 for example, he could move his tasks to the next "easy week". And of course, I asked everyone if the planning was doable.


The nice thing about plannings and deadlines... Once people agree with them, they have a commitment. If the team nicely accomplish their tasks according to the planning, the individual feels forced too. No one likes to let down the team of course. That may sound a bit like being forced to do boring homework for school, but don't forget that we assigned voluntarily to make a game. Shaking Turbo Pascal code or making 3D vases is our hobby... uhm, if the pace goes well, and progress can be shown each week, it's fun to put effort on it. The demo movie and hopefully positive reactions are the reward. And an actual game-release, making filthy money, get famous, wear lady Gaga masks, sniff Heroin and be on the set with 5 naked girls in a new Snoop Dogg track (or just getting a contract at Nintendo) is the pot of gold at the end of the rainbow.


Mapping
---------------------------------------
All right, time to actually do something. So I called Morgan Freeman for voice acting, Sean Connery for texture drawing, Neil Armstrong for the sound and Madonna for the 3D props. They were busy though, so I had to rely on my few team members. Julio on the drums (textures & drawing), Sergi on the Guitar (3D objects to fill the rooms with), Brian on the flute (Website), David on the synthesizer (audio). Later on Robert on the contrabass (monster), and me on the Xylophone (programming & maps).

There are million ways to accomplish something like a Radar Station. Do the textures/props/audio all separate, parallel. Hire a couple Polish construction workers, or use the empty rooms as a framework. I chose the latter. Once you have rooms, you got something to show. From that point, it's easier for others to imagine how a room could look with textures, objects, or how it should sound (see pic above). As a bonus, their assets can be directly tested within that room, inside the game or editor. Don't underestimate the effect of direct feedback! If one makes a chair that will be used a few months later, it's difficult to tell if the chair really fits there. And getting back on your old models months later sucks. Just bring it on and get over with it at once.


Baking the mesh
So, I made all the empty rooms first. Normally mapping is not my task, but since this bunker has relative simple shapes, and the lack of manpower, I took the job. Plus I got pretty fast with Lightwave, doing tricks with cubes for years and years;) Nevertheless, if you have experience with 3D modelers you'd better close your eyes the next few paragraphs, or you may get a heart attack.

It's pretty simple really. First I plot the floor points, then connect them as 1 complex polygon. Then grab that polygon and extrude it into the height. Flip the faces inwards, voila, a basic room. Repeat this for all rooms in the scene so have a bunch of cube-like rooms. Done… Wait, they need doors and windows. In Lightwave, you can toggle to a second layer and create cubes(or another shape) between the rooms. With Boolean operations like "Subtract", "Add" or "Union" you can use these second shapes to drill holes in walls on the first layer, or to connect the meshes.

It already starts looking like a structure now. But to make the rooms more interesting, it needs some Gaudi twinkles. Pillars, skirting, windowsills, play with heights and stairs, pipes, et cetera. The knife-cutting, extrude, and boolean tools are your friends in Lightwave.

Got to mention that the rooms are not equipped with fine details initially. Stuff like wall-sockets, electro cables, doorknobs, broken bricks, furniture, metal railings, doors or lamps are added later as separate 3D objects, or as a special detail layer in the map. The map itself has a relative low polycount to optimize things like collision detection or background rendering passes that don't need the little details. Then again, surfaces do get subdivided into smaller square tiles, and that quickly adds a lot of triangles again. Why is that? Because we store data per vertex for "terrain drawing" and static occlusion values for simple ambient lighting. The more vertices you have, the more detailed you can bring in that. Plus as a general rule, you shouldn't make huge or very thin & long polygons anyway, as they can cause slight interpolation errors. If the normal on vertex X is a bit bended, the connected polygon will show that off in its lighting. If that polygons is huge, you can clearly see the triangular structure of the map, which is not good usually.

A folded, but flat quad... looking like shit due bad triangulation.

UV
Last but not least are the UV coordinates. No, that's not a term for sunburn degrees. These are (secundary) coordinates that tell how a picture is wrapped on your walls, floors, or whatever surface. With these coordinates you can rotate, shift, stretch or deform the way how a picture appears on your walls. Doing UV's is simple with Lightwave... But doing them exactly right takes time, and is as exciting as watching Karate Kid 8 times in a row. Very common errors each gamer probably has seen in the past 14 3D years:

- Scaled too small. Do I need glasses, or do I see the same crack 10 times over and over again? See floor in pic below.
- Scaled too big. The wall from nearby looks like a blurry N64 texture. See right cube in pic.
- Wall shifts. The painted stripe is 3 cm higher or lower on the neighbor wall. See red arrow.
- Stone tiles do not exactly fit in the room, a small strip still appears next to a wall because the scale and/or position was a tiny bitt off.
- Truck-ran-over-cat-stretched-stripes.
Shit happens. Sometimes the artist forgets to define the UV coordinates for a corner.
See center cube.


Honey, who stretched the kids?

But because I found UV-mapping just too boring, the Tower22 map editor has some paint tools that helps automatically scaling and shifting which saves a lot of time. So, no, I didn’t do any UV-mapping at all in Lightwave. Except for the complex shapes such as pipes with curves. That's because the Tower22 UV tools are too stupid to handle those (for now). And that's also the reason you may see some badly mapped polygons in the movie here and there...


Enough for now. Next time the last step of map-building, importing the maps it into the game!

Close, but no cigar

Wednesday, February 22, 2012

Making of Radar demo #2: Map Design

Ah, another making of post, and a bit delayed as usual. Anyway, where were we? Oh yes, map-design. Designing your worlds, like a game God.


1. Mapping: Common sense versus bullshit
------------------------------------------------
Ideas often start with pictures, snapshots from other movies/games, or weird (day)dreaming. Or being drunk. Smart professors found out that being drunk and/or tired makes you switch over to the creative parts of your brain instead of the logic portion. That's why I keep "idea-doodle" lists. If I saw something on TV or imagined freaky stuff just before going to sleep, I write it down on a paper. These lose, random fragments are not directly suitable for a game though. Nor are rusty factory photo’s from the internet. The Canadian/American army didn't build that Radar Station as a secret party spot for kids that want to get drunk. Neither did the design count on Tower22 or any other action-shooter maps to be made in the future.

Most buildings focus purely on a certain task. Sheltered, providing all required facilities, storage space, and maybe some comfort if the wallet allows. Now concrete structures aren't exactly meant to be cozy. And unless you're talking about Hitler’s bunker, don’t expect a lot of secret narrow halls, illogical stairs, or spectacular vistas. As for Soviet apartments flats, there is not much to expect other than a central corridor and apartments... over and over again, each store. If you are lucky, there might be an office section, or shops at the ground-floor. But all in all, a skyscraper is one of the most boring places to start a game ;)

So one of the first things you got to do as a map-designer, is to let go the logics. The player isn't counting toilets or inspecting your building on structural integrity, running water, if the air-ventilation makes sense, if the apartments are up to the ISO norms, or presence of salmonella. He or she wants cool places to explore, have walls and obstacles to cover or hide, find secrets, be amazed by stuff you don't see every day.

Sounds easy, but that's dang difficult, especially for Beta persons. I'm used to fix (program) things with logical thinking, not with bullshit. It's easy to design a place that makes sense, as you have design-rules and countless of references all around you. Just look in your house, a factory, school, or whatever. But if the map relies on fantasy(nonsense), it gets difficult to make a picture. Imagining one crazy room with weird shapes, floating guts and dancing dragons isn't that difficult. But filling a whole game with it...
Powertip

* If you like, use realistic structures / locations as a framework, but fill them up with your own sick ideas.
* Write down all ideas, store all crazy pics, and always keep a doodle paper next to your bed.
* There are many photo collections about old buildings and stuff on internet.
* Or just grab the camera and have a look in a factory. Do your homework.
* Dare to experiment! Add or remove rooms you would normally expect, enter a room via a secret corridor instead of a frontdoor, and don't forget to reserve space for bigger "wow!" scenery.

* Respect the theme. Whether your map needs to be realistic or not, you can't mix up spaghetti with choocolate ice-cream. Variation is needed, but within a certain boundary. Save bizarre ideas that are hard to place for later usage.


The very first room in Doom2, which takes places on Earth apparantly, doesn't make sense already.

Don't even know what I'm looking at here (Silent Hill). Someone had a very bad dream here.


2. Mapping: Stitching socks
------------------------------------------------
Rooms need to be connected somehow. And in such a way that it suits your type of game. Action games require lot's of coverage, plenty stuff to blow up, and locations that lends itself for spectacular (scripted) scenes. A Metroid or Zelda game needs to be more open, contain loads of secrets, blocked routes that can be unlocked later, and fantasy architecture that remind you you are in Hyrule or on Zebes, or whatever those planets are called. Tower22 will be about puzzling and exploration, so count those elements in.

To make things a bit more difficult, it needs to be scary in our case. The Heinz blood-ketchup tool only works for a short while. Your structure needs to be fundamentally f*cking scary to be horror worthy. One dull hallway spoils the climax. Bad lay-out that gives you a sense of safety, and also don’t make things too easy or the fear-factor will be ruined.

The bottom line, you can't just spray random ideas over your mapcharts. All the places need to be linked with each other in such a way that it challenges the player. Whether that is blasting things up, running for monsters or puzzling your way through. You need to think back- and forward. Room1 may influence room45 later on in the game, or vice-versa.
Powertip

* Don't start building blindly. Write down the global game-flow first and use that as a red line.
* Make lists of the items, monsters and puzzles you like to add in the game. So you can pick and mark them on the list.
* Split your world up in sections, chapters, levels, area's. or whatever you like to call them. Making puzzles and routes per sub-section is easier than for the whole game, plus it's also easier to scrap or adjust sub-sections.
* Later on, you can link the sections with bigger-scaled puzzles (find itemX in section1 to proceed in section3).
* Tease. Show interesting stuff that can’t be accessed yet. Reason to keep playing!


Found this cool pic here. It's the floorplan from the Resident Evil mansion. (Virtual) Architect George Trevor sure had weird ideas about making a comfortable home.

3. Mapping: Don't Enlarge your penis
------------------------------------------------
Another important note about map-design, but certainly horror in particular, is the size of your maps. Bigger != Better (that's Nerdish for bigger isn't better), with the exception of Grand Theft Auto or WoW maybe. Development teams often agitate the public by telling "Our world is 8, EIGHT! times bigger this time, covering 100 billion acres in total!!!". And? So? Bigger is only better if the map is filled with useful things. Zelda Twilight Princess had a big world all right, a big empty world. Secrets were too spread, and because you traveled so much I never felt a cozy bond with the location. Which is usually the big charm in Zelda games for me.

Several war/action-games have big environments too... filled with the same houses, trees and rocks over and over again. At first you're curious what's inside such a house so you explore the area. Later on you just keep running forwards. Screw those details, nothing to do there anyway. I just shoot a few terrorists if I need ammo.

What I liked so much about Duke Nukem 3D (1995), was its realism. Realism?! Hey don't forget that all other games of that time took place in dark dungeons or claustrophobic space-stations. Duke Nukem actually had streets, trashcans, cars, shops, and bars. Recognizable elements from real life. But don't mistake, the DN3D maps didn't make that much sense either if you think about it. Streets with 2 dead ends, spaceships, secret tunnels behind posters, green alien goop area’s, flooded cities. They dosed these fun-realistic elements very carefully.

When I did my first DN3D maps with the brilliant “Build” editor (my start as a “game maker”!), I always filled the maps with as much as possible. 4 houses, each with toilets, kitchens, bedrooms and everything. 3 bars, 2 parking lots, 10 skyscrapers, and so on. Exploring the first house and finding the toilet & mirror is fun. Seeing it for the second time is less of a surprise. Seeing it three or more times just isn't fun anymore. That's (probably) why the realistic "wow!" sights in DN3D were carefully spread over all the ~30 maps. One level had a cinema. Another level had a bar. Yet another level had a livingroom + toilet. Level X had a sewer-system. Et cetera.

The moral: don't repeat your ideas too often. If that means you have to reduce the overall map-size, then so be it. Especially horror-scenery can quickly become dull and predictive if you repeat it. If you look at a game like Resident Evil 1, you won't see 5 gardens, 40 bedrooms, and 6 laboratories either. In fact, the game is pretty small. If Jill had a (working) flamethrower and all keys, she could invest the whole building within 30 minutes, like a real Japanese can finish Super Metroid within 30 minutes.

I hate short games though, so instead of adding more floors with the same stuff to Tower22, the puzzles, monsters and interesting sights should stretch the length.
Powertip:

* List all your main ideas (example, I want a lava, forest and ice world)
* Note the sub-ideas, make an "idea tree"
* Try to equally spread the ideas. If one section has too much while the other is empty, shuffle. Or just remove the boring parts if there is no other option.
* Don't start too big. Adding area's can be easier than removing parts.
* Keep closed sections in your maps. A cheap way to grow in size, but you can also fill them later on if you need to stuff more ideas in the same space.


One of my all time favourite game vacation spots is Clocktown (Zelda Majora's Mask). A small town, but you can spend many hours here. Finding out what all characters do on a particular time of the day, finding hidden passages, or just have a stroll on a rainy day.


4. Mapping: Review yourself
------------------------------------------------
Getting started on an idea is always difficult. One day I'm creative like melting butter, the other day it's not coming any further than blocky Wolfenstein 3D corridors. But once you are rolling, it's easy to link a whole chain of ideas and plot them as a superfast matrix-printer on paper. Or Paint in my case. MS Paint? Yeah, you heard me, MS-Paint dammit. Because it boots up within a second and doesn't bother you with anti-aliasing, hundreds of tools, artistic poopbrushes or what else. I just want to draw lines and squares, that's it. Detail is for later.

Anyway, as said a few times before, you'll have to be a bit careful with your enthusiasm though. Ideas that sound better than sliced bread right now, can still suck if you review them later on critically. But if you spend many hours on drawing the whole map, it's hard to take distance of it. Some ideas just rust into your brains, and you're not open anymore for adjustments or complete different ideas. The same issue also counts for other elements in your game btw. Such as the looks of a monster, the story, et cetera.
Powertip:

* Start your maps simple. Don't draw all details yet, just blocky schemes so its easy to adjust shapes or scrap them if needed.
* Make your maps, then let them rest for a few weeks.
* Then look again... Still got that warm feeling about them? Ifso, good for you. If not, just redo them. Probably your second or third attempt combines the best of two worlds.
* Usually I make two or three variants of an idea. Sometimes with a few months or even years between them. Each “iteration”, I pick the best ideas of the previous attempts and mix it with the new fresh ones.



5. Mapping: Radar Station
------------------------------------------------
Luckily, the Radar Station wasn't part of the game. Meaning I didn't have to follow those guidelines that strictly. So why am I telling that whole story. Dunno :p The Radar didn't have to be playable in puzzling and action terms. The monster down below wasn't even planned originally. Hence, it was meant for testing new objects & physics remember? The idea was to throw a few barrels in the water to show some physics, and have a quick fly-through the building.

Yet, we got a bit more ambitious... if we want to record a movie here, it should at least breath the T22 feeling a bit. At the same time, this map is meant as a playground to test objects and physics. So I wrote down the requirements. Uh...

- Needs to be pretty big so you can render larger objects as well
- Stairs for (ragdoll) physics
- Water & ice for physics, and because it looks cool
- The camera has to be able to take 1 smooth path through the whole building. Not entering a room and turning 180 degrees each time.
- Not only boring concrete and metal s'il vous plait

But on top, don't forget we're dealing with a radar. As said, the building didn't have to make perfect sense. Hell, I don't even know how a real Radar structure looks from the inside, other than from a few photos and N64 Goldeneye. Yet I could do some suggestions of course:

- Control room: Charts and computers and stuff
- Storage space: Small warehouse
- High building, so... stairs, elevator
- Personal: restrooms, beds, dressrooms
- We wanted ice and water, so... open roof maybe?
- How about... a radar dish?

With that in mind, it was only a matter of making rooms for each of those ideas and linking them in a somewhat logical, yet playful way. Got to mention that I didn't have a real good idea of how each room would look yet. Just draw a square in Paint and write "Barracks" or "Control Room". The texture setup and micro-details such as junk or rusty decals were for later concern.

All in all, the Radar isn’t exactly the scariest building ever made. You could find such a thing in reality maybe. Yet did we follow the 4 rules mentioned above? Logic mixed with nonsense, check. The building has no front door, there is a hole in the roof, some places aren’t accessible, and no idea why you would need fuel drums in a radar. Connecting the rooms properly? Played with stairs, ladders and dark tunnels… Size of the map? Not too big indeed. All ideas we’re only used once, so that makes each room interesting to explore. Did we review ourselves? Erh… I did, while writing this ;)

After the floorplans were made a bit, I made a simple mesh so the others could have a better look as well. 2D floorplans are fun, but it's hard to tell what someone has in mind without seeing any 3D shapes and colors.