summaryrefslogtreecommitdiff
path: root/servers
diff options
context:
space:
mode:
Diffstat (limited to 'servers')
-rw-r--r--servers/rendering/renderer_viewport.cpp43
-rw-r--r--servers/rendering/renderer_viewport.h4
-rw-r--r--servers/rendering/rendering_server_default.h2
-rw-r--r--servers/rendering_server.cpp12
-rw-r--r--servers/rendering_server.h12
5 files changed, 22 insertions, 51 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)
diff --git a/servers/rendering_server.cpp b/servers/rendering_server.cpp
index 93919a5ec6..7e66ddbb0f 100644
--- a/servers/rendering_server.cpp
+++ b/servers/rendering_server.cpp
@@ -2269,12 +2269,6 @@ void RenderingServer::_bind_methods() {
BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_CLUSTER_REFLECTION_PROBES);
BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_OCCLUDERS);
- BIND_ENUM_CONSTANT(VIEWPORT_SCALE_3D_DISABLED);
- BIND_ENUM_CONSTANT(VIEWPORT_SCALE_3D_75_PERCENT);
- BIND_ENUM_CONSTANT(VIEWPORT_SCALE_3D_50_PERCENT);
- BIND_ENUM_CONSTANT(VIEWPORT_SCALE_3D_33_PERCENT);
- BIND_ENUM_CONSTANT(VIEWPORT_SCALE_3D_25_PERCENT);
-
/* SKY API */
ClassDB::bind_method(D_METHOD("sky_create"), &RenderingServer::sky_create);
@@ -2817,11 +2811,11 @@ RenderingServer::RenderingServer() {
"rendering/vulkan/rendering/back_end",
PROPERTY_HINT_ENUM, "Forward Clustered (Supports Desktop Only),Forward Mobile (Supports Desktop and Mobile)"));
- GLOBAL_DEF("rendering/3d/viewport/scale", 0);
+ GLOBAL_DEF("rendering/3d/viewport/scale", 1.0);
ProjectSettings::get_singleton()->set_custom_property_info("rendering/3d/viewport/scale",
- PropertyInfo(Variant::INT,
+ PropertyInfo(Variant::FLOAT,
"rendering/3d/viewport/scale",
- PROPERTY_HINT_ENUM, "Disabled,75%,50%,33%,25%"));
+ PROPERTY_HINT_RANGE, "0.25,2.0,0.01"));
GLOBAL_DEF("rendering/shader_compiler/shader_cache/enabled", true);
GLOBAL_DEF("rendering/shader_compiler/shader_cache/compress", true);
diff --git a/servers/rendering_server.h b/servers/rendering_server.h
index 2dffa6bc75..b50da66d03 100644
--- a/servers/rendering_server.h
+++ b/servers/rendering_server.h
@@ -752,19 +752,10 @@ public:
CANVAS_ITEM_TEXTURE_REPEAT_MAX,
};
- enum ViewportScale3D {
- VIEWPORT_SCALE_3D_DISABLED,
- VIEWPORT_SCALE_3D_75_PERCENT,
- VIEWPORT_SCALE_3D_50_PERCENT,
- VIEWPORT_SCALE_3D_33_PERCENT,
- VIEWPORT_SCALE_3D_25_PERCENT,
- VIEWPORT_SCALE_3D_MAX,
- };
-
virtual RID viewport_create() = 0;
virtual void viewport_set_use_xr(RID p_viewport, bool p_use_xr) = 0;
- virtual void viewport_set_scale_3d(RID p_viewport, ViewportScale3D p_scale_3d) = 0;
+ virtual void viewport_set_scale_3d(RID p_viewport, float p_scale_3d) = 0;
virtual void viewport_set_size(RID p_viewport, int p_width, int p_height) = 0;
virtual void viewport_set_active(RID p_viewport, bool p_active) = 0;
virtual void viewport_set_parent_viewport(RID p_viewport, RID p_parent_viewport) = 0;
@@ -1553,7 +1544,6 @@ VARIANT_ENUM_CAST(RenderingServer::ViewportDebugDraw);
VARIANT_ENUM_CAST(RenderingServer::ViewportOcclusionCullingBuildQuality);
VARIANT_ENUM_CAST(RenderingServer::ViewportSDFOversize);
VARIANT_ENUM_CAST(RenderingServer::ViewportSDFScale);
-VARIANT_ENUM_CAST(RenderingServer::ViewportScale3D);
VARIANT_ENUM_CAST(RenderingServer::SkyMode);
VARIANT_ENUM_CAST(RenderingServer::EnvironmentBG);
VARIANT_ENUM_CAST(RenderingServer::EnvironmentAmbientSource);