Lovin LINQ

December 12th, 2011 by

One of the many joys I get from programming is creating beautiful LINQ expressions in C#. This is one I made today to create a random sequence of integers containing a few doubles. The Shuffle method is an extension I wrote a while back. It basically creates a random order of an Enumerable.

itemsInOrder = Enumerable.Range(0, itemCount)
                .Concat(
                    Enumerable.Repeat(
                        Enumerable.Range(0, itemCount), doubleOccurance)
                        .Aggregate(Enumerable.Concat)
                        .Shuffle()
                        .Take(numDoubles))
                .Shuffle()
                .ToArray();

Gotta love those things.

Lecture

June 23rd, 2011 by

I gave a 2 hour lecture today together with Marries van de Hoef about Advanced Computer Graphics. It was an introductory course into more advanced graphics topics. Since we went to the GDC2011 this year we wanted to present some of the techniques we saw there. Also there are no advanced graphics course given at the University so Marries and I took on the challenge.

The topics we covered are:

  • Inferred Lighting
  • Culling
  • Subsurface scattering
  • GPU Particle Physics
  • Component based entity system

The slides can be downloaded here.

I did not expect a lot of people to come (about 40), but there were a lot more people. Afterwards we got very positive reactions so I think it was a success.

May questions arise from the lecture, just send me an email and I will try to answer your question. :)

Lecture

DamSchreeuwer

May 21st, 2011 by

DamSchreeuwer is a game we (myself, Adriaan Jansen and Manuel Kerssemakers) created for the Game Engine Programming course at Utrecht University. It was created in just about 4 weeks. The assignment was to create a 3D game. We decided that we would go all out on it.

The goal of the game is to ‘kill’ as many people as possible by running them of the edge of the level. You can do this by screaming which scares the people around you. Once you scared the crowd enough you can also set them on fire. The scared people also light each other on fire which created a major chaos.

Audio also helps a lot with creating the feeling of chaos basically there is this very addictive song and people screaming (in 3D) when they are scared. It sounds really simple but its very funny.

The game contains 4 levels. Since we are all programmers and not artists the levels are very abstract. We baked lighting with Maya with exaggerated global illumination for a cool style.

We used Ogre for rendering, Havok for physics, CEGUI for the UI and Irrklang for audio. We coded the AI from scratch, which uses an event based system. One notable thing is that the game scales to a lot of cores. The heaviest part is the AI simulation. We used Intel Threading Building blocks to update them in parallel. Since each AI requires information from neighboring AI its hard to update them in parallel. We used the State/Mind design pattern first introduced at the GDC Europe 2010 to handle concurrency.

So what was my contribution? I basically setup rendering, physics, all multi threading and the levels. Manuel created the AI and Adriaan did the character graphics and the GUI.

Today we got our grade for this game which is also the reason I posted this post. Our grade? A 10. This is what our teacher had to say about it:

Impressive achievement: not only an original game, but also striving to use cutting-edge techniques.

This game is far from complete, we will keep working on it. Until then you’ll just have to do with these screenshots.

Update

May 10th, 2011 by

Little update on the progress of the FireFly2 engine.

The image below shows

  • dynamic lighting with spotlights
  • normal mapping
  • specular mapping
  • glow maps
  • regular diffuse textures

All this stuff is configurable through XML files which describe just about everything, from materials to the scene.

Showing off some features

The model was made by Dmitriy Parkin

Physics for Game Programmers

March 2nd, 2011 by

Today, my day at the GDC2011 here in San Francisco started with the GDC2011 Dutch Business Breakfast. I met a few people from the Dutch game industry and also a few students who also got a scholarship from the Level-Up project to go to the GDC. What I found really cool and also kinda awkward were the one minute business pitches. In such a pitch someone can speak to everyone there and tell them what they need. Then later, people with the resource can talk to them to see what they can do for them. I found this really weird since these pitchers are not afraid to ask for half a million dollars.

The rest of the day I attended the Physics for Game Programmers tutorials. I did expect much of it because, well I will probably never build my own physics engine because its way to complicated with all the math involved. I have always just used existing physics engines because they always suited my needs. I did create a very simple physics engine for Mia and Momo but that was not very complicated compared to what I had seen today.

Of all the talks I attended today there were two that I found really interesting. The first was about how to network physics and the second was about fluid simulations. Especially the second got me thinking because I am thinking about a new effect involving fluid dynamics.

Networking physics

I didn’t really learn anything new here. I have looked at how to network physics before. Simply put the problem is how to sync the entire physics simulation over all the client computers in a game. This is a non-trivial problem because different games require different focuses. For instance in a first person shooter you generally want zero-lag meaning that when a player performs an action you immediately want to see the result of this action in the game. This becomes extremely hard when sending input to a server because then the client first has to wait for the the response of the server before it is able to continue with the physics simulation. This creates some lag between the input and when the input is processed which is very annoying in a first person shooter. In an RTS game however this might not be a problem.

This lag in the so called client-server model can be partially removed by also running a physics simulation on the client computer. This means the client is predicting what the server will send back as the new state. The problem with this is that the client does not have all the information required to run the simulation because it is missing information from other clients. This is solved by rewinding and replaying the simulation with the correct state that is received from the server. This however introduces a lot of overhead because replaying a few simulation frames can be very expensive. This technique is called client side prediction.

Another proposed method is by using a deterministic physics simulation. With this method the server (or a client) waits until it has received all information from the other clients and than updates the simulation using a deterministic simulation. This implies that the state will be the same at every client. The advantage of this method is that it is very cheap and takes up almost no bandwidth. The disadvantage is that there can be quite a lot of lag and that creating a deterministic simulation is a real pain in the ass.

Last but not least the speaker talked about authority schemes. This removes the need of an explicit server. A client simulates and distributes the state of some of the objects in the world. A client has for instance authority over its player and over all the objects it interacts with. The state of this (sub-)simulation is than distributed to the rest of the client using either a peer-to-peer model or a server. The nasty thing about this approach is that a player is now able cheat because the simulation runs on his own computer instead of on a trustworthy server. Also problems occur when multiple players interact with the same object.

So all and all it really boils down to what kind of game you are trying to network. For first person shooters where a few milliseconds of lag is a problem and where dynamic rigid bodies are scares, client side prediction is good solution. For RTS games a deterministic solution could work very well. There is no out of the box solution here, which is probably also the reason why physics engines don’t provide it.

Fluid simulations

The last session of the day was about fluids simulations. There was actually quite some math involved which I can’t reproduce right here. The reason why I found it interesting is because it is possible to run a fluid simulation completely and quite efficiently on the GPU using either CUDA or Compute shaders. The way it works is using particles that represent a small piece of the fluid’s body. These particles are then simulated on their own and during rendering they form a solid body again. This session gave me some insight in how it works but didn’t really thought me anything new. I had already seen most of the presented work in presentations like this one.

Well thats it for today again. Tomorrow I will be attending a broader variety of sessions. Also check our Marries’ and Emiel’s blog!