diff options
author | Hugo Locurcio <hugo.locurcio@hugo.pro> | 2021-08-29 14:44:09 +0200 |
---|---|---|
committer | Hugo Locurcio <hugo.locurcio@hugo.pro> | 2021-10-08 18:22:10 +0200 |
commit | 73c6e19acc69b7367c4fa67cd4377e2207faf898 (patch) | |
tree | 35720ecbf3c231606efecb3c01fc603fb3a193a0 /servers/rendering | |
parent | a5a52233bc1327d8943c0a2a3866aa314371edec (diff) |
Allow any floating-point value as a 3D rendering scale option
This allows for finer control over 3D rendering resolution.
Supersampling can also be performed by setting a 3D rendering
resolution above 1.0, which is useful for offline rendering or
for very high-end GPUs.
Diffstat (limited to 'servers/rendering')
-rw-r--r-- | servers/rendering/renderer_viewport.cpp | 43 | ||||
-rw-r--r-- | servers/rendering/renderer_viewport.h | 4 | ||||
-rw-r--r-- | servers/rendering/rendering_server_default.h | 2 |
3 files changed, 18 insertions, 31 deletions
diff --git a/servers/rendering/renderer_viewport.cpp b/servers/rendering/renderer_viewport.cpp index 74f18b1da5..b67b1cd806 100644 --- a/servers/rendering/renderer_viewport.cpp +++ b/servers/rendering/renderer_viewport.cpp @@ -77,33 +77,17 @@ void RendererViewport::_configure_3d_render_buffers(Viewport *p_viewport) { RSG::scene->free(p_viewport->render_buffers); p_viewport->render_buffers = RID(); } else { - RS::ViewportScale3D scale_3d = p_viewport->scale_3d; - if (Engine::get_singleton()->is_editor_hint()) { // ignore this inside of the editor - scale_3d = RS::VIEWPORT_SCALE_3D_DISABLED; + float scale_3d = p_viewport->scale_3d; + if (Engine::get_singleton()->is_editor_hint()) { + // Ignore the 3D viewport render scaling inside of the editor. + // The Half Resolution 3D editor viewport option should be used instead. + scale_3d = 1.0; } - int width = p_viewport->size.width; - int height = p_viewport->size.height; - switch (scale_3d) { - case RS::VIEWPORT_SCALE_3D_75_PERCENT: { - width = (width * 3) / 4; - height = (height * 3) / 4; - }; break; - case RS::VIEWPORT_SCALE_3D_50_PERCENT: { - width = width >> 1; - height = height >> 1; - }; break; - case RS::VIEWPORT_SCALE_3D_33_PERCENT: { - width = width / 3; - height = height / 3; - }; break; - case RS::VIEWPORT_SCALE_3D_25_PERCENT: { - width = width >> 2; - height = height >> 2; - }; break; - default: - break; - } + // Clamp 3D rendering resolution to reasonable values supported on most hardware. + // This prevents freezing the engine or outright crashing on lower-end GPUs. + const int width = CLAMP(p_viewport->size.width * scale_3d, 1, 16384); + const int height = CLAMP(p_viewport->size.height * scale_3d, 1, 16384); RSG::scene->render_buffers_configure(p_viewport->render_buffers, p_viewport->render_target, width, height, p_viewport->msaa, p_viewport->screen_space_aa, p_viewport->use_debanding, p_viewport->get_view_count()); } } @@ -690,15 +674,18 @@ void RendererViewport::viewport_set_use_xr(RID p_viewport, bool p_use_xr) { _configure_3d_render_buffers(viewport); } -void RendererViewport::viewport_set_scale_3d(RID p_viewport, RenderingServer::ViewportScale3D p_scale_3d) { +void RendererViewport::viewport_set_scale_3d(RID p_viewport, float p_scale_3d) { Viewport *viewport = viewport_owner.get_or_null(p_viewport); ERR_FAIL_COND(!viewport); - if (viewport->scale_3d == p_scale_3d) { + // Clamp to reasonable values that are actually useful. + // Values above 2.0 don't serve a practical purpose since the viewport + // isn't displayed with mipmaps. + if (viewport->scale_3d == CLAMP(p_scale_3d, 0.1, 2.0)) { return; } - viewport->scale_3d = p_scale_3d; + viewport->scale_3d = CLAMP(p_scale_3d, 0.1, 2.0); _configure_3d_render_buffers(viewport); } diff --git a/servers/rendering/renderer_viewport.h b/servers/rendering/renderer_viewport.h index 41d818cf99..f6e6cc8e84 100644 --- a/servers/rendering/renderer_viewport.h +++ b/servers/rendering/renderer_viewport.h @@ -49,7 +49,7 @@ public: bool use_xr; /* use xr interface to override camera positioning and projection matrices and control output */ - RS::ViewportScale3D scale_3d = RenderingServer::VIEWPORT_SCALE_3D_DISABLED; + float scale_3d = 1.0; Size2i size; RID camera; @@ -207,7 +207,7 @@ public: void viewport_initialize(RID p_rid); void viewport_set_use_xr(RID p_viewport, bool p_use_xr); - void viewport_set_scale_3d(RID p_viewport, RenderingServer::ViewportScale3D p_scale_3d); + void viewport_set_scale_3d(RID p_viewport, float p_scale_3d); void viewport_set_size(RID p_viewport, int p_width, int p_height); diff --git a/servers/rendering/rendering_server_default.h b/servers/rendering/rendering_server_default.h index 49ade3c6a1..911d4c463b 100644 --- a/servers/rendering/rendering_server_default.h +++ b/servers/rendering/rendering_server_default.h @@ -526,7 +526,7 @@ public: FUNCRIDSPLIT(viewport) FUNC2(viewport_set_use_xr, RID, bool) - FUNC2(viewport_set_scale_3d, RID, ViewportScale3D) + FUNC2(viewport_set_scale_3d, RID, float) FUNC3(viewport_set_size, RID, int, int) FUNC2(viewport_set_active, RID, bool) |