On single bilateral blur shader

This commit is contained in:
Olivier Prat 2018-09-27 17:03:14 +02:00
parent 349a8b39ad
commit 1998096630
8 changed files with 14 additions and 59 deletions

View file

@ -32,8 +32,7 @@
#include "ViewFrustum.h"
gpu::PipelinePointer AmbientOcclusionEffect::_occlusionPipeline;
gpu::PipelinePointer AmbientOcclusionEffect::_hBlurPipeline;
gpu::PipelinePointer AmbientOcclusionEffect::_vBlurPipeline;
gpu::PipelinePointer AmbientOcclusionEffect::_bilateralBlurPipeline;
gpu::PipelinePointer AmbientOcclusionEffect::_mipCreationPipeline;
gpu::PipelinePointer AmbientOcclusionEffect::_gatherPipeline;
gpu::PipelinePointer AmbientOcclusionEffect::_buildNormalsPipeline;
@ -415,31 +414,17 @@ const gpu::PipelinePointer& AmbientOcclusionEffect::getOcclusionPipeline() {
return _occlusionPipeline;
}
const gpu::PipelinePointer& AmbientOcclusionEffect::getHBlurPipeline() {
if (!_hBlurPipeline) {
gpu::ShaderPointer program = gpu::Shader::createProgram(shader::render_utils::program::ssao_makeHorizontalBlur);
const gpu::PipelinePointer& AmbientOcclusionEffect::getBilateralBlurPipeline() {
if (!_bilateralBlurPipeline) {
gpu::ShaderPointer program = gpu::Shader::createProgram(shader::render_utils::program::ssao_bilateralBlur);
gpu::StatePointer state = gpu::StatePointer(new gpu::State());
state->setColorWriteMask(true, true, true, false);
// Good to go add the brand new pipeline
_hBlurPipeline = gpu::Pipeline::create(program, state);
_bilateralBlurPipeline = gpu::Pipeline::create(program, state);
}
return _hBlurPipeline;
}
const gpu::PipelinePointer& AmbientOcclusionEffect::getVBlurPipeline() {
if (!_vBlurPipeline) {
gpu::ShaderPointer program = gpu::Shader::createProgram(shader::render_utils::program::ssao_makeVerticalBlur);
gpu::StatePointer state = gpu::StatePointer(new gpu::State());
// Vertical blur write just the final result Occlusion value in the alpha channel
state->setColorWriteMask(true, true, true, false);
// Good to go add the brand new pipeline
_vBlurPipeline = gpu::Pipeline::create(program, state);
}
return _vBlurPipeline;
return _bilateralBlurPipeline;
}
const gpu::PipelinePointer& AmbientOcclusionEffect::getMipCreationPipeline() {
@ -530,8 +515,7 @@ void AmbientOcclusionEffect::run(const render::RenderContextPointer& renderConte
auto framebufferSize = _framebuffer->getSourceFrameSize();
auto occlusionPipeline = getOcclusionPipeline();
auto firstHBlurPipeline = getHBlurPipeline();
auto lastVBlurPipeline = getVBlurPipeline();
auto bilateralBlurPipeline = getBilateralBlurPipeline();
auto mipCreationPipeline = getMipCreationPipeline();
#if SSAO_USE_QUAD_SPLIT
auto gatherPipeline = getGatherPipeline();
@ -680,12 +664,12 @@ void AmbientOcclusionEffect::run(const render::RenderContextPointer& renderConte
model.setScale(uvScale);
batch.setModelTransform(model);
}
batch.setPipeline(bilateralBlurPipeline);
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));
batch.draw(gpu::TRIANGLE_STRIP, 4);
batch.popProfileRange();
@ -705,7 +689,6 @@ void AmbientOcclusionEffect::run(const render::RenderContextPointer& renderConte
batch.setViewportTransform(sourceViewport);
batch.setFramebuffer(occlusionFBO);
batch.setUniformBuffer(render_utils::slot::buffer::SsaoBlurParams, _vblurParametersBuffer);
batch.setPipeline(lastVBlurPipeline);
batch.setResourceTexture(render_utils::slot::texture::SsaoOcclusion, occlusionBlurredFBO->getRenderBuffer(0));
batch.draw(gpu::TRIANGLE_STRIP, 4);
batch.popProfileRange();

View file

@ -190,15 +190,13 @@ private:
BlurParametersBuffer _hblurParametersBuffer;
static const gpu::PipelinePointer& getOcclusionPipeline();
static const gpu::PipelinePointer& getHBlurPipeline(); // first
static const gpu::PipelinePointer& getVBlurPipeline(); // second
static const gpu::PipelinePointer& getBilateralBlurPipeline();
static const gpu::PipelinePointer& getMipCreationPipeline();
static const gpu::PipelinePointer& getGatherPipeline();
static const gpu::PipelinePointer& getBuildNormalsPipeline();
static gpu::PipelinePointer _occlusionPipeline;
static gpu::PipelinePointer _hBlurPipeline;
static gpu::PipelinePointer _vBlurPipeline;
static gpu::PipelinePointer _bilateralBlurPipeline;
static gpu::PipelinePointer _mipCreationPipeline;
static gpu::PipelinePointer _gatherPipeline;
static gpu::PipelinePointer _buildNormalsPipeline;

View file

@ -1 +0,0 @@
VERTEX ssao_blur

View file

@ -1 +0,0 @@
VERTEX ssao_blur

View file

@ -2,7 +2,7 @@
<$VERSION_HEADER$>
// Generated on <$_SCRIBE_DATE$>
//
// ssao_makeVerticalBlur.frag
// ssao_bilateralBlur.frag
//
// Created by Sam Gateau on 1/1/16.
// Copyright 2016 High Fidelity, Inc.
@ -10,6 +10,7 @@
// 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

View file

@ -2,7 +2,7 @@
<$VERSION_HEADER$>
// Generated on <$_SCRIBE_DATE$>
//
// ssao_blur.vert
// ssao_bilateralBlur.vert
//
// Draw the unit quad [-1,-1 -> 1,1] filling in
// Simply draw a Triangle_strip of 2 triangles, no input buffers or index buffer needed

View file

@ -1,26 +0,0 @@
<@include gpu/Config.slh@>
<$VERSION_HEADER$>
// Generated on <$_SCRIBE_DATE$>
//
// ssao_makeHorizontalBlur.frag
//
// Created by Sam Gateau on 1/1/16.
// Copyright 2016 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
<$declareBlurPass()$>
layout(location=0) in vec4 varTexCoord0;
layout(location=0) out vec4 outFragColor;
void main(void) {
outFragColor = vec4(getBlurredOcclusion(ivec2(gl_FragCoord.xy), varTexCoord0.xy, varTexCoord0.zw), 1.0);
}