diff --git a/assets/screenshot.PNG b/assets/screenshot.PNG index c688dcb..281069e 100644 Binary files a/assets/screenshot.PNG and b/assets/screenshot.PNG differ diff --git a/assets/screenshot1.png b/assets/screenshot1.png index cd8c29d..765bde6 100644 Binary files a/assets/screenshot1.png and b/assets/screenshot1.png differ diff --git a/kernels/ray_caster_kernel.cl b/kernels/ray_caster_kernel.cl index bb4638c..ef73dbb 100644 --- a/kernels/ray_caster_kernel.cl +++ b/kernels/ray_caster_kernel.cl @@ -1,4 +1,12 @@ +float DistanceBetweenPoints(float3 a, float3 b) { + return sqrt(pow(a.x - b.x, 2) + pow(a.y - b.y, 2) + pow(a.z - b.z, 2)); +} + +float Distance(float3 a) { + return sqrt(pow(a.x, 2) + pow(a.y, 2) + pow(a.z, 2)); +} + // Naive incident ray light float4 white_light(float4 input, float3 light, int3 mask) { @@ -22,17 +30,19 @@ float4 white_light(float4 input, float3 light, int3 mask) { float4 view_light(float4 in_color, float3 light, float4 light_color, float3 view, int3 mask) { + float d = Distance(light) / 100.0f; + d *= d; + float diffuse = max(dot(normalize(convert_float3(mask)), normalize(light)), 0.0f); - in_color += diffuse * 0.2f * light_color; //(float4)(1.0f, 1.0f, 0.0f, 1.0f); + in_color += diffuse * light_color * 0.5f / d; if (dot(light, normalize(convert_float3(mask))) > 0.0f) { float3 halfwayVector = normalize(normalize(light) + normalize(view)); float specTmp = max(dot(normalize(convert_float3(mask)), halfwayVector), 0.0f); - in_color += pow(specTmp, 1.0f) * 0.5f * light_color;//(float4)(1.0f, 1.0f, 0.0f, 0.0f); + in_color += pow(specTmp, 8.0f) * light_color * 0.5f / d; } - //in_color += 0.02; return in_color; } @@ -46,9 +56,7 @@ int rand(int* seed) // 1 <= *seed < m return(*seed); } -float DistanceBetweenPoints(float3 a, float3 b) { - return sqrt(pow(a.x - b.x, 2) + pow(a.y - b.y, 2) + pow(a.z - b.z, 2)); -} + // =================================== Boolean ray intersection ============================ // ========================================================================================= @@ -230,6 +238,8 @@ __kernel void raycaster( // If we hit a voxel int index = voxel.x + (*map_dim).x * (voxel.y + (*map_dim).z * (voxel.z)); int voxel_data = map[index]; + if (all(voxel == convert_int3((float3)(lights[4], lights[5], lights[6]-3)))) + voxel_data = 1; if (voxel_data != 0) { @@ -307,16 +317,16 @@ __kernel void raycaster( // just a plain color for the voxel color if (voxel_data == 6) { - voxel_color = (float4)(0.0f, 0.239f, 0.419f, 0.3f); + voxel_color = (float4)(0.0f, 0.239f, 0.419f, 0.0f); } else if (voxel_data == 5) { float2 tile_size = convert_float2(*atlas_dim / *tile_dim); voxel_color = read_imagef(texture_atlas, convert_int2(tile_face_position * tile_size) + convert_int2((float2)(3, 0) * tile_size)); - voxel_color.w = 0.3f; + voxel_color.w = 0.0f; //voxel_color = (float4)(0.25, 0.52, 0.30, 0.1); } else if (voxel_data == 1) { - voxel_color = (float4)(0.929f, 0.957f, 0.027f, 0.3f); + voxel_color = (float4)(0.929f, 0.957f, 0.027f, 0.0f); } //else { // voxel_color = (float4)(1.0f, 0.0f, 0.0f, 0.0f); diff --git a/src/main.cpp b/src/main.cpp index a963f65..07b6635 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -179,6 +179,7 @@ int main() { fps_counter fps; float light_color[4] = { 0, 0, 0, 0 }; + float light_pos[4] = { 100, 100, 30 }; while (window.isOpen()) { @@ -263,6 +264,10 @@ int main() { handle->set_rgbi(light); } + if (ImGui::SliderFloat4("Position", light_pos, 0, MAP_X)) { + sf::Vector3f light(light_pos[0], light_pos[1], light_pos[2]); + handle->set_position(light); + } ImGui::End();