Merge branch 'range' into 'master'

Use a dynamic falloff range for soft effect

See merge request OpenMW/openmw!3532
macos_ci_fix
Alexei Kotov 1 year ago
commit 6d776ac833

@ -2708,7 +2708,8 @@ namespace NifOsg
stateset->setAttributeAndModes(polygonOffset, osg::StateAttribute::ON); stateset->setAttributeAndModes(polygonOffset, osg::StateAttribute::ON);
} }
if (shaderprop->softEffect()) if (shaderprop->softEffect())
SceneUtil::setupSoftEffect(*node, shaderprop->mFalloffDepth, true); SceneUtil::setupSoftEffect(
*node, shaderprop->mFalloffDepth, true, shaderprop->mFalloffDepth);
break; break;
} }
default: default:

@ -15,7 +15,7 @@
namespace SceneUtil namespace SceneUtil
{ {
void setupSoftEffect(osg::Node& node, float size, bool falloff) void setupSoftEffect(osg::Node& node, float size, bool falloff, float falloffDepth)
{ {
static const osg::ref_ptr<SceneUtil::AutoDepth> depth = new SceneUtil::AutoDepth(osg::Depth::LESS, 0, 1, false); static const osg::ref_ptr<SceneUtil::AutoDepth> depth = new SceneUtil::AutoDepth(osg::Depth::LESS, 0, 1, false);
@ -23,6 +23,7 @@ namespace SceneUtil
stateset->addUniform(new osg::Uniform("particleSize", size)); stateset->addUniform(new osg::Uniform("particleSize", size));
stateset->addUniform(new osg::Uniform("particleFade", falloff)); stateset->addUniform(new osg::Uniform("particleFade", falloff));
stateset->addUniform(new osg::Uniform("softFalloffDepth", falloffDepth));
stateset->setAttributeAndModes(depth, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE); stateset->setAttributeAndModes(depth, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);
node.setUserValue(Misc::OsgUserValues::sXSoftEffect, true); node.setUserValue(Misc::OsgUserValues::sXSoftEffect, true);
@ -35,6 +36,8 @@ namespace SceneUtil
std::string source; std::string source;
constexpr float defaultFalloffDepth = 300.f; // arbitrary value that simply looks good with common cases
if (node.getUserValue(Misc::OsgUserValues::sExtraData, source) && !source.empty()) if (node.getUserValue(Misc::OsgUserValues::sExtraData, source) && !source.empty())
{ {
YAML::Node root = YAML::Load(source); YAML::Node root = YAML::Load(source);
@ -47,8 +50,9 @@ namespace SceneUtil
{ {
auto size = it.second["size"].as<float>(45.f); auto size = it.second["size"].as<float>(45.f);
auto falloff = it.second["falloff"].as<bool>(false); auto falloff = it.second["falloff"].as<bool>(false);
auto falloffDepth = it.second["falloffDepth"].as<float>(defaultFalloffDepth);
setupSoftEffect(node, size, falloff); setupSoftEffect(node, size, falloff, falloffDepth);
} }
} }
@ -56,7 +60,8 @@ namespace SceneUtil
} }
else if (osgParticle::ParticleSystem* partsys = dynamic_cast<osgParticle::ParticleSystem*>(&node)) else if (osgParticle::ParticleSystem* partsys = dynamic_cast<osgParticle::ParticleSystem*>(&node))
{ {
setupSoftEffect(node, partsys->getDefaultParticleTemplate().getSizeRange().maximum, false); setupSoftEffect(
node, partsys->getDefaultParticleTemplate().getSizeRange().maximum, false, defaultFalloffDepth);
} }
traverse(node); traverse(node);

@ -15,7 +15,7 @@ namespace osg
namespace SceneUtil namespace SceneUtil
{ {
void setupSoftEffect(osg::Node& node, float size, bool falloff); void setupSoftEffect(osg::Node& node, float size, bool falloff, float falloffDepth);
class ProcessExtraDataVisitor : public osg::NodeVisitor class ProcessExtraDataVisitor : public osg::NodeVisitor
{ {

@ -31,13 +31,15 @@ This setting can either be activated in the OpenMW launcher or changed in `setti
Variables. Variables.
+---------+--------------------------------------------------------------------------------------------------------+---------+---------+ +--------------+--------------------------------------------------------------------------------------------------------+---------+---------+
| Name | Description | Type | Default | | Name | Description | Type | Default |
+---------+--------------------------------------------------------------------------------------------------------+---------+---------+ +--------------+--------------------------------------------------------------------------------------------------------+---------+---------+
| size | Scaling ratio. Larger values will make a softer fade effect. Larger geometry requires higher values. | integer | 45 | | size | Scaling ratio. Larger values will make a softer fade effect. Larger geometry requires higher values. | integer | 45 |
+---------+--------------------------------------------------------------------------------------------------------+---------+---------+ +--------------+--------------------------------------------------------------------------------------------------------+---------+---------+
| falloff | Fades away geometry as camera gets closer. Geometry full fades when parallel to camera. | boolean | false | | falloff | Fades away geometry as camera gets closer. Geometry full fades when parallel to camera. | boolean | false |
+---------+--------------------------------------------------------------------------------------------------------+---------+---------+ +--------------+--------------------------------------------------------------------------------------------------------+---------+---------+
| falloffDepth | The units at which geometry starts to fade. | float | 300 |
+--------------+--------------------------------------------------------------------------------------------------------+---------+---------+
Example usage. Example usage.
@ -48,6 +50,7 @@ Example usage.
"soft_effect" : { "soft_effect" : {
"size": 250, "size": 250,
"falloff" : false, "falloff" : false,
"falloffDepth": 5,
} }
} }
} }

@ -38,6 +38,7 @@ uniform float alphaRef;
uniform sampler2D opaqueDepthTex; uniform sampler2D opaqueDepthTex;
uniform float particleSize; uniform float particleSize;
uniform bool particleFade; uniform bool particleFade;
uniform float softFalloffDepth;
#endif #endif
void main() void main()
@ -71,7 +72,8 @@ void main()
far, far,
texture2D(opaqueDepthTex, screenCoords).x, texture2D(opaqueDepthTex, screenCoords).x,
particleSize, particleSize,
particleFade particleFade,
softFalloffDepth
); );
#endif #endif

@ -98,6 +98,7 @@ varying vec3 passNormal;
uniform sampler2D opaqueDepthTex; uniform sampler2D opaqueDepthTex;
uniform float particleSize; uniform float particleSize;
uniform bool particleFade; uniform bool particleFade;
uniform float softFalloffDepth;
#endif #endif
#if @particleOcclusion #if @particleOcclusion
@ -256,7 +257,8 @@ vec3 viewNormal = normalize(gl_NormalMatrix * normal);
far, far,
texture2D(opaqueDepthTex, screenCoords).x, texture2D(opaqueDepthTex, screenCoords).x,
particleSize, particleSize,
particleFade particleFade,
softFalloffDepth
); );
#endif #endif

@ -19,7 +19,8 @@ float calcSoftParticleFade(
float far, float far,
float depth, float depth,
float size, float size,
bool fade bool fade,
float softFalloffDepth
) )
{ {
float euclidianDepth = length(viewPos); float euclidianDepth = length(viewPos);
@ -32,13 +33,12 @@ float calcSoftParticleFade(
float falloff = size * falloffMultiplier; float falloff = size * falloffMultiplier;
float delta = particleDepth - sceneDepth; float delta = particleDepth - sceneDepth;
const float nearMult = 300.0;
float viewBias = 1.0; float viewBias = 1.0;
if (fade) if (fade)
{ {
float VdotN = dot(viewDir, viewNormal); float VdotN = dot(viewDir, viewNormal);
viewBias = abs(VdotN) * quickstep(euclidianDepth / nearMult) * (1.0 - pow(1.0 + VdotN, 1.3)); viewBias = abs(VdotN) * quickstep(euclidianDepth / softFalloffDepth) * (1.0 - pow(1.0 - abs(VdotN), 1.3));
} }
const float shift = 0.845; const float shift = 0.845;

Loading…
Cancel
Save