Model Viewer & Frustum Culling
Note: These Game Engine blogs are a series of write-ups I did when I was in school for my master’s degree. I took a series of three courses run by Ed Keenan where we built a game engine from scratch in C++.
Model Viewer
So in my last update we talked about FBX and why this model converter was important. The good news is that it works! So now I’ve built a viewer to view models in a multitude of ways. This post is going to be much less explanation and more visualization. The proof is in the pudding.
Here is a model in wireframe mode with a shader that colors by position. The color is helpful for debugging purposes, but the wireframe is just cool. Our converter also exports the textured version with lighting enabled.
Here is a viewer with several different models. Some have lighting enabled and some do not. We can switch between the objects and rotate around them. PSA: I did not make these models, some of them are not good lol.
Frustum Culling
So as we discussed earlier in the PCS Tree section, we don’t want to do work when we don’t have to — we want early outs. One major optimization we can make is to not draw objects when the camera can’t even see it. To understand how this works, it’s important to understand how the engine’s camera works.
Here’s a camera’s frustum. Anything in that big box (the frustum) can be seen by the camera. The frustum is defined by a near plane, a far plane, and a field of view. I’m sure you’ve played some older games where you can “clip” inside of an object and you start to see the object disappear a bit. That’s because the object is hitting either the near or far plane and part of that object is falling outside the frustum.
So in this demo below, I’ve drawn the frustum in a wireframe mode and used a “God camera” to show what will happen when an object falls outside the frustum. The God camera looks top-down on the frustum with the near plane at the bottom of the screen and the far plane at the top.
We use a bounding sphere around the object to check if there’s a collision with the sphere and the frustum. If they collide, we need to draw the object! So we keep the sphere green. If the sphere doesn’t touch the frustum at all, we change the sphere to red to indicate that we shouldn’t draw it.
Now obviously even when the sphere is red, we’re still drawing it in this demo because it’s merely a proof of concept. We could stop drawing it but it would just disappear. I thought the change in color made for a better demo.
Thanks for reading! Next up is a full animation system on humanoid characters!