This blog covers the rants, ponderings, considerations, experiences and life of Cameron Harris.

Thursday, 26 June 2008

Understanding the ray tracing debate

Intel are currently working on technology that they think will completely revolutionise video game development: a ray traced graphics system. Now to understand the significance of this, it's necessary to understand a bit about current graphics technology.

Every scene in a video game starts out it's life as a large collection of objects that together are usually combined into a scene graph. These objects are usually expressed in terms of their component polygon meshes, textures, etc. After all the physics calculations, collision detection and other game related work has taken place on the CPU, the resultant information is plugged into a rendering engine which traverses the graph and sends the display information to the graphics card. The graphics card turns this 3D co-ordinate data into a 2D image and presents it into a viewport on the user's monitor. The ray tracing debate primarily revolves around this 3D to 2D rendering process.

Modern graphics cards are very fast at performing floating point calculations and matrix operations. Despite video game graphics only using three dimensions, most APIs use four dimensional homogenous co-ordinates and matrices, with each point specified as a floating point number. The usual x, y, z co-ordinates are supplemented by the mysterious w co-ordinate. You need this extra dimension to perform translations in addition to linear transformations (known as affine transformations) with matrix multiplication. A video game will define a special matrix that is pre-multiplied with each point of every polygon by the graphics card. This special matrix is called a projection matrix and defines how 3D objects will be "projected" into 2D space. Game developers usually want to make their games look photo-realistic, so often they will use a modified perspective matrix to orient and translate the scene around the camera and project the co-ordinates similar to how an eye would observe the objects in real life due to how light works. This process is known as rasterisation. After the graphics card has worked out the position of all the objects, it then iterates over every pixel visible on the screen and performs lighting and texture calculations to work out the colour of the visible pixel.

As you will undoubtedly have noticed, this is extremely non-physical. In real life, a camera has a sensor, a lens and a scene has lights and objects. Photons travel from the lights, get caught up in all sorts of quantum electrodynamic interactions with matter. Eventually, these photons make their way through the camera lens and hit part of the camera sensor causing a change in energy that can be detected and processed electronically.

This important difference means that a lot of the visual effects you take for granted in video games had to be painstakingly emulated by the designers and programmers of the game and it's engine. Shadows, reflection, diffusion, refraction and many other lighting effects aren't possible with raw rasterisation. Often game engines will try to pre-render things like permanent shadows on the floor caused by buildings. Beyond that, it's up to the game developer to write shaders that attempt to simulate lighting effects for the most important elements of the scene, neglecting the less important elements.

This is where ray tracing comes in. When you see photorealistic renders produced by computers, you'll often find that they were produced using a ray tracing algorithm. Ray tracing usually refers to the process of casting a ray from the each pixel of the camera and seeing what object it intersects. When this ray intersects an object, it can produce up to three new types of rays depending on the geometry of the object – a reflection, a refraction and a shadow. This process is repeated until the ray encounters a light source, and a colour for the pixel is generated using the information accumulated during the ray's travels. This algorithm is very simplistic, but modern algorithms can generate multiple rays per pixel, generate multiple rays per intersection, use statistical processes and perform fairly complex calculations at intersection. The core of the algorithm remains the same, however. Further extensions include Radiosity. This makes scenes look far more realistic, but it's far too complex to explain here.

Ray traced graphics will supposedly use a version of this algorithm instead of the rasterisation method outlined above. It's clear where the appeal of this system lies. The calculations are very similar to those required for the physics engine, which is good, because arguably lighting is just an application of physics. nVidia are already on their back foot and acting defensive, probably because such a change in the industry would require a complete redesign of their graphics cards, which are currently optimised for a rasterisation pipeline.

The problem with ray tracing, however, is that it is exceptionally slow. Despite all the recent advances in ray tracing and the hugely complex tasks involved in making rasterised images look decent, on current computers rasterisation has the edge if not only for the fact that it's easier to take shortcuts. However, as video games become increasingly more dynamic, require increasingly more polygons and computers become even more powerful, ray tracing will become more attractive. If you consider rasterisation without all the shortcuts afforded by the fact that users don't expect every little bit of the scene to be photorealistic, it's not much faster than well optimised and accelerated ray tracing. Global illumination, high polygon models, decent lighting effects and motion blur are all far easier to implement with ray tracing. Additionally, models can be represented mathematically when ray tracing, allowing far more realistic curves and shapes. I cringe whenever I see ten sided "wheels" in video games.

A second problem is that ray tracing isn't good for everything. Many of the desktop 3D effects available on Vista, OS X and Linux wouldn't make sense with ray tracing. These desktop effect systems pretty much define the perfect use case for rasterisation. However, by the time that ray tracing becomes viable, the chances are that floating point CPUs will easily be fast enough to perform these calculations without specific rasterisation pipelines.

So where is the future of game development going? Well for the meantime, high quality graphics are rasterised, and they'll stay that way for at least a few years. Though, as time goes on we're going to see more and more research going into ray tracing and perhaps preliminary support in game engines for ray tracing. I think that the computer graphics will never be 100% ray traced simply because certain tasks gain no advantage from ray tracing. The next generation of video game consoles (PS4, Xbox "720"?) may very well have ray tracing hardware. Certainly, if we continue to aspire to photorealism, ray tracing is the future.

Wednesday, 25 June 2008

Stereotypical gamers

The Top 7 Stereotypical Gamers We Hate

I thought that list was quite good. I swear that I've met some of the people that those pictures are based on.

Tuesday, 17 June 2008

Metal Gear Solid 4

Words simply cannot describe how much I enjoyed this game, but I'll try anyway. I picked it up at last Friday afternoon and finished it Saturday night, totalling 25 hours of gameplay – I could not put it down.

The Metal Gear Solid series has always been my favourite example of how deep, intelligent and involving video games can be, and MGS4 is no exception. It largely wraps up the loose ends from the previous Metal Gear games, but does so with unparalleled production quality and despite being the seventh canonical game and the series having very political genres throughout, the plot remained fresh and interesting. Every cutscene was artistically composed and meticulously directed, and ontop of that, the game just looks beautiful.

MGS4 is a departure from the previous games in terms of gameplay, but it works extremely well. Stealth is still a large element of the gameplay, but the action element has been kicked up a notch. Unlike the previous games in the series, the action parts flow well and mesh with the rest of the game. It feels far less clumsy, partly because the controls have been modified to reflect this shift in gameplay. As much as I loved the earlier MGS games, MGS3 and to a lesser extent MGS2 felt a bit like movies with interactive scenes. The gameplay in MGS4 seems to have had extra life breathed into it and more truely resembles it's subtitle, "Tactical Espionage Action".

In MGS4, you revisit some key locations from the first MGS game. The game is full of flashbacks and reminiscence from earlier in Solid Snake's life. If you have played the first MGS game, as I did when I was ten, these ghostly voices will help you relive the events of Shadow Moses. I can't explain why, but this was a very nice touch. Nostalgia perhaps...

I couldn't give any game a 100% rating, but Metal Gear Solid 4, and the MGS series in general, are extremely close. I only hope this game is remembered in years to come for the masterpiece it surely is, so that our children and their children can play it.

Thursday, 5 June 2008

Jersey Transportation

The States of Jersey's have been considering changing the island's transportation system in a key way over the last few days. They're planning on building some sort of public transport network, such as a railway or guided bus lane.

For a change, I actually support these plans. Almost ten thousand people make the journey from the west side of the island into town every morning between 8 and 9. A considerable portion of this journey is spent almost stationary on a single lane road with very little traffic in the reverse direction. And despite it only being a six mile journey, it isn't uncommon to be stuck in traffic for above an hour if you leave at the "wrong" time. Google Maps estimates that the trip should only take fourteen minutes. No-one wants to be stuck in rush hour traffic. Not only is it horribly boring, you have to pay attention rather than just turn off and maybe have a nap. Even once you're out of the fire it's into the frying pan because you have to find parking, or so you hope. That being the case, surely everyone should take the bus?

Unfortunately, our bus service isn't sufficient for this. Last statistics I read, our bus service was only capable of carrying just under one thousand people into town in the morning. The problem is most evident when you decide to try and catch the bus only to find three or four just drive past -- by which time you're late for work, school or wherever you were trying to get to. Even assuming you dont walk under any ladders, kill all the black cats you see and don't step on the cracks in the pavement, and somehow manage to catch one of these elusive beasts, there's still no garauntee you'll get to your destination in time. This is because our busses all take the most traffic-laden paths through the island. It's not even cheap. It costs £1.50 each way, and even more if you want to get a bus from town to somewhere else in the island. It's cheaper in petrol and parking to carpool than it is to individually catch the bus, and if you're lucky enough to have a free parking space, it's cheaper and quicker to just drive in. In our eco-concerned world, what can we do to make public transport a more attractive prospect?

Firstly, and most obviously, have a higher capacity. Secondly, make it cheaper. Lastly, make them quicker. The first is simple to solve, at least on paper. Run more busses or a larger number of trains on a railway. The second is just a matter of accountancy. The latter one comes for free if you decide to create a railway, but it's more difficult for busses, who currently share the same lanes as cars. So far it seems like a railway is ahead, but it might cost millions and might take as long as five years to implement, but an improved bus system could be implemented in a few months for next to nothing in comparison.

Obviously to decide what to do, we need to work out where our priorities lie. Capacity is simply a necessity, without which the service won't thrive. Cost is supposedly an important factor, especially with increasing fuel prices. However, few people carpool, and many people pay for parking since it's more convenient than getting the bus or parking for free a couple of miles away and walking or cycling the rest. That leaves speed. Personally speaking, how long the journey takes is far more important to me than a few quid. I'd love to be able to shed the hassle of a car were it not for those all important 30 minutes of extra sleep I get by driving. Potentially that 30 minutes could mean the difference between performing optimally, getting higher grades in an exam, and getting a job that pays more quids per day. The same holds for people working.

I've missed one thing, though: comfort. Comfort is also an important consideration. Consider Bill Someone, who gets up at 8:00, walks five meters from their door to their comfortable, climate controlled Lexus and rolls along the country roads, cruise control on. Now consider Bob Anyone who gets up at 7:15 to weather the wind and rain for 20 minutes waiting for a bus. When it finally arrives, it's full of people with coughs and colds from standing in the rain all week, and the bus' temperature alternates between too cold and too hot. When he finally gets to the station, he has to dash half way across town in five minutes because the bus was held up. Which one is going to perform better at work? Okay, maybe I'm exaggerating slightly. I said above that driving during the west to east rush hour could be an aggravating process, but it's a damn sight better than getting the bus.

So, price be damned, and Connex: Stop advertising that it's cheaper to take the bus. People are probably going to take the most comfortable, quickest transporation they can get their hands on. Our main choices are an improved bus service and a train service. My say: do both. The further we can distance ourselves from private transport, the better it is on the environment and the economy. Create a prioritised bus lane now, build a railway over the next few years. Just work out what people want; do surveys and research, but I strongly suspect that what people want is speed and comfort, so long as the price is competitive with driving in. A well tuned bus service could get people between the west and town in under 20 minutes, and be just as comfortable as a car, if not moreso. A train would be good, but it won't solve all our problems. We still need a good bus service.