Skip to content

Commit 16f6255

Browse files
committed
Add notes on camera coordinate system
1 parent 0dc41b4 commit 16f6255

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

notes/camera.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# `Camera` coordinate system
2+
3+
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.
4+
5+
![camera-coordinates](img/camera.jpg)
6+
7+
```rust
8+
// A WGSL shader example of how to generate a ray using `Camera`.
9+
fn generateCameraRay(camera: Camera, rngState: ptr<function, u32>, u: f32, v: f32) -> Ray {
10+
let randomPointInAperture = camera.lensRadius * randomVec3InUnitDisk(rngState);
11+
let lensOffset = randomPointInAperture.x * camera.right + randomPointInAperture.y * camera.up;
12+
13+
let origin = camera.origin + lensOffset;
14+
let direction = camera.lowerLeftCorner + u * camera.horizontal + v * camera.vertical - origin;
15+
16+
return Ray(origin, direction);
17+
}
18+
```

notes/img/camera.jpg

134 KB
Loading

src/pt/raytracer.wgsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ struct FrameData {
6060
}
6161

6262
struct Camera {
63-
eye: vec3f,
63+
origin: vec3f,
6464
lowerLeftCorner: vec3f,
6565
horizontal: vec3f,
6666
vertical: vec3f,
@@ -121,7 +121,7 @@ fn rayColor(primaryRay: Ray, rngState: ptr<function, u32>) -> vec3f {
121121
}
122122

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

127127
return Ray(origin, direction);

0 commit comments

Comments
 (0)