R5K engine

From Stunts Wiki
Revision as of 22:16, 18 November 2023 by Cas (talk | contribs) (→‎Capabilities)
View of the track 4:00am using R5KE

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.

Capabilities

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.

Derivative models

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.

Track viewer

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.