Speed up SSAO again

Use log2(xy) = log2(x) + log2(y), and approximate log2(alpha) =
log2(previous alpha) + .5.
Log2 is indeed a costly instruction.
This commit is contained in:
vlj 2014-06-03 03:41:05 +02:00
parent 164ffa2b4f
commit e571afc43b

View File

@ -58,6 +58,7 @@ void main(void)
float r = radius / FragPos.z; float r = radius / FragPos.z;
float phi = 30. * (x ^ y) + 10. * x * y; float phi = 30. * (x ^ y) + 10. * x * y;
float bl = 0.0; float bl = 0.0;
float m = log2(r) + 6 + log2(invSamples);
float theta = 2. * 3.14 * tau * .5 * invSamples + phi; float theta = 2. * 3.14 * tau * .5 * invSamples + phi;
vec2 rotations = vec2(cos(theta), sin(theta)) * screen; vec2 rotations = vec2(cos(theta), sin(theta)) * screen;
@ -69,7 +70,7 @@ void main(void)
float h = r * alpha; float h = r * alpha;
vec2 offset = h * rotations; vec2 offset = h * rotations;
float m = round(log2(h) + 6); m = m + .5;
ivec2 ioccluder_uv = ivec2(x, y) + ivec2(offset); ivec2 ioccluder_uv = ivec2(x, y) + ivec2(offset);
if (ioccluder_uv.x < 0 || ioccluder_uv.x > screen.x || ioccluder_uv.y < 0 || ioccluder_uv.y > screen.y) continue; if (ioccluder_uv.x < 0 || ioccluder_uv.x > screen.x || ioccluder_uv.y < 0 || ioccluder_uv.y > screen.y) continue;