Some fixes for HBAO. Need performance improvements

This commit is contained in:
Olivier Prat 2018-09-11 16:14:54 +02:00
parent fd9d05bdbf
commit 6c0309402f
3 changed files with 15 additions and 9 deletions

View file

@ -184,12 +184,15 @@ void AmbientOcclusionEffect::configure(const Config& config) {
auto& current = _parametersBuffer.edit().radiusInfo;
current.x = radius;
current.y = radius * radius;
current.z = (float)(1.0 / pow((double)radius, RADIUS_POWER));
current.z = 10.0f;
#if !SSAO_USE_HORIZON_BASED
current.z *= (float)(1.0 / pow((double)radius, RADIUS_POWER));
#endif
}
if (config.obscuranceLevel != _parametersBuffer->getObscuranceLevel()) {
auto& current = _parametersBuffer.edit().radiusInfo;
current.w = config.obscuranceLevel * 10.0;
current.w = config.obscuranceLevel;
}
if (config.falloffBias != _parametersBuffer->getFalloffBias()) {

View file

@ -305,8 +305,11 @@ float evalVisibilitySSAO(in vec3 centerPosition, in vec3 centerNormal, in vec3 t
vec3 tapUVZ = fetchTap(side, centerPixelPos, tap, imageSize);
vec3 tapPositionES = evalEyePositionFromZeye(side.x, tapUVZ.z, tapUVZ.xy);
vec3 deltaVec = normalize(tapPositionES - fragPositionES);
float rawHorizon = dot(deltaVec, fragNormalES);
<$horizon$> = max(<$horizon$>, dot(deltaVec, fragNormalES));
rawHorizon *= 1.0 - radius / ssDiskRadius;
<$horizon$> = max(<$horizon$>, rawHorizon);
}
}
<@endfunc@>
@ -368,7 +371,8 @@ vec2 searchHorizons(ivec4 side, ivec2 centerPixelPos, vec2 imageSize, vec2 delta
// Forward search for h1
vec2 clampedSearchVec = clampSearchVec(imageSize, vec2(centerPixelPos), searchVec);
int stepCount = int(floor(length(clampedSearchVec)+0.5));
vec2 absClampedSearchVec = abs(clampedSearchVec);
int stepCount = int(max(absClampedSearchVec.x, absClampedSearchVec.y));
if (stepCount>0) {
vec2 deltaPixelTap = clampedSearchVec / float(stepCount);
float deltaRadius = length(deltaPixelTap);
@ -376,7 +380,8 @@ vec2 searchHorizons(ivec4 side, ivec2 centerPixelPos, vec2 imageSize, vec2 delta
}
// Backward search for h2
clampedSearchVec = clampSearchVec(imageSize, vec2(centerPixelPos), -searchVec);
stepCount = int(floor(length(clampedSearchVec)+0.5));
absClampedSearchVec = abs(clampedSearchVec);
stepCount = int(max(absClampedSearchVec.x, absClampedSearchVec.y));
if (stepCount>0) {
vec2 deltaPixelTap = clampedSearchVec / float(stepCount);
float deltaRadius = length(deltaPixelTap);
@ -411,7 +416,7 @@ vec2 searchHorizons(ivec4 side, ivec2 centerPixelPos, vec2 imageSize, vec2 delta
float evalVisibilityHBAO(ivec4 side, ivec2 centerPixelPos, vec2 imageSize, vec2 deltaTap, float ssDiskRadius,
vec3 fragPositionES, vec3 fragNormalES) {
vec2 horizons = searchHorizons(side, centerPixelPos, imageSize, deltaTap, ssDiskRadius, fragPositionES, fragNormalES);
return (horizons.x + horizons.y) * 0.5;
return (horizons.x + horizons.y) * 0.5 / PI;
}
<@endfunc@>

View file

@ -46,9 +46,7 @@ void main(void) {
// Choose the screen-space sample radius
float ssDiskRadius = evalDiskRadius(fragPositionES.z, imageSize);
#if SSAO_USE_HORIZON_BASED
ssDiskRadius = min(ssDiskRadius, 3.0);
#endif
// Let's make noise
float randomPatternRotationAngle = getAngleDithering(centerPixelPos);