1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-16 16:10:58 +00:00
OpenMW/files/shaders/lib/particle/soft.glsl

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

49 lines
1.1 KiB
Plaintext
Raw Normal View History

2023-02-25 19:03:39 +00:00
#ifndef LIB_PARTICLE_SOFT
#define LIB_PARTICLE_SOFT
2021-10-20 16:42:18 +00:00
2023-02-25 19:03:39 +00:00
#include "lib/util/quickstep.glsl"
float viewDepth(float depth, float near, float far)
2021-10-20 16:42:18 +00:00
{
#if @reverseZ
depth = 1.0 - depth;
#endif
return (near * far) / ((far - near) * depth - far);
}
2023-02-25 19:03:39 +00:00
float calcSoftParticleFade(
in vec3 viewDir,
in vec3 viewPos,
in vec3 viewNormal,
float near,
float far,
float depth,
float size,
bool fade,
float softFalloffDepth
2023-02-25 19:03:39 +00:00
)
2021-10-20 16:42:18 +00:00
{
float euclidianDepth = length(viewPos);
2021-10-20 16:42:18 +00:00
const float falloffMultiplier = 0.33;
const float contrast = 1.30;
2023-02-25 19:03:39 +00:00
float sceneDepth = viewDepth(depth, near, far);
float particleDepth = viewPos.z;
float falloff = size * falloffMultiplier;
2021-10-20 16:42:18 +00:00
float delta = particleDepth - sceneDepth;
float viewBias = 1.0;
2021-10-20 16:42:18 +00:00
2023-04-21 05:02:12 +00:00
if (fade)
{
2022-06-30 15:23:28 +00:00
float VdotN = dot(viewDir, viewNormal);
viewBias = abs(VdotN) * quickstep(euclidianDepth / softFalloffDepth) * (1.0 - pow(1.0 - abs(VdotN), 1.3));
2022-06-30 15:23:28 +00:00
}
2021-10-20 16:42:18 +00:00
const float shift = 0.845;
return shift * pow(clamp(delta/falloff, 0.0, 1.0), contrast) * viewBias;
2021-10-20 16:42:18 +00:00
}
2023-02-25 19:03:39 +00:00
#endif