From 0f00f3fdc28ca3b0e5d4301f2b9e132caf56c1a6 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Fri, 24 Aug 2018 18:04:28 +1000 Subject: [PATCH] ported solid effect to glsl --- effects/video/gaussianblureffect.cpp | 9 +++++---- effects/video/solideffect.cpp | 22 +++++++++++++++------- effects/video/solideffect.h | 9 ++++++--- panels/project.cpp | 2 +- playback/playback.cpp | 2 +- ui/keyframeview.cpp | 4 ++-- ui/timelinewidget.cpp | 11 +++++++---- 7 files changed, 37 insertions(+), 22 deletions(-) diff --git a/effects/video/gaussianblureffect.cpp b/effects/video/gaussianblureffect.cpp index b97b7d1d0..96a4f950b 100644 --- a/effects/video/gaussianblureffect.cpp +++ b/effects/video/gaussianblureffect.cpp @@ -3,8 +3,8 @@ GaussianBlurEffect::GaussianBlurEffect(Clip *c) : Effect(c, EFFECT_TYPE_VIDEO, VIDEO_GAUSSIANBLUR_EFFECT), frag(QOpenGLShader::Fragment), vert(QOpenGLShader::Vertex) { enable_opengl = true; - vert.compileSourceCode("varying vec2 vTexCoord;\nvoid main() {\n\tvTexCoord = gl_MultiTexCoord0.xy;\n\tgl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n}"); - frag.compileSourceCode("uniform mediump float amount_val;\nuniform sampler2D myTexture;\nvarying vec2 vTexCoord;\nvoid main(void) {\n\tvec4 textureColor = texture2D(myTexture, vTexCoord);\n\tgl_FragColor = vec4(textureColor.r+((1.0-textureColor.r-textureColor.r)*amount_val), textureColor.g+((1.0-textureColor.g-textureColor.g)*amount_val), textureColor.b+((1.0-textureColor.b-textureColor.b)*amount_val), textureColor.a);\n}"); + vert.compileSourceCode("attribute vec2 position;\nvoid main() { gl_Position = vec4(position, 1, 1); }"); + frag.compileSourceCode("uniform vec3 resolution;\nuniform sampler2D image;\nuniform bool flip;\nuniform vec2 direction;\n\nvoid main() {\n vec2 uv = vec2(gl_FragCoord.xy / resolution.xy);\n if (flip) {\n uv.y = 1.0 - uv.y;\n }\n\n vec4 color = vec4(0.0);\n vec2 off1 = vec2(1.3846153846) * direction;\n vec2 off2 = vec2(3.2307692308) * direction;\n color += texture2D(image, uv) * 0.2270270270;\n color += texture2D(image, uv + (off1 / resolution.xy)) * 0.3162162162;\n color += texture2D(image, uv - (off1 / resolution.xy)) * 0.3162162162;\n color += texture2D(image, uv + (off2 / resolution.xy)) * 0.0702702703;\n color += texture2D(image, uv - (off2 / resolution.xy)) * 0.0702702703;\n gl_FragColor = color;\n}\n"); program.addShader(&frag); program.addShader(&vert); program.link(); @@ -12,10 +12,11 @@ GaussianBlurEffect::GaussianBlurEffect(Clip *c) : Effect(c, EFFECT_TYPE_VIDEO, V void GaussianBlurEffect::process_gl(double timecode, GLTextureCoords &coords) { program.bind(); + program.setUniformValue("resolution", 1920, 1080, 0); + program.setUniformValue("flip", true); + program.setUniformValue("direction", 0, 20); } void GaussianBlurEffect::clean_gl() { program.release(); } - - diff --git a/effects/video/solideffect.cpp b/effects/video/solideffect.cpp index fad4a6411..c0bc14814 100644 --- a/effects/video/solideffect.cpp +++ b/effects/video/solideffect.cpp @@ -15,7 +15,7 @@ #define SMPTE_STRIP_COUNT 3 #define SMPTE_LOWER_BARS 4 -SolidEffect::SolidEffect(Clip* c) : Effect(c, EFFECT_TYPE_VIDEO, VIDEO_SOLID_EFFECT) { +SolidEffect::SolidEffect(Clip* c) : Effect(c, EFFECT_TYPE_VIDEO, VIDEO_SOLID_EFFECT), vert(QOpenGLShader::Vertex), frag(QOpenGLShader::Fragment) { enable_opengl = true; solid_type = add_row("Type:")->add_field(EFFECT_FIELD_COMBO); @@ -30,18 +30,26 @@ SolidEffect::SolidEffect(Clip* c) : Effect(c, EFFECT_TYPE_VIDEO, VIDEO_SOLID_EFF opacity_field->set_double_maximum_value(100); opacity_field->set_double_default_value(100); - connect(solid_type, SIGNAL(changed()), this, SLOT(field_changed())); - connect(solid_type, SIGNAL(changed()), this, SLOT(enable_color())); + connect(solid_type, SIGNAL(changed()), this, SLOT(field_changed())); connect(solid_color_field, SIGNAL(changed()), this, SLOT(field_changed())); connect(opacity_field, SIGNAL(changed()), this, SLOT(field_changed())); + + vert.compileSourceCode("varying vec2 vTexCoord;\nvoid main() {\n\tvTexCoord = gl_MultiTexCoord0.xy;\n\tgl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n}"); + frag.compileSourceCode("uniform vec4 solidColor;\nuniform float amount_val;\nuniform sampler2D myTexture;\nvarying vec2 vTexCoord;\nvoid main(void) {\n\tvec4 textureColor = texture2D(myTexture, vTexCoord);\n\tgl_FragColor = vec4(textureColor.r+((solidColor.r-textureColor.r)*amount_val), textureColor.g+((solidColor.g-textureColor.g)*amount_val), textureColor.b+((solidColor.b-textureColor.b)*amount_val), textureColor.a);\n}"); + program.addShader(&vert); + program.addShader(&frag); } -void SolidEffect::enable_color() { - solid_color_field->set_enabled(solid_type->get_combo_data(-1) == SOLID_TYPE_COLOR); +void SolidEffect::process_gl(double timecode, GLTextureCoords&) { + solid_color_field->set_enabled(solid_type->get_combo_data(timecode) == SOLID_TYPE_COLOR); + + program.bind(); + program.setUniformValue("solidColor", solid_color_field->get_color_value(timecode)); + program.setUniformValue("amount_val", (GLfloat) (opacity_field->get_double_value(timecode)*0.01)); } -void SolidEffect::process_gl(double timecode, GLTextureCoords& coords) { - +void SolidEffect::clean_gl() { + program.release(); } void SolidEffect::process_image(long frame, uint8_t* data, int w, int h) { diff --git a/effects/video/solideffect.h b/effects/video/solideffect.h index a3b60f147..fb37e4b7f 100644 --- a/effects/video/solideffect.h +++ b/effects/video/solideffect.h @@ -11,9 +11,12 @@ public: EffectField* solid_color_field; EffectField* opacity_field; void process_gl(double timecode, GLTextureCoords& coords); - void process_image(long p, uint8_t* data, int width, int height); -private slots: - void enable_color(); + void clean_gl(); + void process_image(long p, uint8_t* data, int width, int height); +private: + QOpenGLShaderProgram program; + QOpenGLShader vert; + QOpenGLShader frag; }; #endif // SOLIDEFFECT_H diff --git a/panels/project.cpp b/panels/project.cpp index f7a82080d..00f48bb54 100644 --- a/panels/project.cpp +++ b/panels/project.cpp @@ -1277,7 +1277,7 @@ void MediaThrobber::stop(int icon_type, bool replace) { } // redraw clips - panel_timeline->redraw_all_clips(replace); +// panel_timeline->redraw_all_clips(replace); panel_project->source_table->viewport()->update(); deleteLater(); diff --git a/playback/playback.cpp b/playback/playback.cpp index c0685da19..37bc7ce86 100644 --- a/playback/playback.cpp +++ b/playback/playback.cpp @@ -167,7 +167,7 @@ bool get_clip_frame(Clip* c, long playhead) { memcpy(c->comp_frame, current_frame->data[0], c->comp_frame_size); for (int i=0;ieffects.size();i++) { - if (c->effects.at(i)->enable_image) { + if (c->effects.at(i)->is_enabled() && c->effects.at(i)->enable_image) { c->effects.at(i)->process_image(sequence_clip_time, c->comp_frame, current_frame->width, current_frame->height); } } diff --git a/ui/keyframeview.cpp b/ui/keyframeview.cpp index 84842d262..ccffdf894 100644 --- a/ui/keyframeview.cpp +++ b/ui/keyframeview.cpp @@ -27,7 +27,7 @@ KeyframeView::KeyframeView(QWidget *parent) : QWidget(parent), mousedown(false), } void KeyframeView::paintEvent(QPaintEvent*) { - QPainter p(this); + QPainter p(this); int width = getScreenPointFromFrame(panel_effect_controls->zoom, visible_out - visible_in); setMinimumWidth(width); @@ -66,7 +66,7 @@ void KeyframeView::paintEvent(QPaintEvent*) { if (select_rect) { draw_selection_rectangle(p, QRect(rect_select_x, rect_select_y, rect_select_w, rect_select_h)); - } + } /*if (mouseover && mouseover_row < rowY.size()) { draw_keyframe(p, getScreenPointFromFrame(panel_effect_controls->zoom, mouseover_frame - visible_in), rowY.at(mouseover_row), true); diff --git a/ui/timelinewidget.cpp b/ui/timelinewidget.cpp index 15f69bf92..5d8f84ea3 100644 --- a/ui/timelinewidget.cpp +++ b/ui/timelinewidget.cpp @@ -1607,11 +1607,14 @@ void TimelineWidget::redraw_clips() { } else if (ms->preview_done) { // draw thumbnail/waveform long media_length = m->get_length_in_frames(clip->sequence->frame_rate); - int waveform_limit = qMin(clip_rect.width(), panel_timeline->getTimelineScreenPointFromFrame(media_length - clip->clip_in)); + int waveform_limit; - if (waveform_limit < clip_rect.width() && !ms->infinite_length) { - draw_checkerboard = true; - if (waveform_limit > 0) checkerboard_rect.setLeft(checkerboard_rect.left() + waveform_limit); + if (!ms->infinite_length) { + waveform_limit = qMin(clip_rect.width(), panel_timeline->getTimelineScreenPointFromFrame(media_length - clip->clip_in)); + if (waveform_limit < clip_rect.width()) { + draw_checkerboard = true; + if (waveform_limit > 0) checkerboard_rect.setLeft(checkerboard_rect.left() + waveform_limit); + } } if (clip->track < 0) {