mirror of
https://github.com/overte-org/overte.git
synced 2025-04-25 22:36:39 +02:00
Preparing for halton taps
This commit is contained in:
parent
fb7a8bdd4d
commit
60418b36d7
6 changed files with 36 additions and 36 deletions
|
@ -183,7 +183,7 @@ AmbientOcclusionEffectConfig::AmbientOcclusionEffectConfig() :
|
|||
perspectiveScale{ 1.0f },
|
||||
obscuranceLevel{ 0.5f },
|
||||
#if SSAO_USE_HORIZON_BASED
|
||||
falloffAngle{ 0.2f },
|
||||
falloffAngle{ 0.3f },
|
||||
#else
|
||||
falloffAngle{ 0.01f },
|
||||
#endif
|
||||
|
@ -390,6 +390,7 @@ void AmbientOcclusionEffect::run(const render::RenderContextPointer& renderConte
|
|||
const auto& linearDepthFramebuffer = inputs.get2();
|
||||
|
||||
auto linearDepthTexture = linearDepthFramebuffer->getLinearDepthTexture();
|
||||
auto occlusionDepthTexture = linearDepthTexture;
|
||||
auto sourceViewport = args->_viewport;
|
||||
auto occlusionViewport = sourceViewport;
|
||||
auto firstBlurViewport = sourceViewport;
|
||||
|
@ -406,6 +407,7 @@ void AmbientOcclusionEffect::run(const render::RenderContextPointer& renderConte
|
|||
if (_aoParametersBuffer->getResolutionLevel() > 0) {
|
||||
occlusionViewport = occlusionViewport >> _aoParametersBuffer->getResolutionLevel();
|
||||
firstBlurViewport.w = firstBlurViewport.w >> _aoParametersBuffer->getResolutionLevel();
|
||||
occlusionDepthTexture = linearDepthFramebuffer->getHalfLinearDepthTexture();
|
||||
}
|
||||
|
||||
if (_framebuffer->updateLinearDepth(linearDepthTexture)) {
|
||||
|
@ -444,21 +446,20 @@ void AmbientOcclusionEffect::run(const render::RenderContextPointer& renderConte
|
|||
batch.setModelTransform(model);
|
||||
#if SSAO_USE_HORIZON_BASED
|
||||
batch.setPipeline(mipCreationPipeline);
|
||||
batch.generateTextureMipsWithPipeline(_framebuffer->getLinearDepthTexture());
|
||||
batch.generateTextureMipsWithPipeline(occlusionDepthTexture);
|
||||
#else
|
||||
batch.generateTextureMips(_framebuffer->getLinearDepthTexture());
|
||||
batch.generateTextureMips(occlusionDepthTexture);
|
||||
#endif
|
||||
batch.popProfileRange();
|
||||
|
||||
// Occlusion pass
|
||||
batch.pushProfileRange("Occlusion");
|
||||
batch.setUniformBuffer(render_utils::slot::buffer::DeferredFrameTransform, frameTransform->getFrameTransformBuffer());
|
||||
batch.setUniformBuffer(render_utils::slot::buffer::SsaoParams, _aoParametersBuffer);
|
||||
|
||||
// Occlusion pass
|
||||
batch.setUniformBuffer(render_utils::slot::buffer::SsaoParams, _aoParametersBuffer);
|
||||
batch.setFramebuffer(occlusionFBO);
|
||||
batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, glm::vec4(1.0f));
|
||||
batch.setPipeline(occlusionPipeline);
|
||||
batch.setResourceTexture(render_utils::slot::texture::SsaoPyramid, _framebuffer->getLinearDepthTexture());
|
||||
batch.setResourceTexture(render_utils::slot::texture::SsaoDepth, occlusionDepthTexture);
|
||||
batch.draw(gpu::TRIANGLE_STRIP, 4);
|
||||
batch.popProfileRange();
|
||||
|
||||
|
@ -469,6 +470,8 @@ void AmbientOcclusionEffect::run(const render::RenderContextPointer& renderConte
|
|||
batch.setModelTransform(model);
|
||||
batch.setViewportTransform(firstBlurViewport);
|
||||
batch.setFramebuffer(occlusionBlurredFBO);
|
||||
// Use full resolution depth and normal for bilateral upscaling and blur
|
||||
batch.setResourceTexture(render_utils::slot::texture::SsaoDepth, linearDepthTexture);
|
||||
batch.setUniformBuffer(render_utils::slot::buffer::SsaoBlurParams, _hblurParametersBuffer);
|
||||
batch.setPipeline(firstHBlurPipeline);
|
||||
batch.setResourceTexture(render_utils::slot::texture::SsaoOcclusion, occlusionFBO->getRenderBuffer(0));
|
||||
|
@ -485,7 +488,7 @@ void AmbientOcclusionEffect::run(const render::RenderContextPointer& renderConte
|
|||
batch.draw(gpu::TRIANGLE_STRIP, 4);
|
||||
}
|
||||
|
||||
batch.setResourceTexture(render_utils::slot::texture::SsaoPyramid, nullptr);
|
||||
batch.setResourceTexture(render_utils::slot::texture::SsaoDepth, nullptr);
|
||||
batch.setResourceTexture(render_utils::slot::texture::SsaoOcclusion, nullptr);
|
||||
|
||||
_gpuTimer->end(batch);
|
||||
|
@ -581,11 +584,11 @@ void DebugAmbientOcclusion::run(const render::RenderContextPointer& renderContex
|
|||
batch.setUniformBuffer(render_utils::slot::buffer::SsaoDebugParams, _parametersBuffer);
|
||||
|
||||
batch.setPipeline(debugPipeline);
|
||||
batch.setResourceTexture(render_utils::slot::texture::SsaoPyramid, linearDepthTexture);
|
||||
batch.setResourceTexture(render_utils::slot::texture::SsaoDepth, linearDepthTexture);
|
||||
batch.draw(gpu::TRIANGLE_STRIP, 4);
|
||||
|
||||
|
||||
batch.setResourceTexture(render_utils::slot::texture::SsaoPyramid, nullptr);
|
||||
batch.setResourceTexture(render_utils::slot::texture::SsaoDepth, nullptr);
|
||||
});
|
||||
|
||||
}
|
||||
|
|
|
@ -28,10 +28,10 @@ namespace ru {
|
|||
LinearDepthFramebuffer::LinearDepthFramebuffer() {
|
||||
}
|
||||
|
||||
void LinearDepthFramebuffer::updatePrimaryDepth(const gpu::TexturePointer& depthBuffer) {
|
||||
void LinearDepthFramebuffer::update(const gpu::TexturePointer& depthBuffer) {
|
||||
//If the depth buffer or size changed, we need to delete our FBOs
|
||||
bool reset = false;
|
||||
if ((_primaryDepthTexture != depthBuffer)) {
|
||||
if (_primaryDepthTexture != depthBuffer) {
|
||||
_primaryDepthTexture = depthBuffer;
|
||||
reset = true;
|
||||
}
|
||||
|
@ -144,11 +144,12 @@ void LinearDepthPass::run(const render::RenderContextPointer& renderContext, con
|
|||
if (!_linearDepthFramebuffer) {
|
||||
_linearDepthFramebuffer = std::make_shared<LinearDepthFramebuffer>();
|
||||
}
|
||||
_linearDepthFramebuffer->updatePrimaryDepth(deferredFramebuffer->getPrimaryDepthTexture());
|
||||
|
||||
auto depthBuffer = deferredFramebuffer->getPrimaryDepthTexture();
|
||||
auto normalTexture = deferredFramebuffer->getDeferredNormalTexture();
|
||||
|
||||
_linearDepthFramebuffer->update(depthBuffer);
|
||||
|
||||
auto linearDepthFBO = _linearDepthFramebuffer->getLinearDepthFramebuffer();
|
||||
auto linearDepthTexture = _linearDepthFramebuffer->getLinearDepthTexture();
|
||||
|
||||
|
@ -247,7 +248,7 @@ const gpu::PipelinePointer& LinearDepthPass::getDownsamplePipeline(const render:
|
|||
SurfaceGeometryFramebuffer::SurfaceGeometryFramebuffer() {
|
||||
}
|
||||
|
||||
void SurfaceGeometryFramebuffer::updateLinearDepth(const gpu::TexturePointer& linearDepthBuffer) {
|
||||
void SurfaceGeometryFramebuffer::update(const gpu::TexturePointer& linearDepthBuffer) {
|
||||
//If the depth buffer or size changed, we need to delete our FBOs
|
||||
bool reset = false;
|
||||
if ((_linearDepthTexture != linearDepthBuffer)) {
|
||||
|
@ -414,7 +415,7 @@ void SurfaceGeometryPass::run(const render::RenderContextPointer& renderContext,
|
|||
if (!_surfaceGeometryFramebuffer) {
|
||||
_surfaceGeometryFramebuffer = std::make_shared<SurfaceGeometryFramebuffer>();
|
||||
}
|
||||
_surfaceGeometryFramebuffer->updateLinearDepth(linearDepthTexture);
|
||||
_surfaceGeometryFramebuffer->update(linearDepthTexture);
|
||||
|
||||
auto curvatureFramebuffer = _surfaceGeometryFramebuffer->getCurvatureFramebuffer();
|
||||
auto curvatureTexture = _surfaceGeometryFramebuffer->getCurvatureTexture();
|
||||
|
|
|
@ -34,11 +34,10 @@ public:
|
|||
gpu::TexturePointer getHalfNormalTexture();
|
||||
|
||||
// Update the depth buffer which will drive the allocation of all the other resources according to its size.
|
||||
void updatePrimaryDepth(const gpu::TexturePointer& depthBuffer);
|
||||
gpu::TexturePointer getPrimaryDepthTexture();
|
||||
void update(const gpu::TexturePointer& depthBuffer);
|
||||
const glm::ivec2& getDepthFrameSize() const { return _frameSize; }
|
||||
|
||||
void setResolutionLevel(int level);
|
||||
void setResolutionLevel(int level) { _resolutionLevel = std::max(0, level); }
|
||||
int getResolutionLevel() const { return _resolutionLevel; }
|
||||
|
||||
protected:
|
||||
|
@ -107,7 +106,7 @@ public:
|
|||
gpu::TexturePointer getBlurringTexture();
|
||||
|
||||
// Update the source framebuffer size which will drive the allocation of all the other resources.
|
||||
void updateLinearDepth(const gpu::TexturePointer& linearDepthBuffer);
|
||||
void update(const gpu::TexturePointer& linearDepthBuffer);
|
||||
gpu::TexturePointer getLinearDepthTexture();
|
||||
const glm::ivec2& getSourceFrameSize() const { return _frameSize; }
|
||||
|
||||
|
|
|
@ -87,7 +87,7 @@
|
|||
#define RENDER_UTILS_BUFFER_SSAO_PARAMS 2
|
||||
#define RENDER_UTILS_BUFFER_SSAO_DEBUG_PARAMS 3
|
||||
#define RENDER_UTILS_BUFFER_SSAO_BLUR_PARAMS 4
|
||||
#define RENDER_UTILS_TEXTURE_SSAO_PYRAMID 1
|
||||
#define RENDER_UTILS_TEXTURE_SSAO_DEPTH 1
|
||||
#define RENDER_UTILS_TEXTURE_SSAO_OCCLUSION 0
|
||||
|
||||
// Temporal anti-aliasing
|
||||
|
@ -193,7 +193,7 @@ enum Texture {
|
|||
TaaDepth = RENDER_UTILS_TEXTURE_TAA_DEPTH,
|
||||
TaaNext = RENDER_UTILS_TEXTURE_TAA_NEXT,
|
||||
SsaoOcclusion = RENDER_UTILS_TEXTURE_SSAO_OCCLUSION,
|
||||
SsaoPyramid = RENDER_UTILS_TEXTURE_SSAO_PYRAMID,
|
||||
SsaoDepth = RENDER_UTILS_TEXTURE_SSAO_DEPTH,
|
||||
HighlightSceneDepth = RENDER_UTILS_TEXTURE_HIGHLIGHT_SCENE_DEPTH,
|
||||
HighlightDepth = RENDER_UTILS_TEXTURE_HIGHLIGHT_DEPTH,
|
||||
SurfaceGeometryDepth = RENDER_UTILS_TEXTURE_SG_DEPTH,
|
||||
|
|
|
@ -216,14 +216,14 @@ vec3 getTapLocationClampedSSAO(int sampleNumber, float spinAngle, float outerRad
|
|||
<@func declareFetchDepthPyramidMap()@>
|
||||
|
||||
// the depth pyramid texture
|
||||
layout(binding=RENDER_UTILS_TEXTURE_SSAO_PYRAMID) uniform sampler2D pyramidMap;
|
||||
layout(binding=RENDER_UTILS_TEXTURE_SSAO_DEPTH) uniform sampler2D depthPyramidTex;
|
||||
|
||||
float getZEyeAtPixel(ivec2 pixel, int level) {
|
||||
return -texelFetch(pyramidMap, pixel, level).x;
|
||||
return -texelFetch(depthPyramidTex, pixel, level).x;
|
||||
}
|
||||
|
||||
float getZEyeAtUV(vec2 texCoord, int level) {
|
||||
return -texture(pyramidMap, texCoord, level).x;
|
||||
return -texture(depthPyramidTex, texCoord, level).x;
|
||||
}
|
||||
|
||||
const int LOG_MAX_OFFSET = 1;
|
||||
|
@ -243,7 +243,7 @@ vec3 fetchTapUnfiltered(ivec4 side, ivec2 ssC, vec3 tap, vec2 sideImageSize) {
|
|||
|
||||
vec3 P;
|
||||
P.xy = tapUV;
|
||||
P.z = -texture(pyramidMap, fetchUV).x;
|
||||
P.z = -texture(depthPyramidTex, fetchUV).x;
|
||||
|
||||
return P;
|
||||
}
|
||||
|
@ -259,7 +259,7 @@ vec4 fetchTap(ivec4 side, vec2 tapPixelPos, float tapRadius, vec2 sideImageSize)
|
|||
vec4 P;
|
||||
P.xy = tapUV;
|
||||
P.w = float(mipLevel);
|
||||
P.z = -textureLod(pyramidMap, fetchUV, P.w).x;
|
||||
P.z = -textureLod(depthPyramidTex, fetchUV, P.w).x;
|
||||
return P;
|
||||
}
|
||||
|
||||
|
@ -413,9 +413,9 @@ float fetchOcclusion(vec2 coords) {
|
|||
}
|
||||
|
||||
const float BLUR_WEIGHT_OFFSET = 0.01;
|
||||
const float BLUR_EDGE_SCALE = 300.0;
|
||||
const float BLUR_EDGE_DISTANCE_SCALE = 300.0;
|
||||
|
||||
vec2 evalTapWeightedValue(ivec3 side, int r, ivec2 destPixelCoord, vec2 scaledTexCoord, vec2 fullTexCoord, float key) {
|
||||
vec2 evalTapWeightedValue(ivec3 side, int r, ivec2 destPixelCoord, vec2 scaledTexCoord, vec2 fullTexCoord, float fragDepth, vec3 fragNormal) {
|
||||
ivec2 tapOffset = <$axis$> * r;
|
||||
ivec2 tapPixelCoord = destPixelCoord + tapOffset;
|
||||
|
||||
|
@ -432,9 +432,8 @@ vec2 evalTapWeightedValue(ivec3 side, int r, ivec2 destPixelCoord, vec2 scaledTe
|
|||
float weight = BLUR_WEIGHT_OFFSET + getBlurCoef(abs(r));
|
||||
|
||||
// range domain (the "bilateral" weight). As depth difference increases, decrease weight.
|
||||
// weight *= max(0.0, 1.0 - (getBlurEdgeSharpness() * BLUR_EDGE_SCALE) * abs(tapDepth - key));
|
||||
float zDistance = tapDepth - key;
|
||||
weight *= exp(-(getBlurEdgeSharpness() * BLUR_EDGE_SCALE) * zDistance * zDistance);
|
||||
float zDistance = tapDepth - fragDepth;
|
||||
weight *= exp(-getBlurEdgeSharpness() * (zDistance * zDistance * BLUR_EDGE_DISTANCE_SCALE));
|
||||
|
||||
return vec2(tapOcclusion * weight, weight);
|
||||
}
|
||||
|
@ -443,14 +442,14 @@ vec3 getBlurredOcclusion(ivec2 destPixelCoord, vec2 scaledTexCoord, vec2 fullTex
|
|||
// Stereo side info
|
||||
ivec4 side = getStereoSideInfo(destPixelCoord.x, 0);
|
||||
|
||||
float pixelDepth = getZEyeAtUV(fullTexCoord, 0);
|
||||
float fragDepth = getZEyeAtUV(fullTexCoord, 0);
|
||||
vec2 weightedSums = vec2(0.0);
|
||||
|
||||
// Accumulate weighted contributions along the bluring axis in the [-radius, radius] range
|
||||
int blurRadius = getBlurRadius();
|
||||
// negative side first
|
||||
for (int r = -blurRadius; r <= -1; ++r) {
|
||||
weightedSums += evalTapWeightedValue(side.xyz, r, destPixelCoord, scaledTexCoord, fullTexCoord, pixelDepth);
|
||||
weightedSums += evalTapWeightedValue(side.xyz, r, destPixelCoord, scaledTexCoord, fullTexCoord, fragDepth);
|
||||
}
|
||||
|
||||
// Central pixel contribution
|
||||
|
@ -460,7 +459,7 @@ vec3 getBlurredOcclusion(ivec2 destPixelCoord, vec2 scaledTexCoord, vec2 fullTex
|
|||
|
||||
// then positive side
|
||||
for (int r = 1; r <= blurRadius; ++r) {
|
||||
weightedSums += evalTapWeightedValue(side.xyz, r, destPixelCoord, scaledTexCoord, fullTexCoord, pixelDepth);
|
||||
weightedSums += evalTapWeightedValue(side.xyz, r, destPixelCoord, scaledTexCoord, fullTexCoord, fragDepth);
|
||||
}
|
||||
|
||||
// Final normalization
|
||||
|
|
|
@ -26,9 +26,7 @@ layout(location=1) out vec4 outNormal;
|
|||
void main(void) {
|
||||
// Gather 2 by 2 quads from texture and downsample
|
||||
|
||||
// Try different filters for Z
|
||||
vec4 Zeyes = textureGather(linearDepthMap, varTexCoord0, 0);
|
||||
// float Zeye = texture(linearDepthMap, varTexCoord0).x;
|
||||
|
||||
vec4 rawNormalsX = textureGather(normalMap, varTexCoord0, 0);
|
||||
vec4 rawNormalsY = textureGather(normalMap, varTexCoord0, 1);
|
||||
|
|
Loading…
Reference in a new issue