From e0062a6ff168ac3b2a5bb742f9bfae7746ed5776 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 13 Jan 2026 09:07:22 +0100 Subject: [PATCH] Add `RenderColorFormat` option to graphics settings for rendering pipeline buffer format #3618 --- Source/Editor/GUI/EnumComboBox.cs | 9 +++++++ Source/Engine/Core/Config/GraphicsSettings.h | 21 +++++++++++++++ Source/Engine/Graphics/RenderBuffers.cpp | 26 +++++++++++++++++-- .../Attributes/Editor/EnumDisplayAttribute.cs | 2 +- 4 files changed, 55 insertions(+), 3 deletions(-) diff --git a/Source/Editor/GUI/EnumComboBox.cs b/Source/Editor/GUI/EnumComboBox.cs index 2c2d338a4..f327f3e17 100644 --- a/Source/Editor/GUI/EnumComboBox.cs +++ b/Source/Editor/GUI/EnumComboBox.cs @@ -242,6 +242,15 @@ namespace FlaxEditor.GUI { FieldInfo[] fields = type.GetFields(); entries.Capacity = Mathf.Max(fields.Length - 1, entries.Capacity); + if (formatMode == EnumDisplayAttribute.FormatMode.Default) + { + // Override display mode from enum itself + var attr = type.GetCustomAttribute(); + if (attr != null) + { + formatMode = attr.Mode; + } + } for (int i = 0; i < fields.Length; i++) { var field = fields[i]; diff --git a/Source/Engine/Core/Config/GraphicsSettings.h b/Source/Engine/Core/Config/GraphicsSettings.h index a620cee23..9106b406b 100644 --- a/Source/Engine/Core/Config/GraphicsSettings.h +++ b/Source/Engine/Core/Config/GraphicsSettings.h @@ -16,6 +16,21 @@ API_CLASS(sealed, Namespace="FlaxEditor.Content.Settings", NoConstructor) class API_AUTO_SERIALIZATION(); DECLARE_SCRIPTING_TYPE_MINIMAL(GraphicsSettings); +public: + /// + /// List of pixel formats that can be used by the rendering pipeline (for light buffer and post-processing). + /// + API_ENUM(Attributes="EnumDisplay(EnumDisplayAttribute.FormatMode.None)") + enum class RenderColorFormats + { + // HDR 32-bit buffer without alpha channel support. Offers good performance but might result in colors banding or shift towards yellowish colors due to low data precision. + R11G11B10, + // LDR 32-bit buffer with alpha channel support. Offers good performance but doesn't support High Dynamic Range rendering. + R8G8B8A8, + // HDR 64-bit buffer with alpha channel support. Offers very good quality for wide range of colors but requires more memory. + R16G16B16A16, + }; + public: /// /// Enables rendering synchronization with the refresh rate of the display device to avoid "tearing" artifacts. @@ -135,6 +150,12 @@ public: API_FIELD(Attributes="EditorOrder(3000), EditorDisplay(\"Colors\")") bool GammaColorSpace = true; + /// + /// Pixel format used by the rendering pipeline (for light buffer and post-processing). + /// + API_FIELD(Attributes="EditorOrder(3010), EditorDisplay(\"Colors\")") + RenderColorFormats RenderColorFormat = RenderColorFormats::R11G11B10; + public: /// /// The default Post Process settings. Can be overriden by PostFxVolume on a level locally, per camera or for a whole map. diff --git a/Source/Engine/Graphics/RenderBuffers.cpp b/Source/Engine/Graphics/RenderBuffers.cpp index 931312aa5..22eace596 100644 --- a/Source/Engine/Graphics/RenderBuffers.cpp +++ b/Source/Engine/Graphics/RenderBuffers.cpp @@ -1,10 +1,11 @@ // Copyright (c) Wojciech Figat. All rights reserved. #include "RenderBuffers.h" +#include "Engine/Core/Config/GraphicsSettings.h" #include "Engine/Graphics/GPUDevice.h" -#include "Engine/Renderer/Utils/MultiScaler.h" #include "Engine/Graphics/GPULimits.h" #include "Engine/Graphics/RenderTargetPool.h" +#include "Engine/Renderer/Utils/MultiScaler.h" #include "Engine/Engine/Engine.h" // How many frames keep cached buffers for temporal or optional effects? @@ -113,8 +114,29 @@ GPUTexture* RenderBuffers::RequestHalfResDepth(GPUContext* context) PixelFormat RenderBuffers::GetOutputFormat() const { + auto colorFormat = GraphicsSettings::Get()->RenderColorFormat; // TODO: fix incorrect alpha leaking into reflections on PS5 with R11G11B10_Float - return _useAlpha || PLATFORM_PS5 ? PixelFormat::R16G16B16A16_Float : PixelFormat::R11G11B10_Float; + if (_useAlpha || PLATFORM_PS5) + { + // Promote to format when alpha when needed + switch (colorFormat) + { + case GraphicsSettings::RenderColorFormats::R11G11B10: + colorFormat = GraphicsSettings::RenderColorFormats::R16G16B16A16; + break; + } + } + switch (colorFormat) + { + case GraphicsSettings::RenderColorFormats::R11G11B10: + return PixelFormat::R11G11B10_Float; + case GraphicsSettings::RenderColorFormats::R8G8B8A8: + return PixelFormat::R8G8B8A8_UNorm; + case GraphicsSettings::RenderColorFormats::R16G16B16A16: + return PixelFormat::R16G16B16A16_Float; + default: + return PixelFormat::R32G32B32A32_Float; + } } bool RenderBuffers::GetUseAlpha() const diff --git a/Source/Engine/Scripting/Attributes/Editor/EnumDisplayAttribute.cs b/Source/Engine/Scripting/Attributes/Editor/EnumDisplayAttribute.cs index 45805e7d3..686d8372d 100644 --- a/Source/Engine/Scripting/Attributes/Editor/EnumDisplayAttribute.cs +++ b/Source/Engine/Scripting/Attributes/Editor/EnumDisplayAttribute.cs @@ -8,7 +8,7 @@ namespace FlaxEngine /// Allows to change enum type field or property display mode in the editor. /// /// - [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)] + [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Enum)] public sealed class EnumDisplayAttribute : Attribute { ///