shake effect reimplemented and vastly improved

This commit is contained in:
itsmattkc
2018-11-01 19:01:34 +11:00
parent 9f0ff7f561
commit 70565dca7b
6 changed files with 135 additions and 5 deletions
+7
View File
@@ -28,6 +28,7 @@
#include "effects/internal/toneeffect.h"
#include "effects/internal/volumeeffect.h"
#include "effects/internal/paneffect.h"
#include "effects/internal/shakeeffect.h"
#include <QCheckBox>
#include <QGridLayout>
@@ -58,6 +59,7 @@ Effect* create_effect(Clip* c, const EffectMeta* em) {
case EFFECT_INTERNAL_VOLUME: return new VolumeEffect(c, em); break;
case EFFECT_INTERNAL_PAN: return new PanEffect(c, em); break;
case EFFECT_INTERNAL_TONE: return new ToneEffect(c, em); break;
case EFFECT_INTERNAL_SHAKE: return new ShakeEffect(c, em); break;
}
} else {
dout << "[ERROR] Invalid effect data";
@@ -112,6 +114,11 @@ void load_internal_effects() {
em.category = "Render";
em.internal = EFFECT_INTERNAL_SOLID;
video_effects.append(em);
em.name = "Shake";
em.category = "Distort";
em.internal = EFFECT_INTERNAL_SHAKE;
video_effects.append(em);
}
void load_shader_effects() {
+2 -1
View File
@@ -64,7 +64,8 @@ extern QMutex effects_loaded;
#define EFFECT_INTERNAL_VOLUME 4
#define EFFECT_INTERNAL_PAN 5
#define EFFECT_INTERNAL_TONE 6
#define EFFECT_INTERNAL_COUNT 7
#define EFFECT_INTERNAL_SHAKE 7
#define EFFECT_INTERNAL_COUNT 8
struct GLTextureCoords {
int vertexTopLeftX;
+85
View File
@@ -0,0 +1,85 @@
#include "shakeeffect.h"
#include <QGridLayout>
#include <QLabel>
#include <QtMath>
#include <QOpenGLFunctions>
#include "ui/labelslider.h"
#include "ui/collapsiblewidget.h"
#include "project/clip.h"
#include "project/sequence.h"
#include "panels/timeline.h"
#include "debug.h"
ShakeEffect::ShakeEffect(Clip *c, const EffectMeta *em) : Effect(c, em), evolution(INT_MIN) {
enable_coords = true;
EffectRow* intensity_row = add_row("Intensity:");
intensity_val = intensity_row->add_field(EFFECT_FIELD_DOUBLE);
intensity_val->id = "intensity";
intensity_val->set_double_minimum_value(0);
EffectRow* rotation_row = add_row("Rotation:");
rotation_val = rotation_row->add_field(EFFECT_FIELD_DOUBLE);
rotation_val->id = "rotation";
rotation_val->set_double_minimum_value(0);
EffectRow* frequency_row = add_row("Frequency:");
frequency_val = frequency_row->add_field(EFFECT_FIELD_DOUBLE);
frequency_val->id = "frequency";
frequency_val->set_double_minimum_value(0);
// set defaults
intensity_val->set_double_default_value(25);
rotation_val->set_double_default_value(10);
frequency_val->set_double_default_value(5);
srand(QDateTime::currentMSecsSinceEpoch());
for (int i=0;i<RANDOM_VAL_SIZE;i++) {
random_vals[i] = (double)rand()/RAND_MAX;
}
connect(intensity_val, SIGNAL(changed()), this, SLOT(field_changed()));
connect(rotation_val, SIGNAL(changed()), this, SLOT(field_changed()));
connect(frequency_val, SIGNAL(changed()), this, SLOT(field_changed()));
}
void ShakeEffect::process_coords(double timecode, GLTextureCoords& coords) {
int lim = RANDOM_VAL_SIZE/6;
double multiplier = intensity_val->get_double_value(timecode)/lim;
double rotmult = rotation_val->get_double_value(timecode)/lim/10;
double x = timecode * frequency_val->get_double_value(timecode);
double xoff = 0;
double yoff = 0;
double rotoff = 0;
for (int i=0;i<lim;i++) {
int offset = 6*i;
xoff += qSin((x+random_vals[offset])*random_vals[offset+1]);
yoff += qSin((x+random_vals[offset+2])*random_vals[offset+3]);
rotoff += qSin((x+random_vals[offset+4])*random_vals[offset+5]);
}
xoff *= multiplier;
yoff *= multiplier;
rotoff *= rotmult;
coords.vertexTopLeftX += xoff;
coords.vertexTopRightX += xoff;
coords.vertexBottomLeftX += xoff;
coords.vertexBottomRightX += xoff;
coords.vertexTopLeftY += yoff;
coords.vertexTopRightY += yoff;
coords.vertexBottomLeftY += yoff;
coords.vertexBottomRightY += yoff;
glRotatef(rotoff, 0, 0, 1);
evolution++;
}
+37
View File
@@ -0,0 +1,37 @@
#ifndef SHAKEEFFECT_H
#define SHAKEEFFECT_H
#include "../effect.h"
#define RANDOM_VAL_SIZE 30
class ShakeEffect : public Effect {
Q_OBJECT
public:
ShakeEffect(Clip* c, const EffectMeta* em);
void process_coords(double timecode, GLTextureCoords& coords);
EffectField* intensity_val;
EffectField* rotation_val;
EffectField* frequency_val;
private:
int evolution;
double random_vals[RANDOM_VAL_SIZE];
/*double multiplier_1;
double multiplier_2;
double multiplier_3;
double multiplier_4;
double multiplier_5;
double multiplier_6;
double adder_1;
double adder_2;
double adder_3;
double adder_4;
double adder_5;
double adder_6;*/
};
#endif // SHAKEEFFECT_H
+4 -2
View File
@@ -80,7 +80,8 @@ SOURCES += \
effects/internal/paneffect.cpp \
effects/internal/toneeffect.cpp \
effects/internal/volumeeffect.cpp \
effects/internal/crossdissolvetransition.cpp
effects/internal/crossdissolvetransition.cpp \
effects/internal/shakeeffect.cpp
HEADERS += \
mainwindow.h \
@@ -139,7 +140,8 @@ HEADERS += \
effects/internal/audionoiseeffect.h \
effects/internal/paneffect.h \
effects/internal/toneeffect.h \
effects/internal/volumeeffect.h
effects/internal/volumeeffect.h \
effects/internal/shakeeffect.h
FORMS += \
mainwindow.ui \
-2
View File
@@ -132,8 +132,6 @@ void AudioSenderThread::run() {
// got all the bytes, write again
written_bytes += send_audio_to_output(0, audio_ibuffer_size);
}
dout << "read to" << audio_ibuffer_read;
}
}
lock.unlock();