From 36bf5697fa3cbff6d28ccf42f8e89ff1ad32cf26 Mon Sep 17 00:00:00 2001 From: MitchellHansen Date: Sat, 21 Oct 2017 06:54:09 -0700 Subject: [PATCH] Tweaking, fixed a very old off by one bug on voxel gen --- include/Application.h | 14 ++++++++------ include/CLCaster.h | 1 + include/map/Octree.h | 8 ++++---- include/util.hpp | 20 +++++++++---------- kernels/ray_caster_kernel.cl | 37 ++++++++++++++++++------------------ src/Application.cpp | 2 +- src/CLCaster.cpp | 3 ++- src/map/ArrayMap.cpp | 12 ++++++------ src/map/Octree.cpp | 4 +++- 9 files changed, 54 insertions(+), 47 deletions(-) diff --git a/include/Application.h b/include/Application.h index 06000a9..a3cbe53 100644 --- a/include/Application.h +++ b/include/Application.h @@ -23,7 +23,7 @@ #include "util.hpp" #include -#include "CLCaster.h" +//#include "CLCaster.h" #include "Camera.h" #include "Input.h" #include "LightController.h" @@ -36,15 +36,17 @@ #undef ERROR #include "Logger.h" +class CLCaster; + class Application { public: - const int WINDOW_X = 1600; - const int WINDOW_Y = 900; + static const int WINDOW_X = 1600; + static const int WINDOW_Y = 900; - const int MAP_X = 64; - const int MAP_Y = 64; - const int MAP_Z = 64; + static const int MAP_X = 32; + static const int MAP_Y = 32; + static const int MAP_Z = 32; Application(); ~Application(); diff --git a/include/CLCaster.h b/include/CLCaster.h index 1813a30..1486a17 100644 --- a/include/CLCaster.h +++ b/include/CLCaster.h @@ -7,6 +7,7 @@ #include "LightController.h" #include "Camera.h" #include +#include #include #include "Logger.h" #include "map/Map.h" diff --git a/include/map/Octree.h b/include/map/Octree.h index df8ed58..c5c5b7c 100644 --- a/include/map/Octree.h +++ b/include/map/Octree.h @@ -25,7 +25,7 @@ struct OctState { class Octree { public: - static const int buffer_size = 300000; + static const int buffer_size = 100000; Octree(); ~Octree() {}; @@ -42,13 +42,13 @@ public: // know when to switch buffers uint64_t *descriptor_buffer; - uint64_t descriptor_buffer_position = buffer_size; + uint64_t descriptor_buffer_position = buffer_size - 1; uint32_t *attachment_lookup; - uint64_t attachment_lookup_position = buffer_size; + uint64_t attachment_lookup_position = buffer_size - 1; uint64_t *attachment_buffer; - uint64_t attachment_buffer_position = buffer_size; + uint64_t attachment_buffer_position = buffer_size - 1; unsigned int trunk_cutoff = 3; uint64_t root_index = 0; diff --git a/include/util.hpp b/include/util.hpp index 0ef49cb..ee15d67 100644 --- a/include/util.hpp +++ b/include/util.hpp @@ -150,20 +150,20 @@ inline std::string read_file(std::string file_name){ inline void PrettyPrintUINT64(uint64_t i, std::stringstream* ss) { - //*ss << "[" << std::bitset<15>(i) << "]"; - //*ss << "[" << std::bitset<1>(i >> 15) << "]"; - //*ss << "[" << std::bitset<8>(i >> 16) << "]"; - //*ss << "[" << std::bitset<8>(i >> 24) << "]"; - //*ss << "[" << std::bitset<32>(i >> 32) << "]\n"; + *ss << "[" << std::bitset<15>(i) << "]"; + *ss << "[" << std::bitset<1>(i >> 15) << "]"; + *ss << "[" << std::bitset<8>(i >> 16) << "]"; + *ss << "[" << std::bitset<8>(i >> 24) << "]"; + *ss << "[" << std::bitset<32>(i >> 32) << "]"; } inline void PrettyPrintUINT64(uint64_t i) { - //std::cout << "[" << std::bitset<15>(i) << "]"; - //std::cout << "[" << std::bitset<1>(i >> 15) << "]"; - //std::cout << "[" << std::bitset<8>(i >> 16) << "]"; - //std::cout << "[" << std::bitset<8>(i >> 24) << "]"; - //std::cout << "[" << std::bitset<32>(i >> 32) << "]" << std::endl; + std::cout << "[" << std::bitset<15>(i) << "]"; + std::cout << "[" << std::bitset<1>(i >> 15) << "]"; + std::cout << "[" << std::bitset<8>(i >> 16) << "]"; + std::cout << "[" << std::bitset<8>(i >> 24) << "]"; + std::cout << "[" << std::bitset<32>(i >> 32) << "]" << std::endl; } inline void DumpLog(std::stringstream* ss, std::string file_name) { diff --git a/kernels/ray_caster_kernel.cl b/kernels/ray_caster_kernel.cl index 288decd..2cea49b 100644 --- a/kernels/ray_caster_kernel.cl +++ b/kernels/ray_caster_kernel.cl @@ -136,7 +136,7 @@ bool get_oct_vox( // // No? // Break - while (dimension > 64) { + while (dimension > 1) { // So we can be a little bit tricky here and increment our // array index that holds our masks as we build the idx. @@ -268,8 +268,9 @@ __kernel void raycaster( voxel_step *= (ray_dir > 0) - (ray_dir < 0); // Setup the voxel coords from the camera origin - int3 voxel = convert_int3(*cam_pos); + int3 voxel = convert_int3_rtn(*cam_pos); + //voxel = voxel + convert_int3(*cam_pos < 0.0f); // 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); @@ -291,7 +292,7 @@ __kernel void raycaster( // it over the axis like we want. So here, isless returns a boolean if intersection_t // is less than 0 which dictates whether or not we subtract the delta which in effect // mirrors the offset - intersection_t += delta_t * convert_float3(isless(intersection_t, 0)); + intersection_t -= delta_t * convert_float3(isless(intersection_t, 0)); int distance_traveled = 0; int max_distance = 700; @@ -325,22 +326,22 @@ __kernel void raycaster( constant int vox_dim = OCTDIM; - // // If we hit a voxel - // if (voxel.x < vox_dim && voxel.y < vox_dim && voxel.z < vox_dim){ - // if (get_oct_vox( - // voxel, - // octree_descriptor_buffer, - // octree_attachment_lookup_buffer, - // octree_attachment_buffer, - // settings_buffer - // )){ - // voxel_data = 5; - // } else { - // voxel_data = 0; - // } - // } else { + // If we hit a voxel + if (voxel.x < vox_dim && voxel.y < vox_dim && voxel.z < vox_dim){ + if (get_oct_vox( + voxel, + octree_descriptor_buffer, + octree_attachment_lookup_buffer, + octree_attachment_buffer, + settings_buffer + )){ + voxel_data = 5; + } else { + voxel_data = 0; + } + } else { voxel_data = map[voxel.x + (*map_dim).x * (voxel.y + (*map_dim).z * (voxel.z))]; - //} + } diff --git a/src/Application.cpp b/src/Application.cpp index ed73d9c..f391160 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -30,7 +30,7 @@ bool Application::init_clcaster() { sf::Image bitmap = map->GenerateHeightBitmap(sf::Vector3i(MAP_X, MAP_Y, MAP_Z)); map->ApplyHeightmap(bitmap); - map->octree.CastRayOctree(sf::Vector2f(1.5f, -2.0f), sf::Vector3f(5.1f, 5.1f, 5.1f)); + //map->octree.CastRayOctree(sf::Vector2f(1.5f, -2.0f), sf::Vector3f(5.1f, 5.1f, 5.1f)); raycaster->assign_octree(map); raycaster->assign_map(map); diff --git a/src/CLCaster.cpp b/src/CLCaster.cpp index d735348..4f12501 100644 --- a/src/CLCaster.cpp +++ b/src/CLCaster.cpp @@ -710,7 +710,8 @@ bool CLCaster::compile_kernel(std::string kernel_source, bool is_path, std::stri // need a ref to the oct dimensions //std::string oct_dimensions = std::to_string(map->getDimensions().x); - std::string build_string = "-DOCTDIM=256 -cl-finite-math-only -cl-fast-relaxed-math -cl-unsafe-math-optimizations"; + + std::string build_string = "-DOCTDIM=" + std::to_string(Application::MAP_X) + " -cl-finite-math-only -cl-fast-relaxed-math -cl-unsafe-math-optimizations"; error = clBuildProgram(program, 1, &device_id, build_string.c_str(), NULL, NULL); // Check to see if it error'd out diff --git a/src/map/ArrayMap.cpp b/src/map/ArrayMap.cpp index 4bb9b79..356a306 100644 --- a/src/map/ArrayMap.cpp +++ b/src/map/ArrayMap.cpp @@ -9,14 +9,14 @@ ArrayMap::ArrayMap(sf::Vector3i dimensions) { voxel_data = new char[dimensions.x * dimensions.y * dimensions.z]; for (int i = 0; i < dimensions.x * dimensions.y * dimensions.z; i++) { voxel_data[i] = 0; - voxel_data[i] = 1; + //voxel_data[i] = 1; } - //for (int x = 0; x < dimensions.x; x++) { - // for (int y = 0; y < dimensions.y; y++) { - // setVoxel(sf::Vector3i(x, y, 1), 5); - // } - //} + for (int x = 0; x < dimensions.x; x++) { + for (int y = 0; y < dimensions.y; y++) { + setVoxel(sf::Vector3i(x, y, 0), 1); + } + } } diff --git a/src/map/Octree.cpp b/src/map/Octree.cpp index 70648ce..de9aa5c 100644 --- a/src/map/Octree.cpp +++ b/src/map/Octree.cpp @@ -34,6 +34,7 @@ void Octree::Generate(char* data, sf::Vector3i dimensions) { for (int i = 0; i < buffer_size; i++) { PrettyPrintUINT64(descriptor_buffer[i], &output_stream); + output_stream << std::endl; } DumpLog(&output_stream, "raw_data.txt"); @@ -321,6 +322,7 @@ std::tuple Octree::GenerationRecursion(char* data, sf::Vecto } char Octree::get1DIndexedVoxel(char* data, sf::Vector3i dimensions, sf::Vector3i position) { + std::cout << std::to_string((int)data[position.x + oct_dimensions * (position.y + oct_dimensions * position.z)]) << std::endl; return data[position.x + oct_dimensions * (position.y + oct_dimensions * position.z)]; } @@ -338,7 +340,7 @@ bool Octree::Validate(char* data, sf::Vector3i dimensions){ if (arr_val != oct_val) { std::cout << "X: " << pos.x << " Y: " << pos.y << " Z: " << pos.z << " "; std::cout << (int)arr_val << " : " << (int)oct_val << std::endl; - return false; + //return false; } } }