| 722 | } |
| 723 | |
| 724 | void AsyncComputeSample::update(float delta_time) |
| 725 | { |
| 726 | // don't call the parent's update, because it's done differently here... but call the grandparent's update for fps logging |
| 727 | vkb::Application::update(delta_time); |
| 728 | |
| 729 | if (last_async_enabled != async_enabled) |
| 730 | { |
| 731 | setup_queues(); |
| 732 | } |
| 733 | |
| 734 | // We can potentially get more overlap if we double buffer the HDR render target. |
| 735 | // In this scenario, the next frame can run ahead a little further before it needs to block. |
| 736 | if (double_buffer_hdr_frames) |
| 737 | { |
| 738 | forward_render_target_index = 1 - forward_render_target_index; |
| 739 | } |
| 740 | else |
| 741 | { |
| 742 | forward_render_target_index = 0; |
| 743 | } |
| 744 | |
| 745 | auto *forward_subpass = static_cast<ShadowMapForwardSubpass *>(forward_render_pipeline.get_subpasses()[0].get()); |
| 746 | auto *composite_subpass = static_cast<CompositeSubpass *>(get_render_pipeline().get_subpasses()[0].get()); |
| 747 | |
| 748 | forward_subpass->set_shadow_map(&shadow_render_target->get_views()[0], comparison_sampler.get()); |
| 749 | |
| 750 | composite_subpass->set_texture(&get_current_forward_render_target().get_views()[0], blur_chain_views[1].get(), linear_sampler.get()); // blur_chain[1] and color_targets[0] will be used by the present queue |
| 751 | |
| 752 | elapsed_time += delta_time; |
| 753 | float rotation_factor = elapsed_time; |
| 754 | |
| 755 | glm::quat orientation; |
| 756 | |
| 757 | // Lots of random jank to get a desired orientation quaternion for the directional light. |
| 758 | if (rotate_shadows) |
| 759 | { |
| 760 | // Move shadows and directional light slightly. |
| 761 | orientation = glm::normalize( |
| 762 | glm::angleAxis(glm::pi<float>(), glm::vec3(0.0f, -1.0f, 0.0f)) * |
| 763 | glm::angleAxis(-0.2f * glm::half_pi<float>(), glm::vec3(1.0f, 0.0f, 0.0f)) * |
| 764 | glm::angleAxis(glm::two_pi<float>() * glm::fract(rotation_factor * 0.05f), glm::vec3(0.0f, 0.0f, -1.0f)) * |
| 765 | glm::angleAxis(-0.05f * glm::half_pi<float>(), glm::vec3(1.0f, 0.0f, 0.0f))); |
| 766 | } |
| 767 | else |
| 768 | { |
| 769 | orientation = glm::normalize( |
| 770 | glm::angleAxis(glm::pi<float>(), glm::vec3(0.0f, -1.0f, 0.0f)) * |
| 771 | glm::angleAxis(-0.2f * glm::half_pi<float>(), glm::vec3(1.0f, 0.0f, 0.0f))); |
| 772 | } |
| 773 | |
| 774 | auto &shadow_camera_transform = shadow_camera->get_node()->get_component<vkb::sg::Transform>(); |
| 775 | shadow_camera_transform.set_rotation(orientation); |
| 776 | |
| 777 | // Explicit begin_frame and end_frame since we're doing async compute, many submissions and custom semaphores ... |
| 778 | get_render_context().begin_frame(); |
| 779 | |
| 780 | update_scene(delta_time); |
| 781 | update_gui(delta_time); |
no test coverage detected