3
0
Fork 0
mirror of https://github.com/lubosz/overte.git synced 2025-04-26 06:35:25 +02:00

Added gather to split AO

This commit is contained in:
Olivier Prat 2018-09-19 10:37:27 +02:00
parent a127c1e3b2
commit 3493d40fd7
6 changed files with 86 additions and 18 deletions

View file

@ -34,6 +34,7 @@ gpu::PipelinePointer AmbientOcclusionEffect::_occlusionPipeline;
gpu::PipelinePointer AmbientOcclusionEffect::_hBlurPipeline;
gpu::PipelinePointer AmbientOcclusionEffect::_vBlurPipeline;
gpu::PipelinePointer AmbientOcclusionEffect::_mipCreationPipeline;
gpu::PipelinePointer AmbientOcclusionEffect::_gatherPipeline;
AmbientOcclusionFramebuffer::AmbientOcclusionFramebuffer() {
}
@ -395,6 +396,19 @@ const gpu::PipelinePointer& AmbientOcclusionEffect::getMipCreationPipeline() {
return _mipCreationPipeline;
}
const gpu::PipelinePointer& AmbientOcclusionEffect::getGatherPipeline() {
if (!_gatherPipeline) {
gpu::ShaderPointer program = gpu::Shader::createProgram(shader::render_utils::program::ssao_gather);
gpu::StatePointer state = gpu::StatePointer(new gpu::State());
state->setColorWriteMask(true, true, true, false);
// Good to go add the brand new pipeline
_gatherPipeline = gpu::Pipeline::create(program, state);
}
return _gatherPipeline;
}
void AmbientOcclusionEffect::updateGaussianDistribution() {
auto coefs = _aoParametersBuffer.edit()._gaussianCoefs;
GaussianDistribution::evalSampling(coefs, SSAO_BLUR_GAUSSIAN_COEFS_COUNT, _aoParametersBuffer->getBlurRadius(), _aoParametersBuffer->getBlurDeviation());
@ -448,7 +462,10 @@ void AmbientOcclusionEffect::run(const render::RenderContextPointer& renderConte
#if SSAO_USE_HORIZON_BASED
auto mipCreationPipeline = getMipCreationPipeline();
#endif
#if SSAO_USE_QUAD_SPLIT
auto gatherPipeline = getGatherPipeline();
#endif
// Update sample rotation
const int SSAO_RANDOM_SAMPLE_COUNT = int(_randomSamples.size() / SSAO_SPLIT_COUNT);
for (int splitId=0 ; splitId < SSAO_SPLIT_COUNT ; splitId++) {
@ -485,7 +502,11 @@ void AmbientOcclusionEffect::run(const render::RenderContextPointer& renderConte
batch.setUniformBuffer(render_utils::slot::buffer::DeferredFrameTransform, frameTransform->getFrameTransformBuffer());
batch.setUniformBuffer(render_utils::slot::buffer::SsaoParams, _aoParametersBuffer);
#if SSAO_USE_QUAD_SPLIT
batch.setFramebuffer(occlusionBlurredFBO);
#else
batch.setFramebuffer(occlusionFBO);
#endif
batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, glm::vec4(1.0f));
batch.setPipeline(occlusionPipeline);
batch.setResourceTexture(render_utils::slot::texture::SsaoDepth, occlusionDepthTexture);
@ -520,6 +541,17 @@ void AmbientOcclusionEffect::run(const render::RenderContextPointer& renderConte
batch.popProfileRange();
#if SSAO_USE_QUAD_SPLIT
// Gather back the four separate renders into one interleaved one
batch.pushProfileRange("Gather");
batch.setViewportTransform(occlusionViewport);
batch.setFramebuffer(occlusionFBO);
batch.setPipeline(gatherPipeline);
batch.setResourceTexture(render_utils::slot::texture::SsaoOcclusion, occlusionBlurredFBO->getRenderBuffer(0));
batch.draw(gpu::TRIANGLE_STRIP, 4);
batch.popProfileRange();
#endif
{
PROFILE_RANGE_BATCH(batch, "Bilateral Blur");
// Blur 1st pass

View file

@ -167,11 +167,13 @@ private:
static const gpu::PipelinePointer& getHBlurPipeline(); // first
static const gpu::PipelinePointer& getVBlurPipeline(); // second
static const gpu::PipelinePointer& getMipCreationPipeline();
static const gpu::PipelinePointer& getGatherPipeline();
static gpu::PipelinePointer _occlusionPipeline;
static gpu::PipelinePointer _occlusionPipeline;
static gpu::PipelinePointer _hBlurPipeline;
static gpu::PipelinePointer _vBlurPipeline;
static gpu::PipelinePointer _mipCreationPipeline;
static gpu::PipelinePointer _mipCreationPipeline;
static gpu::PipelinePointer _gatherPipeline;
AmbientOcclusionFramebufferPointer _framebuffer;
std::array<float, 16 * SSAO_SPLIT_COUNT> _randomSamples;

View file

@ -0,0 +1 @@
VERTEX gpu::vertex::DrawViewportQuadTransformTexcoord

View file

@ -364,6 +364,14 @@ float evalVisibilityHBAO(ivec4 side, vec2 shadedPixelPos, vec2 sideImageSize, ve
<@endfunc@>
<@func declareGatherPass()@>
<$declareAmbientOcclusion()$>
// the source occlusion texture
layout(binding=RENDER_UTILS_TEXTURE_SSAO_OCCLUSION) uniform sampler2D occlusionMap;
<@endfunc@>
<@func declareBlurPass(axis)@>
<$declarePackOcclusionDepth()$>

View file

@ -0,0 +1,34 @@
<@include gpu/Config.slh@>
<$VERSION_HEADER$>
// Generated on <$_SCRIBE_DATE$>
//
// ssao_gather.frag
//
// Created by Olivier Prat on 09/19/2018.
// Copyright 2018 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
<@include ssao.slh@>
// Hack comment
<$declareGatherPass()$>
layout(location=0) in vec4 varTexCoord0;
layout(location=0) out vec4 outFragColor;
void main(void) {
// Gather the four splits of the occlusion result back into an interleaved full size
// result (at the resolution level, of course)
ivec2 destPixelCoord = ivec2(gl_FragCoord.xy);
ivec2 sourcePixelCoord = destPixelCoord >> 1;
ivec2 splitImageSize = ivec2(getWidthHeight(getResolutionLevel() + 1));
sourcePixelCoord += (destPixelCoord & ivec2(1)) * splitImageSize;
outFragColor = texelFetch(occlusionMap, sourcePixelCoord, 0);
}

View file

@ -25,11 +25,14 @@ layout(location=0) out vec4 outFragColor;
void main(void) {
vec2 sideImageSize = getSideImageSize(getResolutionLevel());
ivec2 splitImageSize = ivec2(getWidthHeight(getResolutionLevel() + SSAO_USE_QUAD_SPLIT));
// Pixel being shaded
vec2 fragCoord = gl_FragCoord.xy;
ivec2 fragPixelPos = ((ivec2(fragCoord.xy) - getPixelOffset()*splitImageSize) << SSAO_USE_QUAD_SPLIT) + getPixelOffset();
ivec2 fragPixelPos = ivec2(fragCoord.xy);
#if SSAO_USE_QUAD_SPLIT
ivec2 splitImageSize = ivec2(getWidthHeight(getResolutionLevel() + SSAO_USE_QUAD_SPLIT));
fragPixelPos = ((fragPixelPos - getPixelOffset()*splitImageSize) << SSAO_USE_QUAD_SPLIT) + getPixelOffset();
#endif
// Stereo side info
ivec4 side = getStereoSideInfo(fragPixelPos.x, getResolutionLevel());
@ -41,7 +44,7 @@ void main(void) {
// Fetch the z under the pixel (stereo or not)
float Zeye = getZEyeAtUV(fragUVPos, 0);
// The position and normal of the pixel fragment in Eye space
// The position and normal of the pixel fragment in Eye space
vec3 fragPositionES = evalEyePositionFromZeye(side.x, Zeye, fragUVPos);
vec3 fragNormalES = evalEyeNormal(fragPositionES);
@ -71,18 +74,6 @@ void main(void) {
}
float occlusion = clamp(1.0 - obscuranceSum * getObscuranceScaling() * getInvNumSamples(), 0.0, 1.0);
// KEEP IT for Debugging
// Bilateral box-filter over a quad for free, respecting depth edges
// (the difference that this makes is subtle)
/* if (abs(dFdx(fragPositionES.z)) < 0.02) {
occlusion -= dFdx(occlusion) * ((fragPixelPos.x & 1) - 0.5);
}
if (abs(dFdy(fragPositionES.z)) < 0.02) {
occlusion -= dFdy(occlusion) * ((fragPixelPos.y & 1) - 0.5);
}*/
//outFragColor = vec4(packOcclusionDepth(occlusion, CSZToDepthKey(fragPositionES.z)), 1.0);
outFragColor = vec4(vec3(occlusion), 1.0);
}