Switched AO buffer to single R8 component

This commit is contained in:
Olivier Prat 2018-09-18 11:54:39 +02:00
parent a2abf33669
commit f7379dfcc9
3 changed files with 7 additions and 6 deletions

View file

@ -78,7 +78,7 @@ void AmbientOcclusionFramebuffer::allocate() {
auto width = _frameSize.x; auto width = _frameSize.x;
auto height = _frameSize.y; auto height = _frameSize.y;
auto format = gpu::Element::COLOR_RGBA_32; auto format = gpu::Element::COLOR_R_8;
_occlusionTexture = gpu::Texture::createRenderBuffer(format, width, height, gpu::Texture::SINGLE_MIP, gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_LINEAR_MIP_POINT, gpu::Sampler::WRAP_CLAMP)); _occlusionTexture = gpu::Texture::createRenderBuffer(format, width, height, gpu::Texture::SINGLE_MIP, gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_LINEAR_MIP_POINT, gpu::Sampler::WRAP_CLAMP));
_occlusionFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create("occlusion")); _occlusionFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create("occlusion"));

View file

@ -229,7 +229,6 @@ float getZEyeAtUV(vec2 texCoord, int level) {
const int LOG_MAX_OFFSET = 2; const int LOG_MAX_OFFSET = 2;
const int MAX_MIP_LEVEL = 5; const int MAX_MIP_LEVEL = 5;
int evalMipFromRadius(float radius) { int evalMipFromRadius(float radius) {
// mipLevel = floor(log(ssR / MAX_OFFSET));
return clamp(findMSB(int(radius)) - LOG_MAX_OFFSET, 0, MAX_MIP_LEVEL); return clamp(findMSB(int(radius)) - LOG_MAX_OFFSET, 0, MAX_MIP_LEVEL);
} }
@ -293,12 +292,14 @@ float computeHorizonFromTap(vec3 tapPositionES, vec3 fragPositionES, vec3 fragNo
vec3 deltaVec = tapPositionES - fragPositionES; vec3 deltaVec = tapPositionES - fragPositionES;
float distance = length(deltaVec); float distance = length(deltaVec);
float cosHorizonAngle = dot(deltaVec, fragNormalES) / (distance + epsilon); float cosHorizonAngle = 0.0;
float radiusFalloff = max(0.0, 1.0 - (distance*distance / getRadius2())); float radiusFalloff = max(0.0, 1.0 - (distance*distance / getRadius2()));
cosHorizonAngle = dot(deltaVec, fragNormalES) / (distance + epsilon);
cosHorizonAngle = max(0.0, (cosHorizonAngle - getFalloffAngle()) * getFalloffAngleScale()); cosHorizonAngle = max(0.0, (cosHorizonAngle - getFalloffAngle()) * getFalloffAngleScale());
cosHorizonAngle *= radiusFalloff; cosHorizonAngle *= radiusFalloff;
return cosHorizonAngle; return cosHorizonAngle;
} }

View file

@ -82,7 +82,7 @@ void main(void) {
// Accumulate the Obscurance for each samples // Accumulate the Obscurance for each samples
float sum = 0.0; float sum = 0.0;
float keepTapRadius = 1.0; float keepTapRadius = 1.0;
int keepedMip = -1; int keptMip = -1;
bool keep = false; bool keep = false;
int sampleCount = int(getNumSamples()); int sampleCount = int(getNumSamples());
for (int i = 0; i < sampleCount; ++i) { for (int i = 0; i < sampleCount; ++i) {
@ -92,7 +92,7 @@ void main(void) {
vec2 fragToTap = vec2(ssC) + tap.xy - fragCoord.xy; vec2 fragToTap = vec2(ssC) + tap.xy - fragCoord.xy;
if (dot(fragToTap,fragToTap) < keepTapRadius) { if (dot(fragToTap,fragToTap) < keepTapRadius) {
keep = true; keep = true;
keepedMip = evalMipFromRadius(tap.z * float(doFetchMips())); keptMip = evalMipFromRadius(tap.z * float(doFetchMips()));
} }
vec3 tapUVZ = fetchTap(side, ssC, tap, imageSize); vec3 tapUVZ = fetchTap(side, ssC, tap, imageSize);
@ -127,6 +127,6 @@ void main(void) {
if (!keep) { if (!keep) {
outFragColor = vec4(0.1); outFragColor = vec4(0.1);
} else { } else {
outFragColor.rgb = colorWheel(float(keepedMip)/float(MAX_MIP_LEVEL)); outFragColor.rgb = colorWheel(float(keptMip)/float(MAX_MIP_LEVEL));
} }
} }