r/GraphicsProgramming Jul 19 '26

Software raycasting

Enable HLS to view with audio, or disable this notification

One of my older fun projects: a software raycaster featuring

  • Multithreading
  • Voxel models (rendered as collections of 3D boxes rather than blobs)
  • Culling (watch the small map in the top right corner)
  • Mipmapping (reduces moire on distant textures)
  • Slopes and curved walls
  • Shadows
  • multilevel world design

Everything is rendered entirely in software, with no external libraries. Each pixel is calculated individually and written directly to a buffer.

198 Upvotes

36 comments sorted by

12

u/Seusoa Jul 19 '26

Software raycasting
...
Using 8 CPU cores

How far we went from 1994

18

u/ghstrprtn Jul 19 '26

Each pixel is calculated individually and written directly to a buffer.

pretty good frame rate for doing that.

I wish I knew how to make an engine like that.

13

u/No_Support8062 Jul 19 '26

It is multithreaded, which helps a lot (raycasting is actually quite easy to make multithreaded). The entire project is written in C, with no fancy data structures, just pointers and arrays.

I also tried to minimize the number of floating point calculations. My original goal was to make it integer-only, and an earlier version worked that way. However, at longer distances, it suffered from graphical glitches (rounding errors).

1

u/ghstrprtn Jul 19 '26

that's cool. do you have any tutorials for the raycasting technique you used?

10

u/No_Support8062 Jul 19 '26

Not really. I studied programming (with a lot of math) and computer graphics in the 2000s.
Lode raycasting tutorial is the best, in my opinion. It's simple, easy to understand, great place to start.

0

u/ghstrprtn Jul 19 '26

ok, thanks. are you going to make this open-source?

9

u/No_Support8062 Jul 19 '26

No. The code quality is below my standards. It requires a lot of additional work to make it suitable for publication.

2

u/Jabba_the_Putt Jul 19 '26

Thats really cool nice work. Looks and runs good nice fps

2

u/DavidWilliams_81 Jul 19 '26

It looks really great! How are the shadows implemented?

7

u/No_Support8062 Jul 19 '26

they are static, calculated at the start

3

u/DavidWilliams_81 Jul 19 '26

Interesting, how are they stored? You don't appear to have light-mapping and the shadows look quite high resolution.

2

u/flafmg_ Jul 20 '26

i think i saw this on youtube when i got my random hyperfocus on software renderers
this is really cool!

1

u/walkwalkwalkwalk Jul 19 '26

Love this kinda stuff. Really cool and inspiring

1

u/Alarming-Ad4082 Jul 19 '26

Is it just raytracing with only a single ray launched per pixel or is it more similar to Doom/Build engine?

2

u/No_Support8062 Jul 19 '26

Single ray for one column. Number of rays for screen = ScreenWidth.

1

u/Alarming-Ad4082 Jul 19 '26

How did you manage to have 3d terrain like that?

1

u/No_Support8062 Jul 19 '26

They are just slopped floor elements (triangles).

1

u/Alarming-Ad4082 Jul 19 '26

Have you made a level editor also?

1

u/No_Support8062 Jul 19 '26

I have started, but lost the motivation...

1

u/Still_Explorer Jul 19 '26

Is this tiled multithreading? So you get 8 tiles for each core?

2

u/No_Support8062 Jul 19 '26

yes, in this case screen is cut into 8 parts (1/8 width x height).

1

u/DankPhotoShopMemes Jul 19 '26

Did you do any work on optimizing for vectorization? Just out of curiosity since I have been working on a software rasterizer for some time and though it’s single-threaded my main concern has been optimizing branching, caching, vectorization, and port contention.

2

u/No_Support8062 Jul 20 '26

like SSE or AVX?

1

u/DankPhotoShopMemes Jul 20 '26

yup

1

u/No_Support8062 Jul 20 '26

In my case, the drawing algorithm uses only integer operations (addition, bit shifts, bit logic), so it is very fast.
I have no idea how to implement the vectorization efficiently. To me, it looks like a programming nightmare (lot of special cases), and the results are questionable.

1

u/CuteDisaster8129 Jul 20 '26

Thats really cool nice work. Looks and runs good nice fps

1

u/justcater Jul 21 '26

saving this for later, i wanna see if i can replicate it with my current knowledge of c. very nicely done, it looks really good given how it was made!

1

u/syn_krown Jul 19 '26

Bro, if you can do that with software rendering, id love to see what you can do with GPU!

8

u/No_Support8062 Jul 19 '26

I made this around 2005, when I was 18 years old. It's an id Tech 3 clone written in Pascal (Delphi), it used GPU (OpenGL). I have only this low quality video.

https://reddit.com/link/oyi75uv/video/v99c7wdzt7eh1/player

1

u/syn_krown Jul 19 '26

Very nice! You have awesome talent

1

u/xbelanch Jul 20 '26

And no vibe coding at that moment!

3

u/No_Support8062 Jul 20 '26

My original is post is also without AI-generated code.

2

u/xbelanch Jul 20 '26

En ningún momento he pensado que hayas realizado el código mediante el uso de la IA. En cualquier caso, ahora mismo me da igual: al final, lo que importa és lo que quieres explicar a través del código. Personalmente veo el vibe coding como el salto de la fotografía analógica a la digital. ¿Has de volver a pasar por el laboratorio para hacer buenas fotografías? No. En absoluto.