Skip to content

Commit 20d14b5

Browse files
committed
Expose sunlight direction to post-processing (#8826)
1 parent 35e2750 commit 20d14b5

File tree

4 files changed

+27
-14
lines changed

4 files changed

+27
-14
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ set(OPENMW_VERSION_MAJOR 0)
8383
set(OPENMW_VERSION_MINOR 51)
8484
set(OPENMW_VERSION_RELEASE 0)
8585
set(OPENMW_LUA_API_REVISION 104)
86-
set(OPENMW_POSTPROCESSING_API_REVISION 3)
86+
set(OPENMW_POSTPROCESSING_API_REVISION 4)
8787

8888
set(OPENMW_VERSION_COMMITHASH "")
8989
set(OPENMW_VERSION_TAGHASH "")

apps/openmw/mwrender/renderingmanager.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,7 @@ namespace MWRender
739739
static const osg::Vec4f interiorSunPos
740740
= osg::Vec4f(-1.f, osg::DegreesToRadians(45.f), osg::DegreesToRadians(45.f), 0.f);
741741
mPostProcessor->getStateUpdater()->setSunPos(interiorSunPos, false);
742+
mPostProcessor->getStateUpdater()->setSunVec(-interiorSunPos);
742743
mSunLight->setPosition(interiorSunPos);
743744
}
744745

@@ -756,19 +757,18 @@ namespace MWRender
756757
{
757758
osg::Vec3f position = -direction;
758759

759-
// The sun is not synchronized with the sunlight because reasons
760-
// This is based on exterior sun orbit and won't make sense for interiors, see WeatherManager::update
760+
// This is based on the exterior sun orbit and won't make sense for interiors, see WeatherManager::update
761761
position.z() = 400.f - std::abs(position.x());
762762

763+
// The sun is not always synchronized with the sunlight because reasons
764+
const osg::Vec3f sunlightPos = Settings::shaders().mMatchSunlightToSun ? position : -direction;
763765
// need to wrap this in a StateUpdater?
764-
if (Settings::shaders().mMatchSunlightToSun)
765-
mSunLight->setPosition(osg::Vec4f(position, 0.f));
766-
else
767-
mSunLight->setPosition(osg::Vec4f(-direction, 0.f));
766+
mSunLight->setPosition(osg::Vec4f(sunlightPos, 0.f));
768767

769768
mSky->setSunDirection(position);
770769

771770
mPostProcessor->getStateUpdater()->setSunPos(osg::Vec4f(position, 0.f), mNight);
771+
mPostProcessor->getStateUpdater()->setSunVec(osg::Vec4f(-sunlightPos, 0.f));
772772
}
773773

774774
void RenderingManager::addCell(const MWWorld::CellStore* store)

components/fx/stateupdater.hpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ namespace Fx
4949
mData.get<SunPos>().z() *= -1.f;
5050
}
5151

52+
void setSunVec(const osg::Vec4f& vec)
53+
{
54+
mData.get<SunVec>() = vec;
55+
mData.get<SunVec>().normalize();
56+
}
57+
5258
void setResolution(const osg::Vec2f& size)
5359
{
5460
mData.get<Resolution>() = size;
@@ -170,6 +176,11 @@ namespace Fx
170176
static constexpr std::string_view sName = "sunPos";
171177
};
172178

179+
struct SunVec : Std140::Vec4
180+
{
181+
static constexpr std::string_view sName = "sunVec";
182+
};
183+
173184
struct Resolution : Std140::Vec2
174185
{
175186
static constexpr std::string_view sName = "resolution";
@@ -270,11 +281,11 @@ namespace Fx
270281
static constexpr std::string_view sName = "isInterior";
271282
};
272283

273-
using UniformData
274-
= Std140::UBO<ProjectionMatrix, InvProjectionMatrix, ViewMatrix, PrevViewMatrix, InvViewMatrix, EyePos,
275-
EyeVec, FogColor, AmbientColor, SkyColor, SunColor, SunPos, Resolution, RcpResolution, FogNear, FogFar,
276-
Near, Far, Fov, GameHour, SunVis, WaterHeight, IsWaterEnabled, SimulationTime, DeltaSimulationTime,
277-
FrameNumber, WindSpeed, WeatherTransition, WeatherID, NextWeatherID, IsUnderwater, IsInterior>;
284+
using UniformData = Std140::UBO<ProjectionMatrix, InvProjectionMatrix, ViewMatrix, PrevViewMatrix,
285+
InvViewMatrix, EyePos, EyeVec, FogColor, AmbientColor, SkyColor, SunColor, SunPos, SunVec, Resolution,
286+
RcpResolution, FogNear, FogFar, Near, Far, Fov, GameHour, SunVis, WaterHeight, IsWaterEnabled,
287+
SimulationTime, DeltaSimulationTime, FrameNumber, WindSpeed, WeatherTransition, WeatherID, NextWeatherID,
288+
IsUnderwater, IsInterior>;
278289

279290
UniformData mData;
280291
bool mUseUBO;

docs/source/reference/postprocessing/omwfx.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,11 @@ Builtin Uniforms
7373
+-------------+------------------------------+--------------------------------------------------+
7474
| vec4 | ``omw.sunColor`` | The RGBA color of sun |
7575
+-------------+------------------------------+--------------------------------------------------+
76-
| vec4 | ``omw.sunPos`` | The normalized sun direction |
76+
| vec4 | ``omw.sunPos`` | The normalized sun disc position |
7777
| | | |
78-
| | | When the sun is set `omw.sunpos.z` is negated |
78+
| | | When the sun is set `omw.sunPos.z` is negated |
79+
+-------------+------------------------------+--------------------------------------------------+
80+
| vec4 | ``omw.sunVec`` | The normalized sunlight direction |
7981
+-------------+------------------------------+--------------------------------------------------+
8082
| vec2 | ``omw.resolution`` | The render target's resolution |
8183
+-------------+------------------------------+--------------------------------------------------+

0 commit comments

Comments
 (0)