Sunday, May 30, 2010

Ouch, apples, head

Normally I’m trying to post new achievements every Sunday, but I didn’t catch the train this week. So if you wonder where the screenshots are, I need a few more days. I’m pretty busy last weeks. Marriages, barbeques, birthdays, beer, and yesterday golfing between the cows on a milk farm. Busy at work as well, letting wireless microcontrollers talk with XBee and got to make this monster fully work & drive within a few weeks:

Anyway, I spent most programming hours this week on “Clothing”. No, not my shoes and pants, but physics to simulate curtains, sheets, flags, Batman's cape, etcetera. To be more specific, the motion caused by gravity, wind and collisions. Brrr… You should know that my math isn't exactly great. I know that 2 + 2 potatoes makes 4 potatoes, but that's about it. And as for physics, I know it hurts when an apple falls on your head. So.., that's why Newton does all the physics for me (not the guy, the physics engine -->

Luckily I had some (old) nVidia SDK demo’s, and I ended up with a simple testprogram that produces pretty good results. Although it still moves a little bit like Princess silk. Stuff like this usually comes in several quality-degrees. From ridiculously realistic to Wolfenstein sprites. First there is the university paper wrote by maniacs; lots of Alien formula's, and awesome results... in theory... Then some handy people start implementing those idea's in practice. Finally “the less smarter” guys like me will copy them, hoping that we chose the right references. We don’t really know what we are doing, but hey, it works. My boss doesn’t care either if I understand the theory or not, as long as it works. Do you think I understand the hydraulics of the machine above? Ha, I can't even park it properly.

100% Princess silk, smooth as baby skin

Well that's a little bit dramatic, but since I only have a short amount of time (and attention span) for each individual technique, the way to get it working is usually by Googling for not-too-difficult demo's and maybe a paper. Luckily another blog helped me on my way:

I should give articles like these a "Rick-understood-it" tag. Really, if I can do it, so can you. I'm not a bad coder but the theory usually disappears 2 seconds after I heard it. Can't help it, that's just the way my 2KB storage brains works.

The final result is a mixture of the techniques I’ve seen, using the GPU (videocard processor). And with just a few passes, making it fast & simple. I never did physics on the GPU before, so that was a useful lesson for this week. Normally the CPU is used for collision and physics stuff, but since the GPU is a whole lot faster with vector calculations, it can be worth it to pass the stick. Only problem is that a GPU does not have direct access to your RAM memory. Which is usually the place where collision volumes, previous positions and scene parameters are stored. Instead textures are used to pass the data around:

• Create a grid of “particles”
Imagine them as tiny invisible balls that are affected by gravity, wind and collisions. And more important, those particles are connected with each other. Of course, your towels don't fall apart, now do they? Your math/shader will try to keep the particles together by maintaining a fixed distance between all particles.
• Render initial 3D positions of those particles to a texture.
That would be the curtain/flag in rest pose.

1.- Apply The Force
Apply gravity, wind and previous motion onto the particles, using previous result textures (initially from step 0). Use FBO's / Rendertargets to draw the results to another texture. Yep, your pixelshader will spit out 3D coordinates instead of colors. So, it's wise to use a 16 or 32 bit floating point buffer to store the results.
2.- Apply constraints
Check for collisions (with a few simple primitives that are nearby) and maintain a fixed distance between the particles. Use the texture from step 1 as input, and render to another texture for the results. Eventually repeat this step 1 or more times for a somewhat smoother result.
3.- Final render
Finally render the particle grid as a quad-strips or something. Render as usual, eventually with a BRDF for velvet material effects. The trick however is to replace the “default” vertices with the transformed vertex positions you calculated in step 1 & 2. You can read the texture from step 2 towards the CPU… or better… use “Vertex Fetch” (read the texture into the vertex-shader).

* Tip, batch things.
If you have 10 curtains, do not redo this whole process for each curtain again. Instead render all of them to the same (bigger) target textures. First do step 1 for all curtains, then step 2, and so on. Prevents a lot of shader & rendertarget switching.

The blue "velvet" gloss is just specular lighting. With an inversed normal. Got this result per accident...

The most difficult part in the end wasn’t the math, but getting the texture coordinates exactly right to retrieve the data from a texture. A slight offset will make your curtains fly around like pee in the ISS space station. Allright, enough difficult talk. Hopefully I can post some curtains in action one of these days.

This place sure could use some curtains

Sunday, May 23, 2010


I’ll buy that for a dollar

Howdy. No, no new scenes for this week. The room I'm doing now is somewhat more advanced and requires several new objects and techniques to be made. Oh well, at least that pushes me to fill the database of available entities. Just like in The Sims, I'll need lots of garbage to decorate the corridors and rooms with. Closets, chairs, beds, ovens, frying pans, or whatever they freakin' need in a flat. Electronic stuff like lamps, computers and televisions. And also smaller details such as light switches, clocks, flowers and paintings. Once made, I can throw them wherever I like. Pretty common for games, but still that database needs to get filled somehow. That means get your hands dirty and start modeling.

Since I'm not a modeler, you can imagine I don't have a complete Sims Vacation Expansion pack of objects available to play with. But once in a while, I'll add an object. These are modeled in LightWave, and for the textures I'm using Paint Shop Pro, a big list of material images to draw with, and some tools to generate normalMaps. Usually the engine gives quite good results, even when the texture and model come from amateur hands.

However, this scene has a little bit more advanced objects. A working television and a big rotating(wow!) fan to start with. By default objects are lifeless, boring pieces of wood/metal or whatever they were made from. But some may require interaction, scripts, damage models, sub-objects or graphical tricks. Take that TV for example. We have the model of the TV itself, but it should also cast (slightly flickering) light into the scene, and more important, display something. Ultimately, I would like to play AVI movies on them. But for a start, the screen is a separate sprite that shows an emissive texture with some noise. If you would shoot or switch off the TV, that sprite is simply hided. Or I could paste another (animated) texture on it when zapping to another channel.

Remember that on your TV? Just noticed that the screen texture is tilted 90 degrees though. That TV needs to go back to the factory I guess.

A spotlight with a square beam texture is placed as a sub-entity inside the TV by default to cast some light

Objects like these are always a puzzle. How to make them do whatever they should do, with the available techniques from the engine? Luckily each object can has its own list of specific properties and script events. Don't want to hard-code each and every possible behavior into the engine, so the Python script will take care instead. Whether it is AI or switching a TV to captain Kangaroo. But scripts can't do everything either. Rendering, heavy algorithms or movement are still part of the engine. Can't let a script let that fan rotate each frame. Too slow, and an ugly way to do it anyway, That means the engine should provide enough “API calls” that can be used in a flexible manner. In this particular case I would need an engine function to make that fan rotate. Or operate a TV.

Sorry for the dark pictures last weeks. Can't help it that they didn't put lights here. That pillar looks pretty good for an ugly pillar by the way. Thanks to detail-normalMaps for close-up details.

Not very difficult all in all, but pasting missing features into the engine must be done with care. But once it fits, it gets easier and easier to create new scenery or objects. And more new stuff has yet to come these weeks. How about curtains? Well that’s a challenge for next week. Got to hit the barbeque and beers now.

Sunday, May 16, 2010


I got myself into troubles by opening that door. You boys (and who knows, girls)expect a new scene every week of course, so I'm modeling like mad. Luckily creating a hallway isn't that difficult. Even I can create a corridor in LightWave. But a scene is much more than that. For one instance, how to make it "scary"? It is supposed to be a horror game, so if there is one important thing...

Well, I never wet my pants while watching a static picture though. Except maybe from a shocking reality photo. A game will never carry the emotional value that real footage sometimes has. Like the naked little girl running for a napalm attack during the Vietnam war. You can see the terrible fear in her eyes, and when really thinking about it, you just hope your children will never have to run like that. Madness. But when looking at a computed image, no matter how realistic, it won't grab you to the throat like that. At least not in the next 10 years I guess. You ever felt sorry for assaulting a grandma in GTA? Ever closed a games-magazine while reading a Silent Hill review because it got too much? There is still a big difference between fiction and reality. And probably that's a good thing.

In other words, it's pretty damn difficult to spook the viewer with a few screenshots, especially without having an daunting orchestra or cinematics with some "boo!" events for backup. Include that with my lacking skills to create awesome maps, models or textures. So I'm not pretending to scare you. But at least let's try to illustrate the setting a little bit. Not that the game will be nothing but dark stinky corridors, but I just can't model a cathedral, hellish ruins or a Resident Evil mansion. And certainly not in a week!


Nah, the scenery I have in mind is a mixture between 'realistic' Soviet building architecture (which is not always necessarily cheap and ugly) and very unrealistic dreamish/nightmarish scenes. There shouldn't be much boundaries to the design, so a mapper can go completely ape(if the engine allows). Although I'm trying to keep away from military complexes and evil laboratories for a change. These are cool as well, but we already have Halflife, Resident Evil, Doom3, Farcry and countless other games for that. Been there, done that.

Choose your weapon. A working flashlight with a simple dusty sprite as lightshaft effect(for now). Got to mirror the tangents here by the way.

The hallway here falls somewhere between realistic and dreamish I suppose. Not very likely you'll see it in an ordinary building, but not impossible either. The goal of this (simple) scene is to build a climax. Just a little one. Not an easy job though. As the creator of this little piece of game universe, I know every detail (and bug) of it, tested it six thousand times, and knowing exactly what is going to happen. So how could I judge this scene? I don't think Stephen King leaps into his wife arms after reading his own books for review.

What I'm trying to do is to post a movie here once the scene is complete. And then let you judge. That would be the first tiny demo scene as well. It's always good to have stuff like that ready to show. Unless the clip will suck of course. Hopefully we'll find out within... let's say 2 months... Dammit, another promise I'll have to make true.

This hallway surely could use some cleaners. Or Quick 'n Brite. Someone smeared the whole thing with dirt. A simple trick to surprise your mom is to paste dirty decals onto the walls. But I was looking for a little bit more effect... Reflective blood, eventually some parallax effect. So I made a handcrafted layer of puke and poop, including reflectivity, normalMapping, parallax mapping and a detail texture for the tiny splatters. Let's call it "shitshader". Basically it's just simple multi-texturing, but using a "Burn" blendingmode instead of additive or multiplying:
......burnedColor = white - (white - baseLayer) / burnTexture
I was quite busy drawing those textures and adding that shader properly this week. And almost reproduced the same results within seconds on the toilet Saturday morning after that marriage party.

Sunday, May 9, 2010

Guess what I see

I had a few things on the planning board this week; fixing the flashlight, creating a new scene, fixing some visual bugs, and letting the legs of my Dumpbot walk (again). Unfortunately, Three days and another half million brain cells were wasted during my alcoholic activities this week. And yet more will follow. A good old friend is finally marrying his girl next Friday so you know what that means. Kidnapping the poor guy to Amsterdam, beer, boobs, dirty hamburgers, and a lot more beer. I never saw so many bars in one night. From the Hardrock café to classy bars where access was initially denied for us Hillbillies. Too drunk to notice the doorman though, so we walked in anyway. Well, for each bar we visited two or more beers were captured, so do the math. The result was a terrible headache while strolling around grumpy in the famous red-light district of Amsterdam. Even the ladies behind the red windows quickly closed their curtains for us.

No surprise the planning vaporized this week. However, I promised to open the doors to a new scene last week, so I did my stinking best to repair the damage today. That's the downside of having a few people finally reading this blog; I actually have to do something now. Can't come up with (alcohol) excuses every week :)

Alright, my Dumpbot still is crippled, but at least he can hover-skate with a flashlight now. The problem is somewhere with mixing multiple bone-transformations on an animated character. While the legs walk, the torso can fire a shotgun or read a newspaper. Also the player can override a few bones with ragdoll physics or aiming the chest/head at a target. Well, for some reasons the legs stopped walking after some adjustments.

The brown sausages with the black stick = A robot hand with MAG-lite. Or something. It's switched off now by the way. Another bug suddenly appeared, the screen goes totally black when shining at some parts. I suppose it has to do with screwed up normals in combination with HDR / Tone Mapping...

Another improvement you can't see are "blocking portals". The engine uses Portal culling to boost speed. For those who don't know what these fancy words mean, imagine your house. You can divide it in hallways and rooms. In computing terms I would call those chambers "sectors". Logically, you always see the sector you are standing in. But how about the others? You'll need (open) doors, windows or holes in the wall to look into other chambers. These openings are called "portals". Portal culling means you'll check which sectors are visible via which portals for a certain point in space. Why would you want to do that? Well, Tower 22 is a skyscraper. Skyscrapers typically have hundreds, if not thousands rooms close together. And your computer really doesn't want to update/compute/render all that shit at once. So instead only render what you'll see.

Not much to see here, except a meat hook. So there is really no need to render all chambers and corridors of the entire tower. By the way a crunchy screen filter has been applied. Noise, HDR, DoF, and overall saturation/contrast/coloring parameters can be adjusted for each room, I mean "sector".

Ok, and what the hell are "blocking portals" then? Well pretty simple, as the distance increases a portal can fade-out the sector behind it. A simple color will replace the sector. The hallway below is much longer than you'll see. But since you only see a small fraction due fog, the portal can close pretty soon to prevent rendering the sector behind it. This is also suitable for the windows you might have seen in previous posts. The floor brightly reflects the glass windows, but not the complex geometry behind them. The cubemaps are too blurry for that. So instead of rendering all those background skyscrapers outside for nothing, a simple sky-colored portal (a quad) is accurate enough. Color and Fade-in/fade-out distances are configurable for every portal of course.

What will await in the darkness? Let's find out, and hopefully with a working flashlight next week. If I still have enough brain cells to operate a computer after the marriage that is...

Sunday, May 2, 2010

What's behind door 2?

Hurray! We got a follower. Although a blog can also be handy to review your own progress after a few years, the purpose is to reach other people of course. Besides from a friend and an email, there hasn't been feedback so far, so this is flattering :) Hello Kyle. Human Head studio's...--> Prey?

Installed some freshly modelled radiators this week after some complaints about the cold.

Now since there is at least one person on this planet reading this tiny place on the World Wide Web, let's give some more details about the project itself. Having progress on the graphics, physics or players handling flashlights is nice, but what exactly are we trying to achieve here? Well, besides from having a good time and learning something, the goal is to create a horror game. Or at least a demo, because making an entire game on your own is not going to happen in a hundred years of course. I may be a dreamer, but not stupid. Pyramids weren't build by two slaves either. Just like any other ambitious project, you can't do without (talented) manpower. But rather than begging people for help on the internet fora, I'll do my own homework first; writing the engine + tools and writing down a solid game concept.

Unfortunately I'm not in the position to attract mappers, modelers, sound engineers or artists with a salary or a project that is guaranteed to hit the store shelves. The only weapon I have is charms. Finding a few talented people that love the game concept can make all the difference. But talented people usually get their paid jobs at Pixar or a big game studio. So, the only thing I can do is trying to create an "impressive" demo and then wait... very, very patiently... Chances are small, but at least I can't say I didn't try.

The game itself will be a horror game. But unlike most other games the thrill doesn't rely onto killing hordes of demons with 100 liters of Heinz ketchup. Not that I don't like gore or action, but I found that fear often lies in suspense and the "unknown" rather than actual confrontation. A little bit like The Blair Witch project, but with a more bizarre setting like that can be found in the Silent Hill games or Hellraiser movies. The purpose is to put you in a surrealistic world that never feels comfortable; Soviet era skyscraper "Tower 22".

You'll wake up in your apartment and start your new job as a caretaker in this massive building. Wiping floors, painting walls, delivering packages, replacing lightbulbs and other dull jobs. However, you'll start to feel claustrophobic soon. Most windows are barricaded, the floor lay-out doesn't make sense, and you can't find an exit anywhere. In fact, you don't even know at which floor you are. And above all, you never actually saw someone from day one. The boss calls you once in a while, but you never met him. And although the building is full of traces, where the hell are its inhabitants?

In your free time, you'll start to explore the building. The deeper you dig, the stranger it gets. An ordinary apartment door on the corridors can reveal something much different than you might expect. And of course, you won't be alone forever... But instead of killing enemies, you'd better stay out of their way...

What would be behind this mysterious looking door? Find out in a next exciting episode