README.md

C++ software renderer

README.md

3.01 KB
### Overview

Interactive software rasterizer written in C++, just to grok some GPU pipeline rendering, associated graphics APIs and math. Attempts to do things more classically in the GPU way. Like a depth buffer instead of sorting, Pineda-style edge triangle rasterization, homogeneous clipping, and floating-point math instead of ints.

- The rasterizer outputs to a color buffer that's blitted to the screen by `SDL_UpdateTexture()`.

- Primitive assembly -> backface culling -> early near plane rejection -> frustum culling.

- Clipping -> NDC and perspective -> depth test -> rasterize -> color buffer.

- The math and the pipeline is handled internally. SDL handles window creation, input events and window surface updates.

- Some clarity on conventions, this uses a right-handed Z-up coordinate system. So X+ is forward, Y- is right and Z+ is up. The math is all in row-major matrices and row vectors. So `v' = v \* m`.

- Currently the scene is hardcoded, just some .obj files that are parsed and loaded at runtime. No textures as of right now.

- There is some initial perspective correct interpolation. I've only validated it with debug textures/patterns seems to check out though.

- Contains a free cam and mouselook, typical `[W][A][S][D]` and `[Q][E]` for +Z, -Z respectively.

### Local setup

Build script for each platform, acquiring SDL is skipped. `-r` for the release build.

**Windows**

```
.\build_win32.bat
```

**Linux**

```
./build_linux.sh
```

**MacOS**

```
./build_macos.sh
```

`/assets` holds the meshes. Scene composition is handled manually in `initialize_scene()`.

### To-do

- Texture sampling
- Transparency and alpha blending
- Shading
- SIMD/Autovec

### Resources

- [OpenGL Specification](https://registry.khronos.org/OpenGL/specs/gl/glspec46.core.pdf)

- [A trip through the Graphics Pipeline](https://fgiesen.wordpress.com/2011/07/09/a-trip-through-the-graphics-pipeline-2011-index/)

- [Mathematics for 3D Game Programming and Computer Graphics, Third Edition](https://mathfor3dgameprogramming.com/)

- [Clipping and culling overview](https://graphicscompendium.com/opengl/24-clipping-culling)

- [Rasterization Overview](https://www.scratchapixel.com/lessons/3d-basic-rendering/rasterization-practical-implementation/overview-rasterization-algorithm.html)

- [3D Clipping in Homogeneous Coordinates](https://chaosinmotion.com/2016/05/22/3d-clipping-in-homogeneous-coordinates/)

- [Polygon Codec/Homogeneous clipping](https://fabiensanglard.net/polygon_codec/)

- **Homogeneous Clipping** [Clipping using homogeneous coordinates (1978)](https://dl.acm.org/doi/pdf/10.1145/965139.807398)

- [Perspective-Correct Interpolation](https://andrewkchan.dev/posts/perspective-interpolation.html)

- [Bresenham's line algorithm](https://wikipedia.org/wiki/Bresenham%27s_line_algorithm)

- [Sutherland–Hodgman algorithm](https://wikipedia.org/wiki/Sutherland%E2%80%93Hodgman_algorithm)

- **Pineda Rasterization**: [A Parallel Algorithm for Polygon Rasterization (1988)](https://www.cs.drexel.edu/~deb39/Classes/Papers/comp175-06-pineda.pdf)