Thursday, September 1, 2011

Velocita Part III

I was actually glad that my drive gave up. I told myself that it'll be cleaner and more robust if I started over , but I wasn't that smart. It was the time when Direct3D 10 was release and I had an nVidia 8800 Ultra powering my machine and I was aching to find out how pretty my game will look if I took the time to get some effects working. I was really pumped about geometry shaders and the magic you could do with them, like mesh extrusion for motion blur etc. I rewrote the same game in Direct3D 10 with the same physics and the same code structure. Minor changes like no support for .x files was a little hiccup and the new shader code took a little time to get familiar with.

I worked a lot on the graphics, I put in a slightly modified version of the SSAO implementation from the CryEngine 'Finding Next Gen' paper. I reworked all the models in the game to add a little city with a lake and some houses. I even threw in a fully procedural water shader to have it reflect the world properly. The game was looking more or less the same and I didn't go through the trouble of adding any geometry shaders. So I started working on this idea I had where I'd blur the environment map that is being generated in realtime and then put that onto the car so that the color from the surroundings would reflect from the car to fake global illumination. It was a cheap imitation of GI but worked rather well, whenever I drove across the red house my car would turn slightly red from that side. I knew it would work after I saw how well hemispherical Lighting worked on the skull model from the DirectX SDK.

Inspired by the smoke in Need for Speed ProStreet, I started working with soft particles. It was easy to get them going. A few comparisons with the depth buffer that my SSAO shader was already working with, removed all the hard edges that the particles were creating when they intersected with the world. But that wasn't it, I wanted true 3D particles in which I could immerse my car while I did donuts around a fake pole without a collision model. I tried all sorts of things but nothing really worked, I was trying to make a 2D screen-aligned quad to look like a 3D particle by tracing the view ray and calculating the angle it makes with the imaginary 3D particle that is suspended in the world to alter the texture on the 2D quad. Coming home from school to tweak a few variables to see how the particles look was a fun game in itself until I realized I was slowing down.

After being distracted by the graphics of the game for quite a while I came to realize that my physics were still dysfunctional, every time the car hit a bump it'd fly into the sky at the speed of light. I needed the suspensions to work properly which involved a lot of work which is when the structure of the game slowly started to change. The previous physics model that I was working with was strictly 2D so it was a quick fix rather than an actual 3D physics model. As I started implementing the suspension I figured out how the car needs to be defined as a rigid body on which I can add up forces and torques to have it react the way I want it to. It obviously took quite a while to get that done, I ran into some nice tutorials that explained rigid body dynamics which were easy to understand and implement. I'll be honest though, I couldn't understand all the 3D math involved but the physics were simple manageable. It was shaping up slowly though there were a lot of errors everywhere, bugs emerged as I tried to take stuff out from the 2D physics implementation into the new 3D one. I positioned all the forces in their right places, the traction frictional force was supposed to be under my rear wheels instead of the center of the car and the lateral frictional forces on the side of the car under the wheels and after lots of hard work and fighting with stability issues with Euler integration, I had finally finished my car physics simulator.