diff --git a/libraries/render-utils/src/AntialiasingEffect.cpp b/libraries/render-utils/src/AntialiasingEffect.cpp index 08905d3b68..92917c5162 100644 --- a/libraries/render-utils/src/AntialiasingEffect.cpp +++ b/libraries/render-utils/src/AntialiasingEffect.cpp @@ -336,7 +336,7 @@ void Antialiasing::run(const render::RenderContextPointer& renderContext, const auto& antiAliasingBuffer = _antialiasingBuffers->edit(i); antiAliasingBuffer = gpu::FramebufferPointer(gpu::Framebuffer::create("antialiasing")); auto format = sourceBuffer->getRenderBuffer(0)->getTexelFormat(); - auto defaultSampler = gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_LINEAR); + auto defaultSampler = gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_LINEAR, gpu::Sampler::WRAP_CLAMP); _antialiasingTextures[i] = gpu::Texture::createRenderBuffer(format, width, height, gpu::Texture::SINGLE_MIP, defaultSampler); antiAliasingBuffer->setRenderBuffer(0, _antialiasingTextures[i]); } diff --git a/libraries/render-utils/src/BloomApply.slf b/libraries/render-utils/src/BloomApply.slf index 953258e8ab..b2e06438a1 100644 --- a/libraries/render-utils/src/BloomApply.slf +++ b/libraries/render-utils/src/BloomApply.slf @@ -13,7 +13,7 @@ uniform sampler2D blurMap0; uniform sampler2D blurMap1; uniform sampler2D blurMap2; -uniform float intensity; +uniform vec3 intensity; in vec2 varTexCoord0; out vec4 outFragColor; @@ -23,5 +23,5 @@ void main(void) { vec4 blur1 = texture(blurMap1, varTexCoord0); vec4 blur2 = texture(blurMap2, varTexCoord0); - outFragColor = vec4((blur0.rgb+blur1.rgb+blur2.rgb)*intensity, 1.0f); + outFragColor = vec4(blur0.rgb*intensity.x+blur1.rgb*intensity.y+blur2.rgb*intensity.z, 1.0f); } diff --git a/libraries/render-utils/src/BloomEffect.cpp b/libraries/render-utils/src/BloomEffect.cpp index ddd63f012f..9c383096b0 100644 --- a/libraries/render-utils/src/BloomEffect.cpp +++ b/libraries/render-utils/src/BloomEffect.cpp @@ -50,7 +50,7 @@ void BloomThreshold::run(const render::RenderContextPointer& renderContext, cons if (!_outputBuffer || _outputBuffer->getSize() != bufferSize) { auto colorTexture = gpu::TexturePointer(gpu::Texture::createRenderBuffer(inputBuffer->getTexelFormat(), bufferSize.x, bufferSize.y, - gpu::Texture::SINGLE_MIP, gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_LINEAR_MIP_POINT))); + gpu::Texture::SINGLE_MIP, gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_LINEAR_MIP_POINT, gpu::Sampler::WRAP_CLAMP))); _outputBuffer = gpu::FramebufferPointer(gpu::Framebuffer::create("BloomThreshold")); _outputBuffer->setRenderBuffer(0, colorTexture); @@ -93,12 +93,15 @@ void BloomThreshold::run(const render::RenderContextPointer& renderContext, cons outputs = _outputBuffer; } -BloomApply::BloomApply() { +BloomApply::BloomApply() : _intensities{ 1.0f, 1.0f, 1.0f } { } void BloomApply::configure(const Config& config) { - _intensity = config.intensity; + _intensities.x = 2.0f * M_PI * config.sigma * config.sigma; + _intensities.y = _intensities.x*_intensities.x; + _intensities.z = _intensities.y*_intensities.x; + _intensities *= config.intensity / 3.0f; } void BloomApply::run(const render::RenderContextPointer& renderContext, const Inputs& inputs) { @@ -149,7 +152,7 @@ void BloomApply::run(const render::RenderContextPointer& renderContext, const In batch.setResourceTexture(BLUR0_SLOT, blur0FB->getRenderBuffer(0)); batch.setResourceTexture(BLUR1_SLOT, blur1FB->getRenderBuffer(0)); batch.setResourceTexture(BLUR2_SLOT, blur2FB->getRenderBuffer(0)); - batch._glUniform1f(INTENSITY_SLOT, _intensity / 3.0f); + batch._glUniform3f(INTENSITY_SLOT, _intensities.x, _intensities.y, _intensities.z); batch.draw(gpu::TRIANGLE_STRIP, 4); }); } @@ -306,19 +309,19 @@ float BloomConfig::getIntensity() const { void BloomConfig::setSize(float value) { std::string blurName{ "BloomBlurN" }; auto sigma = 0.5f+value*3.5f; + auto task = static_cast(_task); for (auto i = 0; i < BLOOM_BLUR_LEVEL_COUNT; i++) { blurName.back() = '0' + i; - auto task = static_cast(_task); auto blurJobIt = task->editJob(blurName); assert(blurJobIt != task->_jobs.end()); auto& gaussianBlur = blurJobIt->edit(); auto gaussianBlurParams = gaussianBlur.getParameters(); gaussianBlurParams->setFilterGaussianTaps(5, sigma); - // Gaussian blur increases at each level to have a slower rolloff on the edge - // of the response - sigma *= 1.5f; } + auto blurJobIt = task->getJob("BloomApply"); + assert(blurJobIt != task->_jobs.end()); + blurJobIt->getConfiguration()->setProperty("sigma", sigma); } Bloom::Bloom() { @@ -350,7 +353,7 @@ void Bloom::build(JobModel& task, const render::Varying& inputs, render::Varying // Mix all blur levels at quarter resolution const auto applyInput = BloomApply::Inputs(bloomInputBuffer, blurFB0, blurFB1, blurFB2).asVarying(); task.addJob("BloomApply", applyInput); - // And them blend result in additive manner on top of final color buffer + // And then blend result in additive manner on top of final color buffer const auto drawInput = BloomDraw::Inputs(frameBuffer, bloomInputBuffer).asVarying(); task.addJob("BloomDraw", drawInput); diff --git a/libraries/render-utils/src/BloomEffect.h b/libraries/render-utils/src/BloomEffect.h index 37282c1feb..f0d5b5c3c6 100644 --- a/libraries/render-utils/src/BloomEffect.h +++ b/libraries/render-utils/src/BloomEffect.h @@ -25,7 +25,7 @@ public: BloomConfig() : render::Task::Config(false) {} - float size{ 0.3f }; + float size{ 0.65f }; void setIntensity(float value); float getIntensity() const; @@ -41,7 +41,7 @@ class BloomThresholdConfig : public render::Job::Config { public: - float threshold{ 0.3f }; + float threshold{ 0.9f }; signals: void dirty(); @@ -71,10 +71,12 @@ private: class BloomApplyConfig : public render::Job::Config { Q_OBJECT Q_PROPERTY(float intensity MEMBER intensity NOTIFY dirty) + Q_PROPERTY(float sigma MEMBER sigma NOTIFY dirty) public: - float intensity{ 0.2f }; + float intensity{ 0.25f }; + float sigma{ 1.0f }; signals: void dirty(); @@ -94,7 +96,7 @@ public: private: gpu::PipelinePointer _pipeline; - float _intensity{ 1.0f }; + glm::vec3 _intensities; }; class BloomDraw { diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index dc4a96f974..ff58d5f0f5 100644 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -190,7 +190,7 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren const auto toneAndPostRangeTimer = task.addJob("BeginToneAndPostRangeTimer", "PostToneOverlaysAntialiasing"); - // AA job + // AA job before bloom to limit flickering const auto antialiasingInputs = Antialiasing::Inputs(deferredFrameTransform, lightingFramebuffer, linearDepthTarget, velocityBuffer).asVarying(); task.addJob("Antialiasing", antialiasingInputs); diff --git a/libraries/render/src/render/BlurTask.cpp b/libraries/render/src/render/BlurTask.cpp index 4c3c52e07b..896482eb2a 100644 --- a/libraries/render/src/render/BlurTask.cpp +++ b/libraries/render/src/render/BlurTask.cpp @@ -163,7 +163,7 @@ bool BlurInOutResource::updateResources(const gpu::FramebufferPointer& sourceFra //if (sourceFramebuffer->hasDepthStencil()) { // _blurredFramebuffer->setDepthStencilBuffer(sourceFramebuffer->getDepthStencilBuffer(), sourceFramebuffer->getDepthStencilBufferFormat()); //} - auto blurringSampler = gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_LINEAR_MIP_POINT); + auto blurringSampler = gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_LINEAR_MIP_POINT, gpu::Sampler::WRAP_CLAMP); auto blurringTarget = gpu::Texture::createRenderBuffer(sourceFramebuffer->getRenderBuffer(0)->getTexelFormat(), blurBufferSize.x, blurBufferSize.y, gpu::Texture::SINGLE_MIP, blurringSampler); _blurredFramebuffer->setRenderBuffer(0, blurringTarget); } @@ -186,7 +186,7 @@ bool BlurInOutResource::updateResources(const gpu::FramebufferPointer& sourceFra /* if (sourceFramebuffer->hasDepthStencil()) { _outputFramebuffer->setDepthStencilBuffer(sourceFramebuffer->getDepthStencilBuffer(), sourceFramebuffer->getDepthStencilBufferFormat()); }*/ - auto blurringSampler = gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_LINEAR_MIP_POINT); + auto blurringSampler = gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_LINEAR_MIP_POINT, gpu::Sampler::WRAP_CLAMP); auto blurringTarget = gpu::Texture::createRenderBuffer(sourceFramebuffer->getRenderBuffer(0)->getTexelFormat(), blurBufferSize.x, blurBufferSize.y, gpu::Texture::SINGLE_MIP, blurringSampler); _outputFramebuffer->setRenderBuffer(0, blurringTarget); } diff --git a/scripts/developer/utilities/render/bloom.qml b/scripts/developer/utilities/render/bloom.qml index 66e92e0eff..52090348d9 100644 --- a/scripts/developer/utilities/render/bloom.qml +++ b/scripts/developer/utilities/render/bloom.qml @@ -93,9 +93,10 @@ Item { integral: false config: root.config property: "intensity" - max: 5.0 + max: 1.0 min: 0.0 width: 280 + height:38 } ConfigSlider { label: "Size" @@ -105,6 +106,7 @@ Item { max: 1.0 min: 0.0 width: 280 + height:38 } ConfigSlider { label: "Threshold" @@ -114,6 +116,7 @@ Item { max: 2.0 min: 0.0 width: 280 + height:38 } } } diff --git a/scripts/developer/utilities/render/debugBloom.js b/scripts/developer/utilities/render/debugBloom.js index 2328d524cf..3a508d351c 100644 --- a/scripts/developer/utilities/render/debugBloom.js +++ b/scripts/developer/utilities/render/debugBloom.js @@ -15,6 +15,6 @@ var window = new OverlayWindow({ title: 'Bloom', source: qml, width: 285, - height: 170, + height: 210, }); window.closed.connect(function() { Script.stop(); }); \ No newline at end of file