R5K Engine (or R5KE) is a graphics rendering engine project worked on by Cas that aims to provide a new, native graphics engine for Stunts under modern operating systems while preserving its classical qualities.
The project started in August 2020 under the name StuntsLegacyEngine, for which this forum thread was created and has been evolving slowly and in steps in the last years. The original repository was at https://notabug.org/xlucas/sle, where an early copy can be found. It can also be obtained from Race For Kicks, at https://www.raceforkicks.com/projects/engine.html, where it comes with the track viewer included.
Slight model incompatilibities
R5KE is based on a painter's algorithm, just like Stunts original graphics engine, but there are a number of differences in their internals. Some of these differences allow the new engine for more flexibility, while others only make things look a little different. Some 3D models will not render the same across engines because the exact workings of the original engine are not known and these models seem to exploit its uniqueness instead of trying to be conservative. This is the case of the lines inside a tunnel or the yellow stripes on ramps, for example. To have R5KE display these models similar to Stunts, one could create some alternative, more conservative models to avoid having to push a lot of exceptions into the new engine's code.
Resolution and viewing distance
In the original Stunts graphics engine, the resolution is always 320x200. With R5KE, the code can be compiled for any resolution and it's possible to make this dynamic. The maximum viewing distance could be configured in some versions of Stunts, but the best quality that could be set was still pretty low. R5KE allows for depth levels that can easily render a complete track.
Like the original engine, R5KE can produce derivative models, that is, transformations of existing models on disk can be generated in memory at load time. Thus, only one model is required for each ramp type, then this can not just be rotated, but also tilted if necessary, when on a slope. In the same way, it can convert any paved-road-based model to a different surface type, including things that are not seen in Stunts (although its engine probably can do it) like dirt road ramps.
Culling and Z-bias
The original engine uses culling flags, which makes the code more complex and prone to errors in exchange for accelerating rendering a little bit. R5KE ignores culling flags because it uses face 1-sided orientation to resolve this and because today's computers are extremely fast and don't need this optimisation. In Stunts, a Z-bias flag allows for two layers of rendering per model, which makes it possible to create rendering exceptions and simplify models. R5KE has a 4-layer system instead and recognises Stunts' Z-bias flag as a first layer, so more complex models can be handled by R5KE. The way Stunts handles Z-bias and one-sided polygons, though, appears to be different from what one would expect and R5KE is more conservative on this.
Model rotation and displacement
R5KE is not a tile-based renderer, so when loading a track, model sets are transformed and placed and then, the engine draws them generically. This means that it's possible to place objects that are not aligned to the grid or that are rotated at an arbitrary vertical angle.
Bugs and unfinished details
R5KE sorts models independently of their size, which currently creates some issues when rendering models larger than 1x1 that are placed on a hill or on water. Wheels and clouds are currently not drawn. Grilles are drawn, but some artifacts can be seen at times. This is because of a bug in the FreeBasic's graphics function that draws dotted lines and can be fixed by using an assembly function instead. The horizon can currently only be drawn horizontal, so when banking, models do rotate normally, but the horizon does not follow. Animations have still not been implemented. This includes Joe's diner's blinking sign and windmill sails "rotation".
The currently published implementation of R5KE comes as a track viewer. You need to provide a track file as well as the GAME*.3SH files that result from decompressing the GAME*.P3S original files. This allows you to move more or less freely around the track and view it in high resolution with maximum field depth rendering.
Integration with ReplDump
In March 2023, Daniel3D had the idea of a bridge between ReplDump and R5KE and he wrote to Cas about it. Cas then got to Duplode to ask for some help on ReplDump and began work on integrating the two pieces of software. This forum thread] documents the work held back then. By combining them, it's possible to create images and videos of races from arbitrary perspectives and with several cars running together.