From ca47f13fbb687789c9481fb0c74363761488186f Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Fri, 16 Nov 2018 10:18:57 +1100 Subject: [PATCH] much faster box blur --- effects/boxblur.frag | 46 +++++++++++-------------------------- effects/boxblur.xml | 3 +++ effects/invert.xml | 6 ++--- effects/volumetriclight.xml | 6 ++--- ui/viewerwidget.cpp | 31 ++++++++++--------------- 5 files changed, 34 insertions(+), 58 deletions(-) diff --git a/effects/boxblur.frag b/effects/boxblur.frag index ba366ec08..4724fd74b 100644 --- a/effects/boxblur.frag +++ b/effects/boxblur.frag @@ -9,42 +9,22 @@ uniform vec2 resolution; uniform bool horiz_blur; uniform bool vert_blur; +uniform bool opt; + void main(void) { + float rad = floor(radius); + float x_rad = (horiz_blur) ? rad : 0.5; + float y_rad = (vert_blur) ? rad : 0.5; + vec2 texCoord = gl_FragCoord.xy/resolution; if (radius == 0.0 || (!horiz_blur && !vert_blur)) { - gl_FragColor = texture2D(image, gl_FragCoord.xy/resolution); + gl_FragColor = texture2D(image, texCoord); } else { - float divider = 1.0 / ((radius*2.0)+1.0); - if (horiz_blur && vert_blur) { - divider *= divider; - - gl_FragColor = texture2D(image, gl_FragCoord.xy/resolution)*divider; - - for (float i=1.0;i<=radius;i++) { - gl_FragColor += texture2D(image, (vec2(gl_FragCoord.x-i, gl_FragCoord.y))/resolution)*(divider); - gl_FragColor += texture2D(image, (vec2(gl_FragCoord.x+i, gl_FragCoord.y))/resolution)*(divider); - gl_FragColor += texture2D(image, (vec2(gl_FragCoord.x, gl_FragCoord.y+i))/resolution)*(divider); - gl_FragColor += texture2D(image, (vec2(gl_FragCoord.x, gl_FragCoord.y-i))/resolution)*(divider); - } - - for (float x=1.0;x<=radius;x++) { - for (float y=1.0;y<=radius;y++) { - gl_FragColor += texture2D(image, (vec2(gl_FragCoord.x-x, gl_FragCoord.y-y))/resolution)*(divider); - gl_FragColor += texture2D(image, (vec2(gl_FragCoord.x+x, gl_FragCoord.y+y))/resolution)*(divider); - gl_FragColor += texture2D(image, (vec2(gl_FragCoord.x-x, gl_FragCoord.y+y))/resolution)*(divider); - gl_FragColor += texture2D(image, (vec2(gl_FragCoord.x+x, gl_FragCoord.y-y))/resolution)*(divider); - } - } - } else { - gl_FragColor = texture2D(image, gl_FragCoord.xy/resolution)*(divider); - - for (float i=1.0;i<=radius;i++) { - if (horiz_blur) { - gl_FragColor += texture2D(image, (vec2(gl_FragCoord.x-i, gl_FragCoord.y))/resolution)*(divider); - gl_FragColor += texture2D(image, (vec2(gl_FragCoord.x+i, gl_FragCoord.y))/resolution)*(divider); - } else { - gl_FragColor += texture2D(image, (vec2(gl_FragCoord.x, gl_FragCoord.y-i))/resolution)*(divider); - gl_FragColor += texture2D(image, (vec2(gl_FragCoord.x, gl_FragCoord.y+i))/resolution)*(divider); - } + float divider = 1.0; + if (horiz_blur) divider /= rad; + if (vert_blur) divider /= rad; + 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) { + gl_FragColor += texture2D(image, (vec2(gl_FragCoord.x+x, gl_FragCoord.y+y))/resolution)*(divider); } } } diff --git a/effects/boxblur.xml b/effects/boxblur.xml index 1dd4cb45e..2f5c04f60 100644 --- a/effects/boxblur.xml +++ b/effects/boxblur.xml @@ -9,5 +9,8 @@ + + + \ No newline at end of file diff --git a/effects/invert.xml b/effects/invert.xml index 0e5d38a64..bc2ee42fb 100644 --- a/effects/invert.xml +++ b/effects/invert.xml @@ -1,7 +1,7 @@ - + - + - + \ No newline at end of file diff --git a/effects/volumetriclight.xml b/effects/volumetriclight.xml index bc2ee42fb..0e5d38a64 100644 --- a/effects/volumetriclight.xml +++ b/effects/volumetriclight.xml @@ -1,7 +1,7 @@ - + - + - + \ No newline at end of file diff --git a/ui/viewerwidget.cpp b/ui/viewerwidget.cpp index b8a0d238d..cd777d15b 100644 --- a/ui/viewerwidget.cpp +++ b/ui/viewerwidget.cpp @@ -256,6 +256,9 @@ void ViewerWidget::process_effect(Clip* c, Effect* e, double timecode, GLTexture } } +int motion_blur_prog = 0; +int motion_blur_lim = 4; + GLuint ViewerWidget::compose_sequence(QVector& nests, bool render_audio) { Sequence* s = viewer->seq; long playhead = s->playhead; @@ -473,25 +476,7 @@ GLuint ViewerWidget::compose_sequence(QVector& nests, bool render_audio) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glBegin(GL_QUADS); - - // calculate the Q coordinate - /*double m1 = ((double)coords.vertexTopRightY - (double)coords.vertexBottomLeftY)/((double)coords.vertexTopRightX - (double)coords.vertexBottomLeftX); - double c1 = (double)coords.vertexBottomLeftY - m1 * (double)coords.vertexBottomLeftX; - double m2 = ((double)coords.vertexBottomRightY - (double)coords.vertexTopLeftY)/((double)coords.vertexBottomRightX - (double)coords.vertexTopLeftX); - double c2 = (double)coords.vertexTopLeftY - m2 * (double)coords.vertexTopLeftX; - double mid_x = (c2 - c1) / (m1 - m2); - double mid_y = m1 * mid_x + c1; - - double d0 = qSqrt(qPow(mid_x - (double)coords.vertexBottomLeftX, 2) + qPow(mid_y - (double)coords.vertexBottomLeftY, 2)); - double d1 = qSqrt(qPow((double)coords.vertexBottomRightX - mid_x, 2) + qPow(mid_y - (double)coords.vertexBottomRightY, 2)); - double d2 = qSqrt(qPow((double)coords.vertexTopRightX - mid_x, 2) + qPow((double)coords.vertexTopRightY - mid_y, 2)); - double d3 = qSqrt(qPow(mid_x - (double)coords.vertexTopLeftX, 2) + qPow((double)coords.vertexTopLeftY - mid_y, 2)); - - double q0 = (d0 + d2)/d2; - double q1 = (d1 + d3)/d3; - double q2 = (d2 + d0)/d0; - double q3 = (d3 + d1)/d1;*/ + glBegin(GL_QUADS); if (coords.grid_size <= 1) { glTexCoord2f(coords.textureTopLeftX, coords.textureTopLeftY); // top left @@ -545,6 +530,14 @@ GLuint ViewerWidget::compose_sequence(QVector& nests, bool render_audio) } glPopMatrix(); + + /*GLfloat motion_blur_frac = (GLfloat) motion_blur_prog / (GLfloat) motion_blur_lim; + if (motion_blur_prog == 0) { + glAccum(GL_LOAD, motion_blur_frac); + } else { + glAccum(GL_ACCUM, motion_blur_frac); + } + motion_blur_prog++;*/ } } else { if (render_audio || (config.enable_audio_scrubbing && audio_scrub)) {