https://github.com/angusgmorrison/rasterizer
A 3D rasterizer coded from scratch in C.
https://github.com/angusgmorrison/rasterizer
Last synced: 11 months ago
JSON representation
A 3D rasterizer coded from scratch in C.
- Host: GitHub
- URL: https://github.com/angusgmorrison/rasterizer
- Owner: AngusGMorrison
- License: gpl-3.0
- Created: 2022-12-07T18:09:19.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-02-03T09:25:32.000Z (over 3 years ago)
- Last Synced: 2025-02-15T20:54:20.028Z (over 1 year ago)
- Language: C
- Size: 726 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# A ground-up 3D renderer in pure C
Behold the limited power of a single CPU core performing an uncomfortable amount of
computational geometry!

This exercise in the mathematical foundations of 3D rendering loads models from .obj files and
renders them with perspective-correct textures. It demonstrates:
* Linear algebra for perspective projection of models and textures
* Flat shading
* Back-face culling
* Ambient lighting
* An .obj file parser
* 8 rendering modes
What did I learn? Why the GPU was invented.
## Usage
Simply drop your model and its PNG texture into the assets folder, update the asset paths in main.c,
compile and run. Low-poly models are recommended unless you have a really good CPU fan.
Rendering mode keybindings:
* 1: Vertex-only
* 2: Vertex wireframe
* 3: Wireframe only
* 4: Flat-shaded
* 5: Flat-shaded with wireframe
* 6: Textured
* 7: Textured with wireframe
* c: Toggle back-face culling
## Future improvements
* Camera control
* Clipping of assets outside the rendering frustum
* Inline triangle and fgace vertex getters with macros
* Improved consistency in the function signatures of rendering methods
* Specify assets to render via the command line
* Further performance optimization
## Acknowledgements
This project is based on [a course by Gustavo
Pezzi](https://pikuma.com/courses/learn-3d-computer-graphics-programming), with significant
modifications to the source code by me to improve performance, readability and maintainability. It
is distributed under the same GNU General Public License as the original. Additional thanks go to
gustavopezzi for [the dynamic array code](https://github.com/gustavopezzi/dynamicarray), and to
elanthis for [the PNG decoder, upng](https://github.com/elanthis/upng). The F22 model and texture
were created by Artem Katrych.