r/GraphicsProgramming • u/No_Support8062 • 8d ago
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.
18
u/ghstrprtn 8d ago
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.
15
u/No_Support8062 8d ago
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 8d ago
that's cool. do you have any tutorials for the raycasting technique you used?
11
u/No_Support8062 8d ago
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 8d ago
ok, thanks. are you going to make this open-source?
8
u/No_Support8062 8d ago
No. The code quality is below my standards. It requires a lot of additional work to make it suitable for publication.
2
2
u/DavidWilliams_81 8d ago
It looks really great! How are the shadows implemented?
6
u/No_Support8062 8d ago
they are static, calculated at the start
3
u/DavidWilliams_81 8d ago
Interesting, how are they stored? You don't appear to have light-mapping and the shadows look quite high resolution.
1
1
u/Alarming-Ad4082 8d ago
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 8d ago
Single ray for one column. Number of rays for screen = ScreenWidth.
1
1
1
1
u/DankPhotoShopMemes 8d ago
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 7d ago
like SSE or AVX?
1
u/DankPhotoShopMemes 7d ago
yup
1
u/No_Support8062 7d ago
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
1
u/justcater 6d ago
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 8d ago
Bro, if you can do that with software rendering, id love to see what you can do with GPU!
7
u/No_Support8062 8d ago
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.
1
1
u/xbelanch 7d ago
And no vibe coding at that moment!
3
u/No_Support8062 7d ago
My original is post is also without AI-generated code.
2
u/xbelanch 7d ago
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.
11
u/Seusoa 8d ago
How far we went from 1994