From d3037351ac52cc79995d7fd9398ab9c5bd37bd2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bu=C4=9Fra=20Altun?= Date: Thu, 14 Nov 2024 13:50:48 +0300 Subject: [PATCH 01/15] Added Nearest headers and added functionality --- scene/main/viewport.cpp | 1 + scene/main/viewport.h | 1 + servers/rendering/renderer_viewport.cpp | 10 +++++++++- servers/rendering_server.h | 1 + 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 4a808c40817..60395732766 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -4874,6 +4874,7 @@ void Viewport::_bind_methods() { BIND_ENUM_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_MAX); BIND_ENUM_CONSTANT(SCALING_3D_MODE_BILINEAR); + BIND_ENUM_CONSTANT(SCALING_3D_MODE_NEAREST); BIND_ENUM_CONSTANT(SCALING_3D_MODE_FSR); BIND_ENUM_CONSTANT(SCALING_3D_MODE_FSR2); BIND_ENUM_CONSTANT(SCALING_3D_MODE_MAX); diff --git a/scene/main/viewport.h b/scene/main/viewport.h index 31fbefe8419..6dfced9acb6 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -100,6 +100,7 @@ class Viewport : public Node { public: enum Scaling3DMode { SCALING_3D_MODE_BILINEAR, + SCALING_3D_MODE_NEAREST, SCALING_3D_MODE_FSR, SCALING_3D_MODE_FSR2, SCALING_3D_MODE_MAX diff --git a/servers/rendering/renderer_viewport.cpp b/servers/rendering/renderer_viewport.cpp index adb0757a63e..1e5f8ceb380 100644 --- a/servers/rendering/renderer_viewport.cpp +++ b/servers/rendering/renderer_viewport.cpp @@ -180,6 +180,14 @@ void RendererViewport::_configure_3d_render_buffers(Viewport *p_viewport) { render_width = CLAMP(target_width * scaling_3d_scale, 1, 16384); render_height = CLAMP(target_height * scaling_3d_scale, 1, 16384); break; + case RS::VIEWPORT_SCALING_3D_MODE_NEAREST: + target_width = p_viewport->size.width; + target_height = p_viewport->size.height; + render_width = int(target_width * scaling_3d_scale); + render_height = int(target_height * scaling_3d_scale); + + RSG::texture_storage->set_filter_mode(p_viewport->render_target, RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST); + break; case RS::VIEWPORT_SCALING_3D_MODE_FSR: case RS::VIEWPORT_SCALING_3D_MODE_FSR2: target_width = p_viewport->size.width; @@ -1582,4 +1590,4 @@ int RendererViewport::get_num_viewports_with_motion_vectors() const { RendererViewport::RendererViewport() { occlusion_rays_per_thread = GLOBAL_GET("rendering/occlusion_culling/occlusion_rays_per_thread"); -} +} \ No newline at end of file diff --git a/servers/rendering_server.h b/servers/rendering_server.h index 9e72c3c2e1d..fdf1a8bbcac 100644 --- a/servers/rendering_server.h +++ b/servers/rendering_server.h @@ -903,6 +903,7 @@ class RenderingServer : public Object { enum ViewportScaling3DMode { VIEWPORT_SCALING_3D_MODE_BILINEAR, + VIEWPORT_SCALING_3D_MODE_NEAREST, VIEWPORT_SCALING_3D_MODE_FSR, VIEWPORT_SCALING_3D_MODE_FSR2, VIEWPORT_SCALING_3D_MODE_MAX, From 9b7a86efe45bc08d300e28c9111f2f1d608a97b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bu=C4=9Fra=20Altun?= Date: Thu, 14 Nov 2024 14:03:37 +0300 Subject: [PATCH 02/15] fix? --- servers/rendering/renderer_viewport.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/servers/rendering/renderer_viewport.cpp b/servers/rendering/renderer_viewport.cpp index 1e5f8ceb380..261fafa19d3 100644 --- a/servers/rendering/renderer_viewport.cpp +++ b/servers/rendering/renderer_viewport.cpp @@ -185,7 +185,6 @@ void RendererViewport::_configure_3d_render_buffers(Viewport *p_viewport) { target_height = p_viewport->size.height; render_width = int(target_width * scaling_3d_scale); render_height = int(target_height * scaling_3d_scale); - RSG::texture_storage->set_filter_mode(p_viewport->render_target, RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST); break; case RS::VIEWPORT_SCALING_3D_MODE_FSR: From 22e032209c8674a9705f32bedfa437ed7ed1d4cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bu=C4=9Fra=20Altun?= Date: Thu, 14 Nov 2024 14:05:44 +0300 Subject: [PATCH 03/15] fix?? --- servers/rendering/renderer_viewport.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/servers/rendering/renderer_viewport.cpp b/servers/rendering/renderer_viewport.cpp index 261fafa19d3..0189933793b 100644 --- a/servers/rendering/renderer_viewport.cpp +++ b/servers/rendering/renderer_viewport.cpp @@ -1589,4 +1589,4 @@ int RendererViewport::get_num_viewports_with_motion_vectors() const { RendererViewport::RendererViewport() { occlusion_rays_per_thread = GLOBAL_GET("rendering/occlusion_culling/occlusion_rays_per_thread"); -} \ No newline at end of file +} From 8efa7d2a4b00c6a6e07a64a51570ad4c74afa916 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bu=C4=9Fra=20Altun?= Date: Thu, 14 Nov 2024 14:16:53 +0300 Subject: [PATCH 04/15] another fix lol --- servers/rendering/renderer_viewport.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/servers/rendering/renderer_viewport.cpp b/servers/rendering/renderer_viewport.cpp index 0189933793b..7aee58d1bae 100644 --- a/servers/rendering/renderer_viewport.cpp +++ b/servers/rendering/renderer_viewport.cpp @@ -185,7 +185,6 @@ void RendererViewport::_configure_3d_render_buffers(Viewport *p_viewport) { target_height = p_viewport->size.height; render_width = int(target_width * scaling_3d_scale); render_height = int(target_height * scaling_3d_scale); - RSG::texture_storage->set_filter_mode(p_viewport->render_target, RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST); break; case RS::VIEWPORT_SCALING_3D_MODE_FSR: case RS::VIEWPORT_SCALING_3D_MODE_FSR2: From 4c26c51a0f6b6727bc39114039a5d1cda5e3c85b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bu=C4=9Fra=20Altun?= Date: Thu, 14 Nov 2024 15:03:23 +0300 Subject: [PATCH 05/15] add to doc --- doc/classes/RenderingServer.xml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/doc/classes/RenderingServer.xml b/doc/classes/RenderingServer.xml index 318a54e74bd..0f9c7d47d30 100644 --- a/doc/classes/RenderingServer.xml +++ b/doc/classes/RenderingServer.xml @@ -4903,13 +4903,16 @@ Use bilinear scaling for the viewport's 3D buffer. The amount of scaling can be set using [member Viewport.scaling_3d_scale]. Values less than [code]1.0[/code] will result in undersampling while values greater than [code]1.0[/code] will result in supersampling. A value of [code]1.0[/code] disables scaling. - + + Use nearest neighbor scaling for the viewport's 3D buffer. The amount of scaling can be set using [member Viewport.scaling_3d_scale]. Values less than [code]1.0[/code] will result in undersampling, while values greater than [code]1.0[/code] will result in supersampling. A value of [code]1.0[/code] disables scaling and applies the closest pixel without interpolation. + + Use AMD FidelityFX Super Resolution 1.0 upscaling for the viewport's 3D buffer. The amount of scaling can be set using [member Viewport.scaling_3d_scale]. Values less than [code]1.0[/code] will be result in the viewport being upscaled using FSR. Values greater than [code]1.0[/code] are not supported and bilinear downsampling will be used instead. A value of [code]1.0[/code] disables scaling. - + Use AMD FidelityFX Super Resolution 2.2 upscaling for the viewport's 3D buffer. The amount of scaling can be set using [member Viewport.scaling_3d_scale]. Values less than [code]1.0[/code] will be result in the viewport being upscaled using FSR2. Values greater than [code]1.0[/code] are not supported and bilinear downsampling will be used instead. A value of [code]1.0[/code] will use FSR2 at native resolution as a TAA solution. - + Represents the size of the [enum ViewportScaling3DMode] enum. From 68493a1bb0f1a786a37cccc2be7e5341189d91bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bu=C4=9Fra=20Altun?= Date: Thu, 14 Nov 2024 15:47:02 +0300 Subject: [PATCH 06/15] added to the editor, added to viewport docs and try to make scaling working --- doc/classes/Viewport.xml | 18 +++++++++++------- servers/rendering/renderer_viewport.cpp | 1 + servers/rendering_server.cpp | 2 +- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/doc/classes/Viewport.xml b/doc/classes/Viewport.xml index 78b6d527ea4..27142b4410b 100644 --- a/doc/classes/Viewport.xml +++ b/doc/classes/Viewport.xml @@ -481,18 +481,22 @@ Represents the size of the [enum PositionalShadowAtlasQuadrantSubdiv] enum. - - Use bilinear scaling for the viewport's 3D buffer. The amount of scaling can be set using [member scaling_3d_scale]. Values less than [code]1.0[/code] will result in undersampling while values greater than [code]1.0[/code] will result in supersampling. A value of [code]1.0[/code] disables scaling. + + Use bilinear scaling for the viewport's 3D buffer. The amount of scaling can be set using [member scaling_3d_scale]. Values less than [code]1.0[/code] will result in undersampling, while values greater than [code]1.0[/code] will result in supersampling. A value of [code]1.0[/code] disables scaling. - - Use AMD FidelityFX Super Resolution 1.0 upscaling for the viewport's 3D buffer. The amount of scaling can be set using [member scaling_3d_scale]. Values less than [code]1.0[/code] will be result in the viewport being upscaled using FSR. Values greater than [code]1.0[/code] are not supported and bilinear downsampling will be used instead. A value of [code]1.0[/code] disables scaling. + + Use nearest neighbor scaling for the viewport's 3D buffer. The amount of scaling can be set using [member scaling_3d_scale]. Values less than [code]1.0[/code] will result in undersampling, while values greater than [code]1.0[/code] will result in supersampling. A value of [code]1.0[/code] disables scaling and applies the closest pixel without interpolation. - - Use AMD FidelityFX Super Resolution 2.2 upscaling for the viewport's 3D buffer. The amount of scaling can be set using [member Viewport.scaling_3d_scale]. Values less than [code]1.0[/code] will be result in the viewport being upscaled using FSR2. Values greater than [code]1.0[/code] are not supported and bilinear downsampling will be used instead. A value of [code]1.0[/code] will use FSR2 at native resolution as a TAA solution. + + Use AMD FidelityFX Super Resolution 1.0 upscaling for the viewport's 3D buffer. The amount of scaling can be set using [member scaling_3d_scale]. Values less than [code]1.0[/code] will result in the viewport being upscaled using FSR. Values greater than [code]1.0[/code] are not supported, and bilinear downsampling will be used instead. A value of [code]1.0[/code] disables scaling. - + + Use AMD FidelityFX Super Resolution 2.2 upscaling for the viewport's 3D buffer. The amount of scaling can be set using [member scaling_3d_scale]. Values less than [code]1.0[/code] will result in the viewport being upscaled using FSR2. Values greater than [code]1.0[/code] are not supported, and bilinear downsampling will be used instead. A value of [code]1.0[/code] will use FSR2 at native resolution as a TAA solution. + + Represents the size of the [enum Scaling3DMode] enum. + Multisample antialiasing mode disabled. This is the default value, and is also the fastest setting. diff --git a/servers/rendering/renderer_viewport.cpp b/servers/rendering/renderer_viewport.cpp index 7aee58d1bae..c9ff20932c9 100644 --- a/servers/rendering/renderer_viewport.cpp +++ b/servers/rendering/renderer_viewport.cpp @@ -185,6 +185,7 @@ void RendererViewport::_configure_3d_render_buffers(Viewport *p_viewport) { target_height = p_viewport->size.height; render_width = int(target_width * scaling_3d_scale); render_height = int(target_height * scaling_3d_scale); + rb_config.set_filter_mode(RenderSceneBuffersConfiguration::FILTER_NEAREST); break; case RS::VIEWPORT_SCALING_3D_MODE_FSR: case RS::VIEWPORT_SCALING_3D_MODE_FSR2: diff --git a/servers/rendering_server.cpp b/servers/rendering_server.cpp index 725ef4d637c..f32332458a4 100644 --- a/servers/rendering_server.cpp +++ b/servers/rendering_server.cpp @@ -3642,7 +3642,7 @@ void RenderingServer::init() { GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "rendering/anti_aliasing/screen_space_roughness_limiter/amount", PROPERTY_HINT_RANGE, "0.01,4.0,0.01"), 0.25); GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "rendering/anti_aliasing/screen_space_roughness_limiter/limit", PROPERTY_HINT_RANGE, "0.01,1.0,0.01"), 0.18); - GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/scaling_3d/mode", PROPERTY_HINT_ENUM, "Bilinear (Fastest),FSR 1.0 (Fast),FSR 2.2 (Slow)"), 0); + GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/scaling_3d/mode", PROPERTY_HINT_ENUM, "Bilinear (Very Fast),Nearest Neighbor (Fastest),FSR 1.0 (Fast),FSR 2.2 (Slow)"), 0); GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "rendering/scaling_3d/scale", PROPERTY_HINT_RANGE, "0.25,2.0,0.01"), 1.0); GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "rendering/scaling_3d/fsr_sharpness", PROPERTY_HINT_RANGE, "0,2,0.1"), 0.2f); GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "rendering/textures/default_filters/texture_mipmap_bias", PROPERTY_HINT_RANGE, "-2,2,0.001"), 0.0f); From 4bf00720f00de9101845a38effa933ecb99f8e27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bu=C4=9Fra=20Altun?= Date: Thu, 14 Nov 2024 15:51:23 +0300 Subject: [PATCH 07/15] fix lol? --- servers/rendering/renderer_viewport.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/servers/rendering/renderer_viewport.cpp b/servers/rendering/renderer_viewport.cpp index c9ff20932c9..2bd9077cbe9 100644 --- a/servers/rendering/renderer_viewport.cpp +++ b/servers/rendering/renderer_viewport.cpp @@ -185,7 +185,7 @@ void RendererViewport::_configure_3d_render_buffers(Viewport *p_viewport) { target_height = p_viewport->size.height; render_width = int(target_width * scaling_3d_scale); render_height = int(target_height * scaling_3d_scale); - rb_config.set_filter_mode(RenderSceneBuffersConfiguration::FILTER_NEAREST); + rb_config.set_filter_mode(RenderSceneBuffersConfiguration::TEXTURE_FILTER_NEAREST); break; case RS::VIEWPORT_SCALING_3D_MODE_FSR: case RS::VIEWPORT_SCALING_3D_MODE_FSR2: From d59a5c84062dd16a9a956097ab3ff1e3d100209a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bu=C4=9Fra=20Altun?= Date: Thu, 14 Nov 2024 15:56:09 +0300 Subject: [PATCH 08/15] another fix attempt --- servers/rendering/renderer_viewport.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/servers/rendering/renderer_viewport.cpp b/servers/rendering/renderer_viewport.cpp index 2bd9077cbe9..6aebc650c65 100644 --- a/servers/rendering/renderer_viewport.cpp +++ b/servers/rendering/renderer_viewport.cpp @@ -170,6 +170,7 @@ void RendererViewport::_configure_3d_render_buffers(Viewport *p_viewport) { int target_height; int render_width; int render_height; + RenderSceneBuffersConfiguration rb_config; switch (scaling_3d_mode) { case RS::VIEWPORT_SCALING_3D_MODE_BILINEAR: @@ -183,8 +184,8 @@ void RendererViewport::_configure_3d_render_buffers(Viewport *p_viewport) { case RS::VIEWPORT_SCALING_3D_MODE_NEAREST: target_width = p_viewport->size.width; target_height = p_viewport->size.height; - render_width = int(target_width * scaling_3d_scale); - render_height = int(target_height * scaling_3d_scale); + render_width = CLAMP(int(target_width * scaling_3d_scale), 1, 16384); + render_height = CLAMP(int(target_height * scaling_3d_scale), 1, 16384); rb_config.set_filter_mode(RenderSceneBuffersConfiguration::TEXTURE_FILTER_NEAREST); break; case RS::VIEWPORT_SCALING_3D_MODE_FSR: @@ -228,7 +229,6 @@ 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; - RenderSceneBuffersConfiguration rb_config; rb_config.set_render_target(p_viewport->render_target); rb_config.set_internal_size(Size2i(render_width, render_height)); rb_config.set_target_size(Size2(target_width, target_height)); From 40b38708d0446ea8387aa91b08f911e9d6dd635f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bu=C4=9Fra=20Altun?= Date: Thu, 14 Nov 2024 16:36:50 +0300 Subject: [PATCH 09/15] test to see if this works lol --- servers/rendering/renderer_viewport.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/servers/rendering/renderer_viewport.cpp b/servers/rendering/renderer_viewport.cpp index 6aebc650c65..3af04bce90e 100644 --- a/servers/rendering/renderer_viewport.cpp +++ b/servers/rendering/renderer_viewport.cpp @@ -170,7 +170,6 @@ void RendererViewport::_configure_3d_render_buffers(Viewport *p_viewport) { int target_height; int render_width; int render_height; - RenderSceneBuffersConfiguration rb_config; switch (scaling_3d_mode) { case RS::VIEWPORT_SCALING_3D_MODE_BILINEAR: @@ -184,8 +183,8 @@ void RendererViewport::_configure_3d_render_buffers(Viewport *p_viewport) { case RS::VIEWPORT_SCALING_3D_MODE_NEAREST: target_width = p_viewport->size.width; target_height = p_viewport->size.height; - render_width = CLAMP(int(target_width * scaling_3d_scale), 1, 16384); - render_height = CLAMP(int(target_height * scaling_3d_scale), 1, 16384); + render_width = target_width; + render_height = target_height; rb_config.set_filter_mode(RenderSceneBuffersConfiguration::TEXTURE_FILTER_NEAREST); break; case RS::VIEWPORT_SCALING_3D_MODE_FSR: @@ -229,6 +228,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; + RenderSceneBuffersConfiguration rb_config; rb_config.set_render_target(p_viewport->render_target); rb_config.set_internal_size(Size2i(render_width, render_height)); rb_config.set_target_size(Size2(target_width, target_height)); From bd73b62dcd871bcb52205bf889bb7219cb4b8581 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bu=C4=9Fra=20Altun?= Date: Thu, 14 Nov 2024 16:37:33 +0300 Subject: [PATCH 10/15] forgot something --- servers/rendering/renderer_viewport.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/servers/rendering/renderer_viewport.cpp b/servers/rendering/renderer_viewport.cpp index 3af04bce90e..2b0ab4ba148 100644 --- a/servers/rendering/renderer_viewport.cpp +++ b/servers/rendering/renderer_viewport.cpp @@ -185,7 +185,6 @@ void RendererViewport::_configure_3d_render_buffers(Viewport *p_viewport) { target_height = p_viewport->size.height; render_width = target_width; render_height = target_height; - rb_config.set_filter_mode(RenderSceneBuffersConfiguration::TEXTURE_FILTER_NEAREST); break; case RS::VIEWPORT_SCALING_3D_MODE_FSR: case RS::VIEWPORT_SCALING_3D_MODE_FSR2: From 236b259bf7fdea370e60efc95c40b0b8886bf40c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bu=C4=9Fra=20Altun?= Date: Thu, 14 Nov 2024 16:49:40 +0300 Subject: [PATCH 11/15] doc fixes --- doc/classes/Viewport.xml | 6 +++--- servers/rendering_server.cpp | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/doc/classes/Viewport.xml b/doc/classes/Viewport.xml index 27142b4410b..3b18b5af795 100644 --- a/doc/classes/Viewport.xml +++ b/doc/classes/Viewport.xml @@ -481,9 +481,9 @@ Represents the size of the [enum PositionalShadowAtlasQuadrantSubdiv] enum. - - Use bilinear scaling for the viewport's 3D buffer. The amount of scaling can be set using [member scaling_3d_scale]. Values less than [code]1.0[/code] will result in undersampling, while values greater than [code]1.0[/code] will result in supersampling. A value of [code]1.0[/code] disables scaling. - + ++ Use bilinear scaling for the viewport's 3D buffer. The amount of scaling can be set using [member scaling_3d_scale]. Values less than [code]1.0[/code] will result in undersampling, while values greater than [code]1.0[/code] will result in supersampling. A value of [code]1.0[/code] disables scaling. + Use nearest neighbor scaling for the viewport's 3D buffer. The amount of scaling can be set using [member scaling_3d_scale]. Values less than [code]1.0[/code] will result in undersampling, while values greater than [code]1.0[/code] will result in supersampling. A value of [code]1.0[/code] disables scaling and applies the closest pixel without interpolation. diff --git a/servers/rendering_server.cpp b/servers/rendering_server.cpp index f32332458a4..e53a39bc652 100644 --- a/servers/rendering_server.cpp +++ b/servers/rendering_server.cpp @@ -2857,6 +2857,7 @@ void RenderingServer::_bind_methods() { ClassDB::bind_method(D_METHOD("viewport_set_vrs_texture", "viewport", "texture"), &RenderingServer::viewport_set_vrs_texture); BIND_ENUM_CONSTANT(VIEWPORT_SCALING_3D_MODE_BILINEAR); + BIND_ENUM_CONSTANT(VIEWPORT_SCALING_3D_MODE_NEAREST); BIND_ENUM_CONSTANT(VIEWPORT_SCALING_3D_MODE_FSR); BIND_ENUM_CONSTANT(VIEWPORT_SCALING_3D_MODE_FSR2); BIND_ENUM_CONSTANT(VIEWPORT_SCALING_3D_MODE_MAX); From 1ef24a01ab0c76995e3cd2611ffc673f3a467cb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bu=C4=9Fra=20Altun?= Date: Thu, 14 Nov 2024 16:52:04 +0300 Subject: [PATCH 12/15] testing --- servers/rendering/renderer_viewport.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/servers/rendering/renderer_viewport.cpp b/servers/rendering/renderer_viewport.cpp index 2b0ab4ba148..df398f8d3ca 100644 --- a/servers/rendering/renderer_viewport.cpp +++ b/servers/rendering/renderer_viewport.cpp @@ -183,8 +183,8 @@ void RendererViewport::_configure_3d_render_buffers(Viewport *p_viewport) { case RS::VIEWPORT_SCALING_3D_MODE_NEAREST: target_width = p_viewport->size.width; target_height = p_viewport->size.height; - render_width = target_width; - render_height = target_height; + render_width = target_width * scaling_3d_scale; + render_height = target_height * scaling_3d_scale; break; case RS::VIEWPORT_SCALING_3D_MODE_FSR: case RS::VIEWPORT_SCALING_3D_MODE_FSR2: From 60a5c189e18ebb5ee94ada8b3aaa299e8f67660c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bu=C4=9Fra=20Altun?= Date: Thu, 14 Nov 2024 17:12:47 +0300 Subject: [PATCH 13/15] fixes --- doc/classes/Viewport.xml | 2 +- servers/rendering/renderer_viewport.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/classes/Viewport.xml b/doc/classes/Viewport.xml index 3b18b5af795..c0a3f9928bc 100644 --- a/doc/classes/Viewport.xml +++ b/doc/classes/Viewport.xml @@ -482,7 +482,7 @@ Represents the size of the [enum PositionalShadowAtlasQuadrantSubdiv] enum. -+ Use bilinear scaling for the viewport's 3D buffer. The amount of scaling can be set using [member scaling_3d_scale]. Values less than [code]1.0[/code] will result in undersampling, while values greater than [code]1.0[/code] will result in supersampling. A value of [code]1.0[/code] disables scaling. + Use bilinear scaling for the viewport's 3D buffer. The amount of scaling can be set using [member scaling_3d_scale]. Values less than [code]1.0[/code] will result in undersampling, while values greater than [code]1.0[/code] will result in supersampling. A value of [code]1.0[/code] disables scaling. Use nearest neighbor scaling for the viewport's 3D buffer. The amount of scaling can be set using [member scaling_3d_scale]. Values less than [code]1.0[/code] will result in undersampling, while values greater than [code]1.0[/code] will result in supersampling. A value of [code]1.0[/code] disables scaling and applies the closest pixel without interpolation. diff --git a/servers/rendering/renderer_viewport.cpp b/servers/rendering/renderer_viewport.cpp index df398f8d3ca..18d4589040f 100644 --- a/servers/rendering/renderer_viewport.cpp +++ b/servers/rendering/renderer_viewport.cpp @@ -183,8 +183,8 @@ void RendererViewport::_configure_3d_render_buffers(Viewport *p_viewport) { case RS::VIEWPORT_SCALING_3D_MODE_NEAREST: target_width = p_viewport->size.width; target_height = p_viewport->size.height; - render_width = target_width * scaling_3d_scale; - render_height = target_height * scaling_3d_scale; + render_width = CLAMP(target_width * scaling_3d_scale, 1, 16384); + render_height = CLAMP(target_width * scaling_3d_scale, 1, 16384); break; case RS::VIEWPORT_SCALING_3D_MODE_FSR: case RS::VIEWPORT_SCALING_3D_MODE_FSR2: From 3fa14247437308228cf821da6336433074a994b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bu=C4=9Fra=20Altun?= Date: Thu, 14 Nov 2024 17:21:14 +0300 Subject: [PATCH 14/15] im losing my sanity --- doc/classes/Viewport.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/doc/classes/Viewport.xml b/doc/classes/Viewport.xml index c0a3f9928bc..e43a3e1e79c 100644 --- a/doc/classes/Viewport.xml +++ b/doc/classes/Viewport.xml @@ -483,7 +483,7 @@ Use bilinear scaling for the viewport's 3D buffer. The amount of scaling can be set using [member scaling_3d_scale]. Values less than [code]1.0[/code] will result in undersampling, while values greater than [code]1.0[/code] will result in supersampling. A value of [code]1.0[/code] disables scaling. - + Use nearest neighbor scaling for the viewport's 3D buffer. The amount of scaling can be set using [member scaling_3d_scale]. Values less than [code]1.0[/code] will result in undersampling, while values greater than [code]1.0[/code] will result in supersampling. A value of [code]1.0[/code] disables scaling and applies the closest pixel without interpolation. @@ -496,7 +496,6 @@ Represents the size of the [enum Scaling3DMode] enum. - Multisample antialiasing mode disabled. This is the default value, and is also the fastest setting. From afbafcf3f8996900bfd1b2f9aef68fe3afa9ed6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bu=C4=9Fra=20Altun?= Date: Thu, 14 Nov 2024 17:40:24 +0300 Subject: [PATCH 15/15] aaahhh --- doc/classes/RenderingServer.xml | 10 +++++----- doc/classes/Viewport.xml | 10 +++++----- scene/main/viewport.cpp | 4 ++-- scene/main/viewport.h | 2 +- servers/rendering/renderer_viewport.cpp | 12 ++++++------ servers/rendering/storage/render_scene_buffers.cpp | 2 +- servers/rendering_server.cpp | 4 ++-- servers/rendering_server.h | 2 +- 8 files changed, 23 insertions(+), 23 deletions(-) diff --git a/doc/classes/RenderingServer.xml b/doc/classes/RenderingServer.xml index 0f9c7d47d30..d4f967d51d5 100644 --- a/doc/classes/RenderingServer.xml +++ b/doc/classes/RenderingServer.xml @@ -4903,15 +4903,15 @@ Use bilinear scaling for the viewport's 3D buffer. The amount of scaling can be set using [member Viewport.scaling_3d_scale]. Values less than [code]1.0[/code] will result in undersampling while values greater than [code]1.0[/code] will result in supersampling. A value of [code]1.0[/code] disables scaling. - - Use nearest neighbor scaling for the viewport's 3D buffer. The amount of scaling can be set using [member Viewport.scaling_3d_scale]. Values less than [code]1.0[/code] will result in undersampling, while values greater than [code]1.0[/code] will result in supersampling. A value of [code]1.0[/code] disables scaling and applies the closest pixel without interpolation. - - + Use AMD FidelityFX Super Resolution 1.0 upscaling for the viewport's 3D buffer. The amount of scaling can be set using [member Viewport.scaling_3d_scale]. Values less than [code]1.0[/code] will be result in the viewport being upscaled using FSR. Values greater than [code]1.0[/code] are not supported and bilinear downsampling will be used instead. A value of [code]1.0[/code] disables scaling. - + Use AMD FidelityFX Super Resolution 2.2 upscaling for the viewport's 3D buffer. The amount of scaling can be set using [member Viewport.scaling_3d_scale]. Values less than [code]1.0[/code] will be result in the viewport being upscaled using FSR2. Values greater than [code]1.0[/code] are not supported and bilinear downsampling will be used instead. A value of [code]1.0[/code] will use FSR2 at native resolution as a TAA solution. + + Use nearest neighbor scaling for the viewport's 3D buffer. The amount of scaling can be set using [member Viewport.scaling_3d_scale]. Values less than [code]1.0[/code] will result in undersampling, while values greater than [code]1.0[/code] will result in supersampling. A value of [code]1.0[/code] disables scaling and applies the closest pixel without interpolation. + Represents the size of the [enum ViewportScaling3DMode] enum. diff --git a/doc/classes/Viewport.xml b/doc/classes/Viewport.xml index e43a3e1e79c..7ce46be5d7f 100644 --- a/doc/classes/Viewport.xml +++ b/doc/classes/Viewport.xml @@ -484,15 +484,15 @@ Use bilinear scaling for the viewport's 3D buffer. The amount of scaling can be set using [member scaling_3d_scale]. Values less than [code]1.0[/code] will result in undersampling, while values greater than [code]1.0[/code] will result in supersampling. A value of [code]1.0[/code] disables scaling. - - Use nearest neighbor scaling for the viewport's 3D buffer. The amount of scaling can be set using [member scaling_3d_scale]. Values less than [code]1.0[/code] will result in undersampling, while values greater than [code]1.0[/code] will result in supersampling. A value of [code]1.0[/code] disables scaling and applies the closest pixel without interpolation. - - + Use AMD FidelityFX Super Resolution 1.0 upscaling for the viewport's 3D buffer. The amount of scaling can be set using [member scaling_3d_scale]. Values less than [code]1.0[/code] will result in the viewport being upscaled using FSR. Values greater than [code]1.0[/code] are not supported, and bilinear downsampling will be used instead. A value of [code]1.0[/code] disables scaling. - + Use AMD FidelityFX Super Resolution 2.2 upscaling for the viewport's 3D buffer. The amount of scaling can be set using [member scaling_3d_scale]. Values less than [code]1.0[/code] will result in the viewport being upscaled using FSR2. Values greater than [code]1.0[/code] are not supported, and bilinear downsampling will be used instead. A value of [code]1.0[/code] will use FSR2 at native resolution as a TAA solution. + + Use nearest neighbor scaling for the viewport's 3D buffer. The amount of scaling can be set using [member scaling_3d_scale]. Values less than [code]1.0[/code] will result in undersampling, while values greater than [code]1.0[/code] will result in supersampling. A value of [code]1.0[/code] disables scaling and applies the closest pixel without interpolation. + Represents the size of the [enum Scaling3DMode] enum. diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 60395732766..d451c0c65de 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -4822,7 +4822,7 @@ void Viewport::_bind_methods() { #ifndef _3D_DISABLED ADD_GROUP("Scaling 3D", ""); - ADD_PROPERTY(PropertyInfo(Variant::INT, "scaling_3d_mode", PROPERTY_HINT_ENUM, "Bilinear (Fastest),FSR 1.0 (Fast),FSR 2.2 (Slow)"), "set_scaling_3d_mode", "get_scaling_3d_mode"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "scaling_3d_mode", PROPERTY_HINT_ENUM, "Bilinear (Very Fast),FSR 1.0 (Fast),FSR 2.2 (Slow),Nearest Neighbor (Fastest)"), "set_scaling_3d_mode", "get_scaling_3d_mode"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "scaling_3d_scale", PROPERTY_HINT_RANGE, "0.25,2.0,0.01"), "set_scaling_3d_scale", "get_scaling_3d_scale"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "texture_mipmap_bias", PROPERTY_HINT_RANGE, "-2,2,0.001"), "set_texture_mipmap_bias", "get_texture_mipmap_bias"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "fsr_sharpness", PROPERTY_HINT_RANGE, "0,2,0.1"), "set_fsr_sharpness", "get_fsr_sharpness"); @@ -4874,9 +4874,9 @@ void Viewport::_bind_methods() { BIND_ENUM_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_MAX); BIND_ENUM_CONSTANT(SCALING_3D_MODE_BILINEAR); - BIND_ENUM_CONSTANT(SCALING_3D_MODE_NEAREST); BIND_ENUM_CONSTANT(SCALING_3D_MODE_FSR); BIND_ENUM_CONSTANT(SCALING_3D_MODE_FSR2); + BIND_ENUM_CONSTANT(SCALING_3D_MODE_NEAREST); BIND_ENUM_CONSTANT(SCALING_3D_MODE_MAX); BIND_ENUM_CONSTANT(MSAA_DISABLED); diff --git a/scene/main/viewport.h b/scene/main/viewport.h index 6dfced9acb6..b8adec01326 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -100,9 +100,9 @@ class Viewport : public Node { public: enum Scaling3DMode { SCALING_3D_MODE_BILINEAR, - SCALING_3D_MODE_NEAREST, SCALING_3D_MODE_FSR, SCALING_3D_MODE_FSR2, + SCALING_3D_MODE_NEAREST, SCALING_3D_MODE_MAX }; diff --git a/servers/rendering/renderer_viewport.cpp b/servers/rendering/renderer_viewport.cpp index 18d4589040f..034d5e6a719 100644 --- a/servers/rendering/renderer_viewport.cpp +++ b/servers/rendering/renderer_viewport.cpp @@ -180,12 +180,6 @@ void RendererViewport::_configure_3d_render_buffers(Viewport *p_viewport) { render_width = CLAMP(target_width * scaling_3d_scale, 1, 16384); render_height = CLAMP(target_height * scaling_3d_scale, 1, 16384); break; - case RS::VIEWPORT_SCALING_3D_MODE_NEAREST: - target_width = p_viewport->size.width; - target_height = p_viewport->size.height; - render_width = CLAMP(target_width * scaling_3d_scale, 1, 16384); - render_height = CLAMP(target_width * scaling_3d_scale, 1, 16384); - break; case RS::VIEWPORT_SCALING_3D_MODE_FSR: case RS::VIEWPORT_SCALING_3D_MODE_FSR2: target_width = p_viewport->size.width; @@ -193,6 +187,12 @@ void RendererViewport::_configure_3d_render_buffers(Viewport *p_viewport) { render_width = MAX(target_width * scaling_3d_scale, 1.0); // target_width / (target_width * scaling) render_height = MAX(target_height * scaling_3d_scale, 1.0); break; + case RS::VIEWPORT_SCALING_3D_MODE_NEAREST: + target_width = p_viewport->size.width; + target_height = p_viewport->size.height; + render_width = CLAMP(target_width * scaling_3d_scale, 1, 16384); + render_height = CLAMP(target_width * scaling_3d_scale, 1, 16384); + break; case RS::VIEWPORT_SCALING_3D_MODE_OFF: target_width = p_viewport->size.width; target_height = p_viewport->size.height; diff --git a/servers/rendering/storage/render_scene_buffers.cpp b/servers/rendering/storage/render_scene_buffers.cpp index fd4131e1fa4..e81212bc214 100644 --- a/servers/rendering/storage/render_scene_buffers.cpp +++ b/servers/rendering/storage/render_scene_buffers.cpp @@ -51,7 +51,7 @@ void RenderSceneBuffersConfiguration::_bind_methods() { ClassDB::bind_method(D_METHOD("get_scaling_3d_mode"), &RenderSceneBuffersConfiguration::get_scaling_3d_mode); ClassDB::bind_method(D_METHOD("set_scaling_3d_mode", "scaling_3d_mode"), &RenderSceneBuffersConfiguration::set_scaling_3d_mode); - ADD_PROPERTY(PropertyInfo(Variant::INT, "scaling_3d_mode", PROPERTY_HINT_ENUM, "Bilinear (Fastest),FSR 1.0 (Fast),FSR 2.2 (Slow)"), "set_scaling_3d_mode", "get_scaling_3d_mode"); // TODO VIEWPORT_SCALING_3D_MODE_OFF is possible here too, but we can't specify an enum string for it. + ADD_PROPERTY(PropertyInfo(Variant::INT, "scaling_3d_mode", PROPERTY_HINT_ENUM, "Bilinear (Very Fast),FSR 1.0 (Fast),FSR 2.2 (Slow),Nearest Neighbor (Fastest)"), "set_scaling_3d_mode", "get_scaling_3d_mode"); // TODO VIEWPORT_SCALING_3D_MODE_OFF is possible here too, but we can't specify an enum string for it. ClassDB::bind_method(D_METHOD("get_msaa_3d"), &RenderSceneBuffersConfiguration::get_msaa_3d); ClassDB::bind_method(D_METHOD("set_msaa_3d", "msaa_3d"), &RenderSceneBuffersConfiguration::set_msaa_3d); diff --git a/servers/rendering_server.cpp b/servers/rendering_server.cpp index e53a39bc652..5a650918e4b 100644 --- a/servers/rendering_server.cpp +++ b/servers/rendering_server.cpp @@ -2857,9 +2857,9 @@ void RenderingServer::_bind_methods() { ClassDB::bind_method(D_METHOD("viewport_set_vrs_texture", "viewport", "texture"), &RenderingServer::viewport_set_vrs_texture); BIND_ENUM_CONSTANT(VIEWPORT_SCALING_3D_MODE_BILINEAR); - BIND_ENUM_CONSTANT(VIEWPORT_SCALING_3D_MODE_NEAREST); BIND_ENUM_CONSTANT(VIEWPORT_SCALING_3D_MODE_FSR); BIND_ENUM_CONSTANT(VIEWPORT_SCALING_3D_MODE_FSR2); + BIND_ENUM_CONSTANT(VIEWPORT_SCALING_3D_MODE_NEAREST); BIND_ENUM_CONSTANT(VIEWPORT_SCALING_3D_MODE_MAX); BIND_ENUM_CONSTANT(VIEWPORT_UPDATE_DISABLED); @@ -3643,7 +3643,7 @@ void RenderingServer::init() { GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "rendering/anti_aliasing/screen_space_roughness_limiter/amount", PROPERTY_HINT_RANGE, "0.01,4.0,0.01"), 0.25); GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "rendering/anti_aliasing/screen_space_roughness_limiter/limit", PROPERTY_HINT_RANGE, "0.01,1.0,0.01"), 0.18); - GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/scaling_3d/mode", PROPERTY_HINT_ENUM, "Bilinear (Very Fast),Nearest Neighbor (Fastest),FSR 1.0 (Fast),FSR 2.2 (Slow)"), 0); + GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/scaling_3d/mode", PROPERTY_HINT_ENUM, "Bilinear (Very Fast),FSR 1.0 (Fast),FSR 2.2 (Slow),Nearest Neighbor (Fastest)"), 0); GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "rendering/scaling_3d/scale", PROPERTY_HINT_RANGE, "0.25,2.0,0.01"), 1.0); GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "rendering/scaling_3d/fsr_sharpness", PROPERTY_HINT_RANGE, "0,2,0.1"), 0.2f); GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "rendering/textures/default_filters/texture_mipmap_bias", PROPERTY_HINT_RANGE, "-2,2,0.001"), 0.0f); diff --git a/servers/rendering_server.h b/servers/rendering_server.h index fdf1a8bbcac..42f60f56308 100644 --- a/servers/rendering_server.h +++ b/servers/rendering_server.h @@ -903,9 +903,9 @@ class RenderingServer : public Object { enum ViewportScaling3DMode { VIEWPORT_SCALING_3D_MODE_BILINEAR, - VIEWPORT_SCALING_3D_MODE_NEAREST, VIEWPORT_SCALING_3D_MODE_FSR, VIEWPORT_SCALING_3D_MODE_FSR2, + VIEWPORT_SCALING_3D_MODE_NEAREST, VIEWPORT_SCALING_3D_MODE_MAX, VIEWPORT_SCALING_3D_MODE_OFF = 255, // for internal use only };