Fixed the camera coords in the view matrix. Tweaked cam position in kernel, odd off by one error.
This commit is contained in:
@@ -105,8 +105,6 @@ __kernel void raycaster(
|
|||||||
int random_number = rand(&seed);
|
int random_number = rand(&seed);
|
||||||
seed_memory[global_id] = seed;
|
seed_memory[global_id] = seed;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
size_t id = get_global_id(0);
|
size_t id = get_global_id(0);
|
||||||
int2 pixel = {id % (*resolution).x, id / (*resolution).x};
|
int2 pixel = {id % (*resolution).x, id / (*resolution).x};
|
||||||
float3 ray_dir = projection_matrix[pixel.x + (*resolution).x * pixel.y];
|
float3 ray_dir = projection_matrix[pixel.x + (*resolution).x * pixel.y];
|
||||||
@@ -116,13 +114,14 @@ __kernel void raycaster(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Pitch
|
||||||
ray_dir = (float3)(
|
ray_dir = (float3)(
|
||||||
// 1.57s are temp fix until view matrix is tweaked
|
ray_dir.z * sin((*cam_dir).x) + ray_dir.x * cos((*cam_dir).x),
|
||||||
ray_dir.z * sin((*cam_dir).x - 1.57) + ray_dir.x * cos((*cam_dir).x - 1.57),
|
|
||||||
ray_dir.y,
|
ray_dir.y,
|
||||||
ray_dir.z * cos((*cam_dir).x - 1.57) - ray_dir.x * sin((*cam_dir).x - 1.57)
|
ray_dir.z * cos((*cam_dir).x) - ray_dir.x * sin((*cam_dir).x)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Yaw
|
||||||
ray_dir = (float3)(
|
ray_dir = (float3)(
|
||||||
ray_dir.x * cos((*cam_dir).y) - ray_dir.y * sin((*cam_dir).y),
|
ray_dir.x * cos((*cam_dir).y) - ray_dir.y * sin((*cam_dir).y),
|
||||||
ray_dir.x * sin((*cam_dir).y) + ray_dir.y * cos((*cam_dir).y),
|
ray_dir.x * sin((*cam_dir).y) + ray_dir.y * cos((*cam_dir).y),
|
||||||
@@ -134,7 +133,9 @@ __kernel void raycaster(
|
|||||||
voxel_step *= (ray_dir > 0) - (ray_dir < 0);
|
voxel_step *= (ray_dir > 0) - (ray_dir < 0);
|
||||||
|
|
||||||
// Setup the voxel coords from the camera origin
|
// Setup the voxel coords from the camera origin
|
||||||
int3 voxel = convert_int3(*cam_pos);
|
// Off by one error here in regards to the camera position.
|
||||||
|
// Will need to hunt this down later
|
||||||
|
int3 voxel = convert_int3(*cam_pos + 1);
|
||||||
|
|
||||||
// Delta T is the units a ray must travel along an axis in order to
|
// Delta T is the units a ray must travel along an axis in order to
|
||||||
// traverse an integer split
|
// traverse an integer split
|
||||||
@@ -144,9 +145,6 @@ __kernel void raycaster(
|
|||||||
float3 offset = ((*cam_pos) - floor(*cam_pos)) * convert_float3(voxel_step);
|
float3 offset = ((*cam_pos) - floor(*cam_pos)) * convert_float3(voxel_step);
|
||||||
|
|
||||||
|
|
||||||
//offset.x += delta_t.x * convert_float((voxel_step.x < 0));
|
|
||||||
//offset -= delta_t * floor(offset / delta_t);
|
|
||||||
|
|
||||||
// Intersection T is the collection of the next intersection points
|
// Intersection T is the collection of the next intersection points
|
||||||
// for all 3 axis XYZ.
|
// for all 3 axis XYZ.
|
||||||
float3 intersection_t = delta_t * offset;
|
float3 intersection_t = delta_t * offset;
|
||||||
|
|||||||
@@ -132,7 +132,6 @@ void Hardware_Caster::create_viewport(int width, int height, float v_fov, float
|
|||||||
static_cast<float>(ray.z * cos(y_increment_radians * y) - ray.x * sin(y_increment_radians * y))
|
static_cast<float>(ray.z * cos(y_increment_radians * y) - ray.x * sin(y_increment_radians * y))
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
// Z axis, yaw
|
// Z axis, yaw
|
||||||
ray = sf::Vector3f(
|
ray = sf::Vector3f(
|
||||||
static_cast<float>(ray.x * cos(x_increment_radians * x) - ray.y * sin(x_increment_radians * x)),
|
static_cast<float>(ray.x * cos(x_increment_radians * x) - ray.y * sin(x_increment_radians * x)),
|
||||||
@@ -140,6 +139,13 @@ void Hardware_Caster::create_viewport(int width, int height, float v_fov, float
|
|||||||
static_cast<float>(ray.z)
|
static_cast<float>(ray.z)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// correct for the base ray pointing to (1, 0, 0) as (0, 0). Should equal (1.57, 0)
|
||||||
|
ray = sf::Vector3f(
|
||||||
|
static_cast<float>(ray.z * sin(-1.57) + ray.x * cos(-1.57)),
|
||||||
|
static_cast<float>(ray.y),
|
||||||
|
static_cast<float>(ray.z * cos(-1.57) - ray.x * sin(-1.57))
|
||||||
|
);
|
||||||
|
|
||||||
int index = (x + view_res.x / 2) + view_res.x * (y + view_res.y / 2);
|
int index = (x + view_res.x / 2) + view_res.x * (y + view_res.y / 2);
|
||||||
ray = Normalize(ray);
|
ray = Normalize(ray);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user