diff --git a/assets/screenshot1.png b/assets/screenshot1.png index a7646bb..c688dcb 100644 Binary files a/assets/screenshot1.png and b/assets/screenshot1.png differ diff --git a/kernels/ray_caster_kernel.cl b/kernels/ray_caster_kernel.cl index 665a88e..4684842 100644 --- a/kernels/ray_caster_kernel.cl +++ b/kernels/ray_caster_kernel.cl @@ -7,7 +7,7 @@ float4 white_light(float4 input, float3 light, int3 mask) { normalize(light), normalize(convert_float3(mask * (-mask))) ) - ) / 2; + ) / 8; return input; @@ -19,6 +19,7 @@ float4 white_light(float4 input, float3 light, int3 mask) { // 0 1 2 3 4 5 6 7 8 9 // {r, g, b, i, x, y, z, x', y', z'} + float4 view_light(float4 in_color, float3 light, float3 view, int3 mask) { float diffuse = max(dot(normalize(convert_float3(mask)), normalize(light)), 0.0f); @@ -31,8 +32,6 @@ float4 view_light(float4 in_color, float3 light, float3 view, int3 mask) { in_color += pow(specTmp, 1.0f) * 0.1; } - //float3 halfwayDir = normalize(normalize(view) + normalize(light)); - //float spec = pow(max(dot(normalize(convert_float3(mask)), halfwayDir), 0.0f), 32.0f); in_color += 0.02; return in_color; } @@ -334,22 +333,13 @@ __kernel void raycaster( if (face_mask.x == -1) { - //float z_percent = ((intersection_t.z - delta_t.z) - intersection_t.x) / delta_t.z; - //float y_percent = ((intersection_t.y - delta_t.y) - intersection_t.x) / delta_t.y; - float z_percent = (intersection_t.z - (intersection_t.x - delta_t.x)) / delta_t.z; float y_percent = (intersection_t.y - (intersection_t.x - delta_t.x)) / delta_t.y; - //if (z_percent > 0 && z_percent > 1) - // face_position = (float3)(-1.0f, 1-y_percent, 1-z_percent); - face_position = (float3)(1.001f, y_percent, z_percent); } else if (face_mask.y == -1) { - //float x_percent = ((intersection_t.x - delta_t.x) - intersection_t.y) / delta_t.x; - //float z_percent = ((intersection_t.z - delta_t.z) - intersection_t.y) / delta_t.z; - float x_percent = (intersection_t.x - (intersection_t.y - delta_t.y)) / delta_t.x; float z_percent = (intersection_t.z - (intersection_t.y - delta_t.y)) / delta_t.z; @@ -359,9 +349,6 @@ __kernel void raycaster( else if (face_mask.z == -1) { - //float x_percent = ((intersection_t.x - delta_t.x) - intersection_t.z) / delta_t.x; - //float y_percent = ((intersection_t.y - delta_t.y) - intersection_t.z) / delta_t.y; - float x_percent = (intersection_t.x - (intersection_t.z - delta_t.z)) / delta_t.x; float y_percent = (intersection_t.y - (intersection_t.z - delta_t.z)) / delta_t.y; @@ -397,9 +384,9 @@ __kernel void raycaster( lights, light_count )) { - - write_imagef(image, pixel, voxel_color); - //write_imagef(image, pixel, voxel_color); + + float4 ambient_color = white_light(voxel_color, (float3)(lights[4], lights[5], lights[6]), face_mask); + write_imagef(image, pixel, ambient_color); return; } diff --git a/src/Old_Map.cpp b/src/Old_Map.cpp index 50a0744..416229e 100644 --- a/src/Old_Map.cpp +++ b/src/Old_Map.cpp @@ -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() % 5 + 10; + double SEED = rand() % 10 + 40; //seed the data set_sample(0, 0, SEED); @@ -46,7 +46,7 @@ void Old_Map::generate_terrain() { set_sample(dimensions.x, 0, SEED); set_sample(dimensions.x, dimensions.y, SEED); - double h = 5.0;//the range (-h -> +h) for the average offset + double h = 40.0;//the range (-h -> +h) for the average offset //for the new value in range of h //side length is distance of a single square side //or distance of diagonal in diamond diff --git a/src/main.cpp b/src/main.cpp index 10037e3..560da68 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -40,9 +40,9 @@ const int WINDOW_X = 1000; const int WINDOW_Y = 1000; const int WORK_SIZE = WINDOW_X * WINDOW_Y; -const int MAP_X = 128; -const int MAP_Y = 128; -const int MAP_Z = 128; +const int MAP_X = 256; +const int MAP_Y = 256; +const int MAP_Z = 256; float elap_time(){ static std::chrono::time_point start; @@ -186,12 +186,33 @@ int main() { //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; + } + if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) { + light_vec.at(0).position.x += delta_time * 10; + } + if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) { + light_vec.at(0).position.y += delta_time * 10; + } + if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) { + light_vec.at(0).position.y -= delta_time * 10; + } + if (sf::Keyboard::isKeyPressed(sf::Keyboard::Home)) { + light_vec.at(0).position.z += delta_time * 10; + } + if (sf::Keyboard::isKeyPressed(sf::Keyboard::End)) { + light_vec.at(0).position.z -= delta_time * 10; + } + + + if (sf::Keyboard::isKeyPressed(sf::Keyboard::LAlt)) { light_vec.at(0).position = camera->get_position(); light_vec.at(0).direction_cartesian = SphereToCart(camera->get_direction()); } if (sf::Keyboard::isKeyPressed(sf::Keyboard::O)) { - light_vec.at(0).orbit_around_center(timer_accumulator += delta_time); + light_vec.at(0).orbit_around_center(fmod(timer_accumulator += delta_time, 3)); } if (sf::Keyboard::isKeyPressed(sf::Keyboard::M)) {