mirror of
https://github.com/lubosz/overte.git
synced 2025-04-24 14:03:17 +02:00
Some small cleanups
This commit is contained in:
parent
fbd158938b
commit
086ba998c8
3 changed files with 27 additions and 39 deletions
|
@ -83,9 +83,9 @@ gpu::TexturePointer AmbientOcclusionFramebuffer::getLinearDepthTexture() {
|
|||
|
||||
void AmbientOcclusionFramebuffer::allocate() {
|
||||
#if SSAO_BILATERAL_BLUR_USE_NORMAL
|
||||
const auto occlusionformat = gpu::Element{ gpu::VEC4, gpu::HALF, gpu::RGBA };
|
||||
auto occlusionformat = gpu::Element{ gpu::VEC4, gpu::HALF, gpu::RGBA };
|
||||
#else
|
||||
const auto occlusionformat = gpu::Element{ gpu::VEC3, gpu::NUINT8, gpu::RGB };
|
||||
auto occlusionformat = gpu::Element{ gpu::VEC3, gpu::NUINT8, gpu::RGB };
|
||||
#endif
|
||||
|
||||
// Full frame
|
||||
|
@ -563,27 +563,8 @@ void AmbientOcclusionEffect::run(const render::RenderContextPointer& renderConte
|
|||
|
||||
#if SSAO_USE_QUAD_SPLIT
|
||||
batch.pushProfileRange("Normal Gen.");
|
||||
{
|
||||
const auto uvScale = glm::vec3(
|
||||
normalViewport.z / (sourceViewport.z * depthResolutionScale),
|
||||
normalViewport.w / (sourceViewport.w * depthResolutionScale),
|
||||
1.0f);
|
||||
const auto postPixelOffset = glm::vec2(0.5f) / glm::vec2(occlusionDepthSize);
|
||||
const auto prePixelOffset = glm::vec2(0.5f * uvScale.x, 0.5f * uvScale.y) / glm::vec2(normalViewport.z, normalViewport.w);
|
||||
const auto uvTranslate = glm::vec3(
|
||||
postPixelOffset.x - prePixelOffset.x,
|
||||
postPixelOffset.y - prePixelOffset.y,
|
||||
0.0f
|
||||
);
|
||||
Transform model;
|
||||
|
||||
model.setScale(uvScale);
|
||||
model.setTranslation(uvTranslate);
|
||||
// TEMPO OP batch.setModelTransform(model);
|
||||
batch.setModelTransform(Transform());
|
||||
}
|
||||
|
||||
// Build face normals pass
|
||||
batch.setModelTransform(Transform());
|
||||
batch.setViewportTransform(normalViewport);
|
||||
batch.setPipeline(buildNormalsPipeline);
|
||||
batch.setResourceTexture(render_utils::slot::texture::SsaoDepth, linearDepthTexture);
|
||||
|
|
|
@ -297,9 +297,7 @@ vec2 fetchTap(ivec4 side, vec2 tapUV, float tapRadius) {
|
|||
}
|
||||
|
||||
vec3 buildPosition(ivec4 side, vec2 fragUVPos) {
|
||||
vec2 fetchUV = clamp(fragUVPos, vec2(0), vec2(1));
|
||||
fetchUV.x = mix(fetchUV.x, (fetchUV.x + getStereoSide(side)) * 0.5, isStereo());
|
||||
float Zeye = getZEyeAtUV(fetchUV, 0);
|
||||
float Zeye = getZEyeAtUV(side, fragUVPos, 0);
|
||||
return evalEyePositionFromZeye(side.x, Zeye, fragUVPos);
|
||||
}
|
||||
|
||||
|
@ -348,12 +346,20 @@ float evalVisibilitySSAO(in vec3 centerPosition, in vec3 centerNormal, in vec3 t
|
|||
return f * f * f * max((vn - getFalloffAngle()) / (epsilon + vv), 0.0);
|
||||
}
|
||||
|
||||
float computeHorizonFromTap(vec3 tapPositionES, vec3 fragPositionES, vec3 fragNormalES) {
|
||||
vec2 computeHorizonFromTap(vec3 tapPositionES, vec3 fragPositionES, vec3 fragNormalES) {
|
||||
const float epsilon = 0.001;
|
||||
|
||||
vec3 deltaVec = tapPositionES - fragPositionES;
|
||||
float distance = length(deltaVec);
|
||||
float cosHorizonAngle = dot(deltaVec, fragNormalES) / (distance + epsilon);
|
||||
|
||||
return vec2(cosHorizonAngle, distance);
|
||||
}
|
||||
|
||||
float computeWeightedHorizonFromTap(vec3 tapPositionES, vec3 fragPositionES, vec3 fragNormalES) {
|
||||
vec2 rawHorizon = computeHorizonFromTap(tapPositionES, fragPositionES, fragNormalES);
|
||||
float distance = rawHorizon.y;
|
||||
float cosHorizonAngle = rawHorizon.x;
|
||||
float radiusFalloff = max(0.0, 1.0 - (distance*distance / getRadius2()));
|
||||
|
||||
cosHorizonAngle = max(0.0, (cosHorizonAngle - getFalloffAngle()) * getFalloffAngleScale());
|
||||
|
@ -363,14 +369,13 @@ float computeHorizonFromTap(vec3 tapPositionES, vec3 fragPositionES, vec3 fragNo
|
|||
}
|
||||
|
||||
<@func computeHorizon()@>
|
||||
vec2 tapSideUVPos = tapUVOffset + fragUVPos;
|
||||
if (tapSideUVPos.x<0 || tapSideUVPos.y<0 || tapSideUVPos.x>=1.0 || tapSideUVPos.y>=1.0) {
|
||||
if (fragUVPos.x<0 || fragUVPos.y<0 || fragUVPos.x>=1.0 || fragUVPos.y>=1.0) {
|
||||
// Early exit because we've hit the borders of the frame
|
||||
break;
|
||||
}
|
||||
vec2 tapMipZ = fetchTap(side, tapSideUVPos, radius);
|
||||
vec3 tapPositionES = evalEyePositionFromZeye(side.x, tapMipZ.y, tapSideUVPos);
|
||||
float tapCosHorizonAngle = computeHorizonFromTap(tapPositionES, fragPositionES, fragNormalES);
|
||||
vec2 tapMipZ = fetchTap(side, fragUVPos, radius);
|
||||
vec3 tapPositionES = evalEyePositionFromZeye(side.x, tapMipZ.y, fragUVPos);
|
||||
float tapCosHorizonAngle = computeWeightedHorizonFromTap(tapPositionES, fragPositionES, fragNormalES);
|
||||
|
||||
cosHorizonAngle = max(cosHorizonAngle, tapCosHorizonAngle);
|
||||
|
||||
|
@ -378,7 +383,8 @@ float computeHorizonFromTap(vec3 tapPositionES, vec3 fragPositionES, vec3 fragNo
|
|||
|
||||
#define HBAO_HORIZON_SEARCH_CONSTANT_STEP 0
|
||||
|
||||
float computeHorizon(ivec4 side, vec2 fragUVPos, vec3 fragPositionES, vec3 fragNormalES, vec2 searchVec, vec2 pixelSearchVec, float searchRadius) {
|
||||
float computeHorizon(ivec4 side, vec2 fragUVPos, vec3 fragPositionES, vec3 fragNormalES, vec2 searchVec, vec2 pixelSearchVec,
|
||||
float searchRadius) {
|
||||
vec2 absSearchVec = abs(searchVec);
|
||||
pixelSearchVec = abs(pixelSearchVec);
|
||||
int stepCount = int(ceil(max(pixelSearchVec.x, pixelSearchVec.y)));
|
||||
|
@ -386,26 +392,26 @@ float computeHorizon(ivec4 side, vec2 fragUVPos, vec3 fragPositionES, vec3 fragN
|
|||
|
||||
if (stepCount>0) {
|
||||
vec2 deltaTapUV = searchVec / float(stepCount);
|
||||
|
||||
float deltaRadius = searchRadius / float(stepCount);
|
||||
vec2 tapUVOffset = vec2(0);
|
||||
|
||||
#if HBAO_HORIZON_SEARCH_CONSTANT_STEP
|
||||
float radius = 0.0;
|
||||
int stepIndex;
|
||||
|
||||
for (stepIndex=0 ; stepIndex<stepCount ; stepIndex++) {
|
||||
tapUVOffset += deltaTapUV;
|
||||
fragUVPos += deltaTapUV;
|
||||
radius += deltaRadius;
|
||||
|
||||
<$computeHorizon()$>
|
||||
}
|
||||
// Step is adapted to Mip level
|
||||
#else
|
||||
// Step is adapted to Mip level
|
||||
float radius = deltaRadius;
|
||||
float mipLevel = evalMipFromRadius(radius * float(doFetchMips()));
|
||||
|
||||
while (radius<=searchRadius) {
|
||||
tapUVOffset += deltaTapUV;
|
||||
fragUVPos += deltaTapUV;
|
||||
|
||||
<$computeHorizon()$>
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
<$declarePackOcclusionDepth()$>
|
||||
|
||||
#define SSAO_HBAO_MAX_RADIUS 100.0
|
||||
#define SSAO_HBAO_MAX_RADIUS 300.0
|
||||
|
||||
layout(location=0) in vec2 varTexCoord0;
|
||||
|
||||
|
@ -82,7 +82,8 @@ void main(void) {
|
|||
}
|
||||
}
|
||||
|
||||
float occlusion = clamp(1.0 - obscuranceSum * getObscuranceScaling() * invNumSamples, 0.0, 1.0);
|
||||
obscuranceSum *= getObscuranceScaling() * invNumSamples;
|
||||
float occlusion = clamp(1.0 - obscuranceSum * obscuranceSum, 0.0, 1.0);
|
||||
|
||||
outFragColor = packOcclusionOutput(occlusion * occlusion, fragPositionES.z, fragNormalES);
|
||||
outFragColor = packOcclusionOutput(occlusion, fragPositionES.z, fragNormalES);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue