From 91226ffef63f0370d49a487cb49dd527a533dd1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tur=C3=A1nszki=20J=C3=A1nos?= Date: Wed, 13 Aug 2025 09:25:32 +0200 Subject: [PATCH] HDR UI calibration slider + lua bindings #1204 --- .../ScriptingAPI-Documentation.md | 2 + Editor/GraphicsWindow.cpp | 17 ++++++- Editor/GraphicsWindow.h | 1 + WickedEngine/wiRenderPath2D_BindLua.cpp | 48 +++++++++++++++++++ WickedEngine/wiRenderPath2D_BindLua.h | 3 ++ WickedEngine/wiRenderPath3D_BindLua.cpp | 2 + WickedEngine/wiVersion.cpp | 2 +- 7 files changed, 73 insertions(+), 2 deletions(-) diff --git a/Content/Documentation/ScriptingAPI-Documentation.md b/Content/Documentation/ScriptingAPI-Documentation.md index 0ba567da9..d6ce38087 100644 --- a/Content/Documentation/ScriptingAPI-Documentation.md +++ b/Content/Documentation/ScriptingAPI-Documentation.md @@ -1817,6 +1817,8 @@ It can hold Sprites and SpriteFonts and can sort them by layers, update and rend - SetLayerOrder(string name, int order) - SetSpriteOrder(Sprite sprite, int order) - SetFontOrder(SpriteFont font, int order) +- GetHDRScaling() : float -- returns HDR scaling value used for SDR to HDR linear output mapping conversion (default: 9.0) +- SetHDRScaling(float value) -- sets HDR scaling value used for SDR to HDR linear output mapping conversion (default: 9.0) - CopyFrom(RenderPath other) -- copies everything from other renderpath into this #### RenderPath3D diff --git a/Editor/GraphicsWindow.cpp b/Editor/GraphicsWindow.cpp index 00413d5d9..cffeb527d 100644 --- a/Editor/GraphicsWindow.cpp +++ b/Editor/GraphicsWindow.cpp @@ -713,7 +713,7 @@ void GraphicsWindow::Create(EditorComponent* _editor) float mod_wid = 100; hdrcalibrationSlider.Create(0, 8, 1, 100, "HDR calibration: "); - hdrcalibrationSlider.SetTooltip("Set multiplier for HDR output, this only takes effect when swapchain output format is non-SRGB"); + hdrcalibrationSlider.SetTooltip("Set multiplier for HDR output for the 3D rendering, this only takes effect when swapchain output format is non-SRGB.\nNote: 3D content (RenderPath3D) is always rendered in HDR internally, this affects the output mapping for HDR display."); hdrcalibrationSlider.OnSlide([=](wi::gui::EventArgs args) { editor->renderPath->setHDRCalibration(args.fValue); editor->main->config.GetSection("graphics").Set("hdr_calibration", args.fValue); @@ -725,6 +725,19 @@ void GraphicsWindow::Create(EditorComponent* _editor) } AddWidget(&hdrcalibrationSlider); + hdrScalingSlider.Create(0.1f, 18, 1, 100, "HDR UI calibration: "); + hdrScalingSlider.SetTooltip("Set multiplier for HDR output for the 2D rendering, this only takes effect when swapchain output format is non-SRGB.\nNote: 2D content (RenderPath2D) is always rendered in SDR internally, this affects the output mapping for HDR display."); + hdrScalingSlider.OnSlide([=](wi::gui::EventArgs args) { + editor->SetHDRScaling(args.fValue); + editor->main->config.GetSection("graphics").Set("hdr_scaling", args.fValue); + editor->main->config.Commit(); + }); + if (editor->main->config.GetSection("graphics").Has("hdr_scaling")) + { + editor->SetHDRScaling(editor->main->config.GetSection("graphics").GetFloat("hdr_scaling")); + } + AddWidget(&hdrScalingSlider); + tonemapCombo.Create("Tonemap: "); tonemapCombo.SetTooltip("Choose tone mapping type"); tonemapCombo.SetScriptTip("RenderPath3D::SetTonemap(Tonemap value)"); @@ -1606,6 +1619,7 @@ void GraphicsWindow::UpdateData() ddgiZ.SetValue(std::to_string(scene.ddgi.grid_dimensions.z)); hdrcalibrationSlider.SetValue(editor->renderPath->getHDRCalibration()); + hdrScalingSlider.SetValue(editor->GetHDRScaling()); occlusionCullingCheckBox.SetCheck(wi::renderer::GetOcclusionCullingEnabled()); GIBoostSlider.SetValue(wi::renderer::GetGIBoost()); visibilityComputeShadingCheckBox.SetCheck(editor->renderPath->getVisibilityComputeShadingEnabled()); @@ -1724,6 +1738,7 @@ void GraphicsWindow::ResizeLayout() layout.add_right(vsyncCheckBox); layout.add(swapchainComboBox); layout.add(hdrcalibrationSlider); + layout.add(hdrScalingSlider); layout.add(renderPathComboBox); layout.add(resolutionScaleSlider); layout.add(streamingSlider); diff --git a/Editor/GraphicsWindow.h b/Editor/GraphicsWindow.h index edfdb149d..022d7c9c8 100644 --- a/Editor/GraphicsWindow.h +++ b/Editor/GraphicsWindow.h @@ -11,6 +11,7 @@ public: wi::gui::CheckBox vsyncCheckBox; wi::gui::ComboBox swapchainComboBox; wi::gui::Slider hdrcalibrationSlider; + wi::gui::Slider hdrScalingSlider; wi::gui::ComboBox renderPathComboBox; wi::gui::Slider pathTraceTargetSlider; wi::gui::Label pathTraceStatisticsLabel; diff --git a/WickedEngine/wiRenderPath2D_BindLua.cpp b/WickedEngine/wiRenderPath2D_BindLua.cpp index 1a5d41516..7ff1f67bc 100644 --- a/WickedEngine/wiRenderPath2D_BindLua.cpp +++ b/WickedEngine/wiRenderPath2D_BindLua.cpp @@ -24,6 +24,8 @@ namespace wi::lua lunamethod(RenderPath2D_BindLua, SetLayerOrder), lunamethod(RenderPath2D_BindLua, SetSpriteOrder), lunamethod(RenderPath2D_BindLua, SetFontOrder), + lunamethod(RenderPath2D_BindLua, GetHDRScaling), + lunamethod(RenderPath2D_BindLua, SetHDRScaling), lunamethod(RenderPath_BindLua, GetLayerMask), lunamethod(RenderPath_BindLua, SetLayerMask), @@ -460,6 +462,52 @@ namespace wi::lua return 0; } + int RenderPath2D_BindLua::GetHDRScaling(lua_State* L) + { + if (component == nullptr) + { + wi::lua::SError(L, "GetHDRScaling() component is empty!"); + return 0; + } + RenderPath2D* ccomp = dynamic_cast(component); + if (ccomp != nullptr) + { + wi::lua::SSetFloat(L, ccomp->GetHDRScaling()); + return 1; + } + else + { + wi::lua::SError(L, "SetHDRScaling(float value) not a RenderPath2D!"); + } + return 0; + } + int RenderPath2D_BindLua::SetHDRScaling(lua_State* L) + { + if (component == nullptr) + { + wi::lua::SError(L, "SetHDRScaling(float value) component is empty!"); + return 0; + } + int argc = wi::lua::SGetArgCount(L); + if (argc > 1) + { + RenderPath2D* ccomp = dynamic_cast(component); + if (ccomp != nullptr) + { + ccomp->SetHDRScaling(wi::lua::SGetFloat(L, 1)); + } + else + { + wi::lua::SError(L, "SetHDRScaling(float value) not a RenderPath2D!"); + } + } + else + { + wi::lua::SError(L, "SetHDRScaling(float value) not enough arguments!"); + } + return 0; + } + int RenderPath2D_BindLua::CopyFrom(lua_State* L) { if (component == nullptr) diff --git a/WickedEngine/wiRenderPath2D_BindLua.h b/WickedEngine/wiRenderPath2D_BindLua.h index 5b5e29475..bef06f025 100644 --- a/WickedEngine/wiRenderPath2D_BindLua.h +++ b/WickedEngine/wiRenderPath2D_BindLua.h @@ -44,6 +44,9 @@ namespace wi::lua int SetSpriteOrder(lua_State* L); int SetFontOrder(lua_State* L); + int GetHDRScaling(lua_State* L); + int SetHDRScaling(lua_State* L); + int CopyFrom(lua_State* L); static void Bind(); diff --git a/WickedEngine/wiRenderPath3D_BindLua.cpp b/WickedEngine/wiRenderPath3D_BindLua.cpp index eedf5ff97..1a9dad75e 100644 --- a/WickedEngine/wiRenderPath3D_BindLua.cpp +++ b/WickedEngine/wiRenderPath3D_BindLua.cpp @@ -19,6 +19,8 @@ namespace wi::lua lunamethod(RenderPath2D_BindLua, SetLayerOrder), lunamethod(RenderPath2D_BindLua, SetSpriteOrder), lunamethod(RenderPath2D_BindLua, SetFontOrder), + lunamethod(RenderPath2D_BindLua, GetHDRScaling), + lunamethod(RenderPath2D_BindLua, SetHDRScaling), lunamethod(RenderPath_BindLua, GetLayerMask), lunamethod(RenderPath_BindLua, SetLayerMask), diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index 84a131417..48e1d2359 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wi::version // minor features, major updates, breaking compatibility changes const int minor = 71; // minor bug fixes, alterations, refactors, updates - const int revision = 816; + const int revision = 817; const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);