Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add "enable_fxaa" in rendering.global.json to enable/disable fxaa pass #218

Merged
merged 5 commits into from
Jun 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions engine/asset/global/rendering.global.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"enable_fxaa": false,
"skybox_irradiance_map": {
"negative_x_map": "asset/texture/sky/skybox_irradiance_X-.hdr",
"positive_x_map": "asset/texture/sky/skybox_irradiance_X+.hdr",
Expand Down
40 changes: 30 additions & 10 deletions engine/source/runtime/function/render/passes/main_camera_pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ namespace Pilot
{
RenderPass::initialize(nullptr);

const MainCameraPassInitInfo* _init_info = static_cast<const MainCameraPassInitInfo*>(init_info);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

local variable naming should be const MainCameraPassInitInfo* init_info

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the init_info has been used in const RenderPassInitInfo* init_info as the parameter of initialize function. i referenced the initialize function of ColorGradingPass which used this naming style.

m_enable_fxaa = _init_info->enble_fxaa;

setupAttachments();
setupRenderPass();
setupDescriptorSetLayout();
Expand Down Expand Up @@ -323,8 +326,16 @@ namespace Pilot
color_grading_pass_input_attachment_reference.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;

VkAttachmentReference color_grading_pass_color_attachment_reference {};
color_grading_pass_color_attachment_reference.attachment =
&post_process_odd_color_attachment_description - attachments;
if (m_enable_fxaa)
{
color_grading_pass_color_attachment_reference.attachment =
&post_process_odd_color_attachment_description - attachments;
}
else
{
color_grading_pass_color_attachment_reference.attachment =
&backup_odd_color_attachment_description - attachments;
}
color_grading_pass_color_attachment_reference.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;

VkSubpassDescription& color_grading_pass = subpasses[_main_camera_subpass_color_grading];
Expand All @@ -338,11 +349,20 @@ namespace Pilot
color_grading_pass.pPreserveAttachments = NULL;

VkAttachmentReference fxaa_pass_input_attachment_reference {};
fxaa_pass_input_attachment_reference.attachment = &post_process_odd_color_attachment_description - attachments;
if (m_enable_fxaa)
{
fxaa_pass_input_attachment_reference.attachment =
&post_process_odd_color_attachment_description - attachments;
}
else
{
fxaa_pass_input_attachment_reference.attachment =
&backup_even_color_attachment_description - attachments;
}
fxaa_pass_input_attachment_reference.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;

VkAttachmentReference fxaa_pass_color_attachment_reference {};
fxaa_pass_color_attachment_reference.attachment = &backup_even_color_attachment_description - attachments;
fxaa_pass_color_attachment_reference.attachment = &backup_odd_color_attachment_description - attachments;
fxaa_pass_color_attachment_reference.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;

VkSubpassDescription& fxaa_pass = subpasses[_main_camera_subpass_fxaa];
Expand All @@ -356,10 +376,10 @@ namespace Pilot
fxaa_pass.pPreserveAttachments = NULL;

VkAttachmentReference ui_pass_color_attachment_reference {};
ui_pass_color_attachment_reference.attachment = &backup_odd_color_attachment_description - attachments;
ui_pass_color_attachment_reference.attachment = &backup_even_color_attachment_description - attachments;
ui_pass_color_attachment_reference.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;

uint32_t ui_pass_preserve_attachment = &backup_even_color_attachment_description - attachments;
uint32_t ui_pass_preserve_attachment = &backup_odd_color_attachment_description - attachments;

VkSubpassDescription& ui_pass = subpasses[_main_camera_subpass_ui];
ui_pass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
Expand All @@ -373,10 +393,10 @@ namespace Pilot

VkAttachmentReference combine_ui_pass_input_attachments_reference[2] = {};
combine_ui_pass_input_attachments_reference[0].attachment =
&backup_even_color_attachment_description - attachments;
&backup_odd_color_attachment_description - attachments;
combine_ui_pass_input_attachments_reference[0].layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
combine_ui_pass_input_attachments_reference[1].attachment =
&backup_odd_color_attachment_description - attachments;
&backup_even_color_attachment_description - attachments;
combine_ui_pass_input_attachments_reference[1].layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;

VkAttachmentReference combine_ui_pass_color_attachment_reference {};
Expand Down Expand Up @@ -2262,7 +2282,7 @@ namespace Pilot

m_vulkan_rhi->m_vk_cmd_next_subpass(m_vulkan_rhi->m_current_command_buffer, VK_SUBPASS_CONTENTS_INLINE);

fxaa_pass.draw();
if (m_enable_fxaa) fxaa_pass.draw();

m_vulkan_rhi->m_vk_cmd_next_subpass(m_vulkan_rhi->m_current_command_buffer, VK_SUBPASS_CONTENTS_INLINE);

Expand Down Expand Up @@ -2357,7 +2377,7 @@ namespace Pilot

m_vulkan_rhi->m_vk_cmd_next_subpass(m_vulkan_rhi->m_current_command_buffer, VK_SUBPASS_CONTENTS_INLINE);

fxaa_pass.draw();
if (m_enable_fxaa) fxaa_pass.draw();

m_vulkan_rhi->m_vk_cmd_next_subpass(m_vulkan_rhi->m_current_command_buffer, VK_SUBPASS_CONTENTS_INLINE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ namespace Pilot
{
class RenderResourceBase;

struct MainCameraPassInitInfo : RenderPassInitInfo
{
bool enble_fxaa;
};

class MainCameraPass : public RenderPass
{
public:
Expand Down Expand Up @@ -71,6 +76,7 @@ namespace Pilot
VkImageView m_directional_light_shadow_color_image_view;

bool m_is_show_axis {false};
bool m_enable_fxaa {false};
size_t m_selected_axis {3};
MeshPerframeStorageBufferObject m_mesh_perframe_storage_buffer_object;
AxisStorageBufferObject m_axis_storage_buffer_object;
Expand Down
12 changes: 7 additions & 5 deletions engine/source/runtime/function/render/render_pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ namespace Pilot
main_camera_pass->m_directional_light_shadow_color_image_view =
std::static_pointer_cast<RenderPass>(m_directional_light_pass)->m_framebuffer.attachments[0].view;

m_main_camera_pass->initialize(nullptr);
MainCameraPassInitInfo main_camera_init_info;
main_camera_init_info.enble_fxaa = init_info.enable_fxaa;
m_main_camera_pass->initialize(&main_camera_init_info);

std::vector<VkDescriptorSetLayout> descriptor_layouts = _main_camera_pass->getDescriptorSetLayouts();
std::static_pointer_cast<PointLightShadowPass>(m_point_light_shadow_pass)
Expand Down Expand Up @@ -81,9 +83,9 @@ namespace Pilot
CombineUIPassInitInfo combine_ui_init_info;
combine_ui_init_info.render_pass = _main_camera_pass->getRenderPass();
combine_ui_init_info.scene_input_attachment =
_main_camera_pass->getFramebufferImageViews()[_main_camera_pass_backup_buffer_even];
combine_ui_init_info.ui_input_attachment =
_main_camera_pass->getFramebufferImageViews()[_main_camera_pass_backup_buffer_odd];
combine_ui_init_info.ui_input_attachment =
_main_camera_pass->getFramebufferImageViews()[_main_camera_pass_backup_buffer_even];
m_combine_ui_pass->initialize(&combine_ui_init_info);

PickPassInitInfo pick_init_info;
Expand Down Expand Up @@ -192,8 +194,8 @@ namespace Pilot
fxaa_pass.updateAfterFramebufferRecreate(
main_camera_pass.getFramebufferImageViews()[_main_camera_pass_post_process_buffer_odd]);
combine_ui_pass.updateAfterFramebufferRecreate(
main_camera_pass.getFramebufferImageViews()[_main_camera_pass_backup_buffer_even],
main_camera_pass.getFramebufferImageViews()[_main_camera_pass_backup_buffer_odd]);
main_camera_pass.getFramebufferImageViews()[_main_camera_pass_backup_buffer_odd],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why change the order?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the _main_camera_pass_backup_buffer_odd VkImageView is used as the scene_input_attachment now no matter enable or disable FXAA pass. and the _main_camera_pass_backup_buffer_even is used as the ui_input_attachment. it doesn't make any difference if not changed the order. for easy understanding, i think the parameter should follow the definition void CombineUIPass::updateAfterFramebufferRecreate(VkImageView scene_input_attachment, VkImageView ui_input_attachment).

main_camera_pass.getFramebufferImageViews()[_main_camera_pass_backup_buffer_even]);
pick_pass.recreateFramebuffer();
}
uint32_t RenderPipeline::getGuidOfPickedMesh(const Vector2& picked_uv)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace Pilot

struct RenderPipelineInitInfo
{
bool enable_fxaa {false};
std::shared_ptr<RenderResourceBase> render_resource;
};

Expand Down
1 change: 1 addition & 0 deletions engine/source/runtime/function/render/render_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ namespace Pilot

// initialize render pipeline
RenderPipelineInitInfo pipeline_init_info;
pipeline_init_info.enable_fxaa = global_rendering_res.m_enable_fxaa;
pipeline_init_info.render_resource = m_render_resource;

m_render_pipeline = std::make_shared<RenderPipeline>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ namespace Pilot
REFLECTION_BODY(GlobalRenderingRes);

public:
bool m_enable_fxaa {false};
SkyBoxIrradianceMap m_skybox_irradiance_map;
SkyBoxSpecularMap m_skybox_specular_map;
std::string m_brdf_map;
Expand Down