Update ssao.frag

samplePos.z bias  can remove banding
This commit is contained in:
binary 2019-11-25 10:13:19 +08:00 committed by GitHub
parent 144b58a253
commit 364c4695a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -40,6 +40,8 @@ void main()
// Calculate occlusion value // Calculate occlusion value
float occlusion = 0.0f; float occlusion = 0.0f;
// remove banding
float bais = 0.01f;
for(int i = 0; i < SSAO_KERNEL_SIZE; i++) for(int i = 0; i < SSAO_KERNEL_SIZE; i++)
{ {
vec3 samplePos = TBN * uboSSAOKernel.samples[i].xyz; vec3 samplePos = TBN * uboSSAOKernel.samples[i].xyz;
@ -57,9 +59,9 @@ void main()
#ifdef RANGE_CHECK #ifdef RANGE_CHECK
// Range check // Range check
float rangeCheck = smoothstep(0.0f, 1.0f, SSAO_RADIUS / abs(fragPos.z - sampleDepth)); float rangeCheck = smoothstep(0.0f, 1.0f, SSAO_RADIUS / abs(fragPos.z - sampleDepth));
occlusion += (sampleDepth >= samplePos.z ? 1.0f : 0.0f) * rangeCheck; occlusion += (sampleDepth >= samplePos.z + bais ? 1.0f : 0.0f) * rangeCheck;
#else #else
occlusion += (sampleDepth >= samplePos.z ? 1.0f : 0.0f); occlusion += (sampleDepth >= samplePos.z + bais ? 1.0f : 0.0f);
#endif #endif
} }
occlusion = 1.0 - (occlusion / float(SSAO_KERNEL_SIZE)); occlusion = 1.0 - (occlusion / float(SSAO_KERNEL_SIZE));