optimized blurs
This commit is contained in:
+18
-14
@@ -6,24 +6,28 @@ uniform float radius;
|
|||||||
uniform vec2 resolution;
|
uniform vec2 resolution;
|
||||||
uniform bool horiz_blur;
|
uniform bool horiz_blur;
|
||||||
uniform bool vert_blur;
|
uniform bool vert_blur;
|
||||||
|
uniform int iteration;
|
||||||
|
|
||||||
|
varying vec2 vTexCoord;
|
||||||
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
float rad = ceil(radius);
|
float rad = ceil(radius);
|
||||||
float x_rad = (horiz_blur) ? rad : 0.5;
|
|
||||||
float y_rad = (vert_blur) ? rad : 0.5;
|
float divider = 1.0 / rad;
|
||||||
vec2 texCoord = gl_FragCoord.xy/resolution;
|
vec4 color = vec4(0.0);
|
||||||
if (radius == 0.0 || (!horiz_blur && !vert_blur)) {
|
bool radius_is_zero = (rad == 0.0);
|
||||||
gl_FragColor = texture2D(image, texCoord);
|
|
||||||
} else {
|
if (iteration == 0 && horiz_blur && !radius_is_zero) {
|
||||||
float divider = 1.0;
|
for (float x=-rad+0.5;x<=rad;x+=2.0) {
|
||||||
if (horiz_blur) divider /= rad;
|
color += texture2D(image, (vec2(gl_FragCoord.x+x, gl_FragCoord.y))/resolution)*(divider);
|
||||||
if (vert_blur) divider /= rad;
|
|
||||||
vec4 color = vec4(0.0);
|
|
||||||
for (float x=-x_rad+0.5;x<=x_rad;x+=2.0) {
|
|
||||||
for (float y=-y_rad+0.5;y<=y_rad;y+=2.0) {
|
|
||||||
color += texture2D(image, (vec2(gl_FragCoord.x+x, gl_FragCoord.y+y))/resolution)*(divider);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
gl_FragColor = color;
|
gl_FragColor = color;
|
||||||
|
} else if (iteration == 1 && vert_blur && !radius_is_zero) {
|
||||||
|
for (float x=-rad+0.5;x<=rad;x+=2.0) {
|
||||||
|
color += texture2D(image, (vec2(gl_FragCoord.x, gl_FragCoord.y+x))/resolution)*(divider);
|
||||||
|
}
|
||||||
|
gl_FragColor = color;
|
||||||
|
} else {
|
||||||
|
gl_FragColor = texture2D(image, vTexCoord);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-1
@@ -9,5 +9,5 @@
|
|||||||
<row name="Vertical">
|
<row name="Vertical">
|
||||||
<field type="bool" default="1" id="vert_blur"/>
|
<field type="bool" default="1" id="vert_blur"/>
|
||||||
</row>
|
</row>
|
||||||
<shader vert="common.vert" frag="boxblur.frag"/>
|
<shader vert="common.vert" frag="boxblur.frag" iterations="2"/>
|
||||||
</effect>
|
</effect>
|
||||||
+25
-19
@@ -4,13 +4,14 @@
|
|||||||
|
|
||||||
uniform sampler2D image;
|
uniform sampler2D image;
|
||||||
|
|
||||||
uniform float radius;
|
// uniform float radius;
|
||||||
uniform float sigma;
|
uniform float sigma;
|
||||||
uniform vec2 resolution;
|
uniform vec2 resolution;
|
||||||
uniform bool horiz_blur;
|
uniform bool horiz_blur;
|
||||||
uniform bool vert_blur;
|
uniform bool vert_blur;
|
||||||
|
uniform int iteration;
|
||||||
|
|
||||||
uniform bool opt;
|
varying vec2 vTexCoord;
|
||||||
|
|
||||||
float gaussian(float x, float sigma) {
|
float gaussian(float x, float sigma) {
|
||||||
return (1.0/(sigma*sqrt(2.0*M_PI)))*exp(-0.5*pow(x/sigma, 2.0));
|
return (1.0/(sigma*sqrt(2.0*M_PI)))*exp(-0.5*pow(x/sigma, 2.0));
|
||||||
@@ -21,28 +22,33 @@ float gaussian2(float x, float y, float sigma) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
if (radius == 0.0 || sigma == 0.0 || (!horiz_blur && !vert_blur)) {
|
float rad = ceil(sigma);
|
||||||
gl_FragColor = texture2D(image, gl_FragCoord.xy/resolution);
|
|
||||||
} else {
|
|
||||||
float rad = ceil(radius);
|
|
||||||
float x_rad = horiz_blur ? rad : 0.5;
|
|
||||||
float y_rad = vert_blur ? rad : 0.5;
|
|
||||||
|
|
||||||
float sum = 0.0;
|
float sum = 0.0;
|
||||||
|
|
||||||
for (float x=-x_rad+0.5;x<=x_rad;x+=2.0) {
|
vec4 color = vec4(0.0);
|
||||||
for (float y=-y_rad+0.5;y<=y_rad;y+=2.0) {
|
|
||||||
sum += gaussian2(x, y, sigma);
|
bool radius_is_zero = (rad == 0.0);
|
||||||
}
|
|
||||||
|
if (!radius_is_zero) {
|
||||||
|
for (float x=-rad+0.5;x<=rad;x+=2.0) {
|
||||||
|
sum += gaussian2(x, 0.0, sigma);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
vec4 color = vec4(0.0);
|
if (iteration == 0 && horiz_blur && !radius_is_zero) {
|
||||||
for (float x=-x_rad+0.5;x<=x_rad;x+=2.0) {
|
for (float x=-rad+0.5;x<=rad;x+=2.0) {
|
||||||
for (float y=-y_rad+0.5;y<=y_rad;y+=2.0) {
|
float weight = (gaussian2(x, 0.0, sigma)/sum);
|
||||||
float weight = (gaussian2(x, y, sigma)/sum);
|
color += texture2D(image, (vec2(gl_FragCoord.x+x, gl_FragCoord.y))/resolution)*(weight);
|
||||||
color += texture2D(image, (vec2(gl_FragCoord.x+x, gl_FragCoord.y+y))/resolution)*(weight);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
gl_FragColor = color;
|
gl_FragColor = color;
|
||||||
|
} else if (iteration == 1 && vert_blur && !radius_is_zero) {
|
||||||
|
for (float x=-rad+0.5;x<=rad;x+=2.0) {
|
||||||
|
float weight = (gaussian2(0.0, x, sigma)/sum);
|
||||||
|
color += texture2D(image, (vec2(gl_FragCoord.x, gl_FragCoord.y+x))/resolution)*(weight);
|
||||||
|
}
|
||||||
|
gl_FragColor = color;
|
||||||
|
} else {
|
||||||
|
gl_FragColor = texture2D(image, vTexCoord);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<effect name="Gaussian Blur" category="Blur">
|
<effect name="Gaussian Blur" category="Blur">
|
||||||
<row name="Radius">
|
<!-- <row name="Radius">
|
||||||
<field type="double" min="0" default="10" id="radius"/>
|
<field type="double" min="0" default="10" id="radius"/>
|
||||||
</row>
|
</row> -->
|
||||||
<row name="Sigma">
|
<row name="Sigma">
|
||||||
<field type="double" min="0" default="5.5" id="sigma"/>
|
<field type="double" min="0" default="5.5" id="sigma"/>
|
||||||
</row>
|
</row>
|
||||||
@@ -12,8 +12,5 @@
|
|||||||
<row name="Vertical">
|
<row name="Vertical">
|
||||||
<field type="bool" default="1" id="vert_blur"/>
|
<field type="bool" default="1" id="vert_blur"/>
|
||||||
</row>
|
</row>
|
||||||
<!-- <row name="Opt">
|
<shader vert="common.vert" frag="gaussianblur.frag" iterations="2"/>
|
||||||
<field type="bool" default="0" id="opt"/>
|
|
||||||
</row> -->
|
|
||||||
<shader vert="common.vert" frag="gaussianblur.frag"/>
|
|
||||||
</effect>
|
</effect>
|
||||||
+14
-2
@@ -102,7 +102,8 @@ Effect::Effect(Clip* c, const EffectMeta *em) :
|
|||||||
texture(nullptr),
|
texture(nullptr),
|
||||||
enable_always_update(false),
|
enable_always_update(false),
|
||||||
isOpen(false),
|
isOpen(false),
|
||||||
bound(false)
|
bound(false),
|
||||||
|
iterations(1)
|
||||||
{
|
{
|
||||||
// set up base UI
|
// set up base UI
|
||||||
container = new CollapsibleWidget();
|
container = new CollapsibleWidget();
|
||||||
@@ -276,6 +277,8 @@ Effect::Effect(Clip* c, const EffectMeta *em) :
|
|||||||
vertPath = attr.value().toString();
|
vertPath = attr.value().toString();
|
||||||
} else if (attr.name() == "frag") {
|
} else if (attr.name() == "frag") {
|
||||||
fragPath = attr.value().toString();
|
fragPath = attr.value().toString();
|
||||||
|
} else if (attr.name() == "iterations") {
|
||||||
|
setIterations(attr.value().toInt());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}/* else if (reader.name() == "superimpose" && reader.isStartElement()) {
|
}/* else if (reader.name() == "superimpose" && reader.isStartElement()) {
|
||||||
@@ -695,6 +698,14 @@ void Effect::endEffect() {
|
|||||||
bound = false;
|
bound = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Effect::getIterations() {
|
||||||
|
return iterations;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Effect::setIterations(int i) {
|
||||||
|
iterations = i;
|
||||||
|
}
|
||||||
|
|
||||||
void Effect::process_image(double, uint8_t *, uint8_t *, int){}
|
void Effect::process_image(double, uint8_t *, uint8_t *, int){}
|
||||||
|
|
||||||
Effect* Effect::copy(Clip* c) {
|
Effect* Effect::copy(Clip* c) {
|
||||||
@@ -704,9 +715,10 @@ Effect* Effect::copy(Clip* c) {
|
|||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Effect::process_shader(double timecode, GLTextureCoords&) {
|
void Effect::process_shader(double timecode, GLTextureCoords&, int iteration) {
|
||||||
glslProgram->setUniformValue("resolution", parent_clip->getWidth(), parent_clip->getHeight());
|
glslProgram->setUniformValue("resolution", parent_clip->getWidth(), parent_clip->getHeight());
|
||||||
glslProgram->setUniformValue("time", GLfloat(timecode));
|
glslProgram->setUniformValue("time", GLfloat(timecode));
|
||||||
|
glslProgram->setUniformValue("iteration", iteration);
|
||||||
|
|
||||||
for (int i=0;i<rows.size();i++) {
|
for (int i=0;i<rows.size();i++) {
|
||||||
EffectRow* row = rows.at(i);
|
EffectRow* row = rows.at(i);
|
||||||
|
|||||||
+2
-1
@@ -193,7 +193,7 @@ public:
|
|||||||
const char* ffmpeg_filter;
|
const char* ffmpeg_filter;
|
||||||
|
|
||||||
virtual void process_image(double timecode, uint8_t* input, uint8_t* output, int size);
|
virtual void process_image(double timecode, uint8_t* input, uint8_t* output, int size);
|
||||||
virtual void process_shader(double timecode, GLTextureCoords&);
|
virtual void process_shader(double timecode, GLTextureCoords&, int iteration);
|
||||||
virtual void process_coords(double timecode, GLTextureCoords& coords, int data);
|
virtual void process_coords(double timecode, GLTextureCoords& coords, int data);
|
||||||
virtual GLuint process_superimpose(double timecode);
|
virtual GLuint process_superimpose(double timecode);
|
||||||
virtual void process_audio(double timecode_start, double timecode_end, quint8* samples, int nb_bytes, int channel_count);
|
virtual void process_audio(double timecode_start, double timecode_end, quint8* samples, int nb_bytes, int channel_count);
|
||||||
@@ -231,6 +231,7 @@ private:
|
|||||||
QGridLayout* ui_layout;
|
QGridLayout* ui_layout;
|
||||||
QWidget* ui;
|
QWidget* ui;
|
||||||
bool bound;
|
bool bound;
|
||||||
|
int iterations;
|
||||||
|
|
||||||
// superimpose functions
|
// superimpose functions
|
||||||
virtual void redraw(double timecode);
|
virtual void redraw(double timecode);
|
||||||
|
|||||||
@@ -97,9 +97,11 @@ void process_effect(Clip* c,
|
|||||||
if (can_process_shaders || e->enable_superimpose) {
|
if (can_process_shaders || e->enable_superimpose) {
|
||||||
e->startEffect();
|
e->startEffect();
|
||||||
if (can_process_shaders && e->is_glsl_linked()) {
|
if (can_process_shaders && e->is_glsl_linked()) {
|
||||||
e->process_shader(timecode, coords);
|
for (int i=0;i<e->getIterations();i++) {
|
||||||
composite_texture = draw_clip(c->fbo[fbo_switcher], composite_texture, true);
|
e->process_shader(timecode, coords, i);
|
||||||
fbo_switcher = !fbo_switcher;
|
composite_texture = draw_clip(c->fbo[fbo_switcher], composite_texture, true);
|
||||||
|
fbo_switcher = !fbo_switcher;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (e->enable_superimpose) {
|
if (e->enable_superimpose) {
|
||||||
GLuint superimpose_texture = e->process_superimpose(timecode);
|
GLuint superimpose_texture = e->process_superimpose(timecode);
|
||||||
|
|||||||
Reference in New Issue
Block a user