https://github.com/a-voronov/computer-graphics-from-scratch

Computer Graphics from Scratch: Lightweight C++ implementation with no external libraries

https://github.com/a-voronov/computer-graphics-from-scratch

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

computer-graphics cpp
Last synced: 5 months ago · JSON representation

Repository

Computer Graphics from Scratch: Lightweight C++ implementation with no external libraries

Basic Info
  • Host: GitHub
  • Owner: a-voronov
  • License: mit
  • Default Branch: main
  • Homepage:
  • Size: 856 KB
Statistics
  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Topics
computer-graphics cpp
Created 8 months ago · Last pushed 6 months ago
Metadata Files
Readme License

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/.cc -o bin/

bin/ && open results/.bmp ```

Results

Raytracing

| 01 - Basic Raytracing | 02 - Diffuse Reflection | 03 - Specular Reflection | |---|---|---| | Basic Raytracing | Diffuse Reflection | Specular Reflection |

| 04 - Shadows | 05 - Reflections | 06 - Camera | |---|---|---| | Shadows | Reflections | 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 | | --- | --- | --- | | 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 | | --- | --- | --- | | 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 | | --- | --- | --- | | Other Primitives | Constructive Solid Geometry | Transparency |

Owner

  • Name: Oleksandr Voronov
  • Login: a-voronov
  • Kind: user
  • Location: Helsinki
  • Company: @qvik

GitHub Events

Total
  • Push event: 18
  • Create event: 2
Last Year
  • Push event: 18
  • Create event: 2

Committers

Last synced: 8 months ago

All Time
  • Total Commits: 7
  • Total Committers: 1
  • Avg Commits per committer: 7.0
  • Development Distribution Score (DDS): 0.0
Past Year
  • Commits: 7
  • Committers: 1
  • Avg Commits per committer: 7.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email 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
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels