diff options
26 files changed, 250 insertions, 77 deletions
diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml index fa7fad9e40..e8e8ca3725 100644 --- a/doc/classes/ProjectSettings.xml +++ b/doc/classes/ProjectSettings.xml @@ -1639,8 +1639,11 @@ </member> <member name="rendering/2d/snap/snap_2d_vertices_to_pixel" type="bool" setter="" getter="" default="false"> </member> - <member name="rendering/anti_aliasing/quality/msaa" type="int" setter="" getter="" default="0"> - Sets the number of MSAA samples to use (as a power of two). MSAA is used to reduce aliasing around the edges of polygons. A higher MSAA value results in smoother edges but can be significantly slower on some hardware. See also bilinear scaling 3d [member rendering/scaling_3d/mode] for supersampling, which provides higher quality but is much more expensive. + <member name="rendering/anti_aliasing/quality/msaa_2d" type="int" setter="" getter="" default="0"> + Sets the number of MSAA samples to use for 2D/Canvas rendering (as a power of two). MSAA is used to reduce aliasing around the edges of polygons. A higher MSAA value results in smoother edges but can be significantly slower on some hardware. This has no effect on shader-induced aliasing or texture aliasing. + </member> + <member name="rendering/anti_aliasing/quality/msaa_3d" type="int" setter="" getter="" default="0"> + Sets the number of MSAA samples to use for 3D rendering (as a power of two). MSAA is used to reduce aliasing around the edges of polygons. A higher MSAA value results in smoother edges but can be significantly slower on some hardware. See also bilinear scaling 3d [member rendering/scaling_3d/mode] for supersampling, which provides higher quality but is much more expensive. This has no effect on shader-induced aliasing or texture aliasing. </member> <member name="rendering/anti_aliasing/quality/screen_space_aa" type="int" setter="" getter="" default="0"> Sets the screen-space antialiasing mode for the default screen [Viewport]. Screen-space antialiasing works by selectively blurring edges in a post-process shader. It differs from MSAA which takes multiple coverage samples while rendering objects. Screen-space AA methods are typically faster than MSAA and will smooth out specular aliasing, but tend to make scenes appear blurry. The blurriness is partially counteracted by automatically using a negative mipmap LOD bias (see [member rendering/textures/default_filters/texture_mipmap_bias]). @@ -1874,7 +1877,7 @@ Sets the scaling 3D mode. Bilinear scaling renders at different resolution to either undersample or supersample the viewport. FidelityFX Super Resolution 1.0, abbreviated to FSR, is an upscaling technology that produces high quality images at fast framerates by using a spatially aware upscaling algorithm. FSR is slightly more expensive than bilinear, but it produces significantly higher image quality. FSR should be used where possible. </member> <member name="rendering/scaling_3d/scale" type="float" setter="" getter="" default="1.0"> - Scales the 3D render buffer based on the viewport size uses an image filter specified in [member rendering/scaling_3d/mode] to scale the output image to the full viewport size. Values lower than [code]1.0[/code] can be used to speed up 3D rendering at the cost of quality (undersampling). Values greater than [code]1.0[/code] are only valid for bilinear mode and can be used to improve 3D rendering quality at a high performance cost (supersampling). See also [member rendering/anti_aliasing/quality/msaa] for multi-sample antialiasing, which is significantly cheaper but only smoothens the edges of polygons. + Scales the 3D render buffer based on the viewport size uses an image filter specified in [member rendering/scaling_3d/mode] to scale the output image to the full viewport size. Values lower than [code]1.0[/code] can be used to speed up 3D rendering at the cost of quality (undersampling). Values greater than [code]1.0[/code] are only valid for bilinear mode and can be used to improve 3D rendering quality at a high performance cost (supersampling). See also [member rendering/anti_aliasing/quality/msaa_3d] for multi-sample antialiasing, which is significantly cheaper but only smooths the edges of polygons. </member> <member name="rendering/shader_compiler/shader_cache/compress" type="bool" setter="" getter="" default="true"> </member> diff --git a/doc/classes/RenderingServer.xml b/doc/classes/RenderingServer.xml index 639db6b3b5..755e8a5839 100644 --- a/doc/classes/RenderingServer.xml +++ b/doc/classes/RenderingServer.xml @@ -3208,12 +3208,20 @@ <description> </description> </method> - <method name="viewport_set_msaa"> + <method name="viewport_set_msaa_2d"> <return type="void" /> <param index="0" name="viewport" type="RID" /> <param index="1" name="msaa" type="int" enum="RenderingServer.ViewportMSAA" /> <description> - Sets the anti-aliasing mode. See [enum ViewportMSAA] for options. + Sets the multisample anti-aliasing mode for 2D/Canvas. See [enum ViewportMSAA] for options. + </description> + </method> + <method name="viewport_set_msaa_3d"> + <return type="void" /> + <param index="0" name="viewport" type="RID" /> + <param index="1" name="msaa" type="int" enum="RenderingServer.ViewportMSAA" /> + <description> + Sets the multisample anti-aliasing mode for 3D. See [enum ViewportMSAA] for options. </description> </method> <method name="viewport_set_occlusion_culling_build_quality"> diff --git a/doc/classes/Viewport.xml b/doc/classes/Viewport.xml index 0071834ccd..87ee26fa32 100644 --- a/doc/classes/Viewport.xml +++ b/doc/classes/Viewport.xml @@ -218,8 +218,11 @@ To control this property on the root viewport, set the [member ProjectSettings.rendering/mesh_lod/lod_change/threshold_pixels] project setting. [b]Note:[/b] [member mesh_lod_threshold] does not affect [GeometryInstance3D] visibility ranges (also known as "manual" LOD or hierarchical LOD). </member> - <member name="msaa" type="int" setter="set_msaa" getter="get_msaa" enum="Viewport.MSAA" default="0"> - The multisample anti-aliasing mode. A higher number results in smoother edges at the cost of significantly worse performance. A value of 2 or 4 is best unless targeting very high-end systems. See also bilinear scaling 3d [member scaling_3d_mode] for supersampling, which provides higher quality but is much more expensive. + <member name="msaa_2d" type="int" setter="set_msaa_2d" getter="get_msaa_2d" enum="Viewport.MSAA" default="0"> + The multisample anti-aliasing mode for 2D/Canvas rendering. A higher number results in smoother edges at the cost of significantly worse performance. A value of 2 or 4 is best unless targeting very high-end systems. This has no effect on shader-induced aliasing or texture aliasing. + </member> + <member name="msaa_3d" type="int" setter="set_msaa_3d" getter="get_msaa_3d" enum="Viewport.MSAA" default="0"> + The multisample anti-aliasing mode for 3D rendering. A higher number results in smoother edges at the cost of significantly worse performance. A value of 2 or 4 is best unless targeting very high-end systems. See also bilinear scaling 3d [member scaling_3d_mode] for supersampling, which provides higher quality but is much more expensive. This has no effect on shader-induced aliasing or texture aliasing. </member> <member name="own_world_3d" type="bool" setter="set_use_own_world_3d" getter="is_using_own_world_3d" default="false"> If [code]true[/code], the viewport will use a unique copy of the [World3D] defined in [member world_3d]. @@ -250,7 +253,7 @@ To control this property on the root viewport, set the [member ProjectSettings.rendering/scaling_3d/mode] project setting. </member> <member name="scaling_3d_scale" type="float" setter="set_scaling_3d_scale" getter="get_scaling_3d_scale" default="1.0"> - Scales the 3D render buffer based on the viewport size uses an image filter specified in [member ProjectSettings.rendering/scaling_3d/mode] to scale the output image to the full viewport size. Values lower than [code]1.0[/code] can be used to speed up 3D rendering at the cost of quality (undersampling). Values greater than [code]1.0[/code] are only valid for bilinear mode and can be used to improve 3D rendering quality at a high performance cost (supersampling). See also [member ProjectSettings.rendering/anti_aliasing/quality/msaa] for multi-sample antialiasing, which is significantly cheaper but only smoothens the edges of polygons. + Scales the 3D render buffer based on the viewport size uses an image filter specified in [member ProjectSettings.rendering/scaling_3d/mode] to scale the output image to the full viewport size. Values lower than [code]1.0[/code] can be used to speed up 3D rendering at the cost of quality (undersampling). Values greater than [code]1.0[/code] are only valid for bilinear mode and can be used to improve 3D rendering quality at a high performance cost (supersampling). See also [member ProjectSettings.rendering/anti_aliasing/quality/msaa_3d] for multi-sample antialiasing, which is significantly cheaper but only smooths the edges of polygons. When using FSR upscaling, AMD recommends exposing the following values as preset options to users "Ultra Quality: 0.77", "Quality: 0.67", "Balanced: 0.59", "Performance: 0.5" instead of exposing the entire scale. To control this property on the root viewport, set the [member ProjectSettings.rendering/scaling_3d/scale] project setting. </member> diff --git a/drivers/gles3/storage/texture_storage.cpp b/drivers/gles3/storage/texture_storage.cpp index 543638e8ff..b8ab4d6839 100644 --- a/drivers/gles3/storage/texture_storage.cpp +++ b/drivers/gles3/storage/texture_storage.cpp @@ -1564,6 +1564,19 @@ void TextureStorage::render_target_clear_used(RID p_render_target) { rt->used_in_frame = false; } +void TextureStorage::render_target_set_msaa(RID p_render_target, RS::ViewportMSAA p_msaa) { + RenderTarget *rt = render_target_owner.get_or_null(p_render_target); + ERR_FAIL_COND(!rt); + if (p_msaa == rt->msaa) { + return; + } + + WARN_PRINT("2D MSAA is not yet supported for GLES3."); + _clear_render_target(rt); + rt->msaa = p_msaa; + _update_render_target(rt); +} + void TextureStorage::render_target_request_clear(RID p_render_target, const Color &p_clear_color) { RenderTarget *rt = render_target_owner.get_or_null(p_render_target); ERR_FAIL_COND(!rt); diff --git a/drivers/gles3/storage/texture_storage.h b/drivers/gles3/storage/texture_storage.h index 71f713bc9f..4f4032723b 100644 --- a/drivers/gles3/storage/texture_storage.h +++ b/drivers/gles3/storage/texture_storage.h @@ -528,6 +528,7 @@ public: virtual void render_target_set_direct_to_screen(RID p_render_target, bool p_direct_to_screen) override; virtual bool render_target_was_used(RID p_render_target) override; void render_target_clear_used(RID p_render_target); + virtual void render_target_set_msaa(RID p_render_target, RS::ViewportMSAA p_msaa) override; // new void render_target_set_as_unused(RID p_render_target) override { diff --git a/drivers/vulkan/rendering_device_vulkan.cpp b/drivers/vulkan/rendering_device_vulkan.cpp index f2d78636d7..6a88f2c442 100644 --- a/drivers/vulkan/rendering_device_vulkan.cpp +++ b/drivers/vulkan/rendering_device_vulkan.cpp @@ -1733,7 +1733,7 @@ RID RenderingDeviceVulkan::texture_create(const TextureFormat &p_format, const T ERR_FAIL_INDEX_V(p_format.samples, TEXTURE_SAMPLES_MAX, RID()); - image_create_info.samples = rasterization_sample_count[p_format.samples]; + image_create_info.samples = _ensure_supported_sample_count(p_format.samples); image_create_info.tiling = (p_format.usage_bits & TEXTURE_USAGE_CPU_READ_BIT) ? VK_IMAGE_TILING_LINEAR : VK_IMAGE_TILING_OPTIMAL; // Usage. @@ -1884,6 +1884,7 @@ RID RenderingDeviceVulkan::texture_create(const TextureFormat &p_format, const T texture.mipmaps = image_create_info.mipLevels; texture.base_mipmap = 0; texture.base_layer = 0; + texture.is_resolve_buffer = p_format.is_resolve_buffer; texture.usage_flags = p_format.usage_bits; texture.samples = p_format.samples; texture.allowed_shared_formats = p_format.shareable_formats; @@ -3425,7 +3426,7 @@ VkRenderPass RenderingDeviceVulkan::_render_pass_create(const Vector<AttachmentF description.pNext = nullptr; description.flags = 0; description.format = vulkan_formats[p_attachments[i].format]; - description.samples = rasterization_sample_count[p_attachments[i].samples]; + description.samples = _ensure_supported_sample_count(p_attachments[i].samples); bool is_sampled = p_attachments[i].usage_flags & TEXTURE_USAGE_SAMPLING_BIT; bool is_storage = p_attachments[i].usage_flags & TEXTURE_USAGE_STORAGE_BIT; @@ -3546,7 +3547,8 @@ VkRenderPass RenderingDeviceVulkan::_render_pass_create(const Vector<AttachmentF break; } } - } else { + } + if (!used_last) { for (int j = 0; j < p_passes[last_pass].color_attachments.size(); j++) { if (p_passes[last_pass].color_attachments[j] == i) { used_last = true; @@ -4116,7 +4118,11 @@ RID RenderingDeviceVulkan::framebuffer_create(const Vector<RID> &p_texture_attac } else if (texture && texture->usage_flags & TEXTURE_USAGE_VRS_ATTACHMENT_BIT) { pass.vrs_attachment = i; } else { - pass.color_attachments.push_back(texture ? i : FramebufferPass::ATTACHMENT_UNUSED); + if (texture && texture->is_resolve_buffer) { + pass.resolve_attachments.push_back(i); + } else { + pass.color_attachments.push_back(texture ? i : FramebufferPass::ATTACHMENT_UNUSED); + } } } @@ -6567,7 +6573,7 @@ RID RenderingDeviceVulkan::render_pipeline_create(RID p_shader, FramebufferForma multisample_state_create_info.pNext = nullptr; multisample_state_create_info.flags = 0; - multisample_state_create_info.rasterizationSamples = rasterization_sample_count[p_multisample_state.sample_count]; + multisample_state_create_info.rasterizationSamples = _ensure_supported_sample_count(p_multisample_state.sample_count); multisample_state_create_info.sampleShadingEnable = p_multisample_state.enable_sample_shading; multisample_state_create_info.minSampleShading = p_multisample_state.min_sample_shading; Vector<VkSampleMask> sample_mask; @@ -7353,7 +7359,9 @@ RenderingDevice::DrawListID RenderingDeviceVulkan::draw_list_begin(RID p_framebu // If it is the first we're likely populating our VRS texture. // Bit dirty but... if (!texture || (!(texture->usage_flags & TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) && !(i != 0 && texture->usage_flags & TEXTURE_USAGE_VRS_ATTACHMENT_BIT))) { - color_count++; + if (!texture || !texture->is_resolve_buffer) { + color_count++; + } } } ERR_FAIL_COND_V_MSG(p_clear_color_values.size() != color_count, INVALID_ID, "Clear color values supplied (" + itos(p_clear_color_values.size()) + ") differ from the amount required for framebuffer color attachments (" + itos(color_count) + ")."); @@ -8993,6 +9001,25 @@ void RenderingDeviceVulkan::_begin_frame() { frames[frame].index = Engine::get_singleton()->get_frames_drawn(); } +VkSampleCountFlagBits RenderingDeviceVulkan::_ensure_supported_sample_count(TextureSamples p_requested_sample_count) const { + VkSampleCountFlags sample_count_flags = limits.framebufferColorSampleCounts & limits.framebufferDepthSampleCounts; + + if (sample_count_flags & rasterization_sample_count[p_requested_sample_count]) { + // The requested sample count is supported. + return rasterization_sample_count[p_requested_sample_count]; + } else { + // Find the closest lower supported sample count. + VkSampleCountFlagBits sample_count = rasterization_sample_count[p_requested_sample_count]; + while (sample_count > VK_SAMPLE_COUNT_1_BIT) { + if (sample_count_flags & rasterization_sample_count[sample_count]) { + return sample_count; + } + sample_count = (VkSampleCountFlagBits)(sample_count >> 1); + } + } + return VK_SAMPLE_COUNT_1_BIT; +} + void RenderingDeviceVulkan::swap_buffers() { ERR_FAIL_COND_MSG(local_device.is_valid(), "Local devices can't swap buffers."); _THREAD_SAFE_METHOD_ diff --git a/drivers/vulkan/rendering_device_vulkan.h b/drivers/vulkan/rendering_device_vulkan.h index 6007e1ab4d..abec1b0e1b 100644 --- a/drivers/vulkan/rendering_device_vulkan.h +++ b/drivers/vulkan/rendering_device_vulkan.h @@ -150,6 +150,8 @@ class RenderingDeviceVulkan : public RenderingDevice { bool used_in_raster = false; bool used_in_compute = false; + bool is_resolve_buffer = false; + uint32_t read_aspect_mask = 0; uint32_t barrier_aspect_mask = 0; bool bound = false; // Bound to framebffer. @@ -1042,6 +1044,8 @@ class RenderingDeviceVulkan : public RenderingDevice { HashMap<RID, String> resource_names; #endif + VkSampleCountFlagBits _ensure_supported_sample_count(TextureSamples p_requested_sample_count) const; + public: virtual RID texture_create(const TextureFormat &p_format, const TextureView &p_view, const Vector<Vector<uint8_t>> &p_data = Vector<Vector<uint8_t>>()); virtual RID texture_create_shared(const TextureView &p_view, RID p_with_texture); diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 7d4c376709..6b68c4127f 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -544,6 +544,9 @@ void EditorNode::_update_from_settings() { Viewport::SDFScale sdf_scale = Viewport::SDFScale(int(GLOBAL_GET("rendering/2d/sdf/scale"))); scene_root->set_sdf_scale(sdf_scale); + Viewport::MSAA msaa = Viewport::MSAA(int(GLOBAL_GET("rendering/anti_aliasing/quality/msaa_2d"))); + scene_root->set_msaa_2d(msaa); + float mesh_lod_threshold = GLOBAL_GET("rendering/mesh_lod/lod_change/threshold_pixels"); scene_root->set_mesh_lod_threshold(mesh_lod_threshold); diff --git a/editor/plugins/material_editor_plugin.cpp b/editor/plugins/material_editor_plugin.cpp index 74a6e90a6d..709f19016c 100644 --- a/editor/plugins/material_editor_plugin.cpp +++ b/editor/plugins/material_editor_plugin.cpp @@ -153,7 +153,7 @@ MaterialEditor::MaterialEditor() { vc->add_child(viewport); viewport->set_disable_input(true); viewport->set_transparent_background(true); - viewport->set_msaa(Viewport::MSAA_4X); + viewport->set_msaa_3d(Viewport::MSAA_4X); camera = memnew(Camera3D); camera->set_transform(Transform3D(Basis(), Vector3(0, 0, 3))); diff --git a/editor/plugins/mesh_editor_plugin.cpp b/editor/plugins/mesh_editor_plugin.cpp index 980d2974a0..90d50d30d9 100644 --- a/editor/plugins/mesh_editor_plugin.cpp +++ b/editor/plugins/mesh_editor_plugin.cpp @@ -112,7 +112,7 @@ MeshEditor::MeshEditor() { viewport->set_world_3d(world_3d); //use own world add_child(viewport); viewport->set_disable_input(true); - viewport->set_msaa(Viewport::MSAA_4X); + viewport->set_msaa_3d(Viewport::MSAA_4X); set_stretch(true); camera = memnew(Camera3D); camera->set_transform(Transform3D(Basis(), Vector3(0, 0, 1.1))); diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp index 7c39549e11..b771faeb33 100644 --- a/editor/plugins/node_3d_editor_plugin.cpp +++ b/editor/plugins/node_3d_editor_plugin.cpp @@ -2393,8 +2393,8 @@ void Node3DEditorViewport::_project_settings_changed() { // Update MSAA, screen-space AA and debanding if changed - const int msaa_mode = ProjectSettings::get_singleton()->get("rendering/anti_aliasing/quality/msaa"); - viewport->set_msaa(Viewport::MSAA(msaa_mode)); + const int msaa_mode = ProjectSettings::get_singleton()->get("rendering/anti_aliasing/quality/msaa_3d"); + viewport->set_msaa_3d(Viewport::MSAA(msaa_mode)); const int ssaa_mode = GLOBAL_GET("rendering/anti_aliasing/quality/screen_space_aa"); viewport->set_screen_space_aa(Viewport::ScreenSpaceAA(ssaa_mode)); const bool use_taa = GLOBAL_GET("rendering/anti_aliasing/quality/use_taa"); diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index e91e2f5c92..ec98ff36a0 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -1418,9 +1418,13 @@ SceneTree::SceneTree() { root->set_as_audio_listener_2d(true); current_scene = nullptr; - const int msaa_mode = GLOBAL_DEF_BASIC("rendering/anti_aliasing/quality/msaa", 0); - ProjectSettings::get_singleton()->set_custom_property_info("rendering/anti_aliasing/quality/msaa", PropertyInfo(Variant::INT, "rendering/anti_aliasing/quality/msaa", PROPERTY_HINT_ENUM, String::utf8("Disabled (Fastest),2× (Average),4× (Slow),8× (Slowest)"))); - root->set_msaa(Viewport::MSAA(msaa_mode)); + const int msaa_mode_2d = GLOBAL_DEF_BASIC("rendering/anti_aliasing/quality/msaa_2d", 0); + ProjectSettings::get_singleton()->set_custom_property_info("rendering/anti_aliasing/quality/msaa_2d", PropertyInfo(Variant::INT, "rendering/anti_aliasing/quality/msaa_2d", PROPERTY_HINT_ENUM, String::utf8("Disabled (Fastest),2× (Average),4× (Slow),8× (Slowest)"))); + root->set_msaa_2d(Viewport::MSAA(msaa_mode_2d)); + + const int msaa_mode_3d = GLOBAL_DEF_BASIC("rendering/anti_aliasing/quality/msaa_3d", 0); + ProjectSettings::get_singleton()->set_custom_property_info("rendering/anti_aliasing/quality/msaa_3d", PropertyInfo(Variant::INT, "rendering/anti_aliasing/quality/msaa_3d", PROPERTY_HINT_ENUM, String::utf8("Disabled (Fastest),2× (Average),4× (Slow),8× (Slowest)"))); + root->set_msaa_3d(Viewport::MSAA(msaa_mode_3d)); const int ssaa_mode = GLOBAL_DEF_BASIC("rendering/anti_aliasing/quality/screen_space_aa", 0); ProjectSettings::get_singleton()->set_custom_property_info("rendering/anti_aliasing/quality/screen_space_aa", PropertyInfo(Variant::INT, "rendering/anti_aliasing/quality/screen_space_aa", PROPERTY_HINT_ENUM, "Disabled (Fastest),FXAA (Fast)")); diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 5d0c6c61ee..a738c6eabc 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -2873,17 +2873,30 @@ Control *Viewport::gui_get_focus_owner() { return gui.key_focus; } -void Viewport::set_msaa(MSAA p_msaa) { +void Viewport::set_msaa_2d(MSAA p_msaa) { ERR_FAIL_INDEX(p_msaa, MSAA_MAX); - if (msaa == p_msaa) { + if (msaa_2d == p_msaa) { return; } - msaa = p_msaa; - RS::get_singleton()->viewport_set_msaa(viewport, RS::ViewportMSAA(p_msaa)); + msaa_2d = p_msaa; + RS::get_singleton()->viewport_set_msaa_2d(viewport, RS::ViewportMSAA(p_msaa)); } -Viewport::MSAA Viewport::get_msaa() const { - return msaa; +Viewport::MSAA Viewport::get_msaa_2d() const { + return msaa_2d; +} + +void Viewport::set_msaa_3d(MSAA p_msaa) { + ERR_FAIL_INDEX(p_msaa, MSAA_MAX); + if (msaa_3d == p_msaa) { + return; + } + msaa_3d = p_msaa; + RS::get_singleton()->viewport_set_msaa_3d(viewport, RS::ViewportMSAA(p_msaa)); +} + +Viewport::MSAA Viewport::get_msaa_3d() const { + return msaa_3d; } void Viewport::set_screen_space_aa(ScreenSpaceAA p_screen_space_aa) { @@ -3675,8 +3688,11 @@ void Viewport::_bind_methods() { ClassDB::bind_method(D_METHOD("set_transparent_background", "enable"), &Viewport::set_transparent_background); ClassDB::bind_method(D_METHOD("has_transparent_background"), &Viewport::has_transparent_background); - ClassDB::bind_method(D_METHOD("set_msaa", "msaa"), &Viewport::set_msaa); - ClassDB::bind_method(D_METHOD("get_msaa"), &Viewport::get_msaa); + ClassDB::bind_method(D_METHOD("set_msaa_2d", "msaa"), &Viewport::set_msaa_2d); + ClassDB::bind_method(D_METHOD("get_msaa_2d"), &Viewport::get_msaa_2d); + + ClassDB::bind_method(D_METHOD("set_msaa_3d", "msaa"), &Viewport::set_msaa_3d); + ClassDB::bind_method(D_METHOD("get_msaa_3d"), &Viewport::get_msaa_3d); ClassDB::bind_method(D_METHOD("set_screen_space_aa", "screen_space_aa"), &Viewport::set_screen_space_aa); ClassDB::bind_method(D_METHOD("get_screen_space_aa"), &Viewport::get_screen_space_aa); @@ -3816,7 +3832,8 @@ void Viewport::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "snap_2d_transforms_to_pixel"), "set_snap_2d_transforms_to_pixel", "is_snap_2d_transforms_to_pixel_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "snap_2d_vertices_to_pixel"), "set_snap_2d_vertices_to_pixel", "is_snap_2d_vertices_to_pixel_enabled"); ADD_GROUP("Rendering", ""); - ADD_PROPERTY(PropertyInfo(Variant::INT, "msaa", PROPERTY_HINT_ENUM, String::utf8("Disabled (Fastest),2× (Average),4× (Slow),8× (Slowest)")), "set_msaa", "get_msaa"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "msaa_2d", PROPERTY_HINT_ENUM, String::utf8("Disabled (Fastest),2× (Average),4× (Slow),8× (Slowest)")), "set_msaa_2d", "get_msaa_2d"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "msaa_3d", PROPERTY_HINT_ENUM, String::utf8("Disabled (Fastest),2× (Average),4× (Slow),8× (Slowest)")), "set_msaa_3d", "get_msaa_3d"); ADD_PROPERTY(PropertyInfo(Variant::INT, "screen_space_aa", PROPERTY_HINT_ENUM, "Disabled (Fastest),FXAA (Fast)"), "set_screen_space_aa", "get_screen_space_aa"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_taa"), "set_use_taa", "is_using_taa"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_debanding"), "set_use_debanding", "is_using_debanding"); diff --git a/scene/main/viewport.h b/scene/main/viewport.h index 83083cd65a..0b3853ba79 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -297,7 +297,8 @@ private: bool positional_shadow_atlas_16_bits = true; PositionalShadowAtlasQuadrantSubdiv positional_shadow_atlas_quadrant_subdiv[4]; - MSAA msaa = MSAA_DISABLED; + MSAA msaa_2d = MSAA_DISABLED; + MSAA msaa_3d = MSAA_DISABLED; ScreenSpaceAA screen_space_aa = SCREEN_SPACE_AA_DISABLED; bool use_taa = false; @@ -522,8 +523,11 @@ public: void set_positional_shadow_atlas_quadrant_subdiv(int p_quadrant, PositionalShadowAtlasQuadrantSubdiv p_subdiv); PositionalShadowAtlasQuadrantSubdiv get_positional_shadow_atlas_quadrant_subdiv(int p_quadrant) const; - void set_msaa(MSAA p_msaa); - MSAA get_msaa() const; + void set_msaa_2d(MSAA p_msaa); + MSAA get_msaa_2d() const; + + void set_msaa_3d(MSAA p_msaa); + MSAA get_msaa_3d() const; void set_screen_space_aa(ScreenSpaceAA p_screen_space_aa); ScreenSpaceAA get_screen_space_aa() const; diff --git a/servers/rendering/dummy/storage/texture_storage.h b/servers/rendering/dummy/storage/texture_storage.h index 73b1284558..d4f832b5f8 100644 --- a/servers/rendering/dummy/storage/texture_storage.h +++ b/servers/rendering/dummy/storage/texture_storage.h @@ -159,6 +159,7 @@ public: virtual void render_target_set_direct_to_screen(RID p_render_target, bool p_direct_to_screen) override {} virtual bool render_target_was_used(RID p_render_target) override { return false; } virtual void render_target_set_as_unused(RID p_render_target) override {} + virtual void render_target_set_msaa(RID p_render_target, RS::ViewportMSAA p_msaa) override {} virtual void render_target_request_clear(RID p_render_target, const Color &p_clear_color) override {} virtual bool render_target_is_clear_requested(RID p_render_target) override { return false; } diff --git a/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp b/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp index 7adc36c57c..2d004baf48 100644 --- a/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp @@ -2484,7 +2484,7 @@ void RendererSceneRenderRD::render_buffers_configure(RID p_render_buffers, RID p rb->height = p_height; rb->fsr_sharpness = p_fsr_sharpness; rb->render_target = p_render_target; - rb->msaa = p_msaa; + rb->msaa_3d = p_msaa; rb->screen_space_aa = p_screen_space_aa; rb->use_taa = p_use_taa; rb->use_debanding = p_use_debanding; @@ -2509,7 +2509,7 @@ void RendererSceneRenderRD::render_buffers_configure(RID p_render_buffers, RID p tf.height = rb->internal_height; // If set to rb->width, msaa won't crash tf.array_layers = rb->view_count; // create a layer for every view tf.usage_bits = RD::TEXTURE_USAGE_SAMPLING_BIT | (_render_buffers_can_be_storage() ? RD::TEXTURE_USAGE_STORAGE_BIT : 0) | RD::TEXTURE_USAGE_COLOR_ATTACHMENT_BIT; - if (rb->msaa != RS::VIEWPORT_MSAA_DISABLED) { + if (rb->msaa_3d != RS::VIEWPORT_MSAA_DISABLED) { tf.usage_bits |= RD::TEXTURE_USAGE_CAN_COPY_TO_BIT; } tf.usage_bits |= RD::TEXTURE_USAGE_INPUT_ATTACHMENT_BIT; // only needed when using subpasses in the mobile renderer @@ -2532,7 +2532,7 @@ void RendererSceneRenderRD::render_buffers_configure(RID p_render_buffers, RID p if (rb->view_count > 1) { tf.texture_type = RD::TEXTURE_TYPE_2D_ARRAY; } - if (rb->msaa == RS::VIEWPORT_MSAA_DISABLED) { + if (rb->msaa_3d == RS::VIEWPORT_MSAA_DISABLED) { tf.format = RD::get_singleton()->texture_is_format_supported_for_usage(RD::DATA_FORMAT_D24_UNORM_S8_UINT, (RD::TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | RD::TEXTURE_USAGE_SAMPLING_BIT)) ? RD::DATA_FORMAT_D24_UNORM_S8_UINT : RD::DATA_FORMAT_D32_SFLOAT_S8_UINT; } else { tf.format = RD::DATA_FORMAT_R32_SFLOAT; @@ -2543,7 +2543,7 @@ void RendererSceneRenderRD::render_buffers_configure(RID p_render_buffers, RID p tf.usage_bits = RD::TEXTURE_USAGE_SAMPLING_BIT; tf.array_layers = rb->view_count; // create a layer for every view - if (rb->msaa != RS::VIEWPORT_MSAA_DISABLED) { + if (rb->msaa_3d != RS::VIEWPORT_MSAA_DISABLED) { tf.usage_bits |= RD::TEXTURE_USAGE_CAN_COPY_TO_BIT | RD::TEXTURE_USAGE_STORAGE_BIT; } else { tf.usage_bits |= RD::TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; diff --git a/servers/rendering/renderer_rd/renderer_scene_render_rd.h b/servers/rendering/renderer_rd/renderer_scene_render_rd.h index 22e9ead243..8e59b21aa8 100644 --- a/servers/rendering/renderer_rd/renderer_scene_render_rd.h +++ b/servers/rendering/renderer_rd/renderer_scene_render_rd.h @@ -456,7 +456,7 @@ private: int width = 0; int height = 0; float fsr_sharpness = 0.2f; - RS::ViewportMSAA msaa = RS::VIEWPORT_MSAA_DISABLED; + RS::ViewportMSAA msaa_3d = RS::VIEWPORT_MSAA_DISABLED; RS::ViewportScreenSpaceAA screen_space_aa = RS::VIEWPORT_SCREEN_SPACE_AA_DISABLED; bool use_taa = false; bool use_debanding = false; @@ -1167,23 +1167,51 @@ public: virtual void decals_set_filter(RS::DecalFilter p_filter) override; virtual void light_projectors_set_filter(RS::LightProjectorFilter p_filter) override; - _FORCE_INLINE_ RS::ShadowQuality shadows_quality_get() const { return shadows_quality; } - _FORCE_INLINE_ RS::ShadowQuality directional_shadow_quality_get() const { return directional_shadow_quality; } - _FORCE_INLINE_ float shadows_quality_radius_get() const { return shadows_quality_radius; } - _FORCE_INLINE_ float directional_shadow_quality_radius_get() const { return directional_shadow_quality_radius; } + _FORCE_INLINE_ RS::ShadowQuality shadows_quality_get() const { + return shadows_quality; + } + _FORCE_INLINE_ RS::ShadowQuality directional_shadow_quality_get() const { + return directional_shadow_quality; + } + _FORCE_INLINE_ float shadows_quality_radius_get() const { + return shadows_quality_radius; + } + _FORCE_INLINE_ float directional_shadow_quality_radius_get() const { + return directional_shadow_quality_radius; + } - _FORCE_INLINE_ float *directional_penumbra_shadow_kernel_get() { return directional_penumbra_shadow_kernel; } - _FORCE_INLINE_ float *directional_soft_shadow_kernel_get() { return directional_soft_shadow_kernel; } - _FORCE_INLINE_ float *penumbra_shadow_kernel_get() { return penumbra_shadow_kernel; } - _FORCE_INLINE_ float *soft_shadow_kernel_get() { return soft_shadow_kernel; } + _FORCE_INLINE_ float *directional_penumbra_shadow_kernel_get() { + return directional_penumbra_shadow_kernel; + } + _FORCE_INLINE_ float *directional_soft_shadow_kernel_get() { + return directional_soft_shadow_kernel; + } + _FORCE_INLINE_ float *penumbra_shadow_kernel_get() { + return penumbra_shadow_kernel; + } + _FORCE_INLINE_ float *soft_shadow_kernel_get() { + return soft_shadow_kernel; + } - _FORCE_INLINE_ int directional_penumbra_shadow_samples_get() const { return directional_penumbra_shadow_samples; } - _FORCE_INLINE_ int directional_soft_shadow_samples_get() const { return directional_soft_shadow_samples; } - _FORCE_INLINE_ int penumbra_shadow_samples_get() const { return penumbra_shadow_samples; } - _FORCE_INLINE_ int soft_shadow_samples_get() const { return soft_shadow_samples; } + _FORCE_INLINE_ int directional_penumbra_shadow_samples_get() const { + return directional_penumbra_shadow_samples; + } + _FORCE_INLINE_ int directional_soft_shadow_samples_get() const { + return directional_soft_shadow_samples; + } + _FORCE_INLINE_ int penumbra_shadow_samples_get() const { + return penumbra_shadow_samples; + } + _FORCE_INLINE_ int soft_shadow_samples_get() const { + return soft_shadow_samples; + } - _FORCE_INLINE_ RS::LightProjectorFilter light_projectors_get_filter() const { return light_projectors_filter; } - _FORCE_INLINE_ RS::DecalFilter decals_get_filter() const { return decals_filter; } + _FORCE_INLINE_ RS::LightProjectorFilter light_projectors_get_filter() const { + return light_projectors_filter; + } + _FORCE_INLINE_ RS::DecalFilter decals_get_filter() const { + return decals_filter; + } int get_roughness_layers() const; bool is_using_radiance_cubemap_array() const; diff --git a/servers/rendering/renderer_rd/storage_rd/texture_storage.cpp b/servers/rendering/renderer_rd/storage_rd/texture_storage.cpp index 84427e1c93..ce19187071 100644 --- a/servers/rendering/renderer_rd/storage_rd/texture_storage.cpp +++ b/servers/rendering/renderer_rd/storage_rd/texture_storage.cpp @@ -2121,6 +2121,10 @@ void TextureStorage::_clear_render_target(RenderTarget *rt) { RD::get_singleton()->free(rt->color); } + if (rt->color_multisample.is_valid()) { + RD::get_singleton()->free(rt->color_multisample); + } + if (rt->backbuffer.is_valid()) { RD::get_singleton()->free(rt->backbuffer); rt->backbuffer = RID(); @@ -2132,6 +2136,7 @@ void TextureStorage::_clear_render_target(RenderTarget *rt) { rt->framebuffer = RID(); rt->color = RID(); + rt->color_multisample = RID(); } void TextureStorage::_update_render_target(RenderTarget *rt) { @@ -2153,30 +2158,50 @@ void TextureStorage::_update_render_target(RenderTarget *rt) { rt->color_format_srgb = RD::DATA_FORMAT_R8G8B8A8_SRGB; rt->image_format = rt->is_transparent ? Image::FORMAT_RGBA8 : Image::FORMAT_RGB8; - RD::TextureFormat rd_format; + RD::TextureFormat rd_color_attachment_format; RD::TextureView rd_view; { //attempt register - rd_format.format = rt->color_format; - rd_format.width = rt->size.width; - rd_format.height = rt->size.height; - rd_format.depth = 1; - rd_format.array_layers = rt->view_count; // for stereo we create two (or more) layers, need to see if we can make fallback work like this too if we don't have multiview - rd_format.mipmaps = 1; - if (rd_format.array_layers > 1) { // why are we not using rt->texture_type ?? - rd_format.texture_type = RD::TEXTURE_TYPE_2D_ARRAY; + rd_color_attachment_format.format = rt->color_format; + rd_color_attachment_format.width = rt->size.width; + rd_color_attachment_format.height = rt->size.height; + rd_color_attachment_format.depth = 1; + rd_color_attachment_format.array_layers = rt->view_count; // for stereo we create two (or more) layers, need to see if we can make fallback work like this too if we don't have multiview + rd_color_attachment_format.mipmaps = 1; + if (rd_color_attachment_format.array_layers > 1) { // why are we not using rt->texture_type ?? + rd_color_attachment_format.texture_type = RD::TEXTURE_TYPE_2D_ARRAY; } else { - rd_format.texture_type = RD::TEXTURE_TYPE_2D; + rd_color_attachment_format.texture_type = RD::TEXTURE_TYPE_2D; + } + rd_color_attachment_format.samples = RD::TEXTURE_SAMPLES_1; + rd_color_attachment_format.usage_bits = RD::TEXTURE_USAGE_SAMPLING_BIT | RD::TEXTURE_USAGE_COLOR_ATTACHMENT_BIT | RD::TEXTURE_USAGE_CAN_COPY_FROM_BIT; + rd_color_attachment_format.shareable_formats.push_back(rt->color_format); + rd_color_attachment_format.shareable_formats.push_back(rt->color_format_srgb); + if (rt->msaa != RS::VIEWPORT_MSAA_DISABLED) { + rd_color_attachment_format.is_resolve_buffer = true; } - rd_format.samples = RD::TEXTURE_SAMPLES_1; - rd_format.usage_bits = RD::TEXTURE_USAGE_SAMPLING_BIT | RD::TEXTURE_USAGE_COLOR_ATTACHMENT_BIT | RD::TEXTURE_USAGE_CAN_COPY_FROM_BIT; - rd_format.shareable_formats.push_back(rt->color_format); - rd_format.shareable_formats.push_back(rt->color_format_srgb); } - rt->color = RD::get_singleton()->texture_create(rd_format, rd_view); + rt->color = RD::get_singleton()->texture_create(rd_color_attachment_format, rd_view); ERR_FAIL_COND(rt->color.is_null()); Vector<RID> fb_textures; + + if (rt->msaa != RS::VIEWPORT_MSAA_DISABLED) { + // Use the texture format of the color attachment for the multisample color attachment. + RD::TextureFormat rd_color_multisample_format = rd_color_attachment_format; + const RD::TextureSamples texture_samples[RS::VIEWPORT_MSAA_MAX] = { + RD::TEXTURE_SAMPLES_1, + RD::TEXTURE_SAMPLES_2, + RD::TEXTURE_SAMPLES_4, + RD::TEXTURE_SAMPLES_8, + }; + rd_color_multisample_format.samples = texture_samples[rt->msaa]; + RD::TextureView rd_view_multisample; + rd_color_multisample_format.is_resolve_buffer = false; + rt->color_multisample = RD::get_singleton()->texture_create(rd_color_multisample_format, rd_view_multisample); + fb_textures.push_back(rt->color_multisample); + ERR_FAIL_COND(rt->color_multisample.is_null()); + } fb_textures.push_back(rt->color); rt->framebuffer = RD::get_singleton()->framebuffer_create(fb_textures, RenderingDevice::INVALID_ID, rt->view_count); if (rt->framebuffer.is_null()) { @@ -2335,6 +2360,17 @@ void TextureStorage::render_target_set_as_unused(RID p_render_target) { rt->was_used = false; } +void TextureStorage::render_target_set_msaa(RID p_render_target, RS::ViewportMSAA p_msaa) { + RenderTarget *rt = render_target_owner.get_or_null(p_render_target); + ERR_FAIL_COND(!rt); + if (p_msaa == rt->msaa) { + return; + } + + rt->msaa = p_msaa; + _update_render_target(rt); +} + Size2 TextureStorage::render_target_get_size(RID p_render_target) { RenderTarget *rt = render_target_owner.get_or_null(p_render_target); ERR_FAIL_COND_V(!rt, Size2()); diff --git a/servers/rendering/renderer_rd/storage_rd/texture_storage.h b/servers/rendering/renderer_rd/storage_rd/texture_storage.h index 682c951f63..25d355d878 100644 --- a/servers/rendering/renderer_rd/storage_rd/texture_storage.h +++ b/servers/rendering/renderer_rd/storage_rd/texture_storage.h @@ -254,6 +254,9 @@ private: uint32_t view_count; RID framebuffer; RID color; + RID color_multisample; // Needed when MSAA is enabled. + + RS::ViewportMSAA msaa = RS::VIEWPORT_MSAA_DISABLED; //used for retrieving from CPU RD::DataFormat color_format = RD::DATA_FORMAT_R4G4_UNORM_PACK8; @@ -556,6 +559,7 @@ public: virtual void render_target_set_direct_to_screen(RID p_render_target, bool p_direct_to_screen) override; virtual bool render_target_was_used(RID p_render_target) override; virtual void render_target_set_as_unused(RID p_render_target) override; + virtual void render_target_set_msaa(RID p_render_target, RS::ViewportMSAA p_msaa) override; void render_target_copy_to_back_buffer(RID p_render_target, const Rect2i &p_region, bool p_gen_mipmaps); void render_target_clear_back_buffer(RID p_render_target, const Rect2i &p_region, const Color &p_color); diff --git a/servers/rendering/renderer_viewport.cpp b/servers/rendering/renderer_viewport.cpp index bfb81925bc..b6f515b223 100644 --- a/servers/rendering/renderer_viewport.cpp +++ b/servers/rendering/renderer_viewport.cpp @@ -177,7 +177,7 @@ void RendererViewport::_configure_3d_render_buffers(Viewport *p_viewport) { // to compensate for the loss of sharpness. const float texture_mipmap_bias = log2f(MIN(scaling_3d_scale, 1.0)) + p_viewport->texture_mipmap_bias; - RSG::scene->render_buffers_configure(p_viewport->render_buffers, p_viewport->render_target, render_width, render_height, width, height, p_viewport->fsr_sharpness, texture_mipmap_bias, p_viewport->msaa, p_viewport->screen_space_aa, p_viewport->use_taa, p_viewport->use_debanding, p_viewport->get_view_count()); + RSG::scene->render_buffers_configure(p_viewport->render_buffers, p_viewport->render_target, render_width, render_height, width, height, p_viewport->fsr_sharpness, texture_mipmap_bias, p_viewport->msaa_3d, p_viewport->screen_space_aa, p_viewport->use_taa, p_viewport->use_debanding, p_viewport->get_view_count()); } } } @@ -1076,14 +1076,25 @@ void RendererViewport::viewport_set_positional_shadow_atlas_quadrant_subdivision RSG::scene->shadow_atlas_set_quadrant_subdivision(viewport->shadow_atlas, p_quadrant, p_subdiv); } -void RendererViewport::viewport_set_msaa(RID p_viewport, RS::ViewportMSAA p_msaa) { +void RendererViewport::viewport_set_msaa_2d(RID p_viewport, RS::ViewportMSAA p_msaa) { Viewport *viewport = viewport_owner.get_or_null(p_viewport); ERR_FAIL_COND(!viewport); - if (viewport->msaa == p_msaa) { + if (viewport->msaa_2d == p_msaa) { return; } - viewport->msaa = p_msaa; + viewport->msaa_2d = p_msaa; + RSG::texture_storage->render_target_set_msaa(viewport->render_target, p_msaa); +} + +void RendererViewport::viewport_set_msaa_3d(RID p_viewport, RS::ViewportMSAA p_msaa) { + Viewport *viewport = viewport_owner.get_or_null(p_viewport); + ERR_FAIL_COND(!viewport); + + if (viewport->msaa_3d == p_msaa) { + return; + } + viewport->msaa_3d = p_msaa; _configure_3d_render_buffers(viewport); } diff --git a/servers/rendering/renderer_viewport.h b/servers/rendering/renderer_viewport.h index ab4893a908..f64b2a986f 100644 --- a/servers/rendering/renderer_viewport.h +++ b/servers/rendering/renderer_viewport.h @@ -66,7 +66,8 @@ public: RID render_target_texture; RID render_buffers; - RS::ViewportMSAA msaa = RenderingServer::VIEWPORT_MSAA_DISABLED; + RS::ViewportMSAA msaa_2d = RenderingServer::VIEWPORT_MSAA_DISABLED; + RS::ViewportMSAA msaa_3d = RenderingServer::VIEWPORT_MSAA_DISABLED; RS::ViewportScreenSpaceAA screen_space_aa = RenderingServer::VIEWPORT_SCREEN_SPACE_AA_DISABLED; bool use_taa = false; bool use_debanding = false; @@ -157,7 +158,6 @@ public: measure_render_time = false; debug_draw = RS::VIEWPORT_DEBUG_DRAW_DISABLED; - msaa = RS::VIEWPORT_MSAA_DISABLED; screen_space_aa = RS::VIEWPORT_SCREEN_SPACE_AA_DISABLED; use_debanding = false; use_occlusion_culling = false; @@ -250,7 +250,8 @@ public: void viewport_set_positional_shadow_atlas_size(RID p_viewport, int p_size, bool p_16_bits = true); void viewport_set_positional_shadow_atlas_quadrant_subdivision(RID p_viewport, int p_quadrant, int p_subdiv); - void viewport_set_msaa(RID p_viewport, RS::ViewportMSAA p_msaa); + void viewport_set_msaa_2d(RID p_viewport, RS::ViewportMSAA p_msaa); + void viewport_set_msaa_3d(RID p_viewport, RS::ViewportMSAA p_msaa); void viewport_set_screen_space_aa(RID p_viewport, RS::ViewportScreenSpaceAA p_mode); void viewport_set_use_taa(RID p_viewport, bool p_use_taa); void viewport_set_use_debanding(RID p_viewport, bool p_use_debanding); diff --git a/servers/rendering/rendering_device.h b/servers/rendering/rendering_device.h index 6dadcab383..276ba8f247 100644 --- a/servers/rendering/rendering_device.h +++ b/servers/rendering/rendering_device.h @@ -462,6 +462,7 @@ public: TextureSamples samples; uint32_t usage_bits; Vector<DataFormat> shareable_formats; + bool is_resolve_buffer = false; TextureFormat() { format = DATA_FORMAT_R8_UNORM; diff --git a/servers/rendering/rendering_server_default.h b/servers/rendering/rendering_server_default.h index 9b174d5879..ba70f02ca5 100644 --- a/servers/rendering/rendering_server_default.h +++ b/servers/rendering/rendering_server_default.h @@ -619,7 +619,8 @@ public: FUNC3(viewport_set_positional_shadow_atlas_size, RID, int, bool) FUNC3(viewport_set_sdf_oversize_and_scale, RID, ViewportSDFOversize, ViewportSDFScale) FUNC3(viewport_set_positional_shadow_atlas_quadrant_subdivision, RID, int, int) - FUNC2(viewport_set_msaa, RID, ViewportMSAA) + FUNC2(viewport_set_msaa_2d, RID, ViewportMSAA) + FUNC2(viewport_set_msaa_3d, RID, ViewportMSAA) FUNC2(viewport_set_screen_space_aa, RID, ViewportScreenSpaceAA) FUNC2(viewport_set_use_taa, RID, bool) FUNC2(viewport_set_use_debanding, RID, bool) diff --git a/servers/rendering/storage/texture_storage.h b/servers/rendering/storage/texture_storage.h index 982ab4a958..08ff88d4a5 100644 --- a/servers/rendering/storage/texture_storage.h +++ b/servers/rendering/storage/texture_storage.h @@ -133,6 +133,7 @@ public: virtual void render_target_set_direct_to_screen(RID p_render_target, bool p_direct_to_screen) = 0; virtual bool render_target_was_used(RID p_render_target) = 0; virtual void render_target_set_as_unused(RID p_render_target) = 0; + virtual void render_target_set_msaa(RID p_render_target, RS::ViewportMSAA p_msaa) = 0; virtual void render_target_request_clear(RID p_render_target, const Color &p_clear_color) = 0; virtual bool render_target_is_clear_requested(RID p_render_target) = 0; diff --git a/servers/rendering_server.cpp b/servers/rendering_server.cpp index 30b6faa360..3e850a9798 100644 --- a/servers/rendering_server.cpp +++ b/servers/rendering_server.cpp @@ -2204,7 +2204,8 @@ void RenderingServer::_bind_methods() { ClassDB::bind_method(D_METHOD("viewport_set_positional_shadow_atlas_size", "viewport", "size", "use_16_bits"), &RenderingServer::viewport_set_positional_shadow_atlas_size, DEFVAL(false)); ClassDB::bind_method(D_METHOD("viewport_set_positional_shadow_atlas_quadrant_subdivision", "viewport", "quadrant", "subdivision"), &RenderingServer::viewport_set_positional_shadow_atlas_quadrant_subdivision); - ClassDB::bind_method(D_METHOD("viewport_set_msaa", "viewport", "msaa"), &RenderingServer::viewport_set_msaa); + ClassDB::bind_method(D_METHOD("viewport_set_msaa_3d", "viewport", "msaa"), &RenderingServer::viewport_set_msaa_3d); + ClassDB::bind_method(D_METHOD("viewport_set_msaa_2d", "viewport", "msaa"), &RenderingServer::viewport_set_msaa_2d); ClassDB::bind_method(D_METHOD("viewport_set_screen_space_aa", "viewport", "mode"), &RenderingServer::viewport_set_screen_space_aa); ClassDB::bind_method(D_METHOD("viewport_set_use_taa", "viewport", "enable"), &RenderingServer::viewport_set_use_taa); ClassDB::bind_method(D_METHOD("viewport_set_use_debanding", "viewport", "enable"), &RenderingServer::viewport_set_use_debanding); diff --git a/servers/rendering_server.h b/servers/rendering_server.h index 56295a2c5f..efa8a24325 100644 --- a/servers/rendering_server.h +++ b/servers/rendering_server.h @@ -874,7 +874,8 @@ public: VIEWPORT_MSAA_MAX, }; - virtual void viewport_set_msaa(RID p_viewport, ViewportMSAA p_msaa) = 0; + virtual void viewport_set_msaa_3d(RID p_viewport, ViewportMSAA p_msaa) = 0; + virtual void viewport_set_msaa_2d(RID p_viewport, ViewportMSAA p_msaa) = 0; enum ViewportScreenSpaceAA { VIEWPORT_SCREEN_SPACE_AA_DISABLED, |