Use a larger blur filter for SSAO

We go from 9 to 15 taps to better match the 16x16 noise pattern.
This commit is contained in:
Mathias Agopian
2019-11-19 16:51:19 -08:00
committed by Mathias Agopian
parent 0ee1d406e0
commit 3ce4dd94f7
3 changed files with 12 additions and 12 deletions

View File

@@ -39,11 +39,11 @@ vertex {
}
fragment {
const int kGaussianCount = 5;
const int kGaussianCount = 8;
const float kGaussianSamples[] = float[](
0.239365, 0.199935, 0.116512, 0.047370, 0.013437
0.149603, 0.139446, 0.112927, 0.079454, 0.048569, 0.025795, 0.011902, 0.004772
);
const float kGaussianWeightSum = 0.993872;
const float kGaussianWeightSum = 0.995331;
ivec2 clampToEdge(const sampler2D s, ivec2 uv) {
ivec2 size = textureSize(s, 0);
@@ -78,7 +78,7 @@ fragment {
}
void postProcess(inout PostProcessInputs postProcess) {
ivec2 uv = ivec2(variable_vertex.xy * materialParams.resolution.xy);
highp ivec2 uv = ivec2(variable_vertex.xy * materialParams.resolution.xy);
float depth = texelFetch(materialParams_depth, uv, 0).r;

View File

@@ -210,7 +210,8 @@ fragment {
return clamp(uv, ivec2(0), size - ivec2(1));
}
float computeAmbientOcclusionSAO(uint i, float ssDiskRadius, const ivec2 ssOrigin,
void computeAmbientOcclusionSAO(inout float occlusion,
uint i, float ssDiskRadius, const ivec2 ssOrigin,
const highp vec3 origin, const vec3 normal, const vec3 noise) {
vec3 tap = tapLocation(i, noise);
@@ -230,13 +231,12 @@ fragment {
float vv = dot(v, v); // squared distance
float vn = dot(v, normal); // distance * cos(v, normal)
const float uu = 0.015;
float falloff = saturate(1.0 - vv * materialParams.invRadiusSquared);
float occlusion = falloff * max(0.0, vn + origin.z * materialParams.bias) / (vv + uu);
return occlusion;
float w = saturate(1.0 - vv * materialParams.invRadiusSquared);
occlusion += w * max(0.0, vn + origin.z * materialParams.bias) / (vv + uu);
}
void postProcess(inout PostProcessInputs postProcess) {
vec2 uv = variable_vertex.xy; // interpolated to pixel center
highp vec2 uv = variable_vertex.xy; // interpolated to pixel center
highp float depth = sampleDepthLinear(uv);
highp vec3 origin = computeViewSpacePositionFromDepth(uv, depth);
@@ -252,7 +252,7 @@ fragment {
float occlusion = 0.0;
for (uint i = 0u; i < kSpiralSampleCount; i++) {
occlusion += computeAmbientOcclusionSAO(i, ssDiskRadius, ssOrigin, origin, normal, noise);
computeAmbientOcclusionSAO(occlusion, i, ssDiskRadius, ssOrigin, origin, normal, noise);
}
float ao = max(0.0, 1.0 - (2.0 / float(kSpiralSampleCount)) * materialParams.intensity * occlusion);

View File

@@ -222,7 +222,7 @@ int main(int argc, char** argv) {
float weightSum = 0;
size_t gaussianWidth = 9; // must be odd
size_t gaussianWidth = 15; // must be odd
const size_t gaussianSampleCount = (gaussianWidth + 1) / 2;
std::cout << "const int kGaussianCount = " << gaussianSampleCount << ";" << std::endl;
std::cout << "const int kRadius = kGaussianCount - 1;" << std::endl;
@@ -241,7 +241,7 @@ int main(int argc, char** argv) {
// Cut-off frequency definition:
// fc = 1.1774 / (2pi * q) (half power frequency or 0.707 amplitude)
float q = (gaussianWidth + 1.0f) / 6.0f; // ~1.667 for 9 taps
float q = (gaussianWidth + 1.0f) / 6.0f; // ~2.667 for 15 taps
float g = float((1.0 / (std::sqrt(2.0 * F_PI) * q)) * std::exp(-(x * x) / (2.0 * q * q)));
weightSum += g * (i == 0 ? 1.0f : 2.0f);