Simplified ray stepping

This commit is contained in:
Jarrod Doyle 2023-05-04 11:28:07 +01:00
parent a01848a7f7
commit c09014e34e
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
1 changed files with 20 additions and 42 deletions

View File

@ -147,30 +147,19 @@ fn brick_ray_cast(
break;
}
if (side_dist.x < side_dist.y) {
if (side_dist.x < side_dist.z) {
side_dist.x += delta_dist.x;
map_pos.x += ray_step.x;
let smallest = min(side_dist.x, min(side_dist.y, side_dist.z));
if (smallest == side_dist.x) {
hit_info.mask = vec3<bool>(true, false, false);
}
else {
side_dist.z += delta_dist.z;
map_pos.z += ray_step.z;
hit_info.mask = vec3<bool>(false, false, true);
}
}
else {
if (side_dist.y < side_dist.z) {
side_dist.y += delta_dist.y;
map_pos.y += ray_step.y;
else if (smallest == side_dist.y) {
hit_info.mask = vec3<bool>(false, true, false);
}
else {
side_dist.z += delta_dist.z;
map_pos.z += ray_step.z;
hit_info.mask = vec3<bool>(false, false, true);
}
}
side_dist += vec3<f32>(hit_info.mask) * delta_dist;
map_pos += vec3<i32>(hit_info.mask) * ray_step;
}
}
@ -248,30 +237,19 @@ fn grid_cast_ray(orig_ray_pos: vec3<f32>, ray_dir: vec3<f32>) -> HitInfo {
}
}
if (side_dist.x < side_dist.y) {
if (side_dist.x < side_dist.z) {
side_dist.x += delta_dist.x;
map_pos.x += ray_step.x;
let smallest = min(side_dist.x, min(side_dist.y, side_dist.z));
if (smallest == side_dist.x) {
hit_info.mask = vec3<bool>(true, false, false);
}
else {
side_dist.z += delta_dist.z;
map_pos.z += ray_step.z;
hit_info.mask = vec3<bool>(false, false, true);
}
}
else {
if (side_dist.y < side_dist.z) {
side_dist.y += delta_dist.y;
map_pos.y += ray_step.y;
else if (smallest == side_dist.y) {
hit_info.mask = vec3<bool>(false, true, false);
}
else {
side_dist.z += delta_dist.z;
map_pos.z += ray_step.z;
hit_info.mask = vec3<bool>(false, false, true);
}
}
side_dist += vec3<f32>(hit_info.mask) * delta_dist;
map_pos += vec3<i32>(hit_info.mask) * ray_step;
}
}