mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-07-03 12:38:47 +02:00
Some cleanup
This commit is contained in:
parent
d9e2c8df69
commit
d0eef1b8d0
2 changed files with 60 additions and 58 deletions
|
@ -80,11 +80,11 @@ void AmbientOcclusionFramebuffer::allocate() {
|
||||||
auto height = _frameSize.y;
|
auto height = _frameSize.y;
|
||||||
auto format = gpu::Element::COLOR_RGBA_32;
|
auto format = gpu::Element::COLOR_RGBA_32;
|
||||||
|
|
||||||
_occlusionTexture = gpu::Texture::createRenderBuffer(format, width, height, gpu::Texture::SINGLE_MIP, gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_LINEAR_MIP_POINT));
|
_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"));
|
||||||
_occlusionFramebuffer->setRenderBuffer(0, _occlusionTexture);
|
_occlusionFramebuffer->setRenderBuffer(0, _occlusionTexture);
|
||||||
|
|
||||||
_occlusionBlurredTexture = gpu::Texture::createRenderBuffer(format, width, height, gpu::Texture::SINGLE_MIP, gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_LINEAR_MIP_POINT));
|
_occlusionBlurredTexture = gpu::Texture::createRenderBuffer(format, width, height, gpu::Texture::SINGLE_MIP, gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_LINEAR_MIP_POINT, gpu::Sampler::WRAP_CLAMP));
|
||||||
_occlusionBlurredFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create("occlusionBlurred"));
|
_occlusionBlurredFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create("occlusionBlurred"));
|
||||||
_occlusionBlurredFramebuffer->setRenderBuffer(0, _occlusionBlurredTexture);
|
_occlusionBlurredFramebuffer->setRenderBuffer(0, _occlusionBlurredTexture);
|
||||||
}
|
}
|
||||||
|
|
|
@ -293,66 +293,29 @@ float evalVisibilitySSAO(in vec3 centerPosition, in vec3 centerNormal, in vec3 t
|
||||||
float computeHorizonFromTap(vec3 tapPositionES, vec3 fragPositionES, vec3 fragNormalES) {
|
float computeHorizonFromTap(vec3 tapPositionES, vec3 fragPositionES, vec3 fragNormalES) {
|
||||||
vec3 deltaVec = tapPositionES - fragPositionES;
|
vec3 deltaVec = tapPositionES - fragPositionES;
|
||||||
float distanceSquared = dot(deltaVec, deltaVec);
|
float distanceSquared = dot(deltaVec, deltaVec);
|
||||||
float rawHorizon = dot(normalize(deltaVec), fragNormalES);
|
float horizon = dot(normalize(deltaVec), fragNormalES);
|
||||||
float radiusFalloff = distanceSquared / getRadius2();
|
float radiusFalloff = max(0.0, 1.0 - (distanceSquared / getRadius2()));
|
||||||
|
|
||||||
rawHorizon = max(0.0, (rawHorizon - getFalloffAngle()) / (1.0 - getFalloffAngle()));
|
horizon = max(0.0, (horizon - getFalloffAngle()) / (1.0 - getFalloffAngle()));
|
||||||
rawHorizon *= max(0.0, 1.0 - radiusFalloff);
|
horizon *= radiusFalloff;
|
||||||
|
|
||||||
return rawHorizon;
|
return horizon;
|
||||||
}
|
}
|
||||||
|
|
||||||
<@func computeHorizon()@>
|
<@func computeHorizon()@>
|
||||||
vec3 tap = vec3(tapPixelPos, radius);
|
vec3 tap = vec3(tapPixelPos, radius);
|
||||||
vec4 tapUVZ_mip = fetchTap(side, centerPixelPos, tap, imageSize);
|
vec4 tapUVZ_mip = fetchTap(side, centerPixelPos, tap, imageSize);
|
||||||
vec3 tapPositionES = evalEyePositionFromZeye(side.x, tapUVZ_mip.z, tapUVZ_mip.xy);
|
vec3 tapPositionES = evalEyePositionFromZeye(side.x, tapUVZ_mip.z, tapUVZ_mip.xy);
|
||||||
float rawHorizon = computeHorizonFromTap(tapPositionES, fragPositionES, fragNormalES);
|
float tapCosHorizonAngle = computeHorizonFromTap(tapPositionES, fragPositionES, fragNormalES);
|
||||||
|
|
||||||
<$horizon$> = max(<$horizon$>, rawHorizon);
|
cosHorizonAngle = max(cosHorizonAngle, tapCosHorizonAngle);
|
||||||
<@endfunc@>
|
<@endfunc@>
|
||||||
|
|
||||||
#define SSAO_LINEAR_SAMPLING 1
|
#define SSAO_LINEAR_SAMPLING 1
|
||||||
|
|
||||||
<@func updateHorizon(horizon, deltaPixelTap)@>
|
|
||||||
{
|
|
||||||
vec2 deltaPixelTap = clampedSearchVec / float(stepCount);
|
|
||||||
float searchRadius = length(clampedSearchVec);
|
|
||||||
float deltaRadius = searchRadius / float(stepCount);
|
|
||||||
vec2 tapPixelPos = vec2(0);
|
|
||||||
|
|
||||||
#if !SSAO_LINEAR_SAMPLING
|
|
||||||
float radius = deltaRadius;
|
|
||||||
float mipLevel = evalMipFromRadius(radius * float(doFetchMips()));
|
|
||||||
|
|
||||||
while (radius<searchRadius) {
|
|
||||||
tapPixelPos += <$deltaPixelTap$>;
|
|
||||||
|
|
||||||
<$computeHorizon()$>
|
|
||||||
|
|
||||||
if (tapUVZ_mip.w != mipLevel) {
|
|
||||||
mipLevel = tapUVZ_mip.w;
|
|
||||||
deltaRadius *= 2;
|
|
||||||
<$deltaPixelTap$> *= 2;
|
|
||||||
}
|
|
||||||
radius += deltaRadius;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
float radius = 0.0;
|
|
||||||
int stepIndex;
|
|
||||||
|
|
||||||
for (stepIndex=0 ; stepIndex<stepCount ; stepIndex++) {
|
|
||||||
tapPixelPos += <$deltaPixelTap$>;
|
|
||||||
radius += deltaRadius;
|
|
||||||
|
|
||||||
<$computeHorizon()$>
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
<@endfunc@>
|
|
||||||
|
|
||||||
vec2 clampSearchVec(vec2 imageSize, vec2 centerPixelPos, vec2 searchVec) {
|
vec2 clampSearchVec(vec2 imageSize, vec2 centerPixelPos, vec2 searchVec) {
|
||||||
vec2 clampdSearchVec = searchVec;
|
vec2 clampdSearchVec = searchVec;
|
||||||
vec2 endPixel = centerPixelPos + clampdSearchVec;
|
/* TEMPO OP vec2 endPixel = centerPixelPos + clampdSearchVec;
|
||||||
|
|
||||||
if (endPixel.x < 0) {
|
if (endPixel.x < 0) {
|
||||||
clampdSearchVec = clampdSearchVec * ((0-centerPixelPos.x) / clampdSearchVec.x);
|
clampdSearchVec = clampdSearchVec * ((0-centerPixelPos.x) / clampdSearchVec.x);
|
||||||
|
@ -368,11 +331,55 @@ vec2 clampSearchVec(vec2 imageSize, vec2 centerPixelPos, vec2 searchVec) {
|
||||||
}
|
}
|
||||||
if (endPixel.y >= imageSize.y) {
|
if (endPixel.y >= imageSize.y) {
|
||||||
clampdSearchVec = clampdSearchVec * ((imageSize.y-1-centerPixelPos.y) / clampdSearchVec.y);
|
clampdSearchVec = clampdSearchVec * ((imageSize.y-1-centerPixelPos.y) / clampdSearchVec.y);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
return clampdSearchVec;
|
return clampdSearchVec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float computeHorizon(ivec4 side, ivec2 centerPixelPos, vec2 imageSize, vec2 deltaTap, float ssDiskRadius,
|
||||||
|
vec3 fragPositionES, vec3 fragNormalES, vec2 clampedSearchVec) {
|
||||||
|
vec2 absClampedSearchVec = abs(clampedSearchVec);
|
||||||
|
int stepCount = int(max(absClampedSearchVec.x, absClampedSearchVec.y));
|
||||||
|
float cosHorizonAngle = 0.0;
|
||||||
|
|
||||||
|
if (stepCount>0) {
|
||||||
|
vec2 deltaPixelTap = clampedSearchVec / float(stepCount);
|
||||||
|
float searchRadius = length(clampedSearchVec);
|
||||||
|
float deltaRadius = searchRadius / float(stepCount);
|
||||||
|
vec2 tapPixelPos = vec2(0);
|
||||||
|
|
||||||
|
#if !SSAO_LINEAR_SAMPLING
|
||||||
|
float radius = deltaRadius;
|
||||||
|
float mipLevel = evalMipFromRadius(radius * float(doFetchMips()));
|
||||||
|
|
||||||
|
while (radius<searchRadius) {
|
||||||
|
tapPixelPos += deltaPixelTap;
|
||||||
|
|
||||||
|
<$computeHorizon()$>
|
||||||
|
|
||||||
|
if (tapUVZ_mip.w != mipLevel) {
|
||||||
|
mipLevel = tapUVZ_mip.w;
|
||||||
|
deltaRadius *= 2;
|
||||||
|
deltaPixelTap *= 2;
|
||||||
|
}
|
||||||
|
radius += deltaRadius;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
float radius = 0.0;
|
||||||
|
int stepIndex;
|
||||||
|
|
||||||
|
for (stepIndex=0 ; stepIndex<stepCount ; stepIndex++) {
|
||||||
|
tapPixelPos += deltaPixelTap;
|
||||||
|
radius += deltaRadius;
|
||||||
|
|
||||||
|
<$computeHorizon()$>
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
return cosHorizonAngle;
|
||||||
|
}
|
||||||
|
|
||||||
vec2 searchHorizons(ivec4 side, ivec2 centerPixelPos, vec2 imageSize, vec2 deltaTap, float ssDiskRadius,
|
vec2 searchHorizons(ivec4 side, ivec2 centerPixelPos, vec2 imageSize, vec2 deltaTap, float ssDiskRadius,
|
||||||
vec3 fragPositionES, vec3 fragNormalES) {
|
vec3 fragPositionES, vec3 fragNormalES) {
|
||||||
vec2 searchVec = deltaTap * ssDiskRadius;
|
vec2 searchVec = deltaTap * ssDiskRadius;
|
||||||
|
@ -380,18 +387,13 @@ vec2 searchHorizons(ivec4 side, ivec2 centerPixelPos, vec2 imageSize, vec2 delta
|
||||||
|
|
||||||
// Forward search for h1
|
// Forward search for h1
|
||||||
vec2 clampedSearchVec = clampSearchVec(imageSize, vec2(centerPixelPos), searchVec);
|
vec2 clampedSearchVec = clampSearchVec(imageSize, vec2(centerPixelPos), searchVec);
|
||||||
vec2 absClampedSearchVec = abs(clampedSearchVec);
|
horizons.x = computeHorizon(side, centerPixelPos, imageSize, deltaTap, ssDiskRadius,
|
||||||
int stepCount = int(max(absClampedSearchVec.x, absClampedSearchVec.y));
|
fragPositionES, fragNormalES, clampedSearchVec);
|
||||||
if (stepCount>0) {
|
|
||||||
<$updateHorizon(horizons.x, deltaPixelTap)$>
|
|
||||||
}
|
|
||||||
// Backward search for h2
|
// Backward search for h2
|
||||||
clampedSearchVec = clampSearchVec(imageSize, vec2(centerPixelPos), -searchVec);
|
clampedSearchVec = clampSearchVec(imageSize, vec2(centerPixelPos), -searchVec);
|
||||||
absClampedSearchVec = abs(clampedSearchVec);
|
horizons.y = computeHorizon(side, centerPixelPos, imageSize, deltaTap, ssDiskRadius,
|
||||||
stepCount = int(max(absClampedSearchVec.x, absClampedSearchVec.y));
|
fragPositionES, fragNormalES, clampedSearchVec);
|
||||||
if (stepCount>0) {
|
|
||||||
<$updateHorizon(horizons.y, deltaPixelTap)$>
|
|
||||||
}
|
|
||||||
|
|
||||||
return horizons;
|
return horizons;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue