Review: Game Physics Pearls by Gino van den Bergen & Dirk Gregorius

GamePhysicsPearls

Game Physics Pearls has been a book on my wishlist for a while, and I’ve finally got the chance to finish reading it and putting up this review. The text is edited by Gino van den Bergen and Dirk Gregorius, and each chapter is written by a unique author. I found that a lot of ground was covered while still keeping the book somewhat cohesive. It doesn’t feel like a complete random mash-up, and the progression is nice.

Some of the chapter content includes: basic mathematics, game physics pitfalls, broad phase, narrow phase, GJK, SPH, parallel particle simulation, ropes, soft bodies, and verlet integration. Even after reading several game physics books, there was still a decent amount of information I had not seen before. I especially appreciated the chapter on verlet integration (and the subsequent chapter on cloth physics that builds upon it). So many of the books I’ve seen seem to focus on Euler integration techniques and it’s rare to see much talk of verlet integration (or position based dynamics for that matter). This is the direction I am going with my physics engine, so it was nice to see some coverage.

Overall I was impressed with the quality of the book. Sometimes with these “gem” style books, it can be a hit or miss if the chapter is relevant to your needs. I did not think that was the case here. Nearly all the chapters had some pertinent information, and (while maybe not directly relevant to my current project) were at least interesting to read. I did not feel bogged down with math, most of the explanations made sense and there wasn’t too much needless minutia.

I would definitely recommend this title to anyone interested in video game physics. While there are other books that may be better places to start (as the book sort of assumes you know the basics already) this would not be a bad book to add to the collection. There are actually only a couple game physics books that I *haven’t* read, so it’s getting to the point I will need to stop researching and start writing code. Wish me luck!

Review: Physics for Game Programmers by Grant Palmer

PhysicsForGameProgrammers

Today I will be reviewing Physics for Game Programmers by Grant Palmer, another stepping stone on my quest to build a custom physics engine. Overall I enjoyed reading the book, and I feel like I learned a lot of general things but not enough to base a physics implementation on. Please read on for more details.

What I found most interesting about this text was the explanations of certain aspects of physics that I had not seen covered before. I have already read about 3 or 4 different books all on game physics, and I was expecting this title to be more of a refresher than anything. However, I was surprised to find a lot of things I didn’t know about. In particular, the coverage of drag forces was extremely detailed including things like turbulent and laminar flow and the Reynolds number. Some of the topics covered include: Newtonian mechanics, kinematics, projectiles, collisions, sports simulation (golf, soccer, basketball), cars and motorcycles, boats, airplanes, rockets and missiles, explosions, and lasers. Quite a lot in a little under 500 pages.

There is certainly a breadth of knowledge living inside this book. It was undeniably an interesting read, and I felt like I learned a decent amount. However, I am not sure it really got me any closer to building the physics engine I have set out to create. Let me explain. While there are equations listed in the text, and some example code is given, it is mostly used to support the 2D sample applications. I am not sure there is much I could just pull from the book an paste into a 3D engine. The concepts are sound, and it wouldn’t be a huge stretch to make it work, it’s just not spelled out for you. To be fair, some topics are explained well, like his discussion on differential equations and drag forces among other things.

My main gripe with the book is that it did not really try to explain rigid-body dynamics at all. There are some interesting things talked about, like sports and boats and planes and all that. And certainly there are probably a ton of sports games and simulators that would benefit from that focus. For my purposes, I was looking more for a rigid or soft body solver, and how bodies can interact with each other. Unfortunately, that was not discussed at all.

It’s not that I want to get down on Physics for Game Programmers, and I think Grant Palmer did a great job within the scope of what he was trying to do. The book was entertaining and relevant, it just wasn’t a one-stop-shop for all your physics needs. However, it does cover some basic things well, and includes topics not even touched by some of the other books I’ve read. That alone would make it worth reading, just set your expectations correctly. Once you are ready to make an actual implementation, you will likely need to seek other books or papers. But I guess it is almost always the case as one book can rarely impart all the knowledge you need in any given topic. To sum up: I liked it but wanted more.

Review: Shadow Algorithms Data Miner by Andrew Woo

ShadowAlgorithmsDataMiner

Shadow Algorithms Data Miner by Andrew Woo was an interesting find for me. The oddly titled book was released over 2 years ago, yet there wasn’t a single review on Amazon (where I purchased the e-book). However, I read the table of contents and it seemed pretty extensive in it’s coverage of computer graphic shadow techniques. So I decided to take a chance and purchase the item. I am glad I did.

Prior to vacationing in Japan, I started reading the book and managed to finish it before the plane ride back. It was only about 200 pages long, somewhat short for a technical text, but Woo managed to fit a lot in there. He speaks about planar shadows, shadow depth maps, shadow volumes, ray tracing, hard and soft shadows, filtering techniques, and more. While it certainly was not exhaustive, I don’t think that was Andrew Woo’s intention with this title. It is much more of a broad overview, with ample references to relevant papers and topics to research further on your own. With that in mind, there is almost zero code or pseudo-code contained in these pages. He just explains the general concepts of how the algorithm functions, and it is up to you to implement after further research.

For any readers using Kindle tablets, you will be in for a treat. The Kindle e-book is formatted exactly like the hard-cover, and happens to be about the same aspect ratio as the Fire HDX. This means it looks basically like a real book, everything is formatted perfectly (a major issue with technical e-books), and you don’t have to zoom or pan around. The disadvantage is that you cannot change the font size or background color like you can with most Kindle titles. A fair price to pay for a more streamline experience.

Overall I was impressed with Shadow Algorithms Data Miner and would recommend the book to anyone wanting to learn about computer graphic shadow techniques. Keep in mind the book is highly approachable, but it may be a tad simple for advanced users. If you already have a good understanding of how different shadow algorithms work, you probably won’t find any gems here. On the other hand, if you are starting out this book can be invaluable. It has my seal of approval.

Creating a 3D Game Engine (Part 23)

engine_zero_08

While I implemented frustum culling a little while ago, I never actually coded a proper bounding volume. For the  bounding test I was using a sphere, but I just set the radius to some hard-coded value. This was fine when I just had a bunch of similar sized cubes on screen, however it broke apart once I started getting varied models imported. This week I decided to do something about it.

After a quick Google search for bounding spheres, I ended up on Wikipedia. There was some good information there regarding minimal bounding spheres (also known as smallest enclosing ball or minimal enclosing ball), and I was given a few options for different algorithms. After reading the whole page I become very interested in the “bouncing bubble” algorithm, especially due to the spiffy gif animation showing it in action. The brief explanation seemed easy to follow compared to the other methods, and the error percentage was only around 1-2% which is much lower than Ritter’s algorithm (which can be as high as 20%). So far so good.

Unfortunately I found next to nothing on the internet describing the method. What I did find is a post from last year on StackOverflow by someone in the same situation as me. This lead me to the original paper describing the method, which was for sale for $18 on Grin.com. Honestly I don’t mind paying the money for quality information if it’s going to help improve my engine. The article was fairly easy to follow, and provided just enough information to base the implementation on. At first I was disappointed that no source-code was given, but I managed to pull it together using the pseudo-code. All in all I think I spent about 4 hours on it (including research) so I’m happy to have got it working so quickly.

Below is my bouncing bubble implementation. Keep in mind I have not profiled this code, it’s possible it’s not fully optimized. However, I’m only doing the calculation when a 3D model is loaded, so it shouldn’t effect performance at all really.

BoundSphere RenderCore::calculateBoundSphere(vector<Vertex> vertices){
	Vector3D center = vertices[0].position;
	float radius = 0.0001f;
	Vector3D pos, diff;
	float len, alpha, alphaSq;
	vector<Vertex>::iterator it;
 
	for (int i = 0; i < 3; i++){
		for (it = vertices.begin(); it != vertices.end(); it++){
			pos = it->position;
			diff = pos - center;
			len = diff.length();
			if (len > radius){
				if (i < 2){
					alpha = len / radius;
					alphaSq = alpha * alpha;
					radius = 0.5f * (alpha + 1 / alpha) * radius;
					center = 0.5f * ((1 + 1 / alphaSq) * center + (1 - 1 / alphaSq) * pos);
				} else {
					radius = (radius + len) / 2.0f;
					center = center + ((len - radius) / len * diff);
				}
			}
		}
	}
 
	return BoundSphere(center, radius);
}

Also, I should remind myself to do benchmarks more often. After I added all the normal mapping and shadow stuff performance has taken a big it. Before I was getting likely over 2400fps, now I’m only getting around 1600fps. Still acceptable, but maybe could be better with such a simple scene. The culling definitely helps, but I may have to look into other optimizations like batching and instancing if I want to get the speeds I need for my project. I’ll probably get started with the physics engine aspect soon and then optimize later if I can’t meet my 120fps target. Cheers.

Creating a 3D Game Engine (Part 22)


 

After struggling for a bit with the shadow mapping implementation, I finally have something presentable. I followed a tutorial from Microsoft and thought I understood what was happening. However, it required a lot of changes in the rendering code and it took a little while to get things working. Even once it was somewhat functional, I still had some issues with what they call shadow acne. It seemed really bad on the self-shadowing side of objects. I tried tweaking all the values I could (i.e. the bias in the shader), but I was not able to get it to look right. Finally I just set it so that there wouldn’t be self-shadowing of a single polygon. This happens to look fine, since the lighting equations make the polygon shaded anyhow. I’m not sure if this will work for every single instance, but with the simple models I’m testing with it’s fine.

I’m at the point where I really want to get the physics engine up and running. Still have some more research to do, so I bet it will take some time before I have something more to show. But it’s coming along.

 

Review: Physics for Game Developers: Science, math, and code for realistic effects by David M Bourg & Bryan Bywalec

PhysicsGameDevs

I can say I had a pretty good time with Physics for Game Developers: Science, math, and code for realistic effects by David M Bourg & Bryan Bywalec. It is a very approachable text, and makes a somewhat complex topic more manageable with concrete examples. It’s definitely a book about 3D physics, but many of the samples are done in 2D for clarity. I did not find this to be an issue, and most of the equations and code were digestible. I did see some heat on the reviews, saying that there were errors in some of the code. I could not verify this, but just from reading the book the authors seemed knowledgeable.

At the beginning, each chapter covers a fundamental aspects of physics. Later they go into examples that could be used in a game. Some of the topics covered include: Newton’s laws of motion, kinematics, force, kinetics, collisions, projectiles, particles, rigid-bodies, springs, aircraft, boats, cars, guns, sports. In the last section it goes over some emerging technology and how they work, like touch screens, motion-sensors, 3D displays, and the physics of sound. I very much enjoyed the whole book, and liked that there were practical examples to go along with every topic.

Many technical books can get lost in the math equations, but I found this text to have a good amount of explanation and not too many long proofs. This could be a pro or a con. On one hand it makes reading it a little more straight-forward, but on the other-hand, it may leave out some important details when it comes time to create your own implementation. I’m not sure I would want to base a physics engine solely on this book. It’s not that it was bad, but it was more of a general concept thing than giving you all the code. That said, there is a good amount of code in the book, it just may not be as complete as some other sources.

Overall I was satisfied with Physics for Game Developers. It may not be my favorite physics book (I found Game Physics Engine Development to be a lot better for my purposes), it still seemed worth reading. Now I am beginning to realize the creating a physics engine will not be easy, but the more I read the more I feel capable of this task. I think the book has helped.

Review: Creating the Art of the Game by Matthew Omernick

CreatingArtGame

Creating the Art of the Game by Matthew Omernick was a quick and easy read. However, I wish I had noticed the age of the book (and also the age of the reviews on Amazon). This book is seriously dated, and it has not aged well. Although some of the topics are still applicable, and lot of the stuff he talks about is ancient in the game dev industry. All things considered, it’s not necessarily a bad book, it’s just not very useful at this point.

The book covers a number of fairly basic topics regarding art creation for video games. Some of what is discussed includes: gathering reference, modeling theory, texturing, lighting, user interface, and tips and tricks. It became clear a few short chapters in that this book was really geared at beginners. I mean total beginners, as in still in high school, no experience whatsoever. Had it not been so dated, I could still recommend it to high school students. The only problem is that a lot of the content is not very useful anymore. He talks a lot about things like vertex lighting (saying per-pixel lighting is to intensive for real-time use), faked shadowing using square/circle textures, planar reflection by duplicating and flipping geometry, etc. These are all pre-shader era techniques and are somewhat amusing to look back on.

Omernick refers to the Playstation 2 a lot (the popular console at the time) and makes some interesting predictions about what the “next generation” (now the last generation) would be able to do. Clearly the guy has worked in the industry and knows what he is talking about. It’s just that the state-of-the-art has advanced considerably in the past 10 years, and this book does not stand the test of time. However, I did learn a trick or two regarding texture creation (which fundamentally has not changed much) so I don’t feel too bad about spending a few days reading this book.

Unfortunately I don’t think I could recommend this to anyone at this point, given the beginning level and dated content. No worries, on to the next book.

Review: Game Physics Engine Development: How to Build a Robust Commercial-Grade Physics Engine for your Game by Ian Millington

Game Physics Engine Development

In this review, I will discuss my experience with Game Physics Engine Development: How to Build a Robust Commercial-Grade Physics Engine for your Game by Ian Millington. This is actually the first book I’ve ever read solely on game physics and I think I made the right choice here. Although I have developed several physics engines previously, they were only in 2D and the extra dimension complicates matters significantly. Game Physics Engine Development is a book specifically about 3D game physics, though the author does make a short reference to 2D physics at the end. I felt like the book had just enough math to explain the concepts, without getting bogged down in technical minutia. I also enjoyed the friendly writing style, the approachable implementations, and a rational coding standard.

Ian Millington’s book covers a lot of ground, and each chapter builds up a single aspect of the engine. Many chapters could stand alone in one aspect or another, though they do come together at the end. Some of the topics covered include: basic 3D math (vectors, matrices, quaternions), laws of motion, particles, rigid bodies, mass aggregate physics, springs, collision, contact resolution, velocity and acceleration, torque, friction, broad-phase collision detection, bounding volumes, and more. While the book is “only” 552 pages, there are a ton of things packed into those pages. I found the coverage to be fairly in-depth, without getting lost of mathematical proofs or anything like that. The book is very practical in that way, and a lot of the code samples could easily be the basis of a real implementation.

Overall I enjoyed the book at lot, and breezed through it within a week, eagerly anticipating each new chapter. Being the only physics book I’ve read so far, I don’t feel 100% confidant creating a physics engine myself just yet. However, I do feel it has explained a lot of key concepts necessary in physics development. The book was everything I was hoping for, and gets my recommendation.

Review: Digital Modeling by William Vaughan

Digital Modeling

There is no question, Digital Modeling by William Vaughan is a book every 3D modeler (or aspiring modeler) should read. It really captures the essence of what makes a good model, and doesn’t get bogged down with technical details of specific modeling packages. In this review, I will briefly go over why I think everyone with any interest in 3D art should pick up this book.

At 432 pages, it’s a pretty light read. The author, William Vaughan, presents the material almost as you’d expect a teacher or a mentor to pass knowledge onto his students. He’s clearly an accomplished artist, and provides some anecdotes on projects he has worked on. I really like the style, and it made for a very comfortable reading.

There are a variety of topics covered including: what 3D modeling is, what roles are required in a 3D production, how to prepare before you model, fundamentals of 3D, modeling techniques, tutorials for creating 3D text, a realistic head, and a full stylized character, digital sculpting, game modeling, and 3D printing. Most of the chapters are not very long, and are very approachable for any skill level. I especially enjoyed the realistic head tutorial, as this is one of the hardest things to get right. His technique in this chapter almost made the task seem easy, and I am excited to try this out on a real project. I also very much liked the last chapter, which discussed how to get a job in the industry. This will be a lot of help for college students or other people trying to break into the industry, and he gives some good tips you may or may not learn in school.

Overall I was impressed with Digital Modeling by William Vaughan, and cannot give it anything other than a glowing review. What’s great is that he makes no assumptions about what tools you are using. The techniques in this book can be applied to almost any 3D package out there. In this way, I feel the information is more fundamental than other books, which concentrate too much of the specifics of one particular application. In addition, the photos on the Kindle e-book were top notch, large, and high resolution color images (unlike some other books, which skimp out on the quality).

If you have even a passing interest in becoming a 3D modeler, you owe it to yourself to pick up this book. Highly recommended.

Creating a 3D Game Engine (Part 21)


 

After a few days of hacking away at the code, I’ve got a new video up. In this update I have added normal mapping and specular lighting. I did have a few set-backs while working on the shaders, and it was made even more difficult since I was basically “flying blind” without a debugger. It seems that the Express version of Visual Studio does not support shader debugging, and neither does Nvidia’s debugger tool. Very sad, and I may (at some point) have to upgrade to the Pro version. I’ll probably hold out for a little bit, and I did end up figuring the problems out this time.

With the specular lighting shader, the issue I had was doing the matrix multiply and output on a float4 instead of a float3. To be honest, I am not quite sure why it didn’t work, but switching things around seemed to help. The change I made was also follows.

output.normal = normalize(mul((float3x3)worldMatrix, normal.xyz));

Instead of:

output.normal = normalize(mul(worldMatrix, normal));

Again, not sure why that works, but I’m happy it does. With the normal mapping, there was a lot of math and changes involved, and it became difficult to find which piece was broken. As it turns out, all the math was (mostly) correct, but the values I was sending to the constant buffer were not being updated. From what I can tell, the pixel shader cannot read the constant buffer (cbuffer) but the vertex shader can. Strange, and I’m not sure why this must be the case. So instead of trying to read the cbuffer values directly from the pixel shader, I passed them in as output values from the vertex shader. In addition, trying to pass bool or int values to the pixel shader would not work. So, as a hack, I added the same int value to all parameters of a float3 and passed that instead. I bet I can figure this one out eventually, but I’ve already spent all day on this and I’m happy just to see something working on the screen.

Next up I will probably try to model something more substantial than a cube so I have something better to look at.