Tweaking, fixed a very old off by one bug on voxel gen

master
MitchellHansen 7 years ago
parent dcf355c636
commit 36bf5697fa

@ -23,7 +23,7 @@
#include "util.hpp" #include "util.hpp"
#include <SFML/Graphics.hpp> #include <SFML/Graphics.hpp>
#include "CLCaster.h" //#include "CLCaster.h"
#include "Camera.h" #include "Camera.h"
#include "Input.h" #include "Input.h"
#include "LightController.h" #include "LightController.h"
@ -36,15 +36,17 @@
#undef ERROR #undef ERROR
#include "Logger.h" #include "Logger.h"
class CLCaster;
class Application { class Application {
public: public:
const int WINDOW_X = 1600; static const int WINDOW_X = 1600;
const int WINDOW_Y = 900; static const int WINDOW_Y = 900;
const int MAP_X = 64; static const int MAP_X = 32;
const int MAP_Y = 64; static const int MAP_Y = 32;
const int MAP_Z = 64; static const int MAP_Z = 32;
Application(); Application();
~Application(); ~Application();

@ -7,6 +7,7 @@
#include "LightController.h" #include "LightController.h"
#include "Camera.h" #include "Camera.h"
#include <GL/glew.h> #include <GL/glew.h>
#include <Application.h>
#include <unordered_map> #include <unordered_map>
#include "Logger.h" #include "Logger.h"
#include "map/Map.h" #include "map/Map.h"

@ -25,7 +25,7 @@ struct OctState {
class Octree { class Octree {
public: public:
static const int buffer_size = 300000; static const int buffer_size = 100000;
Octree(); Octree();
~Octree() {}; ~Octree() {};
@ -42,13 +42,13 @@ public:
// know when to switch buffers // know when to switch buffers
uint64_t *descriptor_buffer; uint64_t *descriptor_buffer;
uint64_t descriptor_buffer_position = buffer_size; uint64_t descriptor_buffer_position = buffer_size - 1;
uint32_t *attachment_lookup; 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;
uint64_t attachment_buffer_position = buffer_size; uint64_t attachment_buffer_position = buffer_size - 1;
unsigned int trunk_cutoff = 3; unsigned int trunk_cutoff = 3;
uint64_t root_index = 0; uint64_t root_index = 0;

@ -150,20 +150,20 @@ inline std::string read_file(std::string file_name){
inline void PrettyPrintUINT64(uint64_t i, std::stringstream* ss) { inline void PrettyPrintUINT64(uint64_t i, std::stringstream* ss) {
//*ss << "[" << std::bitset<15>(i) << "]"; *ss << "[" << std::bitset<15>(i) << "]";
//*ss << "[" << std::bitset<1>(i >> 15) << "]"; *ss << "[" << std::bitset<1>(i >> 15) << "]";
//*ss << "[" << std::bitset<8>(i >> 16) << "]"; *ss << "[" << std::bitset<8>(i >> 16) << "]";
//*ss << "[" << std::bitset<8>(i >> 24) << "]"; *ss << "[" << std::bitset<8>(i >> 24) << "]";
//*ss << "[" << std::bitset<32>(i >> 32) << "]\n"; *ss << "[" << std::bitset<32>(i >> 32) << "]";
} }
inline void PrettyPrintUINT64(uint64_t i) { inline void PrettyPrintUINT64(uint64_t i) {
//std::cout << "[" << std::bitset<15>(i) << "]"; std::cout << "[" << std::bitset<15>(i) << "]";
//std::cout << "[" << std::bitset<1>(i >> 15) << "]"; std::cout << "[" << std::bitset<1>(i >> 15) << "]";
//std::cout << "[" << std::bitset<8>(i >> 16) << "]"; std::cout << "[" << std::bitset<8>(i >> 16) << "]";
//std::cout << "[" << std::bitset<8>(i >> 24) << "]"; std::cout << "[" << std::bitset<8>(i >> 24) << "]";
//std::cout << "[" << std::bitset<32>(i >> 32) << "]" << std::endl; std::cout << "[" << std::bitset<32>(i >> 32) << "]" << std::endl;
} }
inline void DumpLog(std::stringstream* ss, std::string file_name) { inline void DumpLog(std::stringstream* ss, std::string file_name) {

@ -136,7 +136,7 @@ bool get_oct_vox(
// //
// No? // No?
// Break // Break
while (dimension > 64) { while (dimension > 1) {
// So we can be a little bit tricky here and increment our // So we can be a little bit tricky here and increment our
// array index that holds our masks as we build the idx. // 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); voxel_step *= (ray_dir > 0) - (ray_dir < 0);
// Setup the voxel coords from the camera origin // 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 // Delta T is the units a ray must travel along an axis in order to
// traverse an integer split // traverse an integer split
float3 delta_t = fabs(1.0f / ray_dir); 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 // 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 // is less than 0 which dictates whether or not we subtract the delta which in effect
// mirrors the offset // 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 distance_traveled = 0;
int max_distance = 700; int max_distance = 700;
@ -325,22 +326,22 @@ __kernel void raycaster(
constant int vox_dim = OCTDIM; constant int vox_dim = OCTDIM;
// // If we hit a voxel // If we hit a voxel
// if (voxel.x < vox_dim && voxel.y < vox_dim && voxel.z < vox_dim){ if (voxel.x < vox_dim && voxel.y < vox_dim && voxel.z < vox_dim){
// if (get_oct_vox( if (get_oct_vox(
// voxel, voxel,
// octree_descriptor_buffer, octree_descriptor_buffer,
// octree_attachment_lookup_buffer, octree_attachment_lookup_buffer,
// octree_attachment_buffer, octree_attachment_buffer,
// settings_buffer settings_buffer
// )){ )){
// voxel_data = 5; voxel_data = 5;
// } else { } else {
// voxel_data = 0; voxel_data = 0;
// } }
// } else { } else {
voxel_data = map[voxel.x + (*map_dim).x * (voxel.y + (*map_dim).z * (voxel.z))]; voxel_data = map[voxel.x + (*map_dim).x * (voxel.y + (*map_dim).z * (voxel.z))];
//} }

@ -30,7 +30,7 @@ bool Application::init_clcaster() {
sf::Image bitmap = map->GenerateHeightBitmap(sf::Vector3i(MAP_X, MAP_Y, MAP_Z)); sf::Image bitmap = map->GenerateHeightBitmap(sf::Vector3i(MAP_X, MAP_Y, MAP_Z));
map->ApplyHeightmap(bitmap); 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_octree(map);
raycaster->assign_map(map); raycaster->assign_map(map);

@ -710,7 +710,8 @@ bool CLCaster::compile_kernel(std::string kernel_source, bool is_path, std::stri
// need a ref to the oct dimensions // need a ref to the oct dimensions
//std::string oct_dimensions = std::to_string(map->getDimensions().x); //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); error = clBuildProgram(program, 1, &device_id, build_string.c_str(), NULL, NULL);
// Check to see if it error'd out // Check to see if it error'd out

@ -9,14 +9,14 @@ ArrayMap::ArrayMap(sf::Vector3i dimensions) {
voxel_data = new char[dimensions.x * dimensions.y * dimensions.z]; voxel_data = new char[dimensions.x * dimensions.y * dimensions.z];
for (int i = 0; i < dimensions.x * dimensions.y * dimensions.z; i++) { for (int i = 0; i < dimensions.x * dimensions.y * dimensions.z; i++) {
voxel_data[i] = 0; voxel_data[i] = 0;
voxel_data[i] = 1; //voxel_data[i] = 1;
} }
//for (int x = 0; x < dimensions.x; x++) { for (int x = 0; x < dimensions.x; x++) {
// for (int y = 0; y < dimensions.y; y++) { for (int y = 0; y < dimensions.y; y++) {
// setVoxel(sf::Vector3i(x, y, 1), 5); setVoxel(sf::Vector3i(x, y, 0), 1);
// } }
//} }
} }

@ -34,6 +34,7 @@ void Octree::Generate(char* data, sf::Vector3i dimensions) {
for (int i = 0; i < buffer_size; i++) { for (int i = 0; i < buffer_size; i++) {
PrettyPrintUINT64(descriptor_buffer[i], &output_stream); PrettyPrintUINT64(descriptor_buffer[i], &output_stream);
output_stream << std::endl;
} }
DumpLog(&output_stream, "raw_data.txt"); DumpLog(&output_stream, "raw_data.txt");
@ -321,6 +322,7 @@ std::tuple<uint64_t, uint64_t> Octree::GenerationRecursion(char* data, sf::Vecto
} }
char Octree::get1DIndexedVoxel(char* data, sf::Vector3i dimensions, sf::Vector3i position) { 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)]; 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) { if (arr_val != oct_val) {
std::cout << "X: " << pos.x << " Y: " << pos.y << " Z: " << pos.z << " "; std::cout << "X: " << pos.x << " Y: " << pos.y << " Z: " << pos.z << " ";
std::cout << (int)arr_val << " : " << (int)oct_val << std::endl; std::cout << (int)arr_val << " : " << (int)oct_val << std::endl;
return false; //return false;
} }
} }
} }

Loading…
Cancel
Save