Level rendering - CTR-tools/CTR-tools GitHub Wiki

PSX hardware, unlike modern pipelines, provided the ability to render mesh in quads - 2 triangles at a time. This is the reason why some developers were trying to process their mesh in quads and CTR is no exception here.

CTR engine was started by Daniel Chan (currently works at Activison Blizzard), who also previously worked on Gex series. It is known that he partially reused his knowledge for the memory management and inherited similar cheat code mnemonics system.

Unlike previous Crash game that used rail camera to stream long levels from the disc, CTR required the entire level to be loaded at once, hence RAM limitations apply - level files do not usually exceed about 750kb. Since Playstation is not powerful enough to render a level at once, some occlusion technique had to be implemented. CTR engine deals with it in a similar manner Quake engine did - by using BSP (binary space partitioning tree) and linked precalculated PVS data (potentially visible set). As a bonus, it also was used for collision checking. BSP tree here is a rather classic K-tree implementation, every branch is divided in two half along one of the axes and every leaf of the tree links to a set of primitives and some additional parameters we'll cover later.

The way it works, every primitive of the level is linked to a PVS data chunk, that regulates what part of BSP tree is currently visible. As player touches the next primitive, BSP visibility is updated according to this precalculated PVS data. The visibility data calculation was a long process, taking about 2 hours to finish on the contemporary hardware. Developers told they had to let it run overnight, only to find bugs the next day. Some bugs were never fixed, like massive flickering in Cortex Castle near the end (if you look back during the fall).

PSX did not have any built-in LoD implementation (https://en.wikipedia.org/wiki/Level_of_detail_(computer_graphics)) (i.e. modern mip-mapping), so most late games in the PSX library implemented some kind of mesh and/or texture LoDs in attempts to render more stuff on the screen. Best example would be Spyro trilogy, that allowed to see untextured buildings in the distance, which works much better than usual fog that occludes everything within meters from the player.

Another known hardware problem to solve was texture wobbling and by the end of the PSX life cycle it was already known that primitive subdivision closer to the camera did the trick.

In an attempt to address both issues at once, Naughty Dog came up with the idea, that pretty much resembles modern tesselation. Levels were made of the complex primitives, that would be represented by a single quad in a distance, then morph to 4 quads as you get closer, and finally these 4 quads are tesselated down to much smaller 16x16 grid, allowing to use mind blowing for psx 256x256 texture resolution. The system was later refined for Jak & Daxter game. Sony attempted to patent this solution circa 2002-2003, but it seems it was stuck in a pending status.

The primitive we address to as QuadBlock (originally called tFrag) contains 9 vertices. First 4 vertices form a lowest LoD quad, while the rest generates mid level 4 quads. As low quad is subdivided at runtime, it seamlessly morphs into 4quad mesh. Then it loops through 3 texture LoDs and finally starts to subdivide into a much more detailed mesh, but the overall shape doesn't change whatsoever.

Another important thing to note is that final tesselated mesh is using an additional set of smaller tiles, instead of a big texture. This is the approach basically inherited from earlier 3rd/4th gen consoles. As individual tiles could be mirrored and rotated, this allowed to create unique sets from a relatively small amount of tiles, significantly reducing the VRAM usage. The creation process of these tile combinations was called "tageing" by the team - short for "montageing".

There are also specific techniques related to mesh rendering, used in certain levels. The engine allows to freely wobble between 2 values of vertex position, color and UV. This results in simulated aqua refraction effect, algae wavering (Roo's Tubes) and kind of water reflection simulation, using environment texture and combination of uv/vcolor wobble (likely inherited from Crash Bandicoot 3). Also there is "flipbook" texture animation support.