diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml
index 2f8905d6bff..170e8290b87 100644
--- a/doc/classes/ProjectSettings.xml
+++ b/doc/classes/ProjectSettings.xml
@@ -1352,12 +1352,17 @@
[b]Note:[/b] Generally you should only use this option if you encounter bugs when it is set to [code]false[/code], i.e. there are problems with the default method.
- If [code]true[/code], allocates the main framebuffer with high dynamic range. High dynamic range allows the use of [Color] values greater than 1.
+ If [code]true[/code], allocates the root [Viewport]'s framebuffer with high dynamic range. High dynamic range allows the use of [Color] values greater than 1.
[b]Note:[/b] Only available on the GLES3 backend.
Lower-end override for [member rendering/quality/depth/hdr] on mobile devices, due to performance concerns or driver support.
+
+ If [code]true[/code], allocates the root [Viewport]'s framebuffer with full floating-point precision (32-bit) instead of half floating-point precision (16-bit). Only effective when [member rendering/quality/depth/hdr] is also enabled.
+ [b]Note:[/b] Enabling this setting does not improve rendering quality. Using full floating-point precision is slower, and is generally only needed for advanced shaders that require a high level of precision. To reduce banding, enable [member rendering/quality/filters/use_debanding] instead.
+ [b]Note:[/b] Only available on the GLES3 backend.
+
Disables depth pre-pass for some GPU vendors (usually mobile), as their architecture already does this.
diff --git a/doc/classes/Viewport.xml b/doc/classes/Viewport.xml
index 69b03e51cbf..070717c8e4d 100644
--- a/doc/classes/Viewport.xml
+++ b/doc/classes/Viewport.xml
@@ -225,8 +225,9 @@
- If [code]true[/code], the viewport rendering will receive benefits from High Dynamic Range algorithm. High Dynamic Range allows the viewport to receive values that are outside the 0-1 range. In Godot HDR uses 16 bits, meaning it does not store the full range of a floating point number.
+ If [code]true[/code], the viewport rendering will receive benefits from High Dynamic Range algorithm. High Dynamic Range allows the viewport to receive values that are outside the 0-1 range. In Godot, HDR uses half floating-point precision (16-bit) by default. To use full floating-point precision (32-bit), enable [member use_32_bpc_depth].
[b]Note:[/b] Requires [member usage] to be set to [constant USAGE_3D] or [constant USAGE_3D_NO_EFFECTS], since HDR is not supported for 2D.
+ [b]Note:[/b] Only available on the GLES3 backend.
If [code]true[/code], the result after 3D rendering will not have a linear to sRGB color conversion applied. This is important when the viewport is used as a render target where the result is used as a texture on a 3D object rendered in another viewport. It is also important if the viewport is used to create data that is not color based (noise, heightmaps, pickmaps, etc.). Do not enable this when the viewport is used as a texture on a 2D object or if the viewport is your final output. For the GLES2 driver this will convert the sRGB output to linear, this should only be used for VR plugins that require input in linear color space!
@@ -284,6 +285,11 @@
The rendering mode of viewport.
+
+ If [code]true[/code], allocates the viewport's framebuffer with full floating-point precision (32-bit) instead of half floating-point precision (16-bit). Only effective when [member hdr] is also enabled.
+ [b]Note:[/b] Enabling this setting does not improve rendering quality. Using full floating-point precision is slower, and is generally only needed for advanced shaders that require a high level of precision. To reduce banding, enable [member debanding] instead.
+ [b]Note:[/b] Only available on the GLES3 backend.
+
The custom [World] which can be used as 3D environment source.
diff --git a/drivers/gles3/rasterizer_storage_gles3.cpp b/drivers/gles3/rasterizer_storage_gles3.cpp
index 438af1b15b4..5c0d5a16f0b 100644
--- a/drivers/gles3/rasterizer_storage_gles3.cpp
+++ b/drivers/gles3/rasterizer_storage_gles3.cpp
@@ -6905,8 +6905,7 @@ void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt) {
GLuint color_type;
Image::Format image_format;
- bool hdr = rt->flags[RENDER_TARGET_HDR] && config.framebuffer_half_float_supported;
- //hdr = false;
+ const bool hdr = rt->flags[RENDER_TARGET_HDR] && config.framebuffer_half_float_supported;
if (!hdr || rt->flags[RENDER_TARGET_NO_3D]) {
if (rt->flags[RENDER_TARGET_NO_3D_EFFECTS] && !rt->flags[RENDER_TARGET_TRANSPARENT]) {
@@ -6923,10 +6922,21 @@ void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt) {
image_format = Image::FORMAT_RGBA8;
}
} else {
- color_internal_format = GL_RGBA16F;
- color_format = GL_RGBA;
- color_type = GL_HALF_FLOAT;
- image_format = Image::FORMAT_RGBAH;
+ // HDR enabled.
+ if (rt->flags[RENDER_TARGET_USE_32_BPC_DEPTH]) {
+ // 32 bpc. Can be useful for advanced shaders, but should not be used
+ // for general-purpose rendering as it's slower.
+ color_internal_format = GL_RGBA32F;
+ color_format = GL_RGBA;
+ color_type = GL_FLOAT;
+ image_format = Image::FORMAT_RGBAF;
+ } else {
+ // 16 bpc. This is the default HDR mode.
+ color_internal_format = GL_RGBA16F;
+ color_format = GL_RGBA;
+ color_type = GL_HALF_FLOAT;
+ image_format = Image::FORMAT_RGBAH;
+ }
}
{
@@ -7469,6 +7479,7 @@ void RasterizerStorageGLES3::render_target_set_flag(RID p_render_target, RenderT
switch (p_flag) {
case RENDER_TARGET_HDR:
+ case RENDER_TARGET_USE_32_BPC_DEPTH:
case RENDER_TARGET_NO_3D:
case RENDER_TARGET_NO_SAMPLING:
case RENDER_TARGET_NO_3D_EFFECTS: {
diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp
index ba3fc6eb0c0..68cc3e538d9 100644
--- a/editor/plugins/spatial_editor_plugin.cpp
+++ b/editor/plugins/spatial_editor_plugin.cpp
@@ -2617,9 +2617,12 @@ void SpatialEditorViewport::_notification(int p_what) {
float sharpen_intensity = ProjectSettings::get_singleton()->get("rendering/quality/filters/sharpen_intensity");
viewport->set_sharpen_intensity(sharpen_intensity);
- bool hdr = ProjectSettings::get_singleton()->get("rendering/quality/depth/hdr");
+ const bool hdr = ProjectSettings::get_singleton()->get("rendering/quality/depth/hdr");
viewport->set_hdr(hdr);
+ const bool use_32_bpc_depth = ProjectSettings::get_singleton()->get("rendering/quality/depth/use_32_bpc_depth");
+ viewport->set_use_32_bpc_depth(use_32_bpc_depth);
+
bool show_info = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_INFORMATION));
info_label->set_visible(show_info);
diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp
index 42c4cf993a2..8155b5ad937 100644
--- a/scene/main/scene_tree.cpp
+++ b/scene/main/scene_tree.cpp
@@ -2077,12 +2077,17 @@ SceneTree::SceneTree() {
const float sharpen_intensity = GLOBAL_GET("rendering/quality/filters/sharpen_intensity");
root->set_sharpen_intensity(sharpen_intensity);
- GLOBAL_DEF_RST("rendering/quality/depth/hdr", true);
+ GLOBAL_DEF("rendering/quality/depth/hdr", true);
GLOBAL_DEF("rendering/quality/depth/hdr.mobile", false);
- bool hdr = GLOBAL_GET("rendering/quality/depth/hdr");
+ const bool hdr = GLOBAL_GET("rendering/quality/depth/hdr");
root->set_hdr(hdr);
+ GLOBAL_DEF("rendering/quality/depth/use_32_bpc_depth", false);
+
+ const bool use_32_bpc_depth = GLOBAL_GET("rendering/quality/depth/use_32_bpc_depth");
+ root->set_use_32_bpc_depth(use_32_bpc_depth);
+
VS::get_singleton()->scenario_set_reflection_atlas_size(root->get_world()->get_scenario(), ref_atlas_size, ref_atlas_subdiv);
{ //load default fallback environment
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index 55594a72694..147ca1593e5 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -3071,6 +3071,19 @@ bool Viewport::get_hdr() const {
return hdr;
}
+void Viewport::set_use_32_bpc_depth(bool p_enable) {
+ if (use_32_bpc_depth == p_enable) {
+ return;
+ }
+
+ use_32_bpc_depth = p_enable;
+ VS::get_singleton()->viewport_set_use_32_bpc_depth(viewport, p_enable);
+}
+
+bool Viewport::is_using_32_bpc_depth() const {
+ return use_32_bpc_depth;
+}
+
void Viewport::set_usage(Usage p_usage) {
usage = p_usage;
VS::get_singleton()->viewport_set_usage(viewport, VS::ViewportUsage(p_usage));
@@ -3133,7 +3146,7 @@ bool Viewport::is_handling_input_locally() const {
}
void Viewport::_validate_property(PropertyInfo &property) const {
- if (VisualServer::get_singleton()->is_low_end() && property.name == "hdr") {
+ if (VisualServer::get_singleton()->is_low_end() && (property.name == "hdr" || property.name == "use_32_bpc_depth")) {
property.usage = PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL;
}
}
@@ -3196,6 +3209,9 @@ void Viewport::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_hdr", "enable"), &Viewport::set_hdr);
ClassDB::bind_method(D_METHOD("get_hdr"), &Viewport::get_hdr);
+ ClassDB::bind_method(D_METHOD("set_use_32_bpc_depth", "enable"), &Viewport::set_use_32_bpc_depth);
+ ClassDB::bind_method(D_METHOD("get_use_32_bpc_depth"), &Viewport::is_using_32_bpc_depth);
+
ClassDB::bind_method(D_METHOD("set_usage", "usage"), &Viewport::set_usage);
ClassDB::bind_method(D_METHOD("get_usage"), &Viewport::get_usage);
@@ -3287,6 +3303,7 @@ void Viewport::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "debanding"), "set_use_debanding", "get_use_debanding");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "sharpen_intensity"), "set_sharpen_intensity", "get_sharpen_intensity");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "hdr"), "set_hdr", "get_hdr");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_32_bpc_depth"), "set_use_32_bpc_depth", "get_use_32_bpc_depth");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "disable_3d"), "set_disable_3d", "is_3d_disabled");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "keep_3d_linear"), "set_keep_3d_linear", "get_keep_3d_linear");
ADD_PROPERTY(PropertyInfo(Variant::INT, "usage", PROPERTY_HINT_ENUM, "2D,2D Without Sampling,3D,3D Without Effects"), "set_usage", "get_usage");
@@ -3447,6 +3464,7 @@ Viewport::Viewport() {
use_debanding = false;
sharpen_intensity = 0.0;
hdr = true;
+ use_32_bpc_depth = false;
usage = USAGE_3D;
debug_draw = DEBUG_DRAW_DISABLED;
diff --git a/scene/main/viewport.h b/scene/main/viewport.h
index 77890f8147d..6803397f174 100644
--- a/scene/main/viewport.h
+++ b/scene/main/viewport.h
@@ -286,6 +286,7 @@ private:
bool use_debanding;
float sharpen_intensity;
bool hdr;
+ bool use_32_bpc_depth;
Ref default_texture;
Set viewport_textures;
@@ -517,6 +518,9 @@ public:
void set_hdr(bool p_hdr);
bool get_hdr() const;
+ void set_use_32_bpc_depth(bool p_enable);
+ bool is_using_32_bpc_depth() const;
+
Vector2 get_camera_coords(const Vector2 &p_viewport_coords) const;
Vector2 get_camera_rect_size() const;
diff --git a/servers/visual/rasterizer.h b/servers/visual/rasterizer.h
index 26c2b35b082..f3028240b7c 100644
--- a/servers/visual/rasterizer.h
+++ b/servers/visual/rasterizer.h
@@ -569,6 +569,7 @@ public:
RENDER_TARGET_HDR,
RENDER_TARGET_KEEP_3D_LINEAR,
RENDER_TARGET_DIRECT_TO_SCREEN,
+ RENDER_TARGET_USE_32_BPC_DEPTH,
RENDER_TARGET_FLAG_MAX
};
diff --git a/servers/visual/visual_server_raster.h b/servers/visual/visual_server_raster.h
index 90b3b3cdfa9..53e1d100a3a 100644
--- a/servers/visual/visual_server_raster.h
+++ b/servers/visual/visual_server_raster.h
@@ -492,6 +492,7 @@ public:
BIND2(viewport_set_use_debanding, RID, bool)
BIND2(viewport_set_sharpen_intensity, RID, float)
BIND2(viewport_set_hdr, RID, bool)
+ BIND2(viewport_set_use_32_bpc_depth, RID, bool)
BIND2(viewport_set_usage, RID, ViewportUsage)
BIND2R(int, viewport_get_render_info, RID, ViewportRenderInfo)
diff --git a/servers/visual/visual_server_viewport.cpp b/servers/visual/visual_server_viewport.cpp
index 0aec6521459..982d3219dd4 100644
--- a/servers/visual/visual_server_viewport.cpp
+++ b/servers/visual/visual_server_viewport.cpp
@@ -668,6 +668,13 @@ void VisualServerViewport::viewport_set_hdr(RID p_viewport, bool p_enabled) {
VSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_HDR, p_enabled);
}
+void VisualServerViewport::viewport_set_use_32_bpc_depth(RID p_viewport, bool p_enabled) {
+ Viewport *viewport = viewport_owner.getornull(p_viewport);
+ ERR_FAIL_COND(!viewport);
+
+ VSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_USE_32_BPC_DEPTH, p_enabled);
+}
+
void VisualServerViewport::viewport_set_usage(RID p_viewport, VS::ViewportUsage p_usage) {
Viewport *viewport = viewport_owner.getornull(p_viewport);
ERR_FAIL_COND(!viewport);
diff --git a/servers/visual/visual_server_viewport.h b/servers/visual/visual_server_viewport.h
index 201d1c70e63..adcef9f97d0 100644
--- a/servers/visual/visual_server_viewport.h
+++ b/servers/visual/visual_server_viewport.h
@@ -190,6 +190,7 @@ public:
void viewport_set_use_debanding(RID p_viewport, bool p_debanding);
void viewport_set_sharpen_intensity(RID p_viewport, float p_intensity);
void viewport_set_hdr(RID p_viewport, bool p_enabled);
+ void viewport_set_use_32_bpc_depth(RID p_viewport, bool p_enabled);
void viewport_set_usage(RID p_viewport, VS::ViewportUsage p_usage);
virtual int viewport_get_render_info(RID p_viewport, VS::ViewportRenderInfo p_info);
diff --git a/servers/visual/visual_server_wrap_mt.h b/servers/visual/visual_server_wrap_mt.h
index 0552606f8a6..c8fa88c230a 100644
--- a/servers/visual/visual_server_wrap_mt.h
+++ b/servers/visual/visual_server_wrap_mt.h
@@ -420,6 +420,7 @@ public:
FUNC2(viewport_set_use_debanding, RID, bool)
FUNC2(viewport_set_sharpen_intensity, RID, float)
FUNC2(viewport_set_hdr, RID, bool)
+ FUNC2(viewport_set_use_32_bpc_depth, RID, bool)
FUNC2(viewport_set_usage, RID, ViewportUsage)
//this passes directly to avoid stalling, but it's pretty dangerous, so don't call after freeing a viewport
diff --git a/servers/visual_server.h b/servers/visual_server.h
index f257959d18e..d42c1dbb060 100644
--- a/servers/visual_server.h
+++ b/servers/visual_server.h
@@ -706,6 +706,7 @@ public:
};
virtual void viewport_set_hdr(RID p_viewport, bool p_enabled) = 0;
+ virtual void viewport_set_use_32_bpc_depth(RID p_viewport, bool p_enabled) = 0;
virtual void viewport_set_usage(RID p_viewport, ViewportUsage p_usage) = 0;
enum ViewportRenderInfo {