From 20d14b57c1c220bb73d1e7f0f86a565758836841 Mon Sep 17 00:00:00 2001 From: Alexei Kotov Date: Sat, 29 Nov 2025 19:44:45 +0300 Subject: [PATCH] Expose sunlight direction to post-processing (#8826) --- CMakeLists.txt | 2 +- apps/openmw/mwrender/renderingmanager.cpp | 12 +++++------ components/fx/stateupdater.hpp | 21 ++++++++++++++----- .../source/reference/postprocessing/omwfx.rst | 6 ++++-- 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f7b747d53e..ac7e6a5dfa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -83,7 +83,7 @@ set(OPENMW_VERSION_MAJOR 0) set(OPENMW_VERSION_MINOR 51) set(OPENMW_VERSION_RELEASE 0) set(OPENMW_LUA_API_REVISION 104) -set(OPENMW_POSTPROCESSING_API_REVISION 3) +set(OPENMW_POSTPROCESSING_API_REVISION 4) set(OPENMW_VERSION_COMMITHASH "") set(OPENMW_VERSION_TAGHASH "") diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 8b62daba4a..b23f4c11b8 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -739,6 +739,7 @@ namespace MWRender static const osg::Vec4f interiorSunPos = osg::Vec4f(-1.f, osg::DegreesToRadians(45.f), osg::DegreesToRadians(45.f), 0.f); mPostProcessor->getStateUpdater()->setSunPos(interiorSunPos, false); + mPostProcessor->getStateUpdater()->setSunVec(-interiorSunPos); mSunLight->setPosition(interiorSunPos); } @@ -756,19 +757,18 @@ namespace MWRender { osg::Vec3f position = -direction; - // The sun is not synchronized with the sunlight because reasons - // This is based on exterior sun orbit and won't make sense for interiors, see WeatherManager::update + // This is based on the exterior sun orbit and won't make sense for interiors, see WeatherManager::update position.z() = 400.f - std::abs(position.x()); + // The sun is not always synchronized with the sunlight because reasons + const osg::Vec3f sunlightPos = Settings::shaders().mMatchSunlightToSun ? position : -direction; // need to wrap this in a StateUpdater? - if (Settings::shaders().mMatchSunlightToSun) - mSunLight->setPosition(osg::Vec4f(position, 0.f)); - else - mSunLight->setPosition(osg::Vec4f(-direction, 0.f)); + mSunLight->setPosition(osg::Vec4f(sunlightPos, 0.f)); mSky->setSunDirection(position); mPostProcessor->getStateUpdater()->setSunPos(osg::Vec4f(position, 0.f), mNight); + mPostProcessor->getStateUpdater()->setSunVec(osg::Vec4f(-sunlightPos, 0.f)); } void RenderingManager::addCell(const MWWorld::CellStore* store) diff --git a/components/fx/stateupdater.hpp b/components/fx/stateupdater.hpp index a3b2755fde..354df49377 100644 --- a/components/fx/stateupdater.hpp +++ b/components/fx/stateupdater.hpp @@ -49,6 +49,12 @@ namespace Fx mData.get().z() *= -1.f; } + void setSunVec(const osg::Vec4f& vec) + { + mData.get() = vec; + mData.get().normalize(); + } + void setResolution(const osg::Vec2f& size) { mData.get() = size; @@ -170,6 +176,11 @@ namespace Fx static constexpr std::string_view sName = "sunPos"; }; + struct SunVec : Std140::Vec4 + { + static constexpr std::string_view sName = "sunVec"; + }; + struct Resolution : Std140::Vec2 { static constexpr std::string_view sName = "resolution"; @@ -270,11 +281,11 @@ namespace Fx static constexpr std::string_view sName = "isInterior"; }; - using UniformData - = Std140::UBO; + using UniformData = Std140::UBO; UniformData mData; bool mUseUBO; diff --git a/docs/source/reference/postprocessing/omwfx.rst b/docs/source/reference/postprocessing/omwfx.rst index 0efb8f408c..939f3628ed 100644 --- a/docs/source/reference/postprocessing/omwfx.rst +++ b/docs/source/reference/postprocessing/omwfx.rst @@ -73,9 +73,11 @@ Builtin Uniforms +-------------+------------------------------+--------------------------------------------------+ | vec4 | ``omw.sunColor`` | The RGBA color of sun | +-------------+------------------------------+--------------------------------------------------+ -| vec4 | ``omw.sunPos`` | The normalized sun direction | +| vec4 | ``omw.sunPos`` | The normalized sun disc position | | | | | -| | | When the sun is set `omw.sunpos.z` is negated | +| | | When the sun is set `omw.sunPos.z` is negated | ++-------------+------------------------------+--------------------------------------------------+ +| vec4 | ``omw.sunVec`` | The normalized sunlight direction | +-------------+------------------------------+--------------------------------------------------+ | vec2 | ``omw.resolution`` | The render target's resolution | +-------------+------------------------------+--------------------------------------------------+