Skip to content

Commit

Permalink
Add notes on camera coordinate system
Browse files Browse the repository at this point in the history
  • Loading branch information
Nelarius committed Nov 4, 2023
1 parent 0dc41b4 commit 16f6255
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
18 changes: 18 additions & 0 deletions notes/camera.md
@@ -0,0 +1,18 @@
# `Camera` coordinate system

The `Camera` class contains a coordinate system that can be used to generate rays using the thin-lens approximation for depth of field effects. Note: `right`, `up` are just normalized `horizontal`, `vertical` vectors.

![camera-coordinates](img/camera.jpg)

```rust
// A WGSL shader example of how to generate a ray using `Camera`.
fn generateCameraRay(camera: Camera, rngState: ptr<function, u32>, u: f32, v: f32) -> Ray {
let randomPointInAperture = camera.lensRadius * randomVec3InUnitDisk(rngState);
let lensOffset = randomPointInAperture.x * camera.right + randomPointInAperture.y * camera.up;

let origin = camera.origin + lensOffset;
let direction = camera.lowerLeftCorner + u * camera.horizontal + v * camera.vertical - origin;

return Ray(origin, direction);
}
```
Binary file added notes/img/camera.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/pt/raytracer.wgsl
Expand Up @@ -60,7 +60,7 @@ struct FrameData {
}

struct Camera {
eye: vec3f,
origin: vec3f,
lowerLeftCorner: vec3f,
horizontal: vec3f,
vertical: vec3f,
Expand Down Expand Up @@ -121,7 +121,7 @@ fn rayColor(primaryRay: Ray, rngState: ptr<function, u32>) -> vec3f {
}

fn generateCameraRay(camera: Camera, rngState: ptr<function, u32>, u: f32, v: f32) -> Ray {
let origin = camera.eye;
let origin = camera.origin;
let direction = camera.lowerLeftCorner + u * camera.horizontal + v * camera.vertical - origin;

return Ray(origin, direction);
Expand Down

0 comments on commit 16f6255

Please sign in to comment.