mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 18:44:01 +02:00
Added mix parameter to blur and bloom
This commit is contained in:
parent
22b1507597
commit
27b9f3516d
5 changed files with 34 additions and 15 deletions
|
@ -12,15 +12,16 @@
|
|||
|
||||
#include <render/BlurTask.h>
|
||||
|
||||
void BloomConfig::setMix(float value) {
|
||||
|
||||
void BloomConfig::setIntensity(float value) {
|
||||
auto blurConfig = getConfig<render::BlurGaussian>();
|
||||
blurConfig->setProperty("mix", value*0.5f);
|
||||
}
|
||||
|
||||
void BloomConfig::setSize(float value) {
|
||||
auto& blurJob = static_cast<render::Task::TaskConcept*>(_task)->_jobs.front();
|
||||
auto& gaussianBlur = blurJob.edit<render::BlurGaussian>();
|
||||
auto gaussianBlurParams = gaussianBlur.getParameters();
|
||||
gaussianBlurParams->setGaussianFilterTaps((BLUR_MAX_NUM_TAPS - 1) / 2, value*7.0f);
|
||||
gaussianBlurParams->setFilterGaussianTaps((BLUR_MAX_NUM_TAPS - 1) / 2, value*7.0f);
|
||||
}
|
||||
|
||||
Bloom::Bloom() {
|
||||
|
@ -29,7 +30,7 @@ Bloom::Bloom() {
|
|||
|
||||
void Bloom::configure(const Config& config) {
|
||||
auto blurConfig = config.getConfig<render::BlurGaussian>();
|
||||
blurConfig->setProperty("filterScale", 2.5f);
|
||||
blurConfig->setProperty("filterScale", 3.0f);
|
||||
}
|
||||
|
||||
void Bloom::build(JobModel& task, const render::Varying& inputs, render::Varying& outputs) {
|
||||
|
|
|
@ -16,15 +16,15 @@
|
|||
|
||||
class BloomConfig : public render::Task::Config {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(float mix MEMBER mix WRITE setMix NOTIFY dirty)
|
||||
Q_PROPERTY(float intensity MEMBER intensity WRITE setIntensity NOTIFY dirty)
|
||||
Q_PROPERTY(float size MEMBER size WRITE setSize NOTIFY dirty)
|
||||
|
||||
public:
|
||||
|
||||
float mix{ 0.2f };
|
||||
float size{ 0.1f };
|
||||
float intensity{ 0.2f };
|
||||
float size{ 0.4f };
|
||||
|
||||
void setMix(float value);
|
||||
void setIntensity(float value);
|
||||
void setSize(float value);
|
||||
|
||||
signals:
|
||||
|
|
|
@ -32,7 +32,7 @@ enum BlurShaderMapSlots {
|
|||
BlurParams::BlurParams() {
|
||||
Params params;
|
||||
_parametersBuffer = gpu::BufferView(std::make_shared<gpu::Buffer>(sizeof(Params), (const gpu::Byte*) ¶ms));
|
||||
setGaussianFilterTaps(3);
|
||||
setFilterGaussianTaps(3);
|
||||
}
|
||||
|
||||
void BlurParams::setWidthHeight(int width, int height, bool isStereo) {
|
||||
|
@ -77,7 +77,7 @@ void BlurParams::setFilterTap(int index, float offset, float value) {
|
|||
filterTaps[index].y = value;
|
||||
}
|
||||
|
||||
void BlurParams::setGaussianFilterTaps(int numHalfTaps, float sigma) {
|
||||
void BlurParams::setFilterGaussianTaps(int numHalfTaps, float sigma) {
|
||||
auto& params = _parametersBuffer.edit<Params>();
|
||||
const int numTaps = 2 * numHalfTaps + 1;
|
||||
assert(numTaps <= BLUR_MAX_NUM_TAPS);
|
||||
|
@ -106,6 +106,14 @@ void BlurParams::setGaussianFilterTaps(int numHalfTaps, float sigma) {
|
|||
// won't have the same number of taps as in the center.
|
||||
}
|
||||
|
||||
void BlurParams::setOutputAlpha(float value) {
|
||||
value = glm::clamp(value, 0.0f, 1.0f);
|
||||
auto filterInfo = _parametersBuffer.get<Params>().filterInfo;
|
||||
if (value != filterInfo.z) {
|
||||
_parametersBuffer.edit<Params>().filterInfo.z = value;
|
||||
}
|
||||
}
|
||||
|
||||
void BlurParams::setDepthPerspective(float oneOverTan2FOV) {
|
||||
auto depthInfo = _parametersBuffer.get<Params>().depthInfo;
|
||||
if (oneOverTan2FOV != depthInfo.w) {
|
||||
|
@ -238,7 +246,13 @@ gpu::PipelinePointer BlurGaussian::getBlurHPipeline() {
|
|||
}
|
||||
|
||||
void BlurGaussian::configure(const Config& config) {
|
||||
auto blurHPipeline = getBlurHPipeline();
|
||||
|
||||
_parameters->setFilterRadiusScale(config.filterScale);
|
||||
_parameters->setOutputAlpha(config.mix);
|
||||
|
||||
blurHPipeline->getState()->setBlendFunction(config.mix < 1.0f, gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA,
|
||||
gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA);
|
||||
}
|
||||
|
||||
|
||||
|
@ -248,7 +262,6 @@ void BlurGaussian::run(const RenderContextPointer& renderContext, const gpu::Fra
|
|||
|
||||
RenderArgs* args = renderContext->args;
|
||||
|
||||
|
||||
BlurInOutResource::Resources blurringResources;
|
||||
if (!_inOutResources.updateResources(sourceFramebuffer, blurringResources)) {
|
||||
// early exit if no valid blurring resources
|
||||
|
|
|
@ -30,7 +30,8 @@ public:
|
|||
void setFilterNumTaps(int count);
|
||||
// Tap 0 is considered the center of the kernel
|
||||
void setFilterTap(int index, float offset, float value);
|
||||
void setGaussianFilterTaps(int numHalfTaps, float sigma = 1.47f);
|
||||
void setFilterGaussianTaps(int numHalfTaps, float sigma = 1.47f);
|
||||
void setOutputAlpha(float value);
|
||||
|
||||
void setDepthPerspective(float oneOverTan2FOV);
|
||||
void setDepthThreshold(float threshold);
|
||||
|
@ -46,7 +47,7 @@ public:
|
|||
// Viewport to Texcoord info, if the region of the blur (viewport) is smaller than the full frame
|
||||
glm::vec4 texcoordTransform{ 0.0f, 0.0f, 1.0f, 1.0f };
|
||||
|
||||
// Filter info (radius scale, number of taps, mix)
|
||||
// Filter info (radius scale, number of taps, output alpha)
|
||||
glm::vec4 filterInfo{ 1.0f, 0.0f, 0.0f, 0.0f };
|
||||
|
||||
// Depth info (radius scale
|
||||
|
@ -93,12 +94,15 @@ public:
|
|||
class BlurGaussianConfig : public Job::Config {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool enabled WRITE setEnabled READ isEnabled NOTIFY dirty) // expose enabled flag
|
||||
Q_PROPERTY(float filterScale MEMBER filterScale NOTIFY dirty) // expose enabled flag
|
||||
Q_PROPERTY(float filterScale MEMBER filterScale NOTIFY dirty)
|
||||
Q_PROPERTY(float mix MEMBER mix NOTIFY dirty)
|
||||
public:
|
||||
|
||||
BlurGaussianConfig() : Job::Config(true) {}
|
||||
|
||||
float filterScale{ 0.2f };
|
||||
float mix{ 1.0f };
|
||||
|
||||
signals :
|
||||
void dirty();
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ int getFilterNumTaps() {
|
|||
return int(parameters.filterInfo.y);
|
||||
}
|
||||
|
||||
float getFilterMix() {
|
||||
float getOutputAlpha() {
|
||||
return parameters.filterInfo.z;
|
||||
}
|
||||
|
||||
|
@ -102,6 +102,7 @@ vec4 pixelShaderGaussian(vec2 texcoord, vec2 direction, vec2 pixelStep) {
|
|||
if (totalWeight>0.0) {
|
||||
srcBlurred /= totalWeight;
|
||||
}
|
||||
srcBlurred.a = getOutputAlpha();
|
||||
return srcBlurred;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue