further progress on better blending

This commit is contained in:
itsmattkc
2019-01-26 23:34:58 +11:00
parent 97a28ab54a
commit 7a436ef51f
20 changed files with 271 additions and 189 deletions
+5 -1
View File
@@ -47,11 +47,15 @@ void main(void) {
float mask = colorclose(cb, cr, cb_key, cr_key, (tola/100.0), (tolb/100.0));
if (mode == 0) { // composite
float submask = 1.0-mask;
//float submask = 1.0-mask;
float submask = 0.0;
texture_color.r = max(texture_color.r - submask*key_color.r, 0.0) + submask;
texture_color.g = max(texture_color.g - submask*key_color.g, 0.0) + submask;
texture_color.b = max(texture_color.b - submask*key_color.b, 0.0) + submask;
texture_color.a *= mask;
// premultiply
texture_color.rgb *= texture_color.a;
} else if (mode == 1) { // alpha
texture_color.rgb = vec3(mask);
} else if (mode == 2) { // original
@@ -32,6 +32,6 @@ uniform sampler2D texture;
varying vec2 vTexCoord;
void main(void) {
gl_FragColor = texture2D(background, vTexCoord);
// gl_FragColor = texture2D(texture, vTexCoord)*2.0;
// gl_FragColor = texture2D(background, vTexCoord);
gl_FragColor = texture2D(texture, vTexCoord);
}
+8
View File
@@ -0,0 +1,8 @@
#version 110
varying vec2 vTexCoord;
void main() {
vTexCoord = gl_MultiTexCoord0.xy;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
+5 -5
View File
@@ -8,23 +8,23 @@ CornerPinEffect::CornerPinEffect(Clip *c, const EffectMeta *em) : Effect(c, em)
enable_coords = true;
enable_shader = true;
EffectRow* top_left = add_row(tr("Top Left"));
EffectRow* top_left = add_row(tr("Top Left"));
top_left_x = top_left->add_field(EFFECT_FIELD_DOUBLE, "topleftx");
top_left_y = top_left->add_field(EFFECT_FIELD_DOUBLE, "toplefty");
EffectRow* top_right = add_row(tr("Top Right"));
EffectRow* top_right = add_row(tr("Top Right"));
top_right_x = top_right->add_field(EFFECT_FIELD_DOUBLE, "toprightx");
top_right_y = top_right->add_field(EFFECT_FIELD_DOUBLE, "toprighty");
EffectRow* bottom_left = add_row(tr("Bottom Left"));
EffectRow* bottom_left = add_row(tr("Bottom Left"));
bottom_left_x = bottom_left->add_field(EFFECT_FIELD_DOUBLE, "bottomleftx");
bottom_left_y = bottom_left->add_field(EFFECT_FIELD_DOUBLE, "bottomlefty");
EffectRow* bottom_right = add_row(tr("Bottom Right"));
EffectRow* bottom_right = add_row(tr("Bottom Right"));
bottom_right_x = bottom_right->add_field(EFFECT_FIELD_DOUBLE, "bottomrightx");
bottom_right_y = bottom_right->add_field(EFFECT_FIELD_DOUBLE, "bottomrighty");
perspective = add_row(tr("Perspective"))->add_field(EFFECT_FIELD_BOOL, "perspective");
perspective = add_row(tr("Perspective"))->add_field(EFFECT_FIELD_BOOL, "perspective");
perspective->set_bool_value(true);
top_left_gizmo = add_gizmo(GIZMO_TYPE_DOT);
@@ -13,6 +13,7 @@ uniform float shadowdistance;
varying vec2 vTexCoord;
void main(void) {
/*
vec4 master_px = texture2D(image, vTexCoord);
if (shadow == 1) {
vec2 shadow_dist = vec2(shadowdistance)/resolution;
@@ -39,5 +40,7 @@ void main(void) {
gl_FragColor = composition;
} else {
gl_FragColor = master_px;
}
}
*/
gl_FragColor = texture2D(image, vTexCoord);
}
+10
View File
@@ -0,0 +1,10 @@
<RCC>
<qresource prefix="/internalshaders">
<file>blending.frag</file>
<file>common.vert</file>
<file>cornerpin.frag</file>
<file>cornerpin.vert</file>
<file>premultiply.frag</file>
<file>dropshadow.frag</file>
</qresource>
</RCC>
+10
View File
@@ -0,0 +1,10 @@
#version 110
uniform sampler2D tex;
varying vec2 vTexCoord;
void main(void) {
vec4 c = texture2D(tex, vTexCoord);
c.rgb *= c.a;
gl_FragColor = c;
}
+66 -65
View File
@@ -94,67 +94,67 @@ TextEffect::TextEffect(Clip *c, const EffectMeta* em) :
}
void blurred2(QImage& result, const QRect& rect, int radius, bool alphaOnly = false) {
int tab[] = { 14, 10, 8, 6, 5, 5, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2 };
int alpha = (radius < 1) ? 16 : (radius > 17) ? 1 : tab[radius-1];
int tab[] = { 14, 10, 8, 6, 5, 5, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2 };
int alpha = (radius < 1) ? 16 : (radius > 17) ? 1 : tab[radius-1];
int r1 = rect.top();
int r2 = rect.bottom();
int c1 = rect.left();
int c2 = rect.right();
int r1 = rect.top();
int r2 = rect.bottom();
int c1 = rect.left();
int c2 = rect.right();
int bpl = result.bytesPerLine();
int rgba[4];
unsigned char* p;
int bpl = result.bytesPerLine();
int rgba[4];
unsigned char* p;
int i1 = 0;
int i2 = 3;
int i1 = 0;
int i2 = 3;
if (alphaOnly)
i1 = i2 = (QSysInfo::ByteOrder == QSysInfo::BigEndian ? 0 : 3);
if (alphaOnly)
i1 = i2 = (QSysInfo::ByteOrder == QSysInfo::BigEndian ? 0 : 3);
for (int col = c1; col <= c2; col++) {
p = result.scanLine(r1) + col * 4;
for (int i = i1; i <= i2; i++)
rgba[i] = p[i] << 4;
for (int col = c1; col <= c2; col++) {
p = result.scanLine(r1) + col * 4;
for (int i = i1; i <= i2; i++)
rgba[i] = p[i] << 4;
p += bpl;
for (int j = r1; j < r2; j++, p += bpl)
for (int i = i1; i <= i2; i++)
p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 16) >> 4;
}
p += bpl;
for (int j = r1; j < r2; j++, p += bpl)
for (int i = i1; i <= i2; i++)
p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 16) >> 4;
}
for (int row = r1; row <= r2; row++) {
p = result.scanLine(row) + c1 * 4;
for (int i = i1; i <= i2; i++)
rgba[i] = p[i] << 4;
for (int row = r1; row <= r2; row++) {
p = result.scanLine(row) + c1 * 4;
for (int i = i1; i <= i2; i++)
rgba[i] = p[i] << 4;
p += 4;
for (int j = c1; j < c2; j++, p += 4)
for (int i = i1; i <= i2; i++)
p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 16) >> 4;
}
p += 4;
for (int j = c1; j < c2; j++, p += 4)
for (int i = i1; i <= i2; i++)
p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 16) >> 4;
}
for (int col = c1; col <= c2; col++) {
p = result.scanLine(r2) + col * 4;
for (int i = i1; i <= i2; i++)
rgba[i] = p[i] << 4;
for (int col = c1; col <= c2; col++) {
p = result.scanLine(r2) + col * 4;
for (int i = i1; i <= i2; i++)
rgba[i] = p[i] << 4;
p -= bpl;
for (int j = r1; j < r2; j++, p -= bpl)
for (int i = i1; i <= i2; i++)
p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 16) >> 4;
}
p -= bpl;
for (int j = r1; j < r2; j++, p -= bpl)
for (int i = i1; i <= i2; i++)
p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 16) >> 4;
}
for (int row = r1; row <= r2; row++) {
p = result.scanLine(row) + c2 * 4;
for (int i = i1; i <= i2; i++)
rgba[i] = p[i] << 4;
for (int row = r1; row <= r2; row++) {
p = result.scanLine(row) + c2 * 4;
for (int i = i1; i <= i2; i++)
rgba[i] = p[i] << 4;
p -= 4;
for (int j = c1; j < c2; j++, p -= 4)
for (int i = i1; i <= i2; i++)
p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 16) >> 4;
}
p -= 4;
for (int j = c1; j < c2; j++, p -= 4)
for (int i = i1; i <= i2; i++)
p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 16) >> 4;
}
}
void TextEffect::redraw(double timecode) {
@@ -254,25 +254,25 @@ void TextEffect::redraw(double timecode) {
path.addText(text_x, text_y, font, lines.at(i));
}
// draw software shadow
if (!enable_shader && shadow_bool->get_bool_value(timecode)) {
p.setPen(Qt::NoPen);
int shadow_offset = shadow_distance->get_double_value(timecode);
// draw software shadow
if (shadow_bool->get_bool_value(timecode)) {
p.setPen(Qt::NoPen);
int shadow_offset = shadow_distance->get_double_value(timecode);
QPainterPath shadow_path(path);
shadow_path.translate(shadow_offset, shadow_offset);
QPainterPath shadow_path(path);
shadow_path.translate(shadow_offset, shadow_offset);
QColor col = shadow_color->get_color_value(timecode);
col.setAlpha(0);
img.fill(col);
QColor col = shadow_color->get_color_value(timecode);
col.setAlpha(0);
img.fill(col);
col.setAlphaF(shadow_opacity->get_double_value(timecode)*0.01);
p.setBrush(col);
p.drawPath(shadow_path);
col.setAlphaF(shadow_opacity->get_double_value(timecode)*0.01);
p.setBrush(col);
p.drawPath(shadow_path);
int blurSoftness = shadow_softness->get_double_value(timecode);
if (blurSoftness > 0) blurred2(img, img.rect(), blurSoftness, false);
}
int blurSoftness = shadow_softness->get_double_value(timecode);
if (blurSoftness > 0) blurred2(img, img.rect(), blurSoftness, false);
}
// draw outline
int outline_width_val = outline_width->get_double_value(timecode);
@@ -288,10 +288,11 @@ void TextEffect::redraw(double timecode) {
p.setPen(Qt::NoPen);
p.setBrush(set_color_button->get_color_value(timecode));
p.drawPath(path);
p.end();
}
void TextEffect::shadow_enable(bool e) {
enable_shader = (e && !config.use_software_fallback);
close();
shadow_color->set_enabled(e);