📜 ⬆️ ⬇️

How softrender wrote yes the game wrote

Prehistory It so happened that my youth came at the time of the appearance of 3D games. When I first saw the Spectrum Total Eclipse, I immediately began to consider 3D as the top technology. Soon IBM-compatible computers with the famous Wolfenstein and Doom appeared. I was impressed. Having a tendency to programming, I began to try to repeat them. It was the mid-nineties, I had a slow QuickBASIC, 5x86 comp and zero experience. Nothing happened. Well, almost nothing.

image

Our days. And in 2016, I thought: what, now I have experience, why not set myself such a challenge? Namely, write a software rasterizer from scratch. Software here means that the image is built by the CPU, without using the video accelerator. Just like they did those same shooters of the nineties.

The task has been set. I started with simple performance tests: fill the memory with a fixed color and display it. I displayed the function StretchDIBits on the screen, it has many analogs and its work here is just to send my buffer to the screen. And the very first tests showed that the speed is bad. In 1920x1080, even a simple fill color and a mandrel on the screen already drove the FPS to 200. But I had to shape 3d and not fill color, but textured polygons.
')
And I decided that the only option is to render without overdraw. Here it is necessary to clarify that the majority of tips on writing your render is reduced to texturing a polygon, and it is proposed to display the polygons themselves from the far to the near ones one by one. I did it myself in the nineties, trying to repeat Doom.

And this option was dropped for two reasons. First, if we have several polygons in the scene one after another, drawing from the far to the near will give overdraw, in other words, we will repaint the pixel several times. Secondly, polygon drawing will cause frequent cache misses on the screen buffer. After all, the triangles are arbitrary.

So I decided to write a rasterizer as a linear cycle on the screen buffer. In one pass, sequentially. Having organized polygons and textures in memory in the most ingenious way, I was able to achieve this. It should be said that the single pass rasterizer, among other things, is well parallelized, much better than polygon shading.

In the process of writing the engine, I arranged a festival where I offered to repeat the proposed scene on ordinary GPU engines. To my joy, sometimes the software render was even ahead. Here it is .

image

It was inspiring and I decided to go further. And what, why not make the dream to the end and not write a shooter? Here is a straight shooter from the nineties!

Having decided this, I began to choose the main points of implementation. The first thing I thought about the type of monsters. In early shooters, these are Wolfs, Dumas, Heretic and Hexen - the enemies were made in the form of 2d billboards. In later shooters starting from Quake, the enemies are already polygonal, in full 3d. And the thing is, 2d enemies of Heretic and Hexen liked me much more than the enemies of Kveykov. It had its charm in 2D drawing. Although 2D required much longer work, because it was necessary to draw the enemy from all sides, I chose him. 2d billboard, drawing.

Screenshot: 2d vs full 3d billboard.

image

Also needed to decide how to create game levels. The games of those years usually had their vertex editor, but I decided to go differently. I thought that than writing my own 3D editor, it's easier to make downloading models from .obj. After all, the editor is better, for example, Blender, I could hardly have written. And I will say that this decision brought benefits to the one-piece car: I was not constrained in the game-level objects at all. Model that I want despite the fact that Blender mastered for the first time.

With regards to art, I did not split hairs. In Hexen there is a set of cards with autumn and fog, I loved them then and now without hesitation I started with a similar style. Brown foliage, autumn, fog, evening. And then it began to turn: having acquired the first experience with Blender, I began to recall vivid images from my dreams and reflect them in the game. Thus a cozy basement with pipes appeared, then a night with dry trees looking into the sky.

As a result, the work on the project brought a lot of joy. This is not a perfect game, by no means, you should know this. But the time while I was doing it was a ton of fun and positive, plus the fulfillment of a child’s dream of making my own nineties shooter.

I laid out the game itself in Steam, so it turned out that I need money. Actually, as always. If there is a desire, I will be glad to any support: and reviews about the game and criticism, and just any kind words.

Play shooters!

image

Source: https://habr.com/ru/post/328272/


All Articles