mirror of
https://github.com/overte-org/overte.git
synced 2025-08-16 10:32:19 +02:00
BloomApply now uses uniform buffer
This commit is contained in:
parent
1097e666d6
commit
63c03e79d3
5 changed files with 38 additions and 11 deletions
16
libraries/render-utils/src/BloomApply.shared.slh
Normal file
16
libraries/render-utils/src/BloomApply.shared.slh
Normal file
|
@ -0,0 +1,16 @@
|
|||
// glsl / C++ compatible source as interface for BloomApply
|
||||
#ifdef __cplusplus
|
||||
# define BA_VEC3 glm::vec3
|
||||
#else
|
||||
# define BA_VEC3 vec3
|
||||
#endif
|
||||
|
||||
struct Parameters
|
||||
{
|
||||
BA_VEC3 _intensities;
|
||||
};
|
||||
|
||||
// <@if 1@>
|
||||
// Trigger Scribe include
|
||||
// <@endif@> <!def that !>
|
||||
//
|
|
@ -9,11 +9,15 @@
|
|||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
<@include BloomApply.shared.slh@>
|
||||
|
||||
uniform sampler2D blurMap0;
|
||||
uniform sampler2D blurMap1;
|
||||
uniform sampler2D blurMap2;
|
||||
uniform vec3 intensity;
|
||||
|
||||
layout(std140) uniform parametersBuffer {
|
||||
Parameters parameters;
|
||||
};
|
||||
|
||||
in vec2 varTexCoord0;
|
||||
out vec4 outFragColor;
|
||||
|
@ -23,5 +27,5 @@ void main(void) {
|
|||
vec4 blur1 = texture(blurMap1, varTexCoord0);
|
||||
vec4 blur2 = texture(blurMap2, varTexCoord0);
|
||||
|
||||
outFragColor = vec4(blur0.rgb*intensity.x + blur1.rgb*intensity.y + blur2.rgb*intensity.z, 1.0f);
|
||||
outFragColor = vec4(blur0.rgb*parameters._intensities.x + blur1.rgb*parameters._intensities.y + blur2.rgb*parameters._intensities.z, 1.0f);
|
||||
}
|
||||
|
|
|
@ -98,14 +98,19 @@ void BloomThreshold::run(const render::RenderContextPointer& renderContext, cons
|
|||
outputs = _outputBuffer;
|
||||
}
|
||||
|
||||
BloomApply::BloomApply() : _intensities{ 1.0f, 1.0f, 1.0f } {
|
||||
BloomApply::BloomApply() {
|
||||
|
||||
}
|
||||
|
||||
void BloomApply::configure(const Config& config) {
|
||||
_intensities.x = config.intensity / 3.0f;
|
||||
_intensities.y = _intensities.x;
|
||||
_intensities.z = _intensities.x;
|
||||
const auto newIntensity = config.intensity / 3.0f;
|
||||
|
||||
if (_parameters.get()._intensities.x != newIntensity) {
|
||||
auto& parameters = _parameters.edit();
|
||||
parameters._intensities.x = newIntensity;
|
||||
parameters._intensities.y = newIntensity;
|
||||
parameters._intensities.z = newIntensity;
|
||||
}
|
||||
}
|
||||
|
||||
void BloomApply::run(const render::RenderContextPointer& renderContext, const Inputs& inputs) {
|
||||
|
@ -116,7 +121,7 @@ void BloomApply::run(const render::RenderContextPointer& renderContext, const In
|
|||
static const auto BLUR0_SLOT = 0;
|
||||
static const auto BLUR1_SLOT = 1;
|
||||
static const auto BLUR2_SLOT = 2;
|
||||
static const auto INTENSITY_SLOT = 3;
|
||||
static const auto PARAMETERS_SLOT = 0;
|
||||
|
||||
if (!_pipeline) {
|
||||
auto vs = gpu::StandardShaderLib::getDrawTransformUnitQuadVS();
|
||||
|
@ -127,7 +132,7 @@ void BloomApply::run(const render::RenderContextPointer& renderContext, const In
|
|||
slotBindings.insert(gpu::Shader::Binding("blurMap0", BLUR0_SLOT));
|
||||
slotBindings.insert(gpu::Shader::Binding("blurMap1", BLUR1_SLOT));
|
||||
slotBindings.insert(gpu::Shader::Binding("blurMap2", BLUR2_SLOT));
|
||||
slotBindings.insert(gpu::Shader::Binding("intensity", INTENSITY_SLOT));
|
||||
slotBindings.insert(gpu::Shader::Binding("parametersBuffer", PARAMETERS_SLOT));
|
||||
gpu::Shader::makeProgram(*program, slotBindings);
|
||||
|
||||
gpu::StatePointer state = gpu::StatePointer(new gpu::State());
|
||||
|
@ -156,7 +161,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._glUniform3f(INTENSITY_SLOT, _intensities.x, _intensities.y, _intensities.z);
|
||||
batch.setUniformBuffer(PARAMETERS_SLOT, _parameters);
|
||||
batch.draw(gpu::TRIANGLE_STRIP, 4);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -96,8 +96,10 @@ public:
|
|||
|
||||
private:
|
||||
|
||||
#include "BloomApply.shared.slh"
|
||||
|
||||
gpu::PipelinePointer _pipeline;
|
||||
glm::vec3 _intensities;
|
||||
gpu::StructBuffer<Parameters> _parameters;
|
||||
};
|
||||
|
||||
class BloomDraw {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// glsl / C++ compatible source as interface for FadeEffect
|
||||
// glsl / C++ compatible source as interface for BloomThreshold
|
||||
#ifdef __cplusplus
|
||||
# define BT_VEC2 glm::vec2
|
||||
#else
|
||||
|
|
Loading…
Reference in a new issue