get started on writeup
This commit is contained in:
parent
000003802c
commit
0000039063
6 changed files with 41 additions and 26 deletions
|
@ -10,7 +10,7 @@ path = "src/main.rs"
|
|||
|
||||
[dependencies]
|
||||
anyhow = "1.0.68"
|
||||
clap = { version = "4.1.4", features = ["derive"] }
|
||||
clap = { version = "4.1.4", features = ["cargo", "derive"] }
|
||||
derivative = "2.2.0"
|
||||
nalgebra = "0.32.1"
|
||||
num = { version = "0.4.0", features = ["serde"] }
|
||||
|
|
|
@ -8,13 +8,13 @@ pub type Color = Vector3<f64>;
|
|||
/// A representation of an image
|
||||
pub struct Image {
|
||||
/// Width in pixels
|
||||
pub(crate) width: usize,
|
||||
pub width: usize,
|
||||
|
||||
/// Height in pixels
|
||||
pub(crate) height: usize,
|
||||
pub height: usize,
|
||||
|
||||
/// Pixel data in row-major form.
|
||||
pub(crate) data: Vec<Color>,
|
||||
pub data: Vec<Color>,
|
||||
}
|
||||
|
||||
impl Image {
|
||||
|
|
11
assignment-1b/src/lib.rs
Normal file
11
assignment-1b/src/lib.rs
Normal file
|
@ -0,0 +1,11 @@
|
|||
#![doc = include_str!("../writeup.md")]
|
||||
|
||||
#[macro_use]
|
||||
extern crate anyhow;
|
||||
#[macro_use]
|
||||
extern crate derivative;
|
||||
|
||||
pub mod image;
|
||||
pub mod ray;
|
||||
pub mod scene;
|
||||
pub mod utils;
|
|
@ -1,22 +1,11 @@
|
|||
#[macro_use]
|
||||
extern crate anyhow;
|
||||
#[macro_use]
|
||||
extern crate derivative;
|
||||
|
||||
mod image;
|
||||
mod ray;
|
||||
mod scene;
|
||||
mod utils;
|
||||
|
||||
use std::fs::File;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use anyhow::Result;
|
||||
use assignment_1b::image::Image;
|
||||
use assignment_1b::ray::Ray;
|
||||
use assignment_1b::scene::Scene;
|
||||
use clap::Parser;
|
||||
use scene::Scene;
|
||||
|
||||
use crate::image::Image;
|
||||
use crate::ray::Ray;
|
||||
|
||||
/// Simple raycaster.
|
||||
#[derive(Parser)]
|
||||
|
|
|
@ -50,18 +50,19 @@ pub struct Material {
|
|||
#[derive(Debug)]
|
||||
pub enum LightKind {
|
||||
/// A point light source exists at a point and emits light in all directions
|
||||
Point {
|
||||
location: Vector3<f64>,
|
||||
},
|
||||
Point { location: Vector3<f64> },
|
||||
|
||||
Directional {
|
||||
direction: Vector3<f64>,
|
||||
},
|
||||
/// A directional light source exists at an infinitely far location but emits
|
||||
/// light in a specific direction
|
||||
Directional { direction: Vector3<f64> },
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Light {
|
||||
/// The kind of light source, as well as its associated information
|
||||
pub kind: LightKind,
|
||||
|
||||
/// The color, or intensity, of the light source
|
||||
pub color: Vector3<f64>,
|
||||
}
|
||||
|
||||
|
@ -115,7 +116,8 @@ impl Scene {
|
|||
|
||||
// Compute viewing window corners
|
||||
let n = self.view_dir.normalize();
|
||||
#[rustfmt::skip] // Otherwise this line wraps over
|
||||
|
||||
#[rustfmt::skip] // Don't format, or else this line wraps over
|
||||
let view_window = Rect {
|
||||
upper_left: self.eye_pos + n * distance - u * (viewing_width / 2.0) + v * (viewing_height / 2.0),
|
||||
upper_right: self.eye_pos + n * distance + u * (viewing_width / 2.0) + v * (viewing_height / 2.0),
|
||||
|
|
|
@ -3,6 +3,20 @@ geometry: margin=2cm
|
|||
output: pdf_document
|
||||
---
|
||||
|
||||
This project implements a raytracer with Blinn-Phong illumination implemented.
|
||||
The primary formula that is used by this implementation is:
|
||||
|
||||
$$
|
||||
I_{\lambda} = k_a O_{d\lambda} +
|
||||
\sum_{i=1}^{n_\textrm{lights}} \left(
|
||||
IL_{i\lambda} \left[
|
||||
k_d O_{d\lambda} \textrm{max} \{
|
||||
% 0, \overrightarrow{N} \middot \vec{L_i}
|
||||
\}
|
||||
\right]
|
||||
\right)
|
||||
$$
|
||||
|
||||
## Varying $k_a$
|
||||
|
||||
![Varying $k_a$](examples/ka-demo.png){width=240px}
|
||||
|
@ -22,4 +36,3 @@ output: pdf_document
|
|||
# Arbitrary Objects
|
||||
|
||||
![Varying $n$](examples/objects.png){width=240px}
|
||||
|
||||
|
|
Loading…
Reference in a new issue