mouse and camera movement work, stress testing. Can actually handle an

impressive amount of resolution and voxel space for 0 optimization!
master
MitchellHansen 8 years ago
parent f487895f9f
commit 160756186d

@ -15,7 +15,11 @@ public:
for (int x = 0; x < dim.x; x++) { for (int x = 0; x < dim.x; x++) {
for (int y = 0; y < dim.y; y++) { for (int y = 0; y < dim.y; y++) {
for (int z = 0; z < dim.z; z++) { for (int z = 0; z < dim.z; z++) {
if (rand() % 100 < 1)
if (dim.z < 30) {
list[x + dim.x * (y + dim.z * z)] = 3;
}
else if (rand() % 1000 < 1)
list[x + dim.x * (y + dim.z * z)] = rand() % 6; list[x + dim.x * (y + dim.z * z)] = rand() % 6;
else else
list[x + dim.x * (y + dim.z * z)] = 0; list[x + dim.x * (y + dim.z * z)] = 0;

@ -12,7 +12,6 @@ __kernel void min_kern(
int2 pixel = {id % resolution->x, id / resolution->x}; int2 pixel = {id % resolution->x, id / resolution->x};
float3 ray_dir = projection_matrix[pixel.x + resolution->x * pixel.y]; float3 ray_dir = projection_matrix[pixel.x + resolution->x * pixel.y];
//printf("%i === %f, %f, %f\n", id, ray_dir.x, ray_dir.y, ray_dir.z); //printf("%i === %f, %f, %f\n", id, ray_dir.x, ray_dir.y, ray_dir.z);
@ -133,17 +132,18 @@ __kernel void min_kern(
int index = voxel.x + map_dim->x * (voxel.y + map_dim->z * voxel.z); int index = voxel.x + map_dim->x * (voxel.y + map_dim->z * voxel.z);
int voxel_data = map[index]; int voxel_data = map[index];
if (id == 240000) //if (id == 240000)
printf("%i, %i, %i\n", voxel.x, voxel.y, voxel.z); //printf("%i, %i, %i\n", voxel.x, voxel.y, voxel.z);
if (voxel_data != 0) {
switch (voxel_data) { switch (voxel_data) {
case 1: case 1:
write_imagef(image, pixel, (float4)(.50, .00, .00, 1)); write_imagef(image, pixel, (float4)(.50, .00, .00, 1));
return; return;
case 2: case 2:
write_imagef(image, pixel, (float4)(.00, .50, .40, 1.00)); write_imagef(image, pixel, (float4)(.00, .50, .40, 1.00));
if (id == 249000) //if (id == 249000)
printf("%i\n", voxel_data); // printf("%i\n", voxel_data);
return; return;
case 3: case 3:
write_imagef(image, pixel, (float4)(.00, .00, .50, 1.00)); write_imagef(image, pixel, (float4)(.00, .00, .50, 1.00));
@ -158,9 +158,10 @@ __kernel void min_kern(
write_imagef(image, pixel, (float4)(.30, .80, .10, 1.00)); write_imagef(image, pixel, (float4)(.30, .80, .10, 1.00));
return; return;
} }
}
dist++; dist++;
} while (dist < 600); } while (dist < 2500);
write_imagef(image, pixel, (float4)(.00, .00, .00, .00)); write_imagef(image, pixel, (float4)(.00, .00, .00, .00));

@ -32,12 +32,12 @@
#include "RayCaster.h" #include "RayCaster.h"
#include "CL_Wrapper.h" #include "CL_Wrapper.h"
const int WINDOW_X = 500; const int WINDOW_X = 1000;
const int WINDOW_Y = 500; const int WINDOW_Y = 1000;
const int MAP_X = 500; const int MAP_X = 1000;
const int MAP_Y = 500; const int MAP_Y = 1000;
const int MAP_Z = 500; const int MAP_Z = 1000;
float elap_time(){ float elap_time(){
static std::chrono::time_point<std::chrono::system_clock> start; static std::chrono::time_point<std::chrono::system_clock> start;
@ -77,8 +77,10 @@ int main() {
//c.compile_kernel("../kernels/kernel.cl", true, "hello"); //c.compile_kernel("../kernels/kernel.cl", true, "hello");
c.compile_kernel("../kernels/minimal_kernel.cl", true, "min_kern"); c.compile_kernel("../kernels/minimal_kernel.cl", true, "min_kern");
std::cout << "map...";
sf::Vector3i map_dim(MAP_X, MAP_Y, MAP_Z); sf::Vector3i map_dim(MAP_X, MAP_Y, MAP_Z);
Map* map = new Map(map_dim); Map* map = new Map(map_dim);
std::cout << "done...";
map->setVoxel(sf::Vector3i(77, 50, 85), 5); map->setVoxel(sf::Vector3i(77, 50, 85), 5);
@ -105,6 +107,7 @@ int main() {
// SFML 2.4 has Vector4 datatypes....... // SFML 2.4 has Vector4 datatypes.......
std::cout << "view matrix...";
float* view_matrix = new float[WINDOW_X * WINDOW_Y * 4]; float* view_matrix = new float[WINDOW_X * WINDOW_Y * 4];
for (int y = -view_res.y / 2; y < view_res.y / 2; y++) { for (int y = -view_res.y / 2; y < view_res.y / 2; y++) {
for (int x = -view_res.x / 2; x < view_res.x / 2; x++) { for (int x = -view_res.x / 2; x < view_res.x / 2; x++) {
@ -134,7 +137,7 @@ int main() {
view_matrix[index * 4 + 3] = 0; view_matrix[index * 4 + 3] = 0;
} }
} }
std::cout << "done\n";
int ind = 367; int ind = 367;
printf("%i === %f, %f, %f\n", ind, view_matrix[ind * 4 + 0], view_matrix[ind * 4 + 1], view_matrix[ind * 4 + 2]); printf("%i === %f, %f, %f\n", ind, view_matrix[ind * 4 + 0], view_matrix[ind * 4 + 1], view_matrix[ind * 4 + 2]);
@ -146,14 +149,14 @@ int main() {
sf::Vector3f cam_dir(1.0f, 0.0f, 1.00f); sf::Vector3f cam_dir(1.0f, 0.0f, 1.00f);
cl_mem cam_dir_buff = clCreateBuffer( cl_mem cam_dir_buff = clCreateBuffer(
c.getContext(), CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, c.getContext(), CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR,
sizeof(float) * 4, &cam_dir, NULL sizeof(float) * 4, &cam_dir, NULL
); );
sf::Vector3f cam_pos(55, 50, 50); sf::Vector3f cam_pos(55, 50, 50);
cl_mem cam_pos_buff = clCreateBuffer( cl_mem cam_pos_buff = clCreateBuffer(
c.getContext(), CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, c.getContext(), CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR,
sizeof(float) * 4, &cam_pos, NULL sizeof(float) * 4, &cam_pos, NULL
); );
@ -181,9 +184,7 @@ int main() {
if (c.assert(error, "clCreateFromGLTexture")) if (c.assert(error, "clCreateFromGLTexture"))
return -1; return -1;
error = clEnqueueAcquireGLObjects(c.getCommandQueue(), 1, &image_buff, 0, 0, 0);
if (c.assert(error, "clEnqueueAcquireGLObjects"))
return -1;
@ -204,14 +205,8 @@ int main() {
c.set_kernel_arg("min_kern", 6, "image_buffer"); c.set_kernel_arg("min_kern", 6, "image_buffer");
const int size = WINDOW_X * WINDOW_Y; const int size = WINDOW_X * WINDOW_Y;
c.run_kernel("min_kern", size);
clFinish(c.getCommandQueue());
error = clEnqueueReleaseGLObjects(c.getCommandQueue(), 1, &image_buff, 0, NULL, NULL);
if (c.assert(error, "clEnqueueReleaseGLObjects"))
return -1;
s.setTexture(t); s.setTexture(t);
@ -339,12 +334,25 @@ int main() {
//window.draw(window_sprite); //window.draw(window_sprite);
// Give the frame counter the frame time and draw the average frame time // Give the frame counter the frame time and draw the average frame time
fps.frame(delta_time);
fps.draw(&window);
error = clEnqueueAcquireGLObjects(c.getCommandQueue(), 1, &image_buff, 0, 0, 0);
if (c.assert(error, "clEnqueueAcquireGLObjects"))
return -1;
c.run_kernel("min_kern", size);
clFinish(c.getCommandQueue());
error = clEnqueueReleaseGLObjects(c.getCommandQueue(), 1, &image_buff, 0, NULL, NULL);
if (c.assert(error, "clEnqueueReleaseGLObjects"))
return -1;
s.setPosition(0, 0); s.setPosition(0, 0);
window.draw(s); window.draw(s);
fps.frame(delta_time);
fps.draw(&window);
window.display(); window.display();
} }

Loading…
Cancel
Save