Fixed the camera movement so it now take into account sub-voxel movement

Also fixed the distortion around the XY axes
master
MitchellHansen 8 years ago
parent fe0fbc04e1
commit 1620f40d02

@ -198,7 +198,10 @@ public:
if (height_map[x + y * dim.x] > 0) { if (height_map[x + y * dim.x] > 0) {
int z = height_map[x + y * dim.x]; int z = height_map[x + y * dim.x];
while (z > 0){
list[x + dim.x * (y + dim.z * z)] = 5; list[x + dim.x * (y + dim.z * z)] = 5;
z--;
}
} }
} }

@ -45,10 +45,6 @@ __kernel void min_kern(
int3 voxel_step = {1, 1, 1}; int3 voxel_step = {1, 1, 1};
voxel_step *= (ray_dir > 0) - (ray_dir < 0); voxel_step *= (ray_dir > 0) - (ray_dir < 0);
/*voxel_step.x *= (ray_dir.x > 0) - (ray_dir.x < 0);
voxel_step.y *= (ray_dir.y > 0) - (ray_dir.y < 0);
voxel_step.z *= (ray_dir.z > 0) - (ray_dir.z < 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(*cam_pos);
@ -56,9 +52,25 @@ __kernel void min_kern(
// traverse an integer split // traverse an integer split
float3 delta_t = fabs(1.0f / ray_dir); float3 delta_t = fabs(1.0f / ray_dir);
// offset is how far we are into a voxel, enables sub voxel movement
float3 offset = ((*cam_pos) - floor(*cam_pos)) * convert_float3(voxel_step);
//offset.x += delta_t.x * convert_float((voxel_step.x < 0));
//offset -= delta_t * floor(offset / delta_t);
// Intersection T is the collection of the next intersection points // Intersection T is the collection of the next intersection points
// for all 3 axis XYZ. // for all 3 axis XYZ.
float3 intersection_t = delta_t; float3 intersection_t = delta_t * offset;
if (intersection_t.x < 0) {
intersection_t.x += delta_t.x;
}
if (intersection_t.y < 0) {
intersection_t.y += delta_t.y;
}
if (intersection_t.z < 0) {
intersection_t.z += delta_t.z;
}
int2 randoms = { 3, 14 }; int2 randoms = { 3, 14 };
uint seed = randoms.x + id; uint seed = randoms.x + id;

@ -291,18 +291,16 @@ int CL_Wrapper::run_kernel(std::string kernel_name, const int work_size){
if (assert(error, "clEnqueueNDRangeKernel")) if (assert(error, "clEnqueueNDRangeKernel"))
return -1; return -1;
clFinish(getCommandQueue());
// What if errors out and gl objects are never released? // What if errors out and gl objects are never released?
error = clEnqueueReleaseGLObjects(getCommandQueue(), 1, &buffer_map.at("image_buffer"), 0, NULL, NULL); error = clEnqueueReleaseGLObjects(getCommandQueue(), 1, &buffer_map.at("image_buffer"), 0, NULL, NULL);
if (assert(error, "clEnqueueReleaseGLObjects")) if (assert(error, "clEnqueueReleaseGLObjects"))
return -1; return -1;
return 1; return 1;
} }
cl_device_id CL_Wrapper::getDeviceID(){ return device_id; }; cl_device_id CL_Wrapper::getDeviceID(){ return device_id; };
cl_platform_id CL_Wrapper::getPlatformID(){ return platform_id; }; cl_platform_id CL_Wrapper::getPlatformID(){ return platform_id; };
cl_context CL_Wrapper::getContext(){ return context; }; cl_context CL_Wrapper::getContext(){ return context; };
@ -316,7 +314,6 @@ bool CL_Wrapper::assert(int error_code, std::string function_name){
switch (error_code) { switch (error_code) {
case CL_SUCCESS: case CL_SUCCESS:
return false; return false;

@ -68,7 +68,7 @@ int Camera::update(double delta_time) {
// so vector multiplication broke? // so vector multiplication broke?
// have to do it component wise // have to do it component wise
double multiplier = 50; double multiplier = 10;
position.x += movement.x * delta_time * multiplier; position.x += movement.x * delta_time * multiplier;
position.y += movement.y * delta_time * multiplier; position.y += movement.y * delta_time * multiplier;

@ -68,12 +68,8 @@ int main() {
//Map m(sf::Vector3i (50, 50, 50)); //Map m(sf::Vector3i (50, 50, 50));
//return 1; //return 1;
sf::RenderWindow window(sf::VideoMode(WINDOW_X, WINDOW_Y), "SFML"); sf::RenderWindow window(sf::VideoMode(WINDOW_X, WINDOW_Y), "SFML");
// Setup CL, instantiate and pass in values to the kernel // Setup CL, instantiate and pass in values to the kernel
CL_Wrapper c; CL_Wrapper c;
query_platform_devices(); query_platform_devices();
@ -81,9 +77,9 @@ int main() {
c.create_shared_context(); c.create_shared_context();
c.create_command_queue(); c.create_command_queue();
//c.compile_kernel("../kernels/kernel.cl", true, "hello"); if (c.compile_kernel("../kernels/ray_caster_kernel.cl", true, "min_kern") < 0) {
if (c.compile_kernel("../kernels/minimal_kernel.cl", true, "min_kern") < 0) {
std::cin.get(); std::cin.get();
return -1;
} }
std::cout << "map..."; std::cout << "map...";
@ -277,7 +273,7 @@ int main() {
camera.add_relative_impulse(Camera::DIRECTION::RIGHT); camera.add_relative_impulse(Camera::DIRECTION::RIGHT);
} }
if (sf::Keyboard::isKeyPressed(sf::Keyboard::T)) { if (sf::Keyboard::isKeyPressed(sf::Keyboard::T)) {
camera.set_position(sf::Vector3f(20, 20, 20)); camera.set_position(sf::Vector3f(50, 50, 50));
} }
camera.add_static_impulse(cam_vec); camera.add_static_impulse(cam_vec);
@ -313,7 +309,6 @@ int main() {
// Run the raycast // Run the raycast
c.run_kernel("min_kern", WORK_SIZE); c.run_kernel("min_kern", WORK_SIZE);
clFinish(c.getCommandQueue());
// ==== RENDER ==== // ==== RENDER ====

Loading…
Cancel
Save