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.

3 comments:

  1. looks like some hardware tessellation

    ReplyDelete
  2. Hardware tesselation is certainly something to try one day, but all the LOD's you see here are just manually made 3D models. And the floor on picture 1 uses Parallax Offset Mapping to make it look "3D".

    ReplyDelete
  3. Excellent website you have here, so much cool information!..
    Cmos battery

    ReplyDelete