diff --git a/README.md b/README.md index c88f19e..429b1d5 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ # Godot Super Scaling : Add-On For Godot Engine -Godot Super Scaling, a comprehensive post-processing effect for 3D and 2D Godot Engine games that allows you to upscale or downscale the viewport for increased performance or higher quality visuals. Supports up to 200% native resolution or down to 10%. +A fast viewport scaler for 3D and 2D Godot Engine games that allows you to upscale or downscale the screen for increased performance or higher quality visuals. Supports up to 200% native resolution or down to 10%. At 50% scaling on a 3D game, you could potentially get 200% to 300% of native performance, which is key to getting higher quality graphics on low-end hardware. At scales like 90%, you could gain 25% performance with very minimal picture quality loss. Going above 100% does increase quality, however the performance cost is large and might only make sense for users with very high-end graphics cards. -![Screenshot](ScreenShots/Godot_Super_Scaling_3D.jpg) +![Screenshot](ScreenShots/Decay_GSS_4K.jpg) -![Screenshot](ScreenShots/Godot_Super_Scaling_2D.jpg) +![Screenshot](ScreenShots/Decay_GSS_1080p.jpg) ## INSTALLATION @@ -15,30 +15,31 @@ For manual install, download the `SuperScaling` folder from this repository and ## CONFIGURATION * Add the `SuperScaling.tscn` scene to your main scene tree, it should be just below the root node. -* Place your entire game world as a child of a new node under the root node (e.g. Spatial for 3D games or Node2D for 2D games). -* In the `SuperScaling` inspector settings, link the `Game World` property to the node you created above. +* You can leave the rest of your scene tree the same, this add-on no longer requires any special node setup. +* To have UI or HUD elements rendered at native resolution, you should add them to the `UI Nodes` property. * Select `Enable on Play`, this will start the scaling add-on when you play the game (cannot be viewed in editor). * Set `Usage` to either `3D` or `2D` depending on your game type. * `MSAA` and `FXAA` are controlled by the `SuperScaling` add-on and the project settings do not take effect. -* The `SuperScaling` add-on does add some anti-aliasing, however you may want to also enable `MSAA` or `FXAA` or both. -* `Shadow Atlas` controls the map size for omni and spot lights. If you only use a directional light you can set this to `1`. +* The `SuperScaling` add-on does add some anti-aliasing, however you may want to also enable `MSAA` or `FXAA` or both. For the best quality and performance, it is recommended to use `4x` `MSAA`. At higher render scales, using `FXAA` can help soften the image. At scales of 75% or below, it is recommended to disable `FXAA` as it can worsen picture clarity. +* `Shadow Atlas` controls the shadow map size for omni and spot lights. If you only use a directional light you can set this to `1`. * To control the scale of the render, use the `Scale Factor` setting on the top of the inspector for `SuperScaling`. * `1.0` for the `Scale Factor` corresponds to 100% of the native resolution. `0.5` will be 50% and `2.0` will be 200%. -* Note that setting the `Scale Factor` above `1.0` results in higher quality but will have lesser performance. -* Setting the `Scale Factor` lower than `1.0` results in an image quality loss, but higher performance. +* Setting the `Scale Factor` lower than `1.0` will lessen the picture quality slightly, but with much higher performance. +* Note that setting the `Scale Factor` above `1.0` results in higher definition but will have substantially lesser performance. * Please experiment with your game and your desired minimum spec to find an appropriate setting. -* Also consider exposing the scale to users, so that they may tailor the experience to their level of hardware. +* Also consider exposing the scale to users (within limits), so that they may tailor the experience to their level of hardware. * `Smoothness` controls the mix between the two scaling algorithms. `0.0` is more sharp and `1.0` is softer. -* In general, values lower than `0.5` are better for upscaling and values above `0.5` better for downscaling. +* In general, leaving the `Smoothness` value at the default of `0.5` will have the best compatiblity at all scales. +* You should avoid setting `Smoothness` to the extremes. Values between `0.25` and `0.75` work best. * However, this is an artistic choice and you should experiment to find the best value for your game. * In the project settings, for 3D games, the `Stretch Mode` should be set to `disabled` and `Stretch Aspect` to `ignore`. * For 2D games, the best project settings are `2d` for `Stretch Mode` and `keep_height` for `Stretch Aspect`. -* 2D HUD and UI elements will be shown above the scaled game and displayed at native resolution. -* For 3D games, simply create a 2D node (such as Control) as a child of the root node and it will display properly. -* For 2D games, you will need to create a Node2D and place your UI elements inside that. Then set the `Z Index` to `1` or above. -* Be sure that `Use VSync` is set to `On` in the project settings for the smoothest performance. -* One thing to note, `SuperScaling` will take control of your game while enabled, and you will no longer be able to edit as you play. -* It is recommended to leave `Enable on Play` off while developing, and only enable the add-on when you need to test the graphics or performance. +* Native resolution UI nodes for 3D games can be anywhere, as long as they are added to the `UI Nodes` property. +* For 2D games, you will need to create a `Node2D` and place your UI elements inside that. Then set the `Z Index` to `1` or above. +* Be sure that `Use VSync` is set to `On` in the project settings for the smoothest performance. Turning `Use VSync` to `Off` can result in stuttering and an overall choppy experience. +* One thing to note, `SuperScaling` will take control of your game while enabled, and you will no longer be able to edit as you play. Meaning changing variables in the inspector at run-time will not result in visible changes (though you can click the `Remote` tab on the left and edit values, if really necessary). +* So it is recommended to leave `Enable on Play` off while developing, and only enable the add-on when you need to test the graphics or performance. +* Since the add-on moves your game nodes into a dynamically generated viewport, using `get_node()` with absolute paths will no longer function. It is recommended to try to use relative paths as much as possible when getting nodes, and this is supported. There are some cases, though, where special care must be taken. In the case of scripts on the root node, and also when calling in or out of the dynamic viewport (e.g. for a UI node to affect a game object, or vice versa), since the node paths will change at run-time. In these cases, rather than absolute paths, you can use the `find_node()` function, which will work regardless of where the nodes might be. For example `get_tree().get_root().find_node("Player", true, false)`. For this to work, though, all the nodes you are interested in getting this way must have unique names. ## LICENSE diff --git a/ScreenShots/Decay_GSS_1080p.jpg b/ScreenShots/Decay_GSS_1080p.jpg new file mode 100644 index 0000000..e253969 Binary files /dev/null and b/ScreenShots/Decay_GSS_1080p.jpg differ diff --git a/ScreenShots/Decay_GSS_4K.jpg b/ScreenShots/Decay_GSS_4K.jpg new file mode 100644 index 0000000..de0139d Binary files /dev/null and b/ScreenShots/Decay_GSS_4K.jpg differ diff --git a/ScreenShots/Godot_Super_Scaling_2D.jpg b/ScreenShots/Godot_Super_Scaling_2D.jpg deleted file mode 100644 index 2fccb8f..0000000 Binary files a/ScreenShots/Godot_Super_Scaling_2D.jpg and /dev/null differ diff --git a/ScreenShots/Godot_Super_Scaling_3D.jpg b/ScreenShots/Godot_Super_Scaling_3D.jpg deleted file mode 100644 index ade06dc..0000000 Binary files a/ScreenShots/Godot_Super_Scaling_3D.jpg and /dev/null differ diff --git a/SuperScaling.zip b/SuperScaling.zip deleted file mode 100644 index 9c721ba..0000000 Binary files a/SuperScaling.zip and /dev/null differ diff --git a/SuperScaling/SuperScaling.gd b/SuperScaling/SuperScaling.gd index e8490dd..ca7d429 100644 --- a/SuperScaling/SuperScaling.gd +++ b/SuperScaling/SuperScaling.gd @@ -5,14 +5,14 @@ extends Node export (float, 0.1, 2.0) var scale_factor = 1.0 setget change_scale_factor export (float, 0.0, 1.0) var smoothness = 0.5 setget change_smoothness export (bool) var enable_on_play = false -export (NodePath) var game_world +export (Array, NodePath) var ui_nodes export (int, "3D", "2D") var usage = 0 export (int, "Disabled", "2X", "4X", "8X", "16X") var msaa = 0 setget change_msaa export (bool) var fxaa = false setget change_fxaa export (int, 1, 4096) var shadow_atlas = 4096 setget change_shadow_atlas onready var sampler_shader = load(get_script().resource_path.get_base_dir() + "/SuperScaling.tres") var sampler_material -var game_node +var game_nodes var overlay var viewport var viewport_size @@ -23,33 +23,54 @@ var native_aspect_ratio var original_aspect_ratio enum {USAGE_3D, USAGE_2D} const epsilon = 0.01 +var finish_timer func _ready(): if (enable_on_play): - game_node = get_node(game_world) - if game_node: - get_parent().call_deferred("remove_child", game_node) - get_screen_size() - create_viewport() - set_shader_texture() - viewport.call_deferred("add_child", game_node) - get_parent().call_deferred("add_child", viewport) - original_resolution = native_resolution - original_aspect_ratio = native_aspect_ratio - root_viewport = get_viewport() - #warning-ignore:RETURN_VALUE_DISCARDED - viewport.connect("size_changed", self, "on_window_resize") - #warning-ignore:RETURN_VALUE_DISCARDED - root_viewport.connect("size_changed", self, "on_window_resize") - on_window_resize() - create_sampler() - change_msaa(msaa) - change_fxaa(fxaa) - change_smoothness(smoothness) - set_process_input(false) - set_process_unhandled_input(false) - else: - print("ERROR [Godot Super Scaling] Game World must be set in inspector.") + finish_setup() + +func finish_setup(): + remove_all_nodes() + get_screen_size() + create_viewport() + set_shader_texture() + add_all_nodes() + get_parent().call_deferred("add_child", viewport) + original_resolution = native_resolution + original_aspect_ratio = native_aspect_ratio + root_viewport = get_viewport() + #warning-ignore:RETURN_VALUE_DISCARDED + viewport.connect("size_changed", self, "on_window_resize") + #warning-ignore:RETURN_VALUE_DISCARDED + root_viewport.connect("size_changed", self, "on_window_resize") + on_window_resize() + create_sampler() + change_msaa(msaa) + change_fxaa(fxaa) + change_smoothness(smoothness) + set_process_input(false) + set_process_unhandled_input(false) + +func remove_all_nodes(): + game_nodes = get_parent().get_children() + var ui_count = ui_nodes.size() + var done = false + while not done: + for i in range(game_nodes.size()): + if ui_nodes.has(get_path_to(game_nodes[i])): + game_nodes.remove(i) + break + ui_count -= 1 + if ui_count <= 0: + done = true + game_nodes.erase(self) + for node in game_nodes: + if node != self: + get_parent().call_deferred("remove_child", node) + +func add_all_nodes(): + for node in game_nodes: + viewport.call_deferred("add_child", node) func create_viewport(): viewport = Viewport.new() @@ -69,6 +90,7 @@ func create_sampler(): sampler_material = ShaderMaterial.new() sampler_material.shader = sampler_shader overlay.material = sampler_material + overlay.mouse_filter = Control.MOUSE_FILTER_PASS add_child(overlay) func set_shader_texture():