|
|
@ -73,67 +73,64 @@ __kernel void min_kern(
|
|
|
|
int face = -1;
|
|
|
|
int face = -1;
|
|
|
|
// X:0, Y:1, Z:2
|
|
|
|
// X:0, Y:1, Z:2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int3 mask = { 0, 0, 0 };
|
|
|
|
|
|
|
|
|
|
|
|
// Andrew Woo's raycasting algo
|
|
|
|
// Andrew Woo's raycasting algo
|
|
|
|
do {
|
|
|
|
do {
|
|
|
|
if ((intersection_t.x) < (intersection_t.y)) {
|
|
|
|
|
|
|
|
if ((intersection_t.x) < (intersection_t.z)) {
|
|
|
|
mask = intersection_t.xyz <= min(intersection_t.yzx, intersection_t.zxy);
|
|
|
|
|
|
|
|
float3 thing = delta_t * fabs(convert_float3(mask.xyz));
|
|
|
|
face = 0;
|
|
|
|
intersection_t += delta_t * fabs(convert_float3(mask.xyz));
|
|
|
|
voxel.x += voxel_step.x;
|
|
|
|
voxel.xyz += voxel_step.xyz * mask.xyz;
|
|
|
|
intersection_t.x = intersection_t.x + delta_t.x;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
face = 2;
|
|
|
|
|
|
|
|
voxel.z += voxel_step.z;
|
|
|
|
|
|
|
|
intersection_t.z = intersection_t.z + delta_t.z;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if ((intersection_t.y) < (intersection_t.z)) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
face = 1;
|
|
|
|
|
|
|
|
voxel.y += voxel_step.y;
|
|
|
|
|
|
|
|
intersection_t.y = intersection_t.y + delta_t.y;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
face = 2;
|
|
|
|
|
|
|
|
voxel.z += voxel_step.z;
|
|
|
|
|
|
|
|
intersection_t.z = intersection_t.z + delta_t.z;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If the ray went out of bounds
|
|
|
|
// If the ray went out of bounds
|
|
|
|
if (voxel.z >= map_dim->z) {
|
|
|
|
int3 overshoot = voxel.xyz <= map_dim->xyz;
|
|
|
|
write_imagef(image, pixel, (float4)(.5, .50, .00, 1));
|
|
|
|
int3 undershoot = voxel > 0;
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
//if (id == 240000)
|
|
|
|
if (voxel.x >= map_dim->x) {
|
|
|
|
// printf("%i, %i, %i\n", overshoot.x, overshoot.y, overshoot.z);
|
|
|
|
write_imagef(image, pixel, (float4)(.00, .00, .99, 1));
|
|
|
|
|
|
|
|
return;
|
|
|
|
//if (id == 240000)
|
|
|
|
}
|
|
|
|
// printf("%i, %i, %i\n", undershoot.x, undershoot.y, undershoot.z);
|
|
|
|
if (voxel.y >= map_dim->x) {
|
|
|
|
|
|
|
|
write_imagef(image, pixel, (float4)(.00, .44, .00, 1));
|
|
|
|
if (overshoot.x == 0|| overshoot.y == 0 || overshoot.z == 0){
|
|
|
|
return;
|
|
|
|
write_imagef(image, pixel, (float4)(.50 * abs(overshoot.x), .50 * abs(overshoot.y), .50 * abs(overshoot.z), 1));
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
if (voxel.x < 0) {
|
|
|
|
if (undershoot.x == 0 || undershoot.y == 0 || undershoot.z == 0) {
|
|
|
|
write_imagef(image, pixel, (float4)(.99, .00, .99, 1));
|
|
|
|
write_imagef(image, pixel, (float4)(.1 * abs(undershoot.x), .80 * abs(undershoot.y), .20 * abs(undershoot.z), 1));
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (voxel.y < 0) {
|
|
|
|
//if (voxel.x >= map_dim->x) {
|
|
|
|
write_imagef(image, pixel, (float4)(.99, .99, .00, 1));
|
|
|
|
// write_imagef(image, pixel, (float4)(.00, .00, .99, 1));
|
|
|
|
return;
|
|
|
|
// return;
|
|
|
|
}
|
|
|
|
//}
|
|
|
|
if (voxel.z < 0) {
|
|
|
|
//if (voxel.y >= map_dim->x) {
|
|
|
|
write_imagef(image, pixel, (float4)(.00, .99, .99, 1));
|
|
|
|
// write_imagef(image, pixel, (float4)(.00, .44, .00, 1));
|
|
|
|
return;
|
|
|
|
// return;
|
|
|
|
}
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//if (voxel.x < 0) {
|
|
|
|
|
|
|
|
// write_imagef(image, pixel, (float4)(.99, .00, .99, 1));
|
|
|
|
|
|
|
|
// return;
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
//if (voxel.y < 0) {
|
|
|
|
|
|
|
|
// write_imagef(image, pixel, (float4)(.99, .99, .00, 1));
|
|
|
|
|
|
|
|
// return;
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
//if (voxel.z < 0) {
|
|
|
|
|
|
|
|
// write_imagef(image, pixel, (float4)(.00, .99, .99, 1));
|
|
|
|
|
|
|
|
// return;
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
// If we hit a voxel
|
|
|
|
// If we hit a voxel
|
|
|
|
int index = voxel.x + map_dim->x * (voxel.y + map_dim->z * voxel.z);
|
|
|
|
int index = voxel.x + map_dim->x * (voxel.y + map_dim->z * voxel.z);
|
|
|
|
int voxel_data = map[index];
|
|
|
|
int voxel_data = map[index];
|
|
|
|
|
|
|
|
|
|
|
|
//if (id == 240000)
|
|
|
|
|
|
|
|
//printf("%i, %i, %i\n", voxel.x, voxel.y, voxel.z);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (voxel_data != 0) {
|
|
|
|
if (voxel_data != 0) {
|
|
|
|
switch (voxel_data) {
|
|
|
|
switch (voxel_data) {
|
|
|
|