rasterizer

c++ software renderer

README.md

3.1 kB
 1### Overview
 2
 3Interactive 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.
 4
 5- The rasterizer outputs to a color buffer that's blitted to the screen by `SDL_UpdateTexture()`.
 6
 7- Primitive assembly -> backface culling -> early near plane rejection -> frustum culling.
 8
 9- Clipping -> NDC and perspective -> depth test -> rasterize -> color buffer.
10
11- The math and the pipeline is handled internally. SDL handles window creation, input events and window surface updates.
12
13- 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`.
14
15- Currently the scene is hardcoded, just some .obj files that are parsed and loaded at runtime. No textures as of right now.
16
17- There is some initial perspective correct interpolation. I've only validated it with debug textures/patterns seems to check out though.
18
19- Contains a free cam and mouselook, typical `[W][A][S][D]` and `[Q][E]` for +Z, -Z respectively.
20
21### Local setup
22
23Build script for each platform, acquiring SDL is skipped. `-r` for the release build.
24
25**Windows**
26
27```
28.\build_win32.bat
29```
30
31**Linux**
32
33```
34./build_linux.sh
35```
36
37**MacOS**
38
39```
40./build_macos.sh
41```
42
43`/assets` holds the meshes. Scene composition is handled manually in `initialize_scene()`.
44
45### To-do
46
47- Texture sampling
48- Transparency and alpha blending
49- Shading
50- SIMD/Autovec
51
52### Resources
53
54- [OpenGL Specification](https://registry.khronos.org/OpenGL/specs/gl/glspec46.core.pdf)
55
56- [A trip through the Graphics Pipeline](https://fgiesen.wordpress.com/2011/07/09/a-trip-through-the-graphics-pipeline-2011-index/)
57
58- [Mathematics for 3D Game Programming and Computer Graphics, Third Edition](https://mathfor3dgameprogramming.com/)
59
60- [Clipping and culling overview](https://graphicscompendium.com/opengl/24-clipping-culling)
61
62- [Rasterization Overview](https://www.scratchapixel.com/lessons/3d-basic-rendering/rasterization-practical-implementation/overview-rasterization-algorithm.html)
63
64- [3D Clipping in Homogeneous Coordinates](https://chaosinmotion.com/2016/05/22/3d-clipping-in-homogeneous-coordinates/)
65
66- [Polygon Codec/Homogeneous clipping](https://fabiensanglard.net/polygon_codec/)
67
68- **Homogeneous Clipping** [Clipping using homogeneous coordinates (1978)](https://dl.acm.org/doi/pdf/10.1145/965139.807398)
69
70- [Perspective-Correct Interpolation](https://andrewkchan.dev/posts/perspective-interpolation.html)
71
72- [Bresenham's line algorithm](https://wikipedia.org/wiki/Bresenham%27s_line_algorithm)
73
74- [Sutherland–Hodgman algorithm](https://wikipedia.org/wiki/Sutherland%E2%80%93Hodgman_algorithm)
75
76- **Pineda Rasterization**: [A Parallel Algorithm for Polygon Rasterization (1988)](https://www.cs.drexel.edu/~deb39/Classes/Papers/comp175-06-pineda.pdf)
77