From 8f822e14f78d69c8056f6e3cbb1dcbee4e678900 Mon Sep 17 00:00:00 2001 From: mitchellhansen Date: Thu, 1 Mar 2018 21:54:16 -0800 Subject: [PATCH] Have some real bad lock ups when the oct is semi full --- kernels/ray_caster_kernel.cl | 42 +++++++++++++++++++----------------- src/Application.cpp | 2 +- src/map/ArrayMap.cpp | 12 ++++++++++- 3 files changed, 34 insertions(+), 22 deletions(-) diff --git a/kernels/ray_caster_kernel.cl b/kernels/ray_caster_kernel.cl index c999f72..02579a6 100644 --- a/kernels/ray_caster_kernel.cl +++ b/kernels/ray_caster_kernel.cl @@ -302,7 +302,7 @@ __kernel void raycaster( intersection_t -= delta_t * convert_float3(isless(intersection_t, 0)); int distance_traveled = 0; - int max_distance = 700; + int max_distance = 100; uint bounce_count = 0; int3 face_mask = { 0, 0, 0 }; int voxel_data = 0; @@ -433,7 +433,7 @@ __kernel void raycaster( is_valid = (traversal_state.parent_stack[traversal_state.parent_stack_position] >> 16) & mask_8[mask_index]; failsafe++; - if (failsafe > 10000) + if (failsafe > 20) break; } @@ -507,30 +507,32 @@ __kernel void raycaster( is_valid = (traversal_state.parent_stack[traversal_state.parent_stack_position] >> 16) & mask_8[mask_index]; failsafe++; - if (failsafe > 100) + if (failsafe > 20) break; } - intersection_t += delta_t * jump_power * fabs(convert_float3(face_mask.xyz)); + // intersection_t += delta_t * jump_power * fabs(convert_float3(face_mask.xyz)); + // + // //int3 other_faces = face_mask == 1 ? 1 : -1; + // int3 other_faces = select((int3)(1,1,1), (int3)(0,0,0), (int3)(face_mask == 1)); + // //int3 added_diff = last_oct_pos + prev_jump_power - traversal_state.oct_pos; + // + // uint3 multiplier = (1, 1, 1);//convert_uint3(abs(traversal_state.oct_pos - last_oct_pos) * (1.0f/prev_jump_power)); + // + // last_oct_pos = traversal_state.oct_pos; + // + // intersection_t -= delta_t * prev_jump_power * convert_float3(other_faces.xyz); + // intersection_t += delta_t * convert_float3(multiplier) * jump_power * fabs(convert_float3(other_faces.xyz)); - //int3 other_faces = face_mask == 1 ? 1 : -1; - int3 other_faces = select((int3)(1,1,1), (int3)(0,0,0), (int3)(face_mask == 1)); - //int3 added_diff = last_oct_pos + prev_jump_power - traversal_state.oct_pos; - uint3 multiplier = abs(traversal_state.oct_pos - last_oct_pos) / prev_jump_power ; - last_oct_pos = traversal_state.oct_pos; - - intersection_t -= delta_t * prev_jump_power * convert_float3(other_faces.xyz); - intersection_t += delta_t * convert_float3(multiplier) * jump_power * fabs(convert_float3(other_faces.xyz)); - // // Test for out of bounds contions, add fog - // if (traversal_state.scale == 1){ - // //voxel.xyz -= voxel_step.xyz * face_mask.xyz; - // color_accumulator = mix((1.0f, 1.0f, 1.0f, 1.0f), (1.0f, 1.0f, 1.0f, 1.0f), 1.0f - max(distance_traveled / 700.0f, 0.0f)); - // color_accumulator.w *= 4; - // break; - // } - voxel_data = map[voxel.x + (*map_dim).x * (voxel.y + (*map_dim).z * (voxel.z))]; + if (traversal_state.scale == 1 && is_valid){ + //voxel.xyz -= voxel_step.xyz * face_mask.xyz; + color_accumulator = mix((1.0f, 1.0f, 1.0f, 1.0f), (1.0f, 1.0f, 1.0f, 1.0f), 1.0f - max(distance_traveled / 700.0f, 0.0f)); + color_accumulator.w *= 4; + break; + } + //voxel_data = map[voxel.x + (*map_dim).x * (voxel.y + (*map_dim).z * (voxel.z))]; } else { // Fancy no branch version of the logic step face_mask = intersection_t.xyz <= min(intersection_t.yzx, intersection_t.zxy); diff --git a/src/Application.cpp b/src/Application.cpp index 3b9a6cc..3b49bc2 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -51,7 +51,7 @@ bool Application::init_clcaster() { raycaster->assign_map(map); camera = std::make_shared( - sf::Vector3f(3.5f, 3.5f, 3.5f), // Starting position + sf::Vector3f(30.5f, 30.5f, 30.5f), // Starting position sf::Vector2f(1.57f, 0.0f), // Direction window.get() ); diff --git a/src/map/ArrayMap.cpp b/src/map/ArrayMap.cpp index 2755112..eaef2aa 100644 --- a/src/map/ArrayMap.cpp +++ b/src/map/ArrayMap.cpp @@ -16,7 +16,17 @@ ArrayMap::ArrayMap(sf::Vector3i dimensions) { for (int x = 0; x < dimensions.x; x++) { for (int y = 0; y < dimensions.y; y++) { - setVoxel(sf::Vector3i(x, y, 0), 5); + for (int z = 0; z < 2; z++) { + setVoxel(sf::Vector3i(x, y, z), 5); + } + } + } + + for (int x = 0; x < dimensions.x/2-1; x++) { + for (int y = 0; y < dimensions.y/2-1; y++) { + for (int z = 0; z < dimensions.z/2-1; z++) { + setVoxel(sf::Vector3i(x, y, z), 5); + } } } }