From 0d82cd5a203ed41d81ad3aa8d33eccee93e911e1 Mon Sep 17 00:00:00 2001 From: MitchellHansen Date: Sun, 19 Mar 2017 23:08:16 -0700 Subject: [PATCH] Finally moved screenshots and runtime compilation to GUI elements --- kernels/ray_caster_kernel.cl | 9 ++++-- src/main.cpp | 46 +++++++++++++++++-------------- src/raycaster/Hardware_Caster.cpp | 7 ++--- 3 files changed, 35 insertions(+), 27 deletions(-) diff --git a/kernels/ray_caster_kernel.cl b/kernels/ray_caster_kernel.cl index e363bb8..6f4ff58 100644 --- a/kernels/ray_caster_kernel.cl +++ b/kernels/ray_caster_kernel.cl @@ -72,6 +72,9 @@ bool cast_light_intersection_ray( ){ float distance_to_light = DistanceBetweenPoints(ray_pos, (float3)(lights[4], lights[5], lights[6])); + if (distance_to_light > 200.0f){ + return false; + } // Setup the voxel step based on what direction the ray is pointing int3 voxel_step = { 1, 1, 1 }; @@ -148,11 +151,13 @@ __kernel void raycaster( global int2 *tile_dim ){ - int global_id = get_global_id(0); - + + int x = get_global_id(0); int y = get_global_id(1); + int global_id = x * y; + // Get and set the random seed from seed memory int seed = seed_memory[global_id]; int random_number = rand(&seed); diff --git a/src/main.cpp b/src/main.cpp index 8dab75f..cc77ee6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -46,8 +46,8 @@ const int WINDOW_X = 1440; const int WINDOW_Y = 900; const int WORK_SIZE = WINDOW_X * WINDOW_Y; -const int MAP_X = 256; -const int MAP_Y = 256; +const int MAP_X = 512; +const int MAP_Y = 512; const int MAP_Z = 256; float elap_time(){ @@ -181,6 +181,7 @@ int main() { float light_color[4] = { 0, 0, 0, 0 }; float light_pos[4] = { 100, 100, 30 }; + char screenshot_buf[128]{0}; while (window.isOpen()) { @@ -188,24 +189,6 @@ int main() { input_handler.handle_held_keys(); input_handler.dispatch_events(); - if (sf::Keyboard::isKeyPressed(sf::Keyboard::F11)) { - while (raycaster->debug_quick_recompile() != 0); - } - - if (sf::Keyboard::isKeyPressed(sf::Keyboard::Num0)) { - std::string path = "../assets/"; - std::string filename; - std::getline(std::cin, filename); - filename += ".png"; - - sf::Texture window_texture; - window_texture.create(window.getSize().x, window.getSize().y); - window_texture.update(window); - - sf::Image image = window_texture.copyToImage(); - image.saveToFile(path + filename); - } - // Time keeping elapsed_time = elap_time(); delta_time = elapsed_time - current_time; @@ -256,6 +239,29 @@ int main() { ImGui::Text(std::to_string(pos.y).c_str()); ImGui::Text(std::to_string(pos.z).c_str()); + ImGui::NextColumn(); + + ImGui::InputText("filename", screenshot_buf, 128); + if (ImGui::Button("Take Screen shot")) { + + std::string path = "../assets/"; + std::string filename(screenshot_buf); + filename += ".png"; + + sf::Texture window_texture; + window_texture.create(window.getSize().x, window.getSize().y); + window_texture.update(window); + + sf::Image image = window_texture.copyToImage(); + image.saveToFile(path + filename); + + } + + ImGui::NextColumn(); + + if (ImGui::Button("Recompile kernel")) { + while (raycaster->debug_quick_recompile() != 0); + } ImGui::End(); ImGui::Begin("Lights"); diff --git a/src/raycaster/Hardware_Caster.cpp b/src/raycaster/Hardware_Caster.cpp index c7fe33c..ef23bce 100644 --- a/src/raycaster/Hardware_Caster.cpp +++ b/src/raycaster/Hardware_Caster.cpp @@ -518,7 +518,7 @@ int Hardware_Caster::compile_kernel(std::string kernel_source, bool is_path, std // Try and build the program - error = clBuildProgram(program, 1, &device_id, NULL, NULL, NULL); + error = clBuildProgram(program, 1, &device_id, "-cl-finite-math-only -cl-fast-relaxed-math -cl-unsafe-math-optimizations", NULL, NULL); // Check to see if it errored out if (vr_assert(error, "clBuildProgram")) { @@ -665,10 +665,7 @@ int Hardware_Caster::store_buffer(cl_mem buffer, std::string buffer_name) { int Hardware_Caster::run_kernel(std::string kernel_name, const int work_dim_x, const int work_dim_y) { - //size_t global_work_size[2] = { static_cast(work_dim_x), static_cast(work_dim_y)}; - - size_t global_work_size[2] = { static_cast(1440), static_cast(900)}; - //size_t global_work_size[1] = { static_cast(1440*900) }; + size_t global_work_size[2] = { static_cast(work_dim_x), static_cast(work_dim_y)}; cl_kernel kernel = kernel_map.at(kernel_name);