|
|
|
@ -1,15 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint4 white_light(uint4 input, float3 light, int3 mask) {
|
|
|
|
|
float4 white_light(float4 input, float3 light, int3 mask) {
|
|
|
|
|
|
|
|
|
|
input.w = input.w + acos(
|
|
|
|
|
dot(
|
|
|
|
|
normalize(light),
|
|
|
|
|
normalize(fabs(convert_float3(mask)))
|
|
|
|
|
)
|
|
|
|
|
) * 50;
|
|
|
|
|
) / 2;
|
|
|
|
|
|
|
|
|
|
return (input);
|
|
|
|
|
return input;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -25,24 +25,16 @@ __kernel void min_kern(
|
|
|
|
|
__write_only image2d_t image
|
|
|
|
|
){
|
|
|
|
|
|
|
|
|
|
// Get the pixel position of this worker
|
|
|
|
|
size_t id = get_global_id(0);
|
|
|
|
|
int2 pixel = {id % resolution->x, id / resolution->x};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Slew the ray into it's correct position based on the view matrix's starting position
|
|
|
|
|
// and the camera's current direction
|
|
|
|
|
|
|
|
|
|
float3 ray_dir = projection_matrix[pixel.x + resolution->x * pixel.y];
|
|
|
|
|
|
|
|
|
|
// Yaw
|
|
|
|
|
ray_dir = (float3)(
|
|
|
|
|
ray_dir.z * sin(cam_dir->y) + ray_dir.x * cos(cam_dir->y),
|
|
|
|
|
ray_dir.y,
|
|
|
|
|
ray_dir.z * cos(cam_dir->y) - ray_dir.x * sin(cam_dir->y)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Pitch
|
|
|
|
|
ray_dir = (float3)(
|
|
|
|
|
ray_dir.x * cos(cam_dir->z) - ray_dir.y * sin(cam_dir->z),
|
|
|
|
|
ray_dir.x * sin(cam_dir->z) + ray_dir.y * cos(cam_dir->z),
|
|
|
|
@ -53,6 +45,10 @@ __kernel void min_kern(
|
|
|
|
|
int3 voxel_step = {1, 1, 1};
|
|
|
|
|
voxel_step *= (ray_dir > 0) - (ray_dir < 0);
|
|
|
|
|
|
|
|
|
|
/*voxel_step.x *= (ray_dir.x > 0) - (ray_dir.x < 0);
|
|
|
|
|
voxel_step.y *= (ray_dir.y > 0) - (ray_dir.y < 0);
|
|
|
|
|
voxel_step.z *= (ray_dir.z > 0) - (ray_dir.z < 0);*/
|
|
|
|
|
|
|
|
|
|
// Setup the voxel coords from the camera origin
|
|
|
|
|
int3 voxel = convert_int3(*cam_pos);
|
|
|
|
|
|
|
|
|
@ -64,26 +60,21 @@ __kernel void min_kern(
|
|
|
|
|
// for all 3 axis XYZ.
|
|
|
|
|
float3 intersection_t = delta_t;
|
|
|
|
|
|
|
|
|
|
// Create a psuedo random number for view fog
|
|
|
|
|
int2 randoms = { 3, 14 };
|
|
|
|
|
uint seed = randoms.x + id;
|
|
|
|
|
uint t = seed ^ (seed << 11);
|
|
|
|
|
uint result = randoms.y ^ (randoms.y >> 19) ^ (t ^ (t >> 8));
|
|
|
|
|
|
|
|
|
|
// Distance a ray can travel before it terminates
|
|
|
|
|
int max_dist = 200 + result % 50;
|
|
|
|
|
int max_dist = 500 + result % 50;
|
|
|
|
|
int dist = 0;
|
|
|
|
|
|
|
|
|
|
// Bitmask to keep track of which axis was tripped
|
|
|
|
|
int3 mask = { 0, 0, 0 };
|
|
|
|
|
|
|
|
|
|
// Andrew Woo's raycasting algo
|
|
|
|
|
do {
|
|
|
|
|
|
|
|
|
|
// Non-branching test of the lowest delta_t value
|
|
|
|
|
mask = intersection_t.xyz <= min(intersection_t.yzx, intersection_t.zxy);
|
|
|
|
|
|
|
|
|
|
// Based on the result increment the voxel and intersection
|
|
|
|
|
float3 thing = delta_t * fabs(convert_float3(mask.xyz));
|
|
|
|
|
intersection_t += delta_t * fabs(convert_float3(mask.xyz));
|
|
|
|
|
voxel.xyz += voxel_step.xyz * mask.xyz;
|
|
|
|
|
|
|
|
|
@ -91,15 +82,12 @@ __kernel void min_kern(
|
|
|
|
|
int3 overshoot = voxel <= *map_dim;
|
|
|
|
|
int3 undershoot = voxel > 0;
|
|
|
|
|
|
|
|
|
|
// "Sky"
|
|
|
|
|
if (overshoot.x == 0 || overshoot.y == 0 || overshoot.z == 0 || undershoot.x == 0 || undershoot.y == 0){
|
|
|
|
|
write_imageui(image, pixel, (uint4)(135, 206, 235, 255));
|
|
|
|
|
write_imagef(image, pixel, (float4)(.73, .81, .89, 1.0));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// "Water"
|
|
|
|
|
if (undershoot.z == 0) {
|
|
|
|
|
write_imageui(image, pixel, (uint4)(64, 164, 223, 255));
|
|
|
|
|
write_imagef(image, pixel, (float4)(.14, .30, .50, 1.0));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -110,23 +98,23 @@ __kernel void min_kern(
|
|
|
|
|
if (voxel_data != 0) {
|
|
|
|
|
switch (voxel_data) {
|
|
|
|
|
case 1:
|
|
|
|
|
write_imageui(image, pixel, (uint4)(50, 0, 0, 255));
|
|
|
|
|
write_imagef(image, pixel, (float4)(.50, .00, .00, 1));
|
|
|
|
|
return;
|
|
|
|
|
case 2:
|
|
|
|
|
write_imageui(image, pixel, (uint4)(0, 50, 40, 255));
|
|
|
|
|
write_imagef(image, pixel, (float4)(.00, .50, .40, 1.00));
|
|
|
|
|
return;
|
|
|
|
|
case 3:
|
|
|
|
|
write_imageui(image, pixel, (uint4)(0, 0, 50, 255));
|
|
|
|
|
write_imagef(image, pixel, (float4)(.00, .00, .50, 1.00));
|
|
|
|
|
return;
|
|
|
|
|
case 4:
|
|
|
|
|
write_imageui(image, pixel, (uint4)(25, 0, 25, 255));
|
|
|
|
|
write_imagef(image, pixel, (float4)(.25, .00, .25, 1.00));
|
|
|
|
|
return;
|
|
|
|
|
case 5:
|
|
|
|
|
//write_imageui(image, pixel, (uint4)(200, 200, 200, 255));
|
|
|
|
|
write_imageui(image, pixel, white_light((uint4)(44, 176, 55, 100), (float3)(lights[7], lights[8], lights[9]), mask));
|
|
|
|
|
//write_imagef(image, pixel, (float4)(.25, .00, .25, 1.00));
|
|
|
|
|
write_imagef(image, pixel, white_light((float4)(.25, .32, .14, 0.2), (float3)(lights[7], lights[8], lights[9]), mask));
|
|
|
|
|
return;
|
|
|
|
|
case 6:
|
|
|
|
|
write_imageui(image, pixel, (uint4)(30, 80, 10, 255));
|
|
|
|
|
write_imagef(image, pixel, (float4)(.30, .80, .10, 1.00));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -134,6 +122,6 @@ __kernel void min_kern(
|
|
|
|
|
dist++;
|
|
|
|
|
} while (dist < max_dist);
|
|
|
|
|
|
|
|
|
|
write_imageui(image, pixel, (uint4)(135, 206, 235, 255));
|
|
|
|
|
write_imagef(image, pixel, (float4)(.73, .81, .89, 1.0));
|
|
|
|
|
return;
|
|
|
|
|
}
|