Thankfully it wasn't a problem with the data format, I was passing the
address of a ptr, not the address contained by the ptr. With that, preliminary GPU octree interaction works perfectly
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
#include "util.hpp"
|
#include "util.hpp"
|
||||||
#include "map/Octree.h"
|
#include "map/Octree.h"
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include "map/Old_Map.h"
|
||||||
|
|
||||||
#define _USE_MATH_DEFINES
|
#define _USE_MATH_DEFINES
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
@@ -15,7 +16,7 @@ class Map {
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
// Currently takes a
|
// Currently takes a
|
||||||
Map(uint32_t dimensions);
|
Map(uint32_t dimensions, Old_Map* array_map);
|
||||||
|
|
||||||
// Sets a voxel in the 3D char dataset
|
// Sets a voxel in the 3D char dataset
|
||||||
void setVoxel(sf::Vector3i position, int val);
|
void setVoxel(sf::Vector3i position, int val);
|
||||||
|
|||||||
@@ -364,11 +364,11 @@ __kernel void raycaster(
|
|||||||
|
|
||||||
// Test for out of bounds contions, add fog
|
// Test for out of bounds contions, add fog
|
||||||
if (any(voxel >= *map_dim)){
|
if (any(voxel >= *map_dim)){
|
||||||
//write_imagef(image, pixel, white_light(mix(fog_color, overshoot_color, 1.0 - max(dist / 700.0f, (float)0)), (float3)(lights[7], lights[8], lights[9]), face_mask));
|
write_imagef(image, pixel, white_light(mix(fog_color, overshoot_color, 1.0 - max(dist / 700.0f, (float)0)), (float3)(lights[7], lights[8], lights[9]), face_mask));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (any(voxel < 0)) {
|
if (any(voxel < 0)) {
|
||||||
//write_imagef(image, pixel, white_light(mix(fog_color, overshoot_color_2, 1.0 - max(dist / 700.0f, (float)0)), (float3)(lights[7], lights[8], lights[9]), face_mask));
|
write_imagef(image, pixel, white_light(mix(fog_color, overshoot_color_2, 1.0 - max(dist / 700.0f, (float)0)), (float3)(lights[7], lights[8], lights[9]), face_mask));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ bool Application::init_clcaster() {
|
|||||||
// Send the data to the GPU
|
// Send the data to the GPU
|
||||||
raycaster->assign_map(map);
|
raycaster->assign_map(map);
|
||||||
|
|
||||||
octree = std::make_shared<Map>(32);
|
octree = std::make_shared<Map>(32, map.get());
|
||||||
raycaster->assign_octree(octree);
|
raycaster->assign_octree(octree);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -96,11 +96,11 @@ bool CLCaster::assign_octree(std::shared_ptr<Map> octree) {
|
|||||||
|
|
||||||
this->octree = octree;
|
this->octree = octree;
|
||||||
|
|
||||||
if (!create_buffer("octree_descriptor_buffer", octree->octree.buffer_size, &octree->octree.descriptor_buffer))
|
if (!create_buffer("octree_descriptor_buffer", octree->octree.buffer_size * sizeof(uint64_t), octree->octree.descriptor_buffer))
|
||||||
return false;
|
return false;
|
||||||
if (!create_buffer("octree_attachment_lookup_buffer", octree->octree.buffer_size, &octree->octree.attachment_lookup))
|
if (!create_buffer("octree_attachment_lookup_buffer", octree->octree.buffer_size * sizeof(uint32_t), octree->octree.attachment_lookup))
|
||||||
return false;
|
return false;
|
||||||
if (!create_buffer("octree_attachment_buffer", octree->octree.buffer_size, &octree->octree.attachment_buffer))
|
if (!create_buffer("octree_attachment_buffer", octree->octree.buffer_size * sizeof(uint64_t), octree->octree.attachment_buffer))
|
||||||
return false;
|
return false;
|
||||||
if (!create_buffer("settings_buffer", sizeof(uint64_t), &octree->octree.root_index))
|
if (!create_buffer("settings_buffer", sizeof(uint64_t), &octree->octree.root_index))
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
|
|
||||||
|
|
||||||
Map::Map(uint32_t dimensions) {
|
Map::Map(uint32_t dimensions, Old_Map* array_map) {
|
||||||
|
|
||||||
|
|
||||||
if ((int)pow(2, (int)log2(dimensions)) != dimensions)
|
if ((int)pow(2, (int)log2(dimensions)) != dimensions)
|
||||||
@@ -12,12 +12,26 @@ Map::Map(uint32_t dimensions) {
|
|||||||
|
|
||||||
// randomly set the voxel data for testing
|
// randomly set the voxel data for testing
|
||||||
for (uint64_t i = 0; i < dimensions * dimensions * dimensions; i++) {
|
for (uint64_t i = 0; i < dimensions * dimensions * dimensions; i++) {
|
||||||
if (i % 2 == 0)
|
if (rand() % 10000 < 3)
|
||||||
voxel_data[i] = 1;
|
voxel_data[i] = 1;
|
||||||
else
|
else
|
||||||
voxel_data[i] = 0;
|
voxel_data[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char* char_array = array_map->get_voxel_data();
|
||||||
|
sf::Vector3i arr_dimensions = array_map->getDimensions();
|
||||||
|
|
||||||
|
for (int x = 0; x < dimensions; x++) {
|
||||||
|
for (int y = 0; y < dimensions; y++) {
|
||||||
|
for (int z = 0; z < dimensions; z++) {
|
||||||
|
|
||||||
|
char v = char_array[x + arr_dimensions.x * (y + arr_dimensions.z * z)];
|
||||||
|
if (v)
|
||||||
|
voxel_data[x + dimensions * (y + dimensions * z)] = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sf::Vector3i dim3(dimensions, dimensions, dimensions);
|
sf::Vector3i dim3(dimensions, dimensions, dimensions);
|
||||||
|
|
||||||
Logger::log("Generating Octree", Logger::LogLevel::INFO);
|
Logger::log("Generating Octree", Logger::LogLevel::INFO);
|
||||||
|
|||||||
@@ -322,9 +322,9 @@ bool Octree::Validate(char* data, sf::Vector3i dimensions){
|
|||||||
// std::cout << (int)GetVoxel(sf::Vector3i(16, 16, 16)) << std::endl;
|
// std::cout << (int)GetVoxel(sf::Vector3i(16, 16, 16)) << std::endl;
|
||||||
|
|
||||||
|
|
||||||
for (int x = 0; x < OCT_DIM; x++) {
|
for (int x = 0; x < dimensions.x; x++) {
|
||||||
for (int y = 0; y < OCT_DIM; y++) {
|
for (int y = 0; y < dimensions.y; y++) {
|
||||||
for (int z = 0; z < OCT_DIM; z++) {
|
for (int z = 0; z < dimensions.z; z++) {
|
||||||
|
|
||||||
sf::Vector3i pos(x, y, z);
|
sf::Vector3i pos(x, y, z);
|
||||||
|
|
||||||
@@ -334,6 +334,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user