mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2024-12-29 03:19:44 +00:00
use a dynamic falloff range for soft effect and use shader flags
This commit is contained in:
parent
2488ecebc5
commit
09928ba265
@ -2708,7 +2708,8 @@ namespace NifOsg
|
||||
stateset->setAttributeAndModes(polygonOffset, osg::StateAttribute::ON);
|
||||
}
|
||||
if (shaderprop->softEffect())
|
||||
SceneUtil::setupSoftEffect(*node, shaderprop->mFalloffDepth, true);
|
||||
SceneUtil::setupSoftEffect(
|
||||
*node, shaderprop->mFalloffDepth, true, shaderprop->mFalloffDepth);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
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);
|
||||
|
||||
@ -23,6 +23,7 @@ namespace SceneUtil
|
||||
|
||||
stateset->addUniform(new osg::Uniform("particleSize", size));
|
||||
stateset->addUniform(new osg::Uniform("particleFade", falloff));
|
||||
stateset->addUniform(new osg::Uniform("softFalloffDepth", falloffDepth));
|
||||
stateset->setAttributeAndModes(depth, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);
|
||||
|
||||
node.setUserValue(Misc::OsgUserValues::sXSoftEffect, true);
|
||||
@ -35,6 +36,8 @@ namespace SceneUtil
|
||||
|
||||
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())
|
||||
{
|
||||
YAML::Node root = YAML::Load(source);
|
||||
@ -47,8 +50,9 @@ namespace SceneUtil
|
||||
{
|
||||
auto size = it.second["size"].as<float>(45.f);
|
||||
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))
|
||||
{
|
||||
setupSoftEffect(node, partsys->getDefaultParticleTemplate().getSizeRange().maximum, false);
|
||||
setupSoftEffect(
|
||||
node, partsys->getDefaultParticleTemplate().getSizeRange().maximum, false, defaultFalloffDepth);
|
||||
}
|
||||
|
||||
traverse(node);
|
||||
|
@ -15,7 +15,7 @@ namespace osg
|
||||
|
||||
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
|
||||
{
|
||||
|
@ -31,13 +31,15 @@ This setting can either be activated in the OpenMW launcher or changed in `setti
|
||||
|
||||
Variables.
|
||||
|
||||
+---------+--------------------------------------------------------------------------------------------------------+---------+---------+
|
||||
| Name | Description | Type | Default |
|
||||
+---------+--------------------------------------------------------------------------------------------------------+---------+---------+
|
||||
| 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 |
|
||||
+---------+--------------------------------------------------------------------------------------------------------+---------+---------+
|
||||
+--------------+--------------------------------------------------------------------------------------------------------+---------+---------+
|
||||
| Name | Description | Type | Default |
|
||||
+--------------+--------------------------------------------------------------------------------------------------------+---------+---------+
|
||||
| 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 |
|
||||
+--------------+--------------------------------------------------------------------------------------------------------+---------+---------+
|
||||
| falloffDepth | The units at which geometry starts to fade. | float | 300 |
|
||||
+--------------+--------------------------------------------------------------------------------------------------------+---------+---------+
|
||||
|
||||
Example usage.
|
||||
|
||||
@ -48,6 +50,7 @@ Example usage.
|
||||
"soft_effect" : {
|
||||
"size": 250,
|
||||
"falloff" : false,
|
||||
"falloffDepth": 5,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -38,6 +38,7 @@ uniform float alphaRef;
|
||||
uniform sampler2D opaqueDepthTex;
|
||||
uniform float particleSize;
|
||||
uniform bool particleFade;
|
||||
uniform float softFalloffDepth;
|
||||
#endif
|
||||
|
||||
void main()
|
||||
@ -71,7 +72,8 @@ void main()
|
||||
far,
|
||||
texture2D(opaqueDepthTex, screenCoords).x,
|
||||
particleSize,
|
||||
particleFade
|
||||
particleFade,
|
||||
softFalloffDepth
|
||||
);
|
||||
#endif
|
||||
|
||||
|
@ -98,6 +98,7 @@ varying vec3 passNormal;
|
||||
uniform sampler2D opaqueDepthTex;
|
||||
uniform float particleSize;
|
||||
uniform bool particleFade;
|
||||
uniform float softFalloffDepth;
|
||||
#endif
|
||||
|
||||
#if @particleOcclusion
|
||||
@ -256,7 +257,8 @@ vec3 viewNormal = normalize(gl_NormalMatrix * normal);
|
||||
far,
|
||||
texture2D(opaqueDepthTex, screenCoords).x,
|
||||
particleSize,
|
||||
particleFade
|
||||
particleFade,
|
||||
softFalloffDepth
|
||||
);
|
||||
#endif
|
||||
|
||||
|
@ -19,7 +19,8 @@ float calcSoftParticleFade(
|
||||
float far,
|
||||
float depth,
|
||||
float size,
|
||||
bool fade
|
||||
bool fade,
|
||||
float softFalloffDepth
|
||||
)
|
||||
{
|
||||
float euclidianDepth = length(viewPos);
|
||||
@ -32,13 +33,12 @@ float calcSoftParticleFade(
|
||||
float falloff = size * falloffMultiplier;
|
||||
float delta = particleDepth - sceneDepth;
|
||||
|
||||
const float nearMult = 300.0;
|
||||
float viewBias = 1.0;
|
||||
|
||||
if (fade)
|
||||
{
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user