From ad5064b045e88509797310d15b0c574e455240e7 Mon Sep 17 00:00:00 2001 From: Olivier Prat Date: Mon, 17 Sep 2018 14:33:48 +0200 Subject: [PATCH] Removed falloff distance from shader --- .../render-utils/src/AmbientOcclusionEffect.h | 2 +- libraries/render-utils/src/ssao.slh | 14 +++++++------- libraries/render-utils/src/ssao_makeOcclusion.slf | 3 +-- .../utilities/render/ambientOcclusionPass.qml | 2 +- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/libraries/render-utils/src/AmbientOcclusionEffect.h b/libraries/render-utils/src/AmbientOcclusionEffect.h index ad56aff399..81ceee9bf6 100644 --- a/libraries/render-utils/src/AmbientOcclusionEffect.h +++ b/libraries/render-utils/src/AmbientOcclusionEffect.h @@ -79,7 +79,7 @@ public: void setRadius(float newRadius) { radius = std::max(0.01f, newRadius); emit dirty(); } void setObscuranceLevel(float level) { obscuranceLevel = std::max(0.01f, level); emit dirty(); } - void setFalloffAngle(float bias) { falloffAngle = std::max(0.0f, std::min(bias, 0.2f)); emit dirty(); } + void setFalloffAngle(float bias) { falloffAngle = std::max(0.0f, std::min(bias, 1.0f)); emit dirty(); } void setFalloffDistance(float value) { falloffDistance = std::max(0.0f, value); emit dirty(); } void setEdgeSharpness(float sharpness) { edgeSharpness = std::max(0.0f, (float)sharpness); emit dirty(); } void setBlurDeviation(float deviation) { blurDeviation = std::max(0.0f, deviation); emit dirty(); } diff --git a/libraries/render-utils/src/ssao.slh b/libraries/render-utils/src/ssao.slh index b74cb740a8..88d8f08e7a 100644 --- a/libraries/render-utils/src/ssao.slh +++ b/libraries/render-utils/src/ssao.slh @@ -290,14 +290,14 @@ float evalVisibilitySSAO(in vec3 centerPosition, in vec3 centerNormal, in vec3 t return f * f * f * max((vn - getFalloffAngle()) / (epsilon + vv), 0.0); } -float computeHorizonFromTap(vec3 tapPositionES, vec3 fragPositionES, vec3 fragNormalES, float normalizedRadius) { +float computeHorizonFromTap(vec3 tapPositionES, vec3 fragPositionES, vec3 fragNormalES) { vec3 deltaVec = tapPositionES - fragPositionES; - float distance = abs(deltaVec.z); + float distanceSquared = dot(deltaVec, deltaVec); float rawHorizon = dot(normalize(deltaVec), fragNormalES); + float radiusFalloff = distanceSquared / getRadius2(); - rawHorizon = (rawHorizon - getFalloffAngle()) / (1.0 - getFalloffAngle()); - rawHorizon *= 1.0 - normalizedRadius * normalizedRadius; - rawHorizon *= 1.0 - smoothstep(getFalloffDistance()/2, getFalloffDistance(), distance); + rawHorizon = max(0.0, (rawHorizon - getFalloffAngle()) / (1.0 - getFalloffAngle())); + rawHorizon *= 1.0 - radiusFalloff; return rawHorizon; } @@ -306,12 +306,12 @@ float computeHorizonFromTap(vec3 tapPositionES, vec3 fragPositionES, vec3 fragNo vec3 tap = vec3(tapPixelPos, radius); vec4 tapUVZ_mip = fetchTap(side, centerPixelPos, tap, imageSize); vec3 tapPositionES = evalEyePositionFromZeye(side.x, tapUVZ_mip.z, tapUVZ_mip.xy); - float rawHorizon = computeHorizonFromTap(tapPositionES, fragPositionES, fragNormalES, radius / searchRadius); + float rawHorizon = computeHorizonFromTap(tapPositionES, fragPositionES, fragNormalES); <$horizon$> = max(<$horizon$>, rawHorizon); <@endfunc@> -#define SSAO_LINEAR_SAMPLING 0 +#define SSAO_LINEAR_SAMPLING 1 <@func updateHorizon(horizon, deltaPixelTap)@> { diff --git a/libraries/render-utils/src/ssao_makeOcclusion.slf b/libraries/render-utils/src/ssao_makeOcclusion.slf index fc974a7baa..c81644ce58 100644 --- a/libraries/render-utils/src/ssao_makeOcclusion.slf +++ b/libraries/render-utils/src/ssao_makeOcclusion.slf @@ -69,8 +69,7 @@ void main(void) { #endif } - visibilitySum = visibilitySum * getInvNumSamples(); - float occlusion = clamp(1.0 - visibilitySum * getObscuranceScaling(), 0.0, 1.0); + float occlusion = clamp(1.0 - visibilitySum * getObscuranceScaling() * getInvNumSamples(), 0.0, 1.0); // KEEP IT for Debugging // Bilateral box-filter over a quad for free, respecting depth edges diff --git a/scripts/developer/utilities/render/ambientOcclusionPass.qml b/scripts/developer/utilities/render/ambientOcclusionPass.qml index ca00849706..0416443139 100644 --- a/scripts/developer/utilities/render/ambientOcclusionPass.qml +++ b/scripts/developer/utilities/render/ambientOcclusionPass.qml @@ -37,7 +37,7 @@ Rectangle { "Level:obscuranceLevel:1.0:false", "Num Taps:numSamples:32:true", "Taps Spiral:numSpiralTurns:10.0:false", - "Falloff Angle:falloffAngle:0.2:false", + "Falloff Angle:falloffAngle:0.5:false", "Falloff Distance:falloffDistance:2.0:false", "Blur Edge Sharpness:edgeSharpness:1.0:false", "Blur Radius:blurRadius:15.0:false",