Skip to content

Commit

Permalink
Merge branch 'precipitationripples' into 'master'
Browse files Browse the repository at this point in the history
Use fallback weather ripple settings (bug #7292)

Closes #7292

See merge request OpenMW/openmw!3671
  • Loading branch information
elsid committed Dec 26, 2023
2 parents dc8c979 + 099c39a commit 851bad4
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
Bug #7229: Error marker loading failure is not handled
Bug #7243: Supporting loading external files from VFS from esm files
Bug #7284: "Your weapon has no effect." message doesn't always show when the player character attempts to attack
Bug #7292: Weather settings for disabling or enabling snow and rain ripples don't work
Bug #7298: Water ripples from projectiles sometimes are not spawned
Bug #7307: Alchemy "Magic Effect" search string does not match on tool tip for effects related to attributes
Bug #7322: Shadows don't cover groundcover depending on the view angle and perspective with compute scene bounds = primitives
Expand Down
1 change: 1 addition & 0 deletions apps/openmw/mwrender/renderingmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,7 @@ namespace MWRender

float rainIntensity = mSky->getPrecipitationAlpha();
mWater->setRainIntensity(rainIntensity);
mWater->setRainRipplesEnabled(mSky->getRainRipplesEnabled());

mWater->update(dt, paused);
if (!paused)
Expand Down
7 changes: 7 additions & 0 deletions apps/openmw/mwrender/sky.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ namespace MWRender
, mRainMaxHeight(0.f)
, mRainEntranceSpeed(1.f)
, mRainMaxRaindrops(0)
, mRipples(false)
, mWindSpeed(0.f)
, mBaseWindSpeed(0.f)
, mEnabled(true)
Expand Down Expand Up @@ -516,6 +517,11 @@ namespace MWRender
return mRainNode != nullptr;
}

bool SkyManager::getRainRipplesEnabled() const
{
return mRipples;
}

float SkyManager::getPrecipitationAlpha() const
{
if (mEnabled && !mIsStorm && (hasRain() || mParticleNode))
Expand Down Expand Up @@ -630,6 +636,7 @@ namespace MWRender
mRainMinHeight = weather.mRainMinHeight;
mRainMaxHeight = weather.mRainMaxHeight;
mRainSpeed = weather.mRainSpeed;
mRipples = weather.mRipples;
mWindSpeed = weather.mWindSpeed;
mBaseWindSpeed = weather.mBaseWindSpeed;

Expand Down
3 changes: 3 additions & 0 deletions apps/openmw/mwrender/sky.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ namespace MWRender

bool hasRain() const;

bool getRainRipplesEnabled() const;

float getPrecipitationAlpha() const;

void setRainSpeed(float speed);
Expand Down Expand Up @@ -194,6 +196,7 @@ namespace MWRender
float mRainMaxHeight;
float mRainEntranceSpeed;
int mRainMaxRaindrops;
bool mRipples;
float mWindSpeed;
float mBaseWindSpeed;

Expand Down
1 change: 1 addition & 0 deletions apps/openmw/mwrender/skyutil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ namespace MWRender
float mRainSpeed;
float mRainEntranceSpeed;
int mRainMaxRaindrops;
bool mRipples;

osg::Vec3f mStormDirection;
osg::Vec3f mNextStormDirection;
Expand Down
30 changes: 22 additions & 8 deletions apps/openmw/mwrender/water.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,32 +205,40 @@ namespace MWRender
}
};

class RainIntensityUpdater : public SceneUtil::StateSetUpdater
class RainSettingsUpdater : public SceneUtil::StateSetUpdater
{
public:
RainIntensityUpdater()
RainSettingsUpdater()
: mRainIntensity(0.f)
, mEnableRipples(false)
{
}

void setRainIntensity(float rainIntensity) { mRainIntensity = rainIntensity; }
void setRipplesEnabled(bool enableRipples) { mEnableRipples = enableRipples; }

protected:
void setDefaults(osg::StateSet* stateset) override
{
osg::ref_ptr<osg::Uniform> rainIntensityUniform = new osg::Uniform("rainIntensity", 0.0f);
stateset->addUniform(rainIntensityUniform.get());
osg::ref_ptr<osg::Uniform> enableRainRipplesUniform = new osg::Uniform("enableRainRipples", false);
stateset->addUniform(enableRainRipplesUniform.get());
}

void apply(osg::StateSet* stateset, osg::NodeVisitor* /*nv*/) override
{
osg::ref_ptr<osg::Uniform> rainIntensityUniform = stateset->getUniform("rainIntensity");
if (rainIntensityUniform != nullptr)
rainIntensityUniform->set(mRainIntensity);
osg::ref_ptr<osg::Uniform> enableRainRipplesUniform = stateset->getUniform("enableRainRipples");
if (enableRainRipplesUniform != nullptr)
enableRainRipplesUniform->set(mEnableRipples);
}

private:
float mRainIntensity;
bool mEnableRipples;
};

class Refraction : public SceneUtil::RTTNode
Expand Down Expand Up @@ -430,7 +438,7 @@ namespace MWRender

Water::Water(osg::Group* parent, osg::Group* sceneRoot, Resource::ResourceSystem* resourceSystem,
osgUtil::IncrementalCompileOperation* ico)
: mRainIntensityUpdater(nullptr)
: mRainSettingsUpdater(nullptr)
, mParent(parent)
, mSceneRoot(sceneRoot)
, mResourceSystem(resourceSystem)
Expand Down Expand Up @@ -579,7 +587,7 @@ namespace MWRender

node->setStateSet(stateset);
node->setUpdateCallback(nullptr);
mRainIntensityUpdater = nullptr;
mRainSettingsUpdater = nullptr;

// Add animated textures
std::vector<osg::ref_ptr<osg::Texture2D>> textures;
Expand Down Expand Up @@ -711,8 +719,8 @@ namespace MWRender
normalMap->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR);
normalMap->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);

mRainIntensityUpdater = new RainIntensityUpdater();
node->setUpdateCallback(mRainIntensityUpdater);
mRainSettingsUpdater = new RainSettingsUpdater();
node->setUpdateCallback(mRainSettingsUpdater);

mShaderWaterStateSetUpdater
= new ShaderWaterStateSetUpdater(this, mReflection, mRefraction, mRipples, std::move(program), normalMap);
Expand Down Expand Up @@ -801,8 +809,14 @@ namespace MWRender

void Water::setRainIntensity(float rainIntensity)
{
if (mRainIntensityUpdater)
mRainIntensityUpdater->setRainIntensity(rainIntensity);
if (mRainSettingsUpdater)
mRainSettingsUpdater->setRainIntensity(rainIntensity);
}

void Water::setRainRipplesEnabled(bool enableRipples)
{
if (mRainSettingsUpdater)
mRainSettingsUpdater->setRipplesEnabled(enableRipples);
}

void Water::update(float dt, bool paused)
Expand Down
5 changes: 3 additions & 2 deletions apps/openmw/mwrender/water.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ namespace MWRender
class Refraction;
class Reflection;
class RippleSimulation;
class RainIntensityUpdater;
class RainSettingsUpdater;
class Ripples;

/// Water rendering
class Water
{
osg::ref_ptr<RainIntensityUpdater> mRainIntensityUpdater;
osg::ref_ptr<RainSettingsUpdater> mRainSettingsUpdater;

osg::ref_ptr<osg::Group> mParent;
osg::ref_ptr<osg::Group> mSceneRoot;
Expand Down Expand Up @@ -113,6 +113,7 @@ namespace MWRender
void changeCell(const MWWorld::CellStore* store);
void setHeight(const float height);
void setRainIntensity(const float rainIntensity);
void setRainRipplesEnabled(bool enableRipples);

void update(float dt, bool paused);

Expand Down
4 changes: 4 additions & 0 deletions apps/openmw/mwworld/weather.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ namespace MWWorld
, mRainMaxHeight(Fallback::Map::getFloat("Weather_" + name + "_Rain_Height_Max"))
, mParticleEffect(particleEffect)
, mRainEffect(Fallback::Map::getBool("Weather_" + name + "_Using_Precip") ? "meshes\\raindrop.nif" : "")
, mRipples(Fallback::Map::getBool("Weather_" + name + "_Ripples"))
, mStormDirection(Weather::defaultDirection())
, mCloudsMaximumPercent(Fallback::Map::getFloat("Weather_" + name + "_Clouds_Maximum_Percent"))
, mTransitionDelta(Fallback::Map::getFloat("Weather_" + name + "_Transition_Delta"))
Expand Down Expand Up @@ -1129,6 +1130,7 @@ namespace MWWorld
mResult.mRainMinHeight = current.mRainMinHeight;
mResult.mRainMaxHeight = current.mRainMaxHeight;
mResult.mRainMaxRaindrops = current.mRainMaxRaindrops;
mResult.mRipples = current.mRipples;

mResult.mParticleEffect = current.mParticleEffect;
mResult.mRainEffect = current.mRainEffect;
Expand Down Expand Up @@ -1241,6 +1243,7 @@ namespace MWWorld
mResult.mRainMinHeight = current.mRainMinHeight;
mResult.mRainMaxHeight = current.mRainMaxHeight;
mResult.mRainMaxRaindrops = current.mRainMaxRaindrops;
mResult.mRipples = current.mRipples;
}
else
{
Expand All @@ -1257,6 +1260,7 @@ namespace MWWorld
mResult.mRainMinHeight = other.mRainMinHeight;
mResult.mRainMaxHeight = other.mRainMaxHeight;
mResult.mRainMaxRaindrops = other.mRainMaxRaindrops;
mResult.mRipples = other.mRipples;
}
}
}
2 changes: 2 additions & 0 deletions apps/openmw/mwworld/weather.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ namespace MWWorld

std::string mRainEffect;

bool mRipples;

osg::Vec3f mStormDirection;

float mCloudsMaximumPercent;
Expand Down
9 changes: 6 additions & 3 deletions components/fallback/validate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ static const std::set<std::string_view> allowedKeysInt = { "LightAttenuation_Lin
"Water_RippleFrameCount", "Water_SurfaceTileCount", "Water_SurfaceFrameCount", "Weather_Clear_Using_Precip",
"Weather_Cloudy_Using_Precip", "Weather_Foggy_Using_Precip", "Weather_Overcast_Using_Precip",
"Weather_Rain_Using_Precip", "Weather_Thunderstorm_Using_Precip", "Weather_Ashstorm_Using_Precip",
"Weather_Blight_Using_Precip", "Weather_Snow_Using_Precip", "Weather_Blizzard_Using_Precip" };
"Weather_Blight_Using_Precip", "Weather_Snow_Using_Precip", "Weather_Blizzard_Using_Precip",
"Weather_Clear_Ripples", "Weather_Cloudy_Ripples", "Weather_Foggy_Ripples", "Weather_Overcast_Ripples",
"Weather_Rain_Ripples", "Weather_Thunderstorm_Ripples", "Weather_Ashstorm_Ripples", "Weather_Blight_Ripples",
"Weather_Snow_Ripples", "Weather_Blizzard_Ripples" };

static const std::set<std::string_view> allowedKeysFloat = { "General_Werewolf_FOV", "Inventory_DirectionalAmbientB",
"Inventory_DirectionalAmbientG", "Inventory_DirectionalAmbientR", "Inventory_DirectionalDiffuseB",
Expand Down Expand Up @@ -160,15 +163,15 @@ static const std::set<std::string_view> allowedKeysNonNumeric = { "Blood_Model_0
"Weather_Rain_Ambient_Sunrise_Color", "Weather_Rain_Ambient_Sunset_Color", "Weather_Rain_Cloud_Texture",
"Weather_Rain_Fog_Day_Color", "Weather_Rain_Fog_Night_Color", "Weather_Rain_Fog_Sunrise_Color",
"Weather_Rain_Fog_Sunset_Color", "Weather_Rain_Rain_Loop_Sound_ID", "Weather_Rain_Ripple_Radius",
"Weather_Rain_Ripples", "Weather_Rain_Ripple_Scale", "Weather_Rain_Ripple_Speed", "Weather_Rain_Ripples_Per_Drop",
"Weather_Rain_Ripple_Scale", "Weather_Rain_Ripple_Speed", "Weather_Rain_Ripples_Per_Drop",
"Weather_Rain_Sky_Day_Color", "Weather_Rain_Sky_Night_Color", "Weather_Rain_Sky_Sunrise_Color",
"Weather_Rain_Sky_Sunset_Color", "Weather_Rain_Sun_Day_Color", "Weather_Rain_Sun_Disc_Sunset_Color",
"Weather_Rain_Sun_Night_Color", "Weather_Rain_Sun_Sunrise_Color", "Weather_Rain_Sun_Sunset_Color",
"Weather_Snow_Ambient_Day_Color", "Weather_Snow_Ambient_Loop_Sound_ID", "Weather_Snow_Ambient_Night_Color",
"Weather_Snow_Ambient_Sunrise_Color", "Weather_Snow_Ambient_Sunset_Color", "Weather_Snow_Cloud_Texture",
"Weather_Snow_Fog_Day_Color", "Weather_Snow_Fog_Night_Color", "Weather_Snow_Fog_Sunrise_Color",
"Weather_Snow_Fog_Sunset_Color", "Weather_Snow_Gravity_Scale", "Weather_Snow_High_Kill", "Weather_Snow_Low_Kill",
"Weather_Snow_Max_Snowflakes", "Weather_Snow_Ripple_Radius", "Weather_Snow_Ripples", "Weather_Snow_Ripple_Scale",
"Weather_Snow_Max_Snowflakes", "Weather_Snow_Ripple_Radius", "Weather_Snow_Ripple_Scale",
"Weather_Snow_Ripple_Speed", "Weather_Snow_Ripples_Per_Flake", "Weather_Snow_Sky_Day_Color",
"Weather_Snow_Sky_Night_Color", "Weather_Snow_Sky_Sunrise_Color", "Weather_Snow_Sky_Sunset_Color",
"Weather_Snow_Snow_Diameter", "Weather_Snow_Snow_Entrance_Speed", "Weather_Snow_Snow_Height_Max",
Expand Down
3 changes: 2 additions & 1 deletion files/shaders/compatibility/water.frag
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ uniform float near;
uniform float far;

uniform float rainIntensity;
uniform bool enableRainRipples;

uniform vec2 screenRes;

Expand Down Expand Up @@ -113,7 +114,7 @@ void main(void)

vec4 rainRipple;

if (rainIntensity > 0.01)
if (rainIntensity > 0.01 && enableRainRipples)
rainRipple = rainCombined(position.xy/1000.0, waterTimer) * clamp(rainIntensity, 0.0, 1.0);
else
rainRipple = vec4(0.0);
Expand Down

0 comments on commit 851bad4

Please sign in to comment.