mirror of
https://github.com/OpenMW/openmw.git
synced 2025-12-01 22:04:31 +00:00
Expose sunlight direction to post-processing (#8826)
This commit is contained in:
parent
35e27504ee
commit
20d14b57c1
4 changed files with 27 additions and 14 deletions
|
|
@ -83,7 +83,7 @@ set(OPENMW_VERSION_MAJOR 0)
|
||||||
set(OPENMW_VERSION_MINOR 51)
|
set(OPENMW_VERSION_MINOR 51)
|
||||||
set(OPENMW_VERSION_RELEASE 0)
|
set(OPENMW_VERSION_RELEASE 0)
|
||||||
set(OPENMW_LUA_API_REVISION 104)
|
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_COMMITHASH "")
|
||||||
set(OPENMW_VERSION_TAGHASH "")
|
set(OPENMW_VERSION_TAGHASH "")
|
||||||
|
|
|
||||||
|
|
@ -739,6 +739,7 @@ namespace MWRender
|
||||||
static const osg::Vec4f interiorSunPos
|
static const osg::Vec4f interiorSunPos
|
||||||
= osg::Vec4f(-1.f, osg::DegreesToRadians(45.f), osg::DegreesToRadians(45.f), 0.f);
|
= osg::Vec4f(-1.f, osg::DegreesToRadians(45.f), osg::DegreesToRadians(45.f), 0.f);
|
||||||
mPostProcessor->getStateUpdater()->setSunPos(interiorSunPos, false);
|
mPostProcessor->getStateUpdater()->setSunPos(interiorSunPos, false);
|
||||||
|
mPostProcessor->getStateUpdater()->setSunVec(-interiorSunPos);
|
||||||
mSunLight->setPosition(interiorSunPos);
|
mSunLight->setPosition(interiorSunPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -756,19 +757,18 @@ namespace MWRender
|
||||||
{
|
{
|
||||||
osg::Vec3f position = -direction;
|
osg::Vec3f position = -direction;
|
||||||
|
|
||||||
// The sun is not synchronized with the sunlight because reasons
|
// This is based on the exterior sun orbit and won't make sense for interiors, see WeatherManager::update
|
||||||
// This is based on exterior sun orbit and won't make sense for interiors, see WeatherManager::update
|
|
||||||
position.z() = 400.f - std::abs(position.x());
|
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?
|
// need to wrap this in a StateUpdater?
|
||||||
if (Settings::shaders().mMatchSunlightToSun)
|
mSunLight->setPosition(osg::Vec4f(sunlightPos, 0.f));
|
||||||
mSunLight->setPosition(osg::Vec4f(position, 0.f));
|
|
||||||
else
|
|
||||||
mSunLight->setPosition(osg::Vec4f(-direction, 0.f));
|
|
||||||
|
|
||||||
mSky->setSunDirection(position);
|
mSky->setSunDirection(position);
|
||||||
|
|
||||||
mPostProcessor->getStateUpdater()->setSunPos(osg::Vec4f(position, 0.f), mNight);
|
mPostProcessor->getStateUpdater()->setSunPos(osg::Vec4f(position, 0.f), mNight);
|
||||||
|
mPostProcessor->getStateUpdater()->setSunVec(osg::Vec4f(-sunlightPos, 0.f));
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderingManager::addCell(const MWWorld::CellStore* store)
|
void RenderingManager::addCell(const MWWorld::CellStore* store)
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,12 @@ namespace Fx
|
||||||
mData.get<SunPos>().z() *= -1.f;
|
mData.get<SunPos>().z() *= -1.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setSunVec(const osg::Vec4f& vec)
|
||||||
|
{
|
||||||
|
mData.get<SunVec>() = vec;
|
||||||
|
mData.get<SunVec>().normalize();
|
||||||
|
}
|
||||||
|
|
||||||
void setResolution(const osg::Vec2f& size)
|
void setResolution(const osg::Vec2f& size)
|
||||||
{
|
{
|
||||||
mData.get<Resolution>() = size;
|
mData.get<Resolution>() = size;
|
||||||
|
|
@ -170,6 +176,11 @@ namespace Fx
|
||||||
static constexpr std::string_view sName = "sunPos";
|
static constexpr std::string_view sName = "sunPos";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct SunVec : Std140::Vec4
|
||||||
|
{
|
||||||
|
static constexpr std::string_view sName = "sunVec";
|
||||||
|
};
|
||||||
|
|
||||||
struct Resolution : Std140::Vec2
|
struct Resolution : Std140::Vec2
|
||||||
{
|
{
|
||||||
static constexpr std::string_view sName = "resolution";
|
static constexpr std::string_view sName = "resolution";
|
||||||
|
|
@ -270,11 +281,11 @@ namespace Fx
|
||||||
static constexpr std::string_view sName = "isInterior";
|
static constexpr std::string_view sName = "isInterior";
|
||||||
};
|
};
|
||||||
|
|
||||||
using UniformData
|
using UniformData = Std140::UBO<ProjectionMatrix, InvProjectionMatrix, ViewMatrix, PrevViewMatrix,
|
||||||
= Std140::UBO<ProjectionMatrix, InvProjectionMatrix, ViewMatrix, PrevViewMatrix, InvViewMatrix, EyePos,
|
InvViewMatrix, EyePos, EyeVec, FogColor, AmbientColor, SkyColor, SunColor, SunPos, SunVec, Resolution,
|
||||||
EyeVec, FogColor, AmbientColor, SkyColor, SunColor, SunPos, Resolution, RcpResolution, FogNear, FogFar,
|
RcpResolution, FogNear, FogFar, Near, Far, Fov, GameHour, SunVis, WaterHeight, IsWaterEnabled,
|
||||||
Near, Far, Fov, GameHour, SunVis, WaterHeight, IsWaterEnabled, SimulationTime, DeltaSimulationTime,
|
SimulationTime, DeltaSimulationTime, FrameNumber, WindSpeed, WeatherTransition, WeatherID, NextWeatherID,
|
||||||
FrameNumber, WindSpeed, WeatherTransition, WeatherID, NextWeatherID, IsUnderwater, IsInterior>;
|
IsUnderwater, IsInterior>;
|
||||||
|
|
||||||
UniformData mData;
|
UniformData mData;
|
||||||
bool mUseUBO;
|
bool mUseUBO;
|
||||||
|
|
|
||||||
|
|
@ -73,9 +73,11 @@ Builtin Uniforms
|
||||||
+-------------+------------------------------+--------------------------------------------------+
|
+-------------+------------------------------+--------------------------------------------------+
|
||||||
| vec4 | ``omw.sunColor`` | The RGBA color of sun |
|
| 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 |
|
| vec2 | ``omw.resolution`` | The render target's resolution |
|
||||||
+-------------+------------------------------+--------------------------------------------------+
|
+-------------+------------------------------+--------------------------------------------------+
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue