The problem I am having is that the calculation of ray direction for my ray tracer is not correct and therefor the scene is not renderd as the ray directions are not projected in the expected direction, as when I displayed the ray direction as a color it did not yield the expected the result being a completly black frame.
I have tried to change the algorithm/formula for generating rays, but there were no changes to the result. I initialy expected ray direction displayed as a color to be a mix of red and green as the z direction is negative by default, and as the upper left corner in ndc space to be completly black as the values range from -1, -1 to 0, 0. I am using Rust with wgpu and winit and programming the raytracer in WGSL.
Here is the camera_generate_ray functions and relevant structs.
struct Camera {
position: vec3<f32>,
forward: vec3<f32>,
upward: vec3<f32>,
rightward: vec3<f32>,
vfov: f32,
aspect_ratio: f32,
}
struct Ray {
origin: vec3<f32>,
direction: vec3<f32>,
}
fn camera_generate_ray(camera: Camera, u: f32, v: f32) -> Ray {
// e (center)
// u, v, w (horizontal/right, up, direction/forward)
// r = x * u + aspect ratio * y * v + d * w
// d = 1 / tan(alfa / 2)
let x = 2.0 * u - 1.0;
let y = 2.0 * v - 1.0;
let d = 1.0 / tan(camera.vfov / 2.0);
let ray_direction = x * camera.rightward + camera.aspect_ratio * y * camera.upward + d * camera.forward;
let origin = camera.position;
let direction = normalize(ray_direction);
return Ray(origin, direction);
}
Zirconium409122 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.