Prepare a new framebuffer and attachments for offscreen rendering (G-Buffer)
| 588 | |
| 589 | // Prepare a new framebuffer and attachments for offscreen rendering (G-Buffer) |
| 590 | void HPPHDR::prepare_offscreen_buffer() |
| 591 | { |
| 592 | // We need to select a format that supports the color attachment blending flag, so we iterate over multiple formats to find one that supports this flag |
| 593 | const std::vector<vk::Format> float_format_priority_list = { |
| 594 | vk::Format::eR32G32B32A32Sfloat, |
| 595 | vk::Format::eR16G16B16A16Sfloat // Guaranteed blend support for this |
| 596 | }; |
| 597 | |
| 598 | vk::Format color_format = vkb::common::choose_blendable_format(get_device().get_gpu().get_handle(), float_format_priority_list); |
| 599 | |
| 600 | { |
| 601 | offscreen.extent = extent; |
| 602 | |
| 603 | // Color attachments |
| 604 | |
| 605 | // We are using two 128-Bit RGBA floating point color buffers for this sample |
| 606 | // In a performance or bandwidth-limited scenario you should consider using a format with lower precision |
| 607 | offscreen.color[0] = create_attachment(color_format, vk::ImageUsageFlagBits::eColorAttachment); |
| 608 | offscreen.color[1] = create_attachment(color_format, vk::ImageUsageFlagBits::eColorAttachment); |
| 609 | // Depth attachment |
| 610 | offscreen.depth = create_attachment(depth_format, vk::ImageUsageFlagBits::eDepthStencilAttachment); |
| 611 | |
| 612 | offscreen.render_pass = create_offscreen_render_pass(); |
| 613 | |
| 614 | offscreen.framebuffer = vkb::common::create_framebuffer( |
| 615 | get_device().get_handle(), offscreen.render_pass, {offscreen.color[0].view, offscreen.color[1].view, offscreen.depth.view}, offscreen.extent); |
| 616 | |
| 617 | // Create sampler to sample from the color attachments |
| 618 | offscreen.sampler = vkb::common::create_sampler(get_device().get_gpu().get_handle(), get_device().get_handle(), color_format, |
| 619 | vk::Filter::eNearest, vk::SamplerAddressMode::eClampToEdge, 1.0f, 1.0f); |
| 620 | } |
| 621 | |
| 622 | // Bloom separable filter pass |
| 623 | { |
| 624 | filter_pass.extent = extent; |
| 625 | |
| 626 | // Color attachments |
| 627 | |
| 628 | // Floating point color attachment |
| 629 | filter_pass.color = create_attachment(color_format, vk::ImageUsageFlagBits::eColorAttachment); |
| 630 | filter_pass.render_pass = create_filter_render_pass(); |
| 631 | filter_pass.framebuffer = vkb::common::create_framebuffer(get_device().get_handle(), filter_pass.render_pass, {filter_pass.color.view}, filter_pass.extent); |
| 632 | filter_pass.sampler = vkb::common::create_sampler(get_device().get_gpu().get_handle(), get_device().get_handle(), |
| 633 | color_format, vk::Filter::eNearest, vk::SamplerAddressMode::eClampToEdge, 1.0f, 1.0f); |
| 634 | } |
| 635 | } |
| 636 | |
| 637 | // Prepare and initialize uniform buffer containing shader uniforms |
| 638 | void HPPHDR::prepare_uniform_buffers() |
nothing calls this directly
no test coverage detected