I decided to completely rewrite Project OPFRAME's rendering engine.

That is basically what I have been doing over the last couple of weeks. Before I go into a bit more detail, here is another development video drop (the last one to use the "old" rendering tech)...
So yeah, I decided to modernise the renderer. I love this s**t. I wish someone would pay me to do it professionally.
Lengthy read incoming...
For most of its life so far (up until I decided to change it up), OPFRAME has drawn its 3D view with what's called a
forward renderer. It's the straightforward way to do it. You draw each object, and as you draw it you work out exactly what colour every pixel of it should be. For the terrain, that means working out the sun, the light from the sky, the shadows and the haze between the camera and the ground all at once, then writing the finished colour to the screen. The buildings do the same, then the trees, and so on. It works, and it's easy to reason about, but it has two problems that got worse as the scene filled up.
The first is wasted effort. When a tree stands in front of a hillside, the hill's pixels behind it have already been fully lit and hazed, only for the tree to be drawn over the top. With thousands of trees, buildings and models layered over one another, a good share of the graphics card's time went on lighting pixels nobody would ever see. The second problem matters more, though it's less obvious. Once a forward pass has written its colour, everything it knew about the surface is thrown away: which way it faced, what colour it was before it was lit, how far away it was. Nothing later in the frame can go back and light it again. That rules out a lot of what modern renderers rely on. One example is ambient occlusion, the soft darkening in corners and where things meet the ground. Another is anti-aliasing that blends several frames together (temporal anti-aliasing). A third is upscalers like DLSS and FSR.
Deferred rendering splits the job in two. In the first step, objects don't work out their lighting at all. Each one just writes down the "facts" about its surface into a set of screen-sized images called the G-buffer (G for geometry). One image holds the plain colour, another which way the surface faces, another how rough or metallic it is (PBR textures/workflow), and the depth sits alongside them. If something is drawn over the top, its facts simply replace the ones underneath, which is cheap. Then a single pass runs once over the whole screen, reads those facts for each pixel and lights it. Every pixel is lit exactly once, however many things are stacked in front of one another. Expensive work like the haze is paid for once per pixel rather than once for every object that happened to cover it.
Because the surface information is still there after everything has been drawn, the other features I wanted followed quite quickly. Ambient occlusion now reads the depth and the facing of each surface and darkens whatever is tucked away from the sky. Temporal anti-aliasing (yup, implemented my own version of this too) nudges the camera by a fraction of a pixel each frame and blends the results, which smooths the jagged edges on rooftops and trees far better than before. It also opens the door to adding an upscaler later on (if I go down that route)...
Lights are where
forward+ comes in. The sun is easy, but a town at night has hundreds of street lights, and checking every light against every pixel would be hopeless. So each frame the screen is cut into tiles, and the distance from the camera is cut into slices, which makes a grid of small boxes called clusters. Each light is listed only in the boxes it can actually reach, so when a pixel is lit it only has to look at the few lights in its own box. The weak spot of deferred rendering is anything you can see through, like glass or a vehicle's windows, because the G-buffer only holds one surface per pixel. Those are still drawn the old forward way, after everything else, but they read the same cluster lists, so a street lamp lights a window just as it lights the wall behind it. That mix of forward drawing and clustered lights is what's meant by forward+.
It isn't free! The G-buffer takes ~126 MB of video memory on a 3440×1440 screen (~206 MB at 4K), and a few things, like the map's overlays, need care while the image is being nudged around for the anti-aliasing. But it's the foundation nearly every modern engine is built on. It's let me add what would have been awkward or impossible before.
That was a lot of text so here are a few images.
This first image is what the G-buffer looks like. 15 screen-sized buffers are built each frame to capture the required information in order to calculate the final rendered image. A lot goes on behind the scenes before something gets presented on screen!
As you can see from the G-buffer image, I have added 3D model loading (with PBR support of course). A few more examples...
I have also been continuing the work on procedural content generation...
Looking inland over Swansea (by day).
Looking inland over Swansea (by night). Each light is a real-time/dynamic light which has been made possible with moving to deferred rendering with the G-buffer.
Shout up if you want to know more about the temporal anti-aliasing, or ambient occluison, or whatever. Fascinating stuff. LOL!

