Add an option to match sunlight to the sun (#8032)

This commit is contained in:
Alexei Kotov 2024-12-27 15:38:41 +03:00
parent 63b8e636f3
commit aa277c0934
11 changed files with 82 additions and 15 deletions

View file

@ -650,6 +650,7 @@ namespace MWGui
Settings::shaders().mForcePerPixelLighting.reset();
Settings::shaders().mClassicFalloff.reset();
Settings::shaders().mMatchSunlightToSun.reset();
Settings::shaders().mLightBoundsMultiplier.reset();
Settings::shaders().mMaximumLightDistance.reset();
Settings::shaders().mLightFadeStart.reset();

View file

@ -754,13 +754,18 @@ namespace MWRender
void RenderingManager::setSunDirection(const osg::Vec3f& direction)
{
osg::Vec3 position = direction * -1;
// need to wrap this in a StateUpdater?
mSunLight->setPosition(osg::Vec4(position.x(), position.y(), position.z(), 0));
osg::Vec3f position = -direction;
// The sun is not synchronized with the sunlight because sunlight origin can't reach the horizon
// 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
position.z() = 400.f - std::abs(position.x());
// 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));
mSky->setSunDirection(position);
mPostProcessor->getStateUpdater()->setSunPos(osg::Vec4f(position, 0.f), mNight);