Bringing up to date before I try something

master
MitchellHansen 8 years ago
parent 86f342432a
commit ccdcb382fd

@ -32,7 +32,7 @@ float4 view_light(float4 in_color, float3 light, float3 view, int3 mask) {
in_color += pow(specTmp, 1.0f) * 0.1;
}
in_color += 0.02;
//in_color += 0.02;
return in_color;
}
@ -120,91 +120,6 @@ bool cast_light_intersection_ray(
return false;
}
// =================================== float4 of intersected voxel ============================
// ============================================================================================
float4 cast_color_ray(
global char* map,
global int3* map_dim,
float3 ray_dir,
float3 ray_pos,
global float* lights,
global int* light_count
) {
// Setup the voxel step based on what direction the ray is pointing
int3 voxel_step = { 1, 1, 1 };
voxel_step *= (ray_dir > 0) - (ray_dir < 0);
// Setup the voxel coords from the camera origin
int3 voxel = convert_int3(ray_pos);
// Delta T is the units a ray must travel along an axis in order to
// traverse an integer split
float3 delta_t = fabs(1.0f / ray_dir);
// offset is how far we are into a voxel, enables sub voxel movement
float3 offset = ((ray_pos)-floor(ray_pos)) * convert_float3(voxel_step);
// Intersection T is the collection of the next intersection points
// for all 3 axis XYZ.
float3 intersection_t = delta_t *offset;
// for negative values, wrap around the delta_t, rather not do this
// component wise, but it doesn't appear to want to work
if (intersection_t.x < 0) {
intersection_t.x += delta_t.x;
}
if (intersection_t.y < 0) {
intersection_t.y += delta_t.y;
}
if (intersection_t.z < 0) {
intersection_t.z += delta_t.z;
}
// Hard cut-off for how far the ray can travel
int max_dist = 800;
int dist = 0;
int3 face_mask = { 0, 0, 0 };
// Andrew Woo's raycasting algo
do {
// If we hit a voxel
int index = voxel.x + (*map_dim).x * (voxel.y + (*map_dim).z * (voxel.z));
int voxel_data = map[index];
if (voxel_data != 0) {
return true;
}
// Fancy no branch version of the logic step
face_mask = intersection_t.xyz <= min(intersection_t.yzx, intersection_t.zxy);
intersection_t += delta_t * fabs(convert_float3(face_mask.xyz));
voxel.xyz += voxel_step.xyz * face_mask.xyz;
// If the ray went out of bounds
int3 overshoot = voxel < *map_dim;
int3 undershoot = voxel >= 0;
if (overshoot.x == 0 || overshoot.y == 0 || overshoot.z == 0 || undershoot.x == 0 || undershoot.y == 0) {
return false;
}
if (undershoot.z == 0) {
return false;
}
dist++;
} while (dist < 700);
return false;
}
// ====================================== Raycaster entry point =====================================
// ==================================================================================================
@ -315,7 +230,6 @@ __kernel void raycaster(
if (voxel_data != 0) {
// write_imagef(image, pixel, (float4)(0.90, 0.00, 0.40, 0.9));
if (voxel_data == 6) {
voxel_color = (float4)(0.0, 0.239, 0.419, 0.3);
@ -328,7 +242,7 @@ __kernel void raycaster(
}
// set to which face
float3 face_position = (float)(0); //convert_float3(-face_mask * voxel_step);// convert_float3(face_mask * voxel_step) * -1;
float3 face_position = (float)(0);
if (face_mask.x == -1) {
@ -412,8 +326,8 @@ __kernel void raycaster(
dist++;
} while (dist / 700.0f < 1);
//dist < max_dist
write_imagef(image, pixel, white_light(mix(fog_color, (float4)(0.40, 0.00, 0.40, 0.2), 1.0 - max(dist / 700.0f, (float)0)), (float3)(lights[7], lights[8], lights[9]), face_mask));
//write_imagef(image, pixel, (float4)(.73, .81, .89, 1.0));
return;
}

@ -38,7 +38,7 @@ void Old_Map::generate_terrain() {
int DATA_SIZE = dimensions.x + 1;
//an initial seed value for the corners of the data
//srand(f_rand());
double SEED = rand() % 10 + 40;
double SEED = rand() % 40 + 40;
//seed the data
set_sample(0, 0, SEED);

@ -40,8 +40,8 @@ const int WINDOW_X = 1000;
const int WINDOW_Y = 1000;
const int WORK_SIZE = WINDOW_X * WINDOW_Y;
const int MAP_X = 256;
const int MAP_Y = 256;
const int MAP_X = 1024;
const int MAP_Y = 1024;
const int MAP_Z = 256;
float elap_time(){
@ -180,29 +180,23 @@ int main() {
if (sf::Keyboard::isKeyPressed(sf::Keyboard::F11)) {
while (raycaster->debug_quick_recompile() != 0);
}
//if (sf::Keyboard::isKeyPressed(sf::Keyboard::Equal)) {
// raycaster->test_edit_viewport(WINDOW_X, WINDOW_Y, w += 5, h += 5);
//}
//if (sf::Keyboard::isKeyPressed(sf::Keyboard::Dash)) {
// raycaster->test_edit_viewport(WINDOW_X, WINDOW_Y, w -= 5, h -= 5);
//}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
light_vec.at(0).position.x -= delta_time * 10;
light_vec.at(0).position.x -= delta_time * 100;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
light_vec.at(0).position.x += delta_time * 10;
light_vec.at(0).position.x += delta_time * 100;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) {
light_vec.at(0).position.y += delta_time * 10;
light_vec.at(0).position.y += delta_time * 100;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) {
light_vec.at(0).position.y -= delta_time * 10;
light_vec.at(0).position.y -= delta_time * 100;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Home)) {
light_vec.at(0).position.z += delta_time * 10;
light_vec.at(0).position.z += delta_time * 100;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::End)) {
light_vec.at(0).position.z -= delta_time * 10;
light_vec.at(0).position.z -= delta_time * 100;
}
@ -212,7 +206,7 @@ int main() {
light_vec.at(0).direction_cartesian = SphereToCart(camera->get_direction());
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::O)) {
light_vec.at(0).orbit_around_center(fmod(timer_accumulator += delta_time, 3));
light_vec.at(0).orbit_around_center(timer_accumulator += delta_time);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::M)) {

Loading…
Cancel
Save