https://github.com/cdriehuys/raytracer
A Rust implementation of "The Ray Tracer Challenge"
https://github.com/cdriehuys/raytracer
graphics ray-tracer rendering
Last synced: 4 months ago
JSON representation
A Rust implementation of "The Ray Tracer Challenge"
- Host: GitHub
- URL: https://github.com/cdriehuys/raytracer
- Owner: cdriehuys
- License: mit
- Created: 2021-03-28T18:32:51.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2023-05-05T13:53:33.000Z (about 2 years ago)
- Last Synced: 2025-01-07T07:44:15.123Z (5 months ago)
- Topics: graphics, ray-tracer, rendering
- Language: Rust
- Homepage:
- Size: 86.9 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# raytracer-rs
[](https://github.com/cdriehuys/raytracer/actions/workflows/ci.yml)
A ray tracer written in Rust, built by following
[*The Ray Tracer Challenge* by Jamis Buck][ray-tracer-challenge].## Playground
At the end of each chapter, the new capabilities of the ray tracer are utilized
in the main program. It can be executed with:```bash
# Using the release profile instead of the default debug profile has a massive
# effect on performance.
cargo run --release
```### Current Behavior (Ch. 9)
We have our first alternate shape type: planes. Planes allow us to replace our
hacky floors/walls made of deformed spheres with proper infinite, flat planes.
This isn't a huge visual change, but there was a significant amount of
refactoring to make it easier to share logic between shapes.
### History
Expand the section below to see a progression of the project. These milestones
generally correspond to the exercises at the end of each chapter in the book
which utilize the new functionality added in the chapter.Expand to see progression
#### Canvas Usage (Ch. 2)
This was the first visual output from the project. It exercised basic tuple math
to compute the trajectory of a projectile and used the new canvas to plot the
projectile's position over time.
#### Matrix Transforms (Ch. 4)
The next major addition was matrix transformations which allows us to use a
consistent operation (matrix multiplication) to perform arbitrary transforms of
objects. For example, the hour markers on a clock can be drawn by applying
rotations to a single hour marker as shown in the image:
#### Casting Rays (Ch. 5)
The next step was actually casting rays to produce the silhouette of a sphere.
The sphere is a unit-sphere located at the origin. Rays are cast from a point in
space towards a "wall" behind the sphere. Locations on the wall are colored red
if the ray hits the sphere. This produces an image like:
#### Light and Shading (Ch. 6)
Objects now have an associated material. The material utilizes ambient, diffuse,
and specular reflections to produce a specific color at each position on the
sphere. When rendered with a light source, the sphere looks like:
#### Making a Scene (Ch. 7)
The ray tracer now has abstractions for groups of objects that make up a scene
as well as an abstraction for positioning the camera. This makes it much easier
to render scenes with multiple objects, like the following:
#### Shadows (Ch. 8)
Shadows have now been added. For each rendered pixel of an object, we do an
additional ray cast towards the light source to determine if there is direct
light cast at that particular point. If not, then the location is in shadow, and
only the material's ambient reflection affects the final color.
## License
This project is licensed under the [MIT License](LICENSE).
[ray-tracer-challenge]: http://www.raytracerchallenge.com/