So i am aware there is already a lot of info on this topic but i am having trouble putting the theory into actual code.
I am making a raymarcher to march into an octree and get the color of the voxel the ray hits.
But i am having trouble getting the direction of the ray. I saw this https://computergraphics.stackexchange.com/questions/8479/how-to-calculate-ray but i dont understand how the code works.
im working with bevy on the cpu side, so using wgsl in gpu land.
this is my direction code now but it does not take into account where the camera is facing
fn ray_dir(x: f32, y: f32) -> vec3<f32> {
let d = 1/tan(radians(screen.fov/2));
let px = x + 0.5;
let py = y + 0.5;
let aspect_ratio = f32(screen.width) / f32(screen.height);
let ray_dir_x = aspect_ratio * (2 * px / f32(screen.width)) - 1;
let ray_dir_y = (2 * py/f32(screen.height)) - 1;
let ray_dir_z = d;
return vec3<f32>(ray_dir_x, ray_dir_y, ray_dir_z);
}
this makes the screen either full background or full voxel(all voxels are the same colour as of now)
so my Question is how do i get the direction of the ray for each pixel in wgsl?