ported solid effect to glsl

This commit is contained in:
itsmattkc
2018-08-24 18:04:28 +10:00
parent b3c41b6305
commit 0f00f3fdc2
7 changed files with 37 additions and 22 deletions
+5 -4
View File
@@ -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();
}
+15 -7
View File
@@ -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) {
+6 -3
View File
@@ -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
+1 -1
View File
@@ -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();
+1 -1
View File
@@ -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;i<c->effects.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);
}
}
+2 -2
View File
@@ -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);
+7 -4
View File
@@ -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) {