Replace uniform with define

pull/3208/head^2^2
wareya 3 years ago
parent d47770df19
commit e1378cd290

@ -307,12 +307,10 @@ namespace MWGui
if (waterTextureSize >= 2048)
mWaterTextureSize->setIndexSelected(2);
int waterReflectionDetail = Settings::Manager::getInt("reflection detail", "Water");
waterReflectionDetail = std::min(5, std::max(0, waterReflectionDetail));
int waterReflectionDetail = std::clamp(Settings::Manager::getInt("reflection detail", "Water"), 0, 5);
mWaterReflectionDetail->setIndexSelected(waterReflectionDetail);
int waterRainRippleDetail = Settings::Manager::getInt("rain ripple density", "Water");
waterRainRippleDetail = std::min(2, std::max(0, waterRainRippleDetail));
int waterRainRippleDetail = std::clamp(Settings::Manager::getInt("rain ripple detail", "Water"), 0, 2);
mWaterRainRippleDetail->setIndexSelected(waterRainRippleDetail);
updateMaxLightsComboBox(mMaxLights);
@ -398,15 +396,15 @@ namespace MWGui
void SettingsWindow::onWaterReflectionDetailChanged(MyGUI::ComboBox* _sender, size_t pos)
{
unsigned int level = std::min((unsigned int)5, (unsigned int)pos);
unsigned int level = std::min(unsigned int(pos), unsigned int(5));
Settings::Manager::setInt("reflection detail", "Water", level);
apply();
}
void SettingsWindow::onWaterRainRippleDetailChanged(MyGUI::ComboBox* _sender, size_t pos)
{
unsigned int level = std::min((unsigned int)2, (unsigned int)(pos));
Settings::Manager::setInt("rain ripple density", "Water", level);
unsigned int level = std::min(unsigned int(pos), unsigned int(2));
Settings::Manager::setInt("rain ripple detail", "Water", level);
apply();
}

@ -32,6 +32,7 @@
#include <components/sceneutil/lightmanager.hpp>
#include <components/misc/constants.hpp>
#include <components/misc/stringops.hpp>
#include <components/nifosg/controller.hpp>
@ -619,8 +620,6 @@ public:
stateset->setAttributeAndModes(depth, osg::StateAttribute::ON);
}
stateset->addUniform(new osg::Uniform("nodePosition", osg::Vec3f(mWater->getPosition())));
stateset->addUniform(new osg::Uniform("rainRippleDensity", Settings::Manager::getInt("rain ripple density", "Water")));
}
void apply(osg::StateSet* stateset, osg::NodeVisitor* nv) override
@ -649,6 +648,8 @@ void Water::createShaderWaterStateSet(osg::Node* node, Reflection* reflection, R
// use a define map to conditionally compile the shader
std::map<std::string, std::string> defineMap;
defineMap.insert(std::make_pair(std::string("refraction_enabled"), std::string(mRefraction ? "1" : "0")));
unsigned int rippleDetail = std::clamp(Settings::Manager::getInt("rain ripple detail", "Water"), 0, 2);
defineMap.insert(std::make_pair(std::string("rain_ripple_detail"), Misc::StringUtils::format("%u", rippleDetail)));
Shader::ShaderManager& shaderMgr = mResourceSystem->getSceneManager()->getShaderManager();
osg::ref_ptr<osg::Shader> vertexShader(shaderMgr.getShader("water_vertex.glsl", defineMap, osg::Shader::VERTEX));

@ -649,9 +649,9 @@ refraction = false
# Draw objects on water reflections.
reflection detail = 2
# Whether to use fully detailed raindrop ripples.
# 2 means more, 1 means less, 0 means less with simpler ring-only ripples (no normal mapping).
rain ripple density = 2
# Whether to use fully detailed raindrop ripples. (0, 1, 2).
# 0 = rings only; 1 = sparse, high detail; 2 = dense, high detail
rain ripple detail = 2
# Overrides the value in '[Camera] small feature culling pixel size' specifically for water reflection/refraction textures.
small feature culling pixel size = 20.0

@ -9,6 +9,7 @@
#endif
#define REFRACTION @refraction_enabled
#define RAIN_RIPPLE_DETAIL @rain_ripple_detail
// Inspired by Blender GLSL Water by martinsh ( https://devlog-martinsh.blogspot.de/2012/07/waterundewater-shader-wip.html )
@ -55,8 +56,6 @@ const float WOBBLY_SHORE_FADE_DISTANCE = 6200.0; // fade out wobbly shores to
// ---------------- rain ripples related stuff ---------------------
uniform int rainRippleDensity;
const float RAIN_RIPPLE_GAPS = 10.0;
const float RAIN_RIPPLE_RADIUS = 0.2;
@ -92,6 +91,7 @@ float blipDerivative(float x)
}
const float RAIN_RING_TIME_OFFSET = 1.0/6.0;
vec4 circle(vec2 coords, vec2 corner, float adjusted_time)
{
vec2 center = vec2(0.5,0.5) + (0.5 - RAIN_RIPPLE_RADIUS) * (2.0 * randOffset(corner, floor(adjusted_time)) - 1.0);
@ -101,6 +101,9 @@ vec4 circle(vec2 coords, vec2 corner, float adjusted_time)
float r = RAIN_RIPPLE_RADIUS;
float d = length(toCenter);
float ringfollower = (phase-d/r)/RAIN_RING_TIME_OFFSET-1.0; // -1.0 ~ +1.0 cover the breadth of the ripple's ring
#if RAIN_RIPPLE_DETAIL > 0
// normal mapped ripples
if(ringfollower < -1.0 || ringfollower > 1.0)
return vec4(0.0);
@ -119,6 +122,16 @@ vec4 circle(vec2 coords, vec2 corner, float adjusted_time)
ret.xyz = normalize(ret.xyz) * energy*range_limit;
ret.z *= range_limit;
return ret;
#else
// ring-only ripples
if(ringfollower < -1.0 || ringfollower > 0.5)
return vec4(0.0);
float energy = 1.0-phase;
float height = blip(ringfollower*2.0+0.5)*energy*energy; // fake specularity
return vec4(0.0, 0.0, 0.0, height);
#endif
}
vec4 rain(vec2 uv, float time)
{
@ -126,6 +139,7 @@ vec4 rain(vec2 uv, float time)
vec2 f_part = fract(uv);
vec2 i_part = floor(uv);
float adjusted_time = time * 1.2 + randPhase(i_part);
#if RAIN_RIPPLE_DETAIL > 0
vec4 a = circle(f_part, i_part, adjusted_time);
vec4 b = circle(f_part, i_part, adjusted_time - RAIN_RING_TIME_OFFSET);
vec4 c = circle(f_part, i_part, adjusted_time - RAIN_RING_TIME_OFFSET*2.0);
@ -138,50 +152,26 @@ vec4 rain(vec2 uv, float time)
// fake specularity looks weird if we use every single ring, also if the inner rings are too bright
ret.w = (a.w + c.w /8.0)*1.5;
return ret;
#else
return circle(f_part, i_part, adjusted_time) * 1.5;
#endif
}
vec4 circleSimple(vec2 coords, vec2 corner, float adjusted_time) // only returns fake specularity
{
vec2 center = vec2(0.5,0.5) + (0.5 - RAIN_RIPPLE_RADIUS) * (2.0 * randOffset(corner, floor(adjusted_time)) - 1.0);
float phase = fract(adjusted_time);
vec2 toCenter = coords - center;
float r = RAIN_RIPPLE_RADIUS;
float d = length(toCenter);
float ringfollower = (phase-d/r)/RAIN_RING_TIME_OFFSET-1.0; // -1.0 ~ +1.0 cover the breadth of the ripple's ring
if(ringfollower < -1.0 || ringfollower > 0.5)
return vec4(0.0);
float energy = 1.0-phase;
float height = blip(ringfollower*2.0+0.5)*energy*energy; // fake specularity
return vec4(0.0, 0.0, 0.0, height);
}
vec4 rainSimple(vec2 uv, float time)
{
uv *= RAIN_RIPPLE_GAPS;
vec2 f_part = fract(uv);
vec2 i_part = floor(uv);
float adjusted_time = time * 1.2 + randPhase(i_part);
return circleSimple(f_part, i_part, adjusted_time) * 1.5;
}
vec2 complex_mult(vec2 a, vec2 b)
{
return vec2(a.x*b.x - a.y*b.y, a.x*b.y + a.y*b.x);
}
vec4 rainCombined(vec2 uv, float time) // returns ripple normal in xyz and fake specularity in w
{
if(rainRippleDensity == 0)
return rainSimple(uv, time) + rainSimple(complex_mult(uv, vec2(0.4, 0.7)) + vec2( 1.2, 3.0), time);
vec4 ret =
return
rain(uv, time)
+ rain(complex_mult(uv, vec2(0.4, 0.7)) + vec2(1.2, 3.0),time);
if(rainRippleDensity == 2)
ret +=
rain(uv * 0.75 + vec2( 3.7,18.9),time)
+ rain(uv * 0.9 + vec2( 5.7,30.1),time)
+ rain(uv * 1.0 + vec2(10.5 ,5.7),time);
return ret;
+ rain(complex_mult(uv, vec2(0.4, 0.7)) + vec2(1.2, 3.0),time)
#if RAIN_RIPPLE_DETAIL == 2
+ rain(uv * 0.75 + vec2( 3.7,18.9),time)
+ rain(uv * 0.9 + vec2( 5.7,30.1),time)
+ rain(uv * 1.0 + vec2(10.5 ,5.7),time)
#endif
;
}

Loading…
Cancel
Save