https://github.com/a-voronov/computer-graphics-from-scratch
Computer Graphics from Scratch: Lightweight C++ implementation with no external libraries
Science Score: 26.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (9.0%) to scientific vocabulary
Keywords
Repository
Computer Graphics from Scratch: Lightweight C++ implementation with no external libraries
Statistics
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
- Releases: 0
Topics
Metadata Files
README.md
Computer Graphics from Scratch
C++ implementation of Computer Graphics from Scratch book for self-studying purposes.
The book is using JavaScript and HTML Canvas to implement logic and display results. It seems to me that the easiest implementation in C++ without using any libraries, is to render results straight into the bmp files. So I've added a quick bmp implementation.
Run Examples
``` mkdir -p bin results
clang++ -std=c++17 examples/
bin/
Results
Raytracing
| 01 - Basic Raytracing | 02 - Diffuse Reflection | 03 - Specular Reflection |
|---|---|---|
|
|
|
|
| 04 - Shadows | 05 - Reflections | 06 - Camera |
|---|---|---|
|
|
|
|
Here I had to introduce few changes to the code.
First, a "shadow acne" appeared on the yellow ball when I've added a reflections computation. We're recursively firing rays that are very close to the surface, and a floating-point error can be accumulated after each bounce. The book examples don't have it since, they are using JS language where numbers have double-precision, while here I'm using a float which has a single-precision.
Another thing I've noticed is that when I was using uint8_t values to represent a color ranging from 0 to 255, I was getting a bit different results with lights and reflections.
So I switched to float with 0 to 1 range, which allowed me to represent more variety of colors during computations. I also didn't need to clamp values anymore until the very last moment when converting the image data into the bmp file format.
| Shadow Acne | Color uint8_t | Color float |
| --- | --- | --- |
|
|
|
|
Extending the Raytracer
Here I've implemented shadow optimization and bounding volume hierarchy tree (BVH) myself as an extra exploration of the topic. I've also added a subsampled option to see what effect it has on quality and performance.
| Original | BVH & Shadow Optimizations | Subsampling |
| --- | --- | --- |
|
|
|
|
Next, based on the existing BVH tree and Object abstraction, I've added Triangles to the scene. Then I've spent quite some time to get CSG right - had to rewrite intersect method few times and ended up with the simple event-walking which suits any amount of enter-exit object pairs. Reflection was a bit easier but not less fun - it looks pretty cool when you see the result of CSG+Transparency combo as a magnifying glass on top of the pyramid. And blending reflection with refraction colors showed that I had to increase raytracing recursion depth to see the refracted reflection of the maginfying glass :D
| Other Primitives | Constructive Solid Geometry | Transparency |
| --- | --- | --- |
|
|
|
|
Owner
- Name: Oleksandr Voronov
- Login: a-voronov
- Kind: user
- Location: Helsinki
- Company: @qvik
- Twitter: aleks_voronov
- Repositories: 4
- Profile: https://github.com/a-voronov
GitHub Events
Total
- Push event: 18
- Create event: 2
Last Year
- Push event: 18
- Create event: 2
Committers
Last synced: 8 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| Oleksandr Voronov | v****1@g****m | 7 |
Issues and Pull Requests
Last synced: 8 months ago
All Time
- Total issues: 0
- Total pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Total issue authors: 0
- Total pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0