#version 450 layout(location = 0) flat in uvec2 fragRasterPos; layout(location = 1) flat in uint fragVolumeStart; layout(location = 2) in vec3 origPosition; layout(location = 3) flat in uint facing; layout(location = 0) out vec4 outColor; layout(binding = 2) buffer SceneInfoBuffer{ uint infos[]; } scene_info; uvec4 unpack_color(uint val) { // left most 8 bits first uint val1 = (val >> 24); uint val2 = (val << 8) >> 24; uint val3 = (val << 16) >> 24; uint val4 = (val << 24) >> 24; return uvec4(val4, val3, val2, val1); } uint sample_neighbor_from_scene_info(uint volume_start, uvec2 raster_pos, uint f) { uint array_descr_start = volume_start + 6 + scene_info.infos[0]; uint color_array_start = array_descr_start + 24; uint top_color_size_u = scene_info.infos[array_descr_start]; uint top_color_size_v = scene_info.infos[array_descr_start + 1]; uint bottom_color_size_u = scene_info.infos[array_descr_start + 2]; uint bottom_color_size_v = scene_info.infos[array_descr_start + 3]; uint left_color_size_u = scene_info.infos[array_descr_start + 4]; uint left_color_size_v = scene_info.infos[array_descr_start + 5]; uint right_color_size_u = scene_info.infos[array_descr_start + 6]; uint right_color_size_v = scene_info.infos[array_descr_start + 7]; uint front_color_size_u = scene_info.infos[array_descr_start + 8]; uint front_color_size_v = scene_info.infos[array_descr_start + 9]; uint back_color_size_u = scene_info.infos[array_descr_start + 10]; uint back_color_size_v = scene_info.infos[array_descr_start + 11]; uint top_neighbor_size_u = scene_info.infos[array_descr_start + 12]; uint top_neighbor_size_v = scene_info.infos[array_descr_start + 13]; uint bottom_neighbor_size_u = scene_info.infos[array_descr_start + 14]; uint bottom_neighbor_size_v = scene_info.infos[array_descr_start + 15]; uint left_neighbor_size_u = scene_info.infos[array_descr_start + 16]; uint left_neighbor_size_v = scene_info.infos[array_descr_start + 17]; uint right_neighbor_size_u = scene_info.infos[array_descr_start + 18]; uint right_neighbor_size_v = scene_info.infos[array_descr_start + 19]; uint front_neighbor_size_u = scene_info.infos[array_descr_start + 20]; uint front_neighbor_size_v = scene_info.infos[array_descr_start + 21]; uint back_neighbor_size_u = scene_info.infos[array_descr_start + 22]; uint back_neighbor_size_v = scene_info.infos[array_descr_start + 23]; uint top_color_size = top_color_size_u * top_color_size_v; uint bottom_color_size = bottom_color_size_u * bottom_color_size_v; uint left_color_size = left_color_size_u * left_color_size_v; uint right_color_size = right_color_size_u * right_color_size_v; uint front_color_size = front_color_size_u * front_color_size_v; uint back_color_size = back_color_size_u * back_color_size_v; uint color_array_end = color_array_start + top_color_size + bottom_color_size + left_color_size + right_color_size + front_color_size + back_color_size; uint top_neighbor_size = top_neighbor_size_u * top_neighbor_size_v; uint bottom_neighbor_size = bottom_neighbor_size_u * bottom_neighbor_size_v; uint left_neighbor_size = left_neighbor_size_u * left_neighbor_size_v; uint right_neighbor_size = right_neighbor_size_u * right_neighbor_size_v; uint front_neighbor_size = front_neighbor_size_u * front_neighbor_size_v; uint back_neighbor_size = back_neighbor_size_u * back_neighbor_size_v; // maybe do an array solution for this as well uint array_start = color_array_end + uint(f > 0) * top_neighbor_size + uint(f > 1) * bottom_neighbor_size + uint(f > 2) * left_neighbor_size + uint(f > 3) * right_neighbor_size + uint(f > 4) * front_neighbor_size; uint us[6] = {top_neighbor_size_u, bottom_neighbor_size_u, left_neighbor_size_u, right_neighbor_size_u, front_neighbor_size_u, back_neighbor_size_u}; uint vs[6] = {top_neighbor_size_v, bottom_neighbor_size_v, left_neighbor_size_v, right_neighbor_size_v, front_neighbor_size_v, back_neighbor_size_v}; uint u_size = us[f]; uint v_size = vs[f]; uint value = scene_info.infos[array_start + raster_pos.x * v_size * uint(u_size > 1) + raster_pos.y * uint(v_size > 1)]; return value; } uvec4 sample_color_from_scene_info(uint volume_start, uvec2 raster_pos, uint f) { uint array_descr_start = volume_start + 6 + scene_info.infos[0]; uint color_array_start = array_descr_start + 24; uint top_color_size_u = scene_info.infos[array_descr_start]; uint top_color_size_v = scene_info.infos[array_descr_start + 1]; uint bottom_color_size_u = scene_info.infos[array_descr_start + 2]; uint bottom_color_size_v = scene_info.infos[array_descr_start + 3]; uint left_color_size_u = scene_info.infos[array_descr_start + 4]; uint left_color_size_v = scene_info.infos[array_descr_start + 5]; uint right_color_size_u = scene_info.infos[array_descr_start + 6]; uint right_color_size_v = scene_info.infos[array_descr_start + 7]; uint front_color_size_u = scene_info.infos[array_descr_start + 8]; uint front_color_size_v = scene_info.infos[array_descr_start + 9]; uint back_color_size_u = scene_info.infos[array_descr_start + 10]; uint back_color_size_v = scene_info.infos[array_descr_start + 11]; uint top_neighbor_size_u = scene_info.infos[array_descr_start + 12]; uint top_neighbor_size_v = scene_info.infos[array_descr_start + 13]; uint top_size = top_color_size_u * top_color_size_v; uint bottom_size = bottom_color_size_u * bottom_color_size_v; uint left_size = left_color_size_u * left_color_size_v; uint right_size = right_color_size_u * right_color_size_v; uint front_size = front_color_size_u * front_color_size_v; uint back_size = back_color_size_u * back_color_size_v; // maybe do an array solution for this as well uint array_start = color_array_start + uint(f > 0) * top_size + uint(f > 1) * bottom_size + uint(f > 2) * left_size + uint(f > 3) * right_size + uint(f > 4) * front_size; uint us[6] = {top_color_size_u, bottom_color_size_u, left_color_size_u, right_color_size_u, front_color_size_u, back_color_size_u}; uint vs[6] = {top_color_size_v, bottom_color_size_v, left_color_size_v, right_color_size_v, front_color_size_v, back_color_size_v}; uint u_size = us[f]; uint v_size = vs[f]; uint value = scene_info.infos[array_start + raster_pos.x * v_size * uint(u_size > 1) + raster_pos.y * uint(v_size > 1)]; return unpack_color(value); } vec3 get_light_position(uint light_index) { return vec3(float(scene_info.infos[light_index]), float(scene_info.infos[light_index + 1]), float(scene_info.infos[light_index + 2])); } vec4 get_light_color(uint light_index) { return vec4(float(scene_info.infos[light_index + 3]) / 255.0, float(scene_info.infos[light_index + 4]) / 255.0, float(scene_info.infos[light_index + 5]) / 255.0, 1.0); } void main() { uint max_length = scene_info.infos[0]; uint last = scene_info.infos[max_length]; uvec4 color_roughness = sample_color_from_scene_info(fragVolumeStart, fragRasterPos, facing); vec4 color_sample = vec4(float(color_roughness.x) / 255.0, float(color_roughness.y) / 255.0, float(color_roughness.z) / 255.0, 1); uint max_light_num = scene_info.infos[0]; uint light_num = 0; uint volume_index = fragVolumeStart; uint light_index = scene_info.infos[fragVolumeStart + 3]; vec3 light_direction = get_light_position(light_index) - origPosition; vec4 light_color = get_light_color(light_index); bool x_pos = light_direction.x > 0.0; bool x_null = light_direction.x == 0.0; bool y_pos = light_direction.y > 0.0; bool y_null = light_direction.y == 0.0; bool z_pos = light_direction.z > 0.0; bool z_null = light_direction.z == 0.0; uint max_iterations = max_light_num * 20; for (int i = 0; i < max_iterations; i++) { float x_border = float(scene_info.infos[volume_index + 0] + scene_info.infos[volume_index + 3] * uint(x_pos)); float y_border = float(scene_info.infos[volume_index + 1] + scene_info.infos[volume_index + 4] * uint(y_pos)); float z_border = float(scene_info.infos[volume_index + 2] + scene_info.infos[volume_index + 5] * uint(z_pos)); // 2 is way behind the light position and should result in no collision being detected float x_factor = 2.0; float y_factor = 2.0; float z_factor = 2.0; if (!x_null) { x_factor = (x_border - origPosition.x) / light_direction.x; } if (!y_null) { float y_factor = (y_border - origPosition.y) / light_direction.y; } if (!z_null) { float z_factor = (z_border - origPosition.z) / light_direction.z; } } outColor = color_sample; /*if (scene_info.infos[1] == 16) { outColor = vec4(0, 1, 0, 1); }*/ /*if (fragVolumeStart == 1 && scene_info.infos[fragVolumeStart] == 16) { outColor = vec4(0, 1, 0, 1); }*/ /*if (facing == 0) { outColor = vec4(1, 0, 0, 1); } else if (facing == 1) { outColor = vec4(0, 1, 1, 1); } else if (facing == 2) { outColor = vec4(0, 1, 0, 1); } else if (facing == 3) { outColor = vec4(1, 0, 1, 1); } else if (facing == 4) { outColor = vec4(0, 0, 1, 1); } else if (facing == 5) { outColor = vec4(1, 1, 0, 1); }*/ }