#version 450 layout(location = 0) in vec2 fragRasterPos; layout(location = 1) flat in uint fragVolumeStart; layout(location = 2) in vec3 origPosition; layout(location = 3) flat in uint facing; layout(location = 4) flat in uvec2 minRasterPos; layout(location = 5) flat in uvec2 maxRasterPos; layout(location = 0) out vec4 outColor; #include rt_lib.frag void main() { vec3 clamped_pos = clamp_to_volume(fragVolumeStart, origPosition); vec2 clamped_raster_pos = clamp_to_quad(fragRasterPos, minRasterPos, maxRasterPos); uvec4 color_roughness = sample_color_from_scene_info(fragVolumeStart, clamped_raster_pos, facing); vec3 orig_color_sample = vec3(float(color_roughness.x) / 255.0, float(color_roughness.y) / 255.0, float(color_roughness.z) / 255.0); vec3 color_sum; uint orig_neighbor = sample_neighbor_from_scene_info(fragVolumeStart, clamped_raster_pos, facing); if (orig_neighbor != 0) { vec3 color_direct = diffuse_tracing(fragVolumeStart, color_roughness, clamped_pos, facing); Tracing t = trace_ray(fragVolumeStart, ubo.camera_pos, clamped_pos - ubo.camera_pos, pos_infinity, false); float opacity = float(color_roughness.w) / 255.0; vec3 color_seen_through; if (t.has_hit) { //color_seen_through = vec3(float(t.end_color.x) / 255.0, float(t.end_color.y) / 255.0, float(t.end_color.z) / 255.0); color_seen_through = diffuse_tracing(t.end_volume, t.end_color, t.end_pos, t.end_facing) * orig_color_sample * t.color_mul; color_seen_through = add_reflection(t.end_direction, t.end_facing, t.end_volume, t.end_pos, t.end_color, color_seen_through); } else { // Todo: hit sky box color_seen_through = vec3(0.0, 0.0, 0.0); } color_direct = add_reflection(normalize(clamped_pos - ubo.camera_pos), facing, fragVolumeStart, clamped_pos, color_roughness, color_direct); color_sum = opacity * color_direct + (1.0 - opacity) * color_seen_through; //color_sum = color_seen_through; } else { color_sum = diffuse_tracing(fragVolumeStart, color_roughness, clamped_pos, facing); color_sum = add_reflection(normalize(clamped_pos - ubo.camera_pos), facing, fragVolumeStart, clamped_pos, color_roughness, color_sum); } outColor = vec4(color_sum, 1.0); }