summaryrefslogtreecommitdiffstats
path: root/src/Runtime/res/effectlib/screenSpaceAO.glsllib
diff options
context:
space:
mode:
Diffstat (limited to 'src/Runtime/res/effectlib/screenSpaceAO.glsllib')
-rw-r--r--src/Runtime/res/effectlib/screenSpaceAO.glsllib40
1 files changed, 20 insertions, 20 deletions
diff --git a/src/Runtime/res/effectlib/screenSpaceAO.glsllib b/src/Runtime/res/effectlib/screenSpaceAO.glsllib
index bb6cbbe6..54204a1f 100644
--- a/src/Runtime/res/effectlib/screenSpaceAO.glsllib
+++ b/src/Runtime/res/effectlib/screenSpaceAO.glsllib
@@ -39,7 +39,7 @@ float hashRot(vec2 pos)
// Basically an odd-even hash.
float px = 2.0 * fract(floor(pos.x) * 0.5);
float py = fract(floor(pos.y) * 0.5);
-
+
return px + py;
}
@@ -52,7 +52,7 @@ vec3 getViewSpacePos( sampler2D depthSampler, vec2 camProps, vec2 UV, vec4 UvToE
{
float sampleDepth = getDepthValue( texture(depthSampler, UV), camProps );
sampleDepth = depthValueToLinearDistance( sampleDepth, camProps );
-
+
vec2 scaledUV = (UV * UvToEye.xy) + UvToEye.zw;
return vec3(scaledUV * sampleDepth, sampleDepth);
}
@@ -62,7 +62,7 @@ vec2 computeDir( vec2 baseDir, int v )
float ang = 3.1415926535 * hashRot( gl_FragCoord.xy ) + float(v - 1);
vec2 vX = vec2(cos(ang), sin(ang));
vec2 vY = vec2(-sin(ang), cos(ang));
-
+
return vec2( dot(baseDir, vX), dot(baseDir, vY) );
}
@@ -71,23 +71,23 @@ vec2 offsetDir( vec2 baseDir, int v )
float ang = float(v - 1);
vec2 vX = vec2(cos(ang), sin(ang));
vec2 vY = vec2(-sin(ang), cos(ang));
-
+
return vec2( dot(baseDir, vX), dot(baseDir, vY) );
}
float SSambientOcclusion(sampler2D depthSampler, vec3 viewNorm, vec4 aoParams, vec4 aoParams2, vec2 camProps, vec4 aoScreen, vec4 UvToEye)
{
float ret = 0.0;
-
+
vec2 centerUV = gl_FragCoord.xy * aoScreen.zw;
vec3 viewPos = getViewSpacePos( depthSampler, camProps, centerUV, UvToEye );
viewPos += viewNorm * aoParams.w;
-
+
float screenRadius = aoParams.y * aoScreen.y / viewPos.z;
if (screenRadius < 1.0) { return 1.0; }
vec3 kernel[9];
-
+
// The X and Y are the 2d direction, while the Z is the height of the sphere at that point.
// In essence, it normalizes the 3d vector, but we're really interested in the 2D offset.
kernel[0] = vec3(-0.1376476, 0.2842022, 0.948832);
@@ -99,52 +99,52 @@ float SSambientOcclusion(sampler2D depthSampler, vec3 viewNorm, vec4 aoParams, v
kernel[6] = vec3(0.7343006, 0.3774331, 0.5642);
kernel[7] = vec3(0.1408805, -0.88915, 0.4353);
kernel[8] = vec3(-0.6642616, -0.543601, 0.5130);
-
+
int radLevels = int(floor(aoParams2.x));
float radStep = 1.0 / aoParams2.x;
-
+
for (int j = 1; j <= radLevels; ++j)
{
for (int i = 0; i < 9; ++i)
{
float curRange = aoParams.y * radStep * float(j);
float curRadius = curRange * kernel[i].z;
-
+
vec3 smpDir;
smpDir.xy = computeDir(kernel[i].xy, j) * aoParams2.y + (1.0 - aoParams2.y) * offsetDir(kernel[i].xy, j);
smpDir.z = kernel[i].z;
smpDir *= curRange;
-
+
vec2 smpUV = centerUV.xy + smpDir.xy * aoScreen.zw;
-
+
// First method is based on Horizon-Based AO
vec3 samplePos = getViewSpacePos( depthSampler, camProps, smpUV, UvToEye );
vec3 smpVec = samplePos - viewPos;
-
+
float lenRad = dot(smpVec, smpVec);
smpVec = normalize(smpVec);
float lenDot = dot(smpVec, viewNorm);
- lenRad /= aoParams.y*aoParams.y;
+ lenRad /= aoParams.y*aoParams.y;
float falloff = smoothstep(8.0, 0.0, (lenRad - 1.0) * 0.125);
float occl = 1.0 - clamp(lenDot * falloff, 0.0, 1.0);
-
+
ret += occl * occl;
}
}
-
+
ret = (ret) / (9.0 * float(radLevels));
-
+
// Blend between soft and hard based on softness param
// NOTE : the 0.72974 is actually an gamma-inverted 0.5 (assuming gamma 2.2)
// Would not need this if we linearized color instead.
float hardCut = (1.0 - aoParams.z) * 0.72974;
ret = smoothstep(0.0, 1.0, (ret - hardCut) / (1.0 - hardCut));
-
+
// Blend between full and no occlusion based on strength param
ret = aoParams.x * ret + (1.0 - aoParams.x);
-
- return ret;
+
+ return ret;
}
#endif