diff --git a/app/node/filter/blur/blur.cpp b/app/node/filter/blur/blur.cpp index 66efd333f..fbc42efda 100644 --- a/app/node/filter/blur/blur.cpp +++ b/app/node/filter/blur/blur.cpp @@ -83,7 +83,7 @@ void BlurFilterNode::Retranslate() ShaderCode BlurFilterNode::GetShaderCode(const QString &shader_id) const { Q_UNUSED(shader_id) - return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/blur.frag"), QString()); + return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/blur.frag")); } NodeValueTable BlurFilterNode::Value(NodeValueDatabase &value) const @@ -96,6 +96,8 @@ NodeValueTable BlurFilterNode::Value(NodeValueDatabase &value) const job.InsertValue(horiz_input_, value); job.InsertValue(vert_input_, value); job.InsertValue(repeat_edge_pixels_input_, value); + job.InsertValue(QStringLiteral("resolution_in"), + ShaderValue(value[QStringLiteral("global")].Get(NodeParam::kVec2, QStringLiteral("resolution")), NodeParam::kVec2)); NodeValueTable table = value.Merge(); diff --git a/app/node/filter/mosaic/mosaicfilternode.cpp b/app/node/filter/mosaic/mosaicfilternode.cpp index 8e657151a..001c12be5 100644 --- a/app/node/filter/mosaic/mosaicfilternode.cpp +++ b/app/node/filter/mosaic/mosaicfilternode.cpp @@ -28,11 +28,11 @@ MosaicFilterNode::MosaicFilterNode() AddInput(tex_input_); horiz_input_ = new NodeInput(QStringLiteral("horiz_in"), NodeParam::kFloat); - horiz_input_->set_property(QStringLiteral("min"), 1.0f); + horiz_input_->set_property(QStringLiteral("min"), 1.0); AddInput(horiz_input_); vert_input_ = new NodeInput(QStringLiteral("vert_in"), NodeParam::kFloat); - vert_input_->set_property(QStringLiteral("min"), 1.0f); + vert_input_->set_property(QStringLiteral("min"), 1.0); AddInput(vert_input_); } @@ -51,7 +51,7 @@ NodeValueTable MosaicFilterNode::Value(NodeValueDatabase &value) const job.InsertValue(horiz_input_, value); job.InsertValue(vert_input_, value); - // Mipmapping makes this look weird + // Mipmapping makes this look weird, so we just use bilinear for finding the color of each block job.SetInterpolation(tex_input_, Texture::kLinear); NodeValueTable table = value.Merge(); @@ -75,7 +75,7 @@ ShaderCode MosaicFilterNode::GetShaderCode(const QString &shader_id) const { Q_UNUSED(shader_id) - return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/mosaic.frag"), QString()); + return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/mosaic.frag")); } } diff --git a/app/node/filter/stroke/stroke.cpp b/app/node/filter/stroke/stroke.cpp index 41448e04d..c2aca5c3d 100644 --- a/app/node/filter/stroke/stroke.cpp +++ b/app/node/filter/stroke/stroke.cpp @@ -91,6 +91,8 @@ NodeValueTable StrokeFilterNode::Value(NodeValueDatabase &value) const job.InsertValue(radius_input_, value); job.InsertValue(opacity_input_, value); job.InsertValue(inner_input_, value); + job.InsertValue(QStringLiteral("resolution_in"), + ShaderValue(value[QStringLiteral("global")].Get(NodeParam::kVec2, QStringLiteral("resolution")), NodeParam::kVec2)); NodeValueTable table = value.Merge(); @@ -110,7 +112,7 @@ ShaderCode StrokeFilterNode::GetShaderCode(const QString &shader_id) const { Q_UNUSED(shader_id) - return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/stroke.frag"), QString()); + return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/stroke.frag")); } } diff --git a/app/node/generator/solid/solid.cpp b/app/node/generator/solid/solid.cpp index 15e5b1d2c..c722b910a 100644 --- a/app/node/generator/solid/solid.cpp +++ b/app/node/generator/solid/solid.cpp @@ -77,7 +77,7 @@ ShaderCode SolidGenerator::GetShaderCode(const QString &shader_id) const { Q_UNUSED(shader_id) - return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/solid.frag"), QString()); + return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/solid.frag")); } } diff --git a/app/node/math/merge/merge.cpp b/app/node/math/merge/merge.cpp index b85096458..877b73a31 100644 --- a/app/node/math/merge/merge.cpp +++ b/app/node/math/merge/merge.cpp @@ -66,7 +66,7 @@ ShaderCode MergeNode::GetShaderCode(const QString &shader_id) const { Q_UNUSED(shader_id) - return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/alphaover.frag"), QString()); + return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/alphaover.frag")); } NodeValueTable MergeNode::Value(NodeValueDatabase &value) const diff --git a/app/render/shadercode.h b/app/render/shadercode.h index 12d805c43..1042c5c02 100644 --- a/app/render/shadercode.h +++ b/app/render/shadercode.h @@ -27,7 +27,7 @@ namespace olive { class ShaderCode { public: - ShaderCode(const QString& frag_code, const QString& vert_code) : + ShaderCode(const QString& frag_code = QString(), const QString& vert_code = QString()) : frag_code_(frag_code), vert_code_(vert_code) { diff --git a/app/shaders/blur.frag b/app/shaders/blur.frag index c59ba6da2..dcb0bf253 100644 --- a/app/shaders/blur.frag +++ b/app/shaders/blur.frag @@ -4,8 +4,8 @@ uniform float radius_in; uniform bool horiz_in; uniform bool vert_in; uniform bool repeat_edge_pixels_in; +uniform vec2 resolution_in; -uniform vec2 ove_resolution; uniform int ove_iteration; in vec2 ove_texcoord; @@ -107,9 +107,9 @@ void main(void) { vec2 pixel_coord = ove_texcoord; if (mode == MODE_HORIZONTAL) { - pixel_coord.x += i / ove_resolution.x; + pixel_coord.x += i / resolution_in.x; } else if (mode == MODE_VERTICAL) { - pixel_coord.y += i / ove_resolution.y; + pixel_coord.y += i / resolution_in.y; } if (repeat_edge_pixels_in diff --git a/app/shaders/colorgradient.frag b/app/shaders/colorgradient.frag deleted file mode 100644 index c1eba0b91..000000000 --- a/app/shaders/colorgradient.frag +++ /dev/null @@ -1,26 +0,0 @@ -// Inputs -uniform int orientation; -uniform vec3 color_a; -uniform vec3 color_b; - -// Standard inputs -uniform vec2 ove_resolution; - -in vec2 ove_texcoord; - -out vec4 fragColor; - -void main(void) { - float t; - - // This very roughly conforms to Qt::Orientation - if (orientation == 1) { - // Horizontal orientation - t = ove_texcoord.x; - } else { - // Vertical orientation - t = 1.0 - ove_texcoord.y; - } - - fragColor = vec4(mix(color_a, color_b, t), 1.0); -} diff --git a/app/shaders/colorwheel.frag b/app/shaders/colorwheel.frag deleted file mode 100644 index 2c7f41109..000000000 --- a/app/shaders/colorwheel.frag +++ /dev/null @@ -1,92 +0,0 @@ -// Custom inputs -uniform float hsv_value; - -// Standard inputs -uniform vec2 ove_resolution; - -in vec2 ove_texcoord; - -out vec4 fragColor; - -// Color wheel uses PI -#define M_PI 3.1415926535897932384626433832795 - -vec3 hsv_to_rgb(float H, float S, float V) { - float C = S * V; - float X = C * (1.0 - abs(mod(H / 60.0, 2.0) - 1.0)); - float m = V - C; - float Rs, Gs, Bs; - - if(H >= 0.0 && H < 60.0) { - Rs = C; - Gs = X; - Bs = 0.0; - } - else if(H >= 60.0 && H < 120.0) { - Rs = X; - Gs = C; - Bs = 0.0; - } - else if(H >= 120.0 && H < 180.0) { - Rs = 0.0; - Gs = C; - Bs = X; - } - else if(H >= 180.0 && H < 240.0) { - Rs = 0.0; - Gs = X; - Bs = C; - } - else if(H >= 240.0 && H < 300.0) { - Rs = X; - Gs = 0.0; - Bs = C; - } - else { - Rs = C; - Gs = 0.0; - Bs = X; - } - - return vec3(Rs + m, Gs + m, Bs + m); -} - -void main(void) { - vec2 center = vec2(0.5, 0.5); - float radius = 0.5; - - vec2 flipped_texcoord = vec2(ove_texcoord.x, (1.0 - ove_texcoord.y)); - - // Calculate scale - if (ove_resolution.x != ove_resolution.y) { - // Scale around center - flipped_texcoord -= vec2(0.5, 0.5); - - if (ove_resolution.x > ove_resolution.y) { - flipped_texcoord.x *= ove_resolution.x / ove_resolution.y; - } else { - flipped_texcoord.y *= ove_resolution.y / ove_resolution.x; - } - - flipped_texcoord += vec2(0.5, 0.5); - } - - float dist = distance(flipped_texcoord, center); - - if (dist <= radius) { - float opposite = flipped_texcoord.y - center.y; - float adjacent = flipped_texcoord.x - center.x; - - float hue = atan(opposite, adjacent) * 180.0 / M_PI + 180.0; - float sat = dist / radius; - - // Extremely simple antialiasing, we taper off the edges between (radius) and (radius - 1) - float pixel_radius = min(ove_resolution.x, ove_resolution.y) * 0.5; - float pixel_dist = (pixel_radius / radius) * dist; - float alpha = min((pixel_radius - pixel_dist), 1.0); - - fragColor = vec4(hsv_to_rgb(hue, sat, hsv_value), alpha); - } else { - fragColor = vec4(0.0); - } -} diff --git a/app/shaders/crop.frag b/app/shaders/crop.frag new file mode 100644 index 000000000..22248e0ef --- /dev/null +++ b/app/shaders/crop.frag @@ -0,0 +1,55 @@ +// Input variables +uniform sampler2D tex_in; +uniform float left_in; +uniform float top_in; +uniform float right_in; +uniform float bottom_in; +uniform float feather_in; +uniform vec2 resolution_in; + +// Input texture coordinate +in vec2 ove_texcoord; + +// Output color +out vec4 fragColor; + +void main() { + float multiplier = 1.0; + + vec2 feather_normalized = vec2(feather_in / resolution_in.x, feather_in / resolution_in.y); + vec2 feather_normalized_half = feather_normalized * 0.5; + + // Calculate left cropping + float left_adjustment; + float right_adjustment; + float top_adjustment; + float bottom_adjustment; + + if (feather_in == 0.0) { + if (ove_texcoord.x < left_in + || ove_texcoord.x > (1.0-right_in) + || ove_texcoord.y < (top_in) + || ove_texcoord.y > (1.0-bottom_in)) { + multiplier = 0.0; + } + } else { + float left_adjustment = clamp((ove_texcoord.x - (left_in - feather_normalized.x*(1.0-left_in))) / feather_normalized.x, 0.0, 1.0); + multiplier *= left_adjustment; + + float right_adjustment = 1.0-clamp((ove_texcoord.x - ((1.0-right_in) - feather_normalized.x*(right_in))) / feather_normalized.x, 0.0, 1.0); + multiplier *= right_adjustment; + + float top_adjustment = clamp((ove_texcoord.y - (top_in - feather_normalized.y*(1.0-top_in))) / feather_normalized.y, 0.0, 1.0); + multiplier *= top_adjustment; + + float bottom_adjustment = 1.0-clamp((ove_texcoord.y - ((1.0-bottom_in) - feather_normalized.y*(bottom_in))) / feather_normalized.y, 0.0, 1.0); + multiplier *= bottom_adjustment; + } + + if (multiplier > 0.0) { + vec4 color = texture(tex_in, ove_texcoord) * multiplier; + fragColor = color; + } else { + fragColor = vec4(0.0); + } +} diff --git a/app/shaders/deinterlace.frag b/app/shaders/deinterlace.frag index f6c0204e6..45104a145 100644 --- a/app/shaders/deinterlace.frag +++ b/app/shaders/deinterlace.frag @@ -1,5 +1,6 @@ uniform sampler2D ove_maintex; -uniform vec2 ove_resolution; + +uniform vec2 resolution_in; in vec2 ove_texcoord; @@ -11,9 +12,9 @@ void main() { // A very basic deinterlace that halves the vertical // resolution and linearly interpolates the two fields // by reading the texture coord between them. - float half_vert = round(ove_resolution.y / 2.0); + float half_vert = round(resolution_in.y / 2.0); using_texcoord.y = (round(using_texcoord.y * half_vert) + 0.25) / half_vert; - vec4 color = %1(texture(ove_maintex, using_texcoord)); + vec4 color = texture(ove_maintex, using_texcoord); fragColor = color; } diff --git a/app/shaders/polygon.frag b/app/shaders/polygon.frag index 9ffc32433..b5fa0fed1 100644 --- a/app/shaders/polygon.frag +++ b/app/shaders/polygon.frag @@ -2,7 +2,7 @@ uniform vec2[256] points_in; uniform int points_in_count; uniform vec4 color_in; -uniform vec2 ove_resolution; +uniform vec2 resolution_in; in vec2 ove_texcoord; @@ -34,7 +34,7 @@ bool pnpoly(vec2 p) { } void main(void) { - if (points_in_count > 0 && pnpoly(ove_texcoord * ove_resolution)) { + if (points_in_count > 0 && pnpoly(ove_texcoord * resolution_in)) { fragColor = color_in; } else { fragColor = vec4(0.0, 0.0, 0.0, 0.0); diff --git a/app/shaders/rgbwaveform.vert b/app/shaders/rgbwaveform.vert index 5f9cce1b9..33980f284 100644 --- a/app/shaders/rgbwaveform.vert +++ b/app/shaders/rgbwaveform.vert @@ -1,5 +1,4 @@ uniform float waveform_scale; -uniform vec2 ove_resolution; in vec4 a_position; in vec2 a_texcoord; @@ -24,4 +23,4 @@ void main() { gl_Position = transform * a_position; ove_texcoord = a_texcoord; -} \ No newline at end of file +} diff --git a/app/shaders/stroke.frag b/app/shaders/stroke.frag index 1ac8d3daf..147b1db55 100644 --- a/app/shaders/stroke.frag +++ b/app/shaders/stroke.frag @@ -4,9 +4,9 @@ uniform vec4 color_in; uniform float radius_in; uniform float opacity_in; uniform bool inner_in; +uniform vec2 resolution_in; // Standard inputs -uniform vec2 ove_resolution; uniform int ove_iteration; in vec2 ove_texcoord; @@ -32,10 +32,10 @@ void main(void) { // Loop over box for (float i=-radius + 0.5; i<=radius; i += 2.0) { - float x_coord = i / ove_resolution.x; + float x_coord = i / resolution_in.x; for (float j=-radius + 0.5; j<=radius; j += 2.0) { - float y_coord = j / ove_resolution.y; + float y_coord = j / resolution_in.y; if (abs(length(vec2(i, j))) < radius) { // Get pixel here