diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f5587a..2350aa1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -600,6 +600,7 @@ set(VMIX_RSC_FILES ./rsc/shaders/filters/resample_double.glsl ./rsc/shaders/filters/resample_half.glsl ./rsc/shaders/filters/resample_quarter.glsl + ./rsc/shaders/filters/earlybird.glsl ) # Include the CMake RC module diff --git a/ImageFilter.cpp b/ImageFilter.cpp index f8249e8..c70c7d2 100644 --- a/ImageFilter.cpp +++ b/ImageFilter.cpp @@ -65,8 +65,9 @@ std::string fragmentFooter = "void main() {\n" std::list< FilteringProgram > FilteringProgram::presets = { FilteringProgram(), - FilteringProgram("Bilateral","shaders/filters/bilinear.glsl", "", { }), + FilteringProgram("Bilateral","shaders/filters/focus.glsl", "", { }), FilteringProgram("Pixelate", "shaders/filters/pixelate.glsl", "", { }), + FilteringProgram("Earlybird","shaders/filters/earlybird.glsl", "", { }), FilteringProgram("Bloom", "shaders/filters/bloom.glsl", "", { }), FilteringProgram("Bokeh", "shaders/filters/bokeh.glsl", "", { }), FilteringProgram("Talk", "shaders/filters/talk.glsl", "", { }), @@ -714,7 +715,7 @@ const char* SmoothFilter::method_label[SmoothFilter::SMOOTH_INVALID] = { }; std::vector< FilteringProgram > SmoothFilter::programs_ = { - FilteringProgram("Bilateral","shaders/filters/focus.glsl", "", { { "Factor", 0.5} }), + FilteringProgram("Bilateral","shaders/filters/bilinear.glsl", "", { { "Factor", 0.5} }), FilteringProgram("Kuwahara", "shaders/filters/kuwahara.glsl", "", { { "Radius", 1.0} }), FilteringProgram("Opening", "shaders/filters/erosion.glsl", "shaders/filters/dilation.glsl", { { "Radius", 0.5} }), FilteringProgram("Closing", "shaders/filters/dilation.glsl", "shaders/filters/erosion.glsl", { { "Radius", 0.5} }), @@ -764,7 +765,7 @@ const char* EdgeFilter::method_label[EdgeFilter::EDGE_INVALID] = { std::vector< FilteringProgram > EdgeFilter::programs_ = { FilteringProgram("Sobel", "shaders/filters/sobel.glsl", "", { { "Factor", 0.5} }), FilteringProgram("Freichen", "shaders/filters/freichen.glsl", "", { { "Factor", 0.5} }), - FilteringProgram("Edge", "shaders/filters/bilinear.glsl", "shaders/filters/edge.glsl", { { "Threshold", 0.5} }), + FilteringProgram("Edge", "shaders/filters/focus.glsl", "shaders/filters/edge.glsl", { { "Threshold", 0.5} }), FilteringProgram("Contour", "shaders/filters/sharpen_1.glsl", "shaders/filters/contour_2.glsl", { { "Amount", 0.5} }), }; diff --git a/rsc/shaders/filters/bilinear.glsl b/rsc/shaders/filters/bilinear.glsl index 8f5d572..2405780 100644 --- a/rsc/shaders/filters/bilinear.glsl +++ b/rsc/shaders/filters/bilinear.glsl @@ -1,53 +1,42 @@ -#define SIGMA 10.0 -#define BSIGMA 0.1 +// Fast simple bilinear RGBA filter +// by Bruno Herbelin -float kernel[15]; +#define SIGMA 10.0 + +uniform float Factor; + +float kernel[15] = {0.031225216, 0.033322271, 0.035206333, 0.036826804, 0.038138565, +0.039104044, 0.039695028, 0.039894000, 0.039695028, 0.039104044, +0.038138565, 0.036826804, 0.035206333, 0.033322271, 0.031225216 }; float normpdf(in float x, in float sigma) { - return 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma; + return 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma; } -float normpdf3(in vec3 v, in float sigma) +float normpdf3(in vec4 v, in float sigma) { - return 0.39894*exp(-0.5*dot(v,v)/(sigma*sigma))/sigma; + return 0.39894*exp(-0.5*dot(v,v)/(sigma*sigma))/sigma; } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { - vec3 c = texture(iChannel0, (fragCoord.xy / iResolution.xy)).rgb; - - kernel[0] = 0.031225216; - kernel[1] = 0.033322271; - kernel[2] = 0.035206333; - kernel[3] = 0.036826804; - kernel[4] = 0.038138565; - kernel[5] = 0.039104044; - kernel[6] = 0.039695028; - kernel[7] = 0.039894000; - kernel[8] = 0.039695028; - kernel[9] = 0.039104044; - kernel[10] = 0.038138565; - kernel[11] = 0.036826804; - kernel[12] = 0.035206333; - kernel[13] = 0.033322271; - kernel[14] = 0.031225216; - - vec3 final_colour = vec3(0.0); + vec4 O = vec4(0.0); float Z = 0.0; - vec3 cc; - float f; - float bZ = 1.0/normpdf(0.0, mix(BSIGMA, 1.0, .0) ); - + vec4 cc; + float bsigma = mix(0.01, 0.5, Factor); + float bZ = 1.0/normpdf(0.0, mix(bsigma, 1.0, .0) ); + vec4 C = texture(iChannel0, (fragCoord.xy / iResolution.xy)); + for (int i = -7; i <= 7; ++i) { for (int j = -7; j <= 7; ++j) { - cc = texture(iChannel0, (fragCoord.xy+vec2(float(i),float(j))) / iResolution.xy).rgb; - f = normpdf3(cc-c, mix(BSIGMA, 1.0, .0) ) * bZ * kernel[7+j] * kernel[7+i]; + cc = texture(iChannel0, (fragCoord+vec2(float(i),float(j))) / iResolution.xy); + float f = normpdf3(cc -C, mix(bsigma, 1.0, .0) ) * bZ * kernel[7+j] * kernel[7+i]; Z += f; - final_colour += f*cc; + O += f*cc; } } - fragColor = vec4(final_colour/Z, 1.0); + fragColor = O/Z; } diff --git a/rsc/shaders/filters/blackhat.glsl b/rsc/shaders/filters/blackhat.glsl index 213c056..14c83f2 100644 --- a/rsc/shaders/filters/blackhat.glsl +++ b/rsc/shaders/filters/blackhat.glsl @@ -1,3 +1,9 @@ +/* + * This file is part of vimix - video live mixer + * https://github.com/brunoherbelin/vimix + * (C) 2019-2022 Bruno Herbelin + * Distributed under GNU GPL3+ License +**/ uniform float Radius; #define MAX_SIZE 5 diff --git a/rsc/shaders/filters/blur_1.glsl b/rsc/shaders/filters/blur_1.glsl index fd208de..0dc3626 100644 --- a/rsc/shaders/filters/blur_1.glsl +++ b/rsc/shaders/filters/blur_1.glsl @@ -1,5 +1,9 @@ -// Gaussian blur with mipmapping -// Bruno Herbelin +/* + * This file is part of vimix - video live mixer + * https://github.com/brunoherbelin/vimix + * (C) 2019-2022 Bruno Herbelin + * Distributed under GNU GPL3+ License +**/ // Following tutorial https://www.shadertoy.com/view/WtKfD3 #define N 13 diff --git a/rsc/shaders/filters/blur_2.glsl b/rsc/shaders/filters/blur_2.glsl index 917b00f..65eff71 100644 --- a/rsc/shaders/filters/blur_2.glsl +++ b/rsc/shaders/filters/blur_2.glsl @@ -1,3 +1,9 @@ +/* + * This file is part of vimix - video live mixer + * https://github.com/brunoherbelin/vimix + * (C) 2019-2022 Bruno Herbelin + * Distributed under GNU GPL3+ License +**/ // Following tutorial https://www.shadertoy.com/view/WtKfD3 #define N 13 diff --git a/rsc/shaders/filters/chromakey.glsl b/rsc/shaders/filters/chromakey.glsl index 4daf959..d7b248d 100644 --- a/rsc/shaders/filters/chromakey.glsl +++ b/rsc/shaders/filters/chromakey.glsl @@ -1,14 +1,11 @@ /* -chroma key algorithm used to remove the greens screen -this technique is nice as you can choose a color removal range. -using this range, the algorithm will either remove the given color -or blend it with background + * This file is part of vimix - video live mixer + * https://github.com/brunoherbelin/vimix + * (C) 2019-2022 Bruno Herbelin + * Distributed under GNU GPL3+ License +**/ +// Inspired by https://www.shadertoy.com/view/MlVXWD by tudordot -because of this, difficult parts (ie. the sword) can either have a -green-ish look or are a bit transparent (hard to catch with a lot of movement) - -(c) tudordot from https://www.shadertoy.com/view/MlVXWD -*/ uniform float Red; uniform float Green; diff --git a/rsc/shaders/filters/circularblur.glsl b/rsc/shaders/filters/circularblur.glsl index 2e3400a..c18cf7f 100644 --- a/rsc/shaders/filters/circularblur.glsl +++ b/rsc/shaders/filters/circularblur.glsl @@ -1,3 +1,10 @@ +/* + * This file is part of vimix - video live mixer + * https://github.com/brunoherbelin/vimix + * (C) 2019-2022 Bruno Herbelin + * Distributed under GNU GPL3+ License +**/ + #define TWOPI 6.28318530718 uniform float Radius; diff --git a/rsc/shaders/filters/coloralpha.glsl b/rsc/shaders/filters/coloralpha.glsl index d87d39d..91a4e52 100644 --- a/rsc/shaders/filters/coloralpha.glsl +++ b/rsc/shaders/filters/coloralpha.glsl @@ -1,3 +1,9 @@ +/* + * This file is part of vimix - video live mixer + * https://github.com/brunoherbelin/vimix + * (C) 2019-2022 Bruno Herbelin + * Distributed under GNU GPL3+ License +**/ uniform float Red; uniform float Green; uniform float Blue; diff --git a/rsc/shaders/filters/contour_2.glsl b/rsc/shaders/filters/contour_2.glsl index 44a91e4..7130655 100644 --- a/rsc/shaders/filters/contour_2.glsl +++ b/rsc/shaders/filters/contour_2.glsl @@ -1,3 +1,9 @@ +/* + * This file is part of vimix - video live mixer + * https://github.com/brunoherbelin/vimix + * (C) 2019-2022 Bruno Herbelin + * Distributed under GNU GPL3+ License +**/ uniform float Amount; #define N 7 diff --git a/rsc/shaders/filters/dilation.glsl b/rsc/shaders/filters/dilation.glsl index 537dd22..e8eb371 100644 --- a/rsc/shaders/filters/dilation.glsl +++ b/rsc/shaders/filters/dilation.glsl @@ -1,3 +1,9 @@ +/* + * This file is part of vimix - video live mixer + * https://github.com/brunoherbelin/vimix + * (C) 2019-2022 Bruno Herbelin + * Distributed under GNU GPL3+ License +**/ uniform float Radius; #define MAX_SIZE 5 diff --git a/rsc/shaders/filters/dithering.glsl b/rsc/shaders/filters/dithering.glsl index b4f8734..5b32bb5 100644 --- a/rsc/shaders/filters/dithering.glsl +++ b/rsc/shaders/filters/dithering.glsl @@ -1,3 +1,6 @@ +// Ordered Dithering Shader https://www.shadertoy.com/view/4lSSRR +// by mooglemoogle +// Adapted by Bruno Herbelin for vimix float Factor = 0.5; const float mult = 1.0 / 17.0; diff --git a/rsc/shaders/filters/earlybird.glsl b/rsc/shaders/filters/earlybird.glsl new file mode 100644 index 0000000..6ff4735 --- /dev/null +++ b/rsc/shaders/filters/earlybird.glsl @@ -0,0 +1,85 @@ +/** + * Earlybird Filter by Ruofei Du (DuRuofei.com) + * Demo: https://www.shadertoy.com/view/4lSyDK + * starea @ ShaderToy,License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. + * https://creativecommons.org/licenses/by-nc-sa/3.0/ + * + * Reference: + * [1] colorBurn function forked from ben's https://www.shadertoy.com/view/XdS3RW + * [2] starea's Dotted Drawing / Sketch Effect: https://www.shadertoy.com/view/ldSyzV + * [3] starea's BrightnessContrastSaturationHue: https://www.shadertoy.com/view/MdjBRy + * + * Series: + * [1] Brannan Filter: https://www.shadertoy.com/view/4lSyDK + * [2] Earlybird Filter: https://www.shadertoy.com/view/XlSyWV + * [3] Starea Filter: https://www.shadertoy.com/view/MtjyDK + * + * + * Write-ups: + * [1] http://blog.ruofeidu.com/implementing-instagram-filters-brannan/ + **/ +float greyScale(in vec3 col) +{ + return dot(col, vec3(0.3, 0.59, 0.11)); +} + +mat3 saturationMatrix( float saturation ) { + vec3 luminance = vec3( 0.3086, 0.6094, 0.0820 ); + float oneMinusSat = 1.0 - saturation; + vec3 red = vec3( luminance.x * oneMinusSat ); + red.r += saturation; + + vec3 green = vec3( luminance.y * oneMinusSat ); + green.g += saturation; + + vec3 blue = vec3( luminance.z * oneMinusSat ); + blue.b += saturation; + + return mat3(red, green, blue); +} + +void levels(inout vec3 col, in vec3 inleft, in vec3 inright, in vec3 outleft, in vec3 outright) { + col = clamp(col, inleft, inright); + col = (col - inleft) / (inright - inleft); + col = outleft + col * (outright - outleft); +} + +void brightnessAdjust( inout vec3 color, in float b) { + color += b; +} + +void contrastAdjust( inout vec3 color, in float c) { + float t = 0.5 - c * 0.5; + color = color * c + t; +} + + +vec3 colorBurn(in vec3 s, in vec3 d ) +{ + return 1.0 - (1.0 - d) / s; +} + +void mainImage( out vec4 fragColor, in vec2 fragCoord ) +{ + vec2 uv = fragCoord.xy / iResolution.xy; + vec3 col = texture(iChannel0, uv).rgb; + vec2 coord = ( fragCoord.xy + fragCoord.xy - iResolution.xy ) / iResolution.y; + vec3 gradient = vec3(pow(1.0 - length(coord * 0.4), 0.6) * 1.2); + vec3 grey = vec3(184./255.); + vec3 tint = vec3(252., 243., 213.) / 255.; + col = saturationMatrix(0.68) * col; + levels(col, vec3(0.), vec3(1.0), + vec3(27.,0.,0.) / 255., vec3(255.) / 255.); + col = pow(col, vec3(1.19)); + brightnessAdjust(col, 0.13); + contrastAdjust(col, 1.05); + col = saturationMatrix(0.85) * col; + levels(col, vec3(0.), vec3(235./255.), + vec3(0.,0.,0.) / 255., vec3(255.) / 255.); + + col = mix(tint * col, col, gradient); + col = colorBurn(grey, col); + //col *= 0.8; + fragColor = vec4(col, 1.0); +} + diff --git a/rsc/shaders/filters/edge.glsl b/rsc/shaders/filters/edge.glsl index 44efb7c..6a3503a 100644 --- a/rsc/shaders/filters/edge.glsl +++ b/rsc/shaders/filters/edge.glsl @@ -1,3 +1,9 @@ +/* + * This file is part of vimix - video live mixer + * https://github.com/brunoherbelin/vimix + * (C) 2019-2022 Bruno Herbelin + * Distributed under GNU GPL3+ License +**/ uniform float Threshold; diff --git a/rsc/shaders/filters/erosion.glsl b/rsc/shaders/filters/erosion.glsl index fe42629..b1c11c7 100644 --- a/rsc/shaders/filters/erosion.glsl +++ b/rsc/shaders/filters/erosion.glsl @@ -1,3 +1,9 @@ +/* + * This file is part of vimix - video live mixer + * https://github.com/brunoherbelin/vimix + * (C) 2019-2022 Bruno Herbelin + * Distributed under GNU GPL3+ License +**/ uniform float Radius; #define MAX_SIZE 5 diff --git a/rsc/shaders/filters/focus.glsl b/rsc/shaders/filters/focus.glsl index 5368037..13c82a1 100644 --- a/rsc/shaders/filters/focus.glsl +++ b/rsc/shaders/filters/focus.glsl @@ -1,11 +1,10 @@ -// Bilateral filter -// (c) mrharicot https://www.shadertoy.com/view/4dfGDH +// Bilateral filter +// inspired from mrharicot https://www.shadertoy.com/view/4dfGDH #define SIGMA 10.0 +#define BSIGMA 0.1 #define MSIZE 13 -uniform float Factor; - float normpdf(in float x, in float sigma) { return 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma; @@ -18,34 +17,29 @@ float normpdf3(in vec4 v, in float sigma) void mainImage( out vec4 fragColor, in vec2 fragCoord ) { - vec4 c = texture(iChannel0, (fragCoord.xy / iResolution.xy) ); - const int kSize = (MSIZE-1)/2; float kernel[MSIZE]; - vec4 final_colour = vec4(0.0); + vec4 O = vec4(0.0); //create the 1-D kernel float Z = 0.0; for (int j = 0; j <= kSize; ++j) - { kernel[kSize+j] = kernel[kSize-j] = normpdf(float(j), SIGMA); - } vec4 cc; - float fac; - float bsigma = mix(0.01, 1.2, Factor); - float bZ = 1.0/normpdf(0.0, bsigma); + vec4 c = texture(iChannel0, (fragCoord.xy / iResolution.xy) ); + float bZ = 1.0/normpdf(0.0, BSIGMA); for (int i=-kSize; i <= kSize; ++i) { for (int j=-kSize; j <= kSize; ++j) { - cc = texture(iChannel0, (fragCoord.xy+vec2(float(i),float(j))) / iResolution.xy); - fac = normpdf3(cc-c, bsigma)*bZ*kernel[kSize+j]*kernel[kSize+i]; + cc = texture(iChannel0, (fragCoord+vec2(float(i),float(j))) / iResolution.xy); + float fac = normpdf3(cc-c, BSIGMA)*bZ*kernel[kSize+j]*kernel[kSize+i]; Z += fac; - final_colour += fac*cc; + O += fac*cc; } } - fragColor = final_colour/Z; + fragColor = O/Z; } diff --git a/rsc/shaders/filters/freichen.glsl b/rsc/shaders/filters/freichen.glsl index 9017f88..5ab297a 100644 --- a/rsc/shaders/filters/freichen.glsl +++ b/rsc/shaders/filters/freichen.glsl @@ -1,3 +1,9 @@ +/* + * This file is part of vimix - video live mixer + * https://github.com/brunoherbelin/vimix + * (C) 2019-2022 Bruno Herbelin + * Distributed under GNU GPL3+ License +**/ uniform float Factor; const mat3 G[9] = mat3[]( diff --git a/rsc/shaders/filters/hasheddilation.glsl b/rsc/shaders/filters/hasheddilation.glsl index a432813..d594bc8 100644 --- a/rsc/shaders/filters/hasheddilation.glsl +++ b/rsc/shaders/filters/hasheddilation.glsl @@ -1,11 +1,13 @@ +/* + * This file is part of vimix - video live mixer + * https://github.com/brunoherbelin/vimix + * (C) 2019-2022 Bruno Herbelin + * Distributed under GNU GPL3+ License +**/ #define TWOPI 6.28318530718 uniform float Radius; -// float hash(vec2 co){ -// return fract(sin(dot(co.xy, vec2(12.9898,78.233))) * 43758.5453); -// } - #define SEED uvec4(0x5C995C6Du, 0x6A3C6A57u, 0xC65536CBu, 0x3563995Fu) const uint lcgM = 2891336453u;// ideal for 32 bits with odd c uint asuint2(float x) { return x == 0.0 ? 0u : floatBitsToUint(x); } diff --git a/rsc/shaders/filters/hashederosion.glsl b/rsc/shaders/filters/hashederosion.glsl index f558e62..26884ee 100644 --- a/rsc/shaders/filters/hashederosion.glsl +++ b/rsc/shaders/filters/hashederosion.glsl @@ -1,3 +1,9 @@ +/* + * This file is part of vimix - video live mixer + * https://github.com/brunoherbelin/vimix + * (C) 2019-2022 Bruno Herbelin + * Distributed under GNU GPL3+ License +**/ #define TWOPI 6.28318530718 uniform float Radius; diff --git a/rsc/shaders/filters/kuwahara.glsl b/rsc/shaders/filters/kuwahara.glsl index 6427dec..0da0cc7 100644 --- a/rsc/shaders/filters/kuwahara.glsl +++ b/rsc/shaders/filters/kuwahara.glsl @@ -5,6 +5,7 @@ // This shader is modified to be compatible with LOVE2D's quirky shader engine! // Modified by Christian D. Madsen // https://github.com/strangewarp/LoveAnisotropicKuwahara +// Adapted by Bruno Herbelin for vimix uniform float Radius; diff --git a/rsc/shaders/filters/lumakey.glsl b/rsc/shaders/filters/lumakey.glsl index edca9d0..ba5e42d 100644 --- a/rsc/shaders/filters/lumakey.glsl +++ b/rsc/shaders/filters/lumakey.glsl @@ -1,3 +1,9 @@ +/* + * This file is part of vimix - video live mixer + * https://github.com/brunoherbelin/vimix + * (C) 2019-2022 Bruno Herbelin + * Distributed under GNU GPL3+ License +**/ uniform float Threshold; uniform float Tolerance; diff --git a/rsc/shaders/filters/pixelate.glsl b/rsc/shaders/filters/pixelate.glsl index 44da75e..c3f9998 100644 --- a/rsc/shaders/filters/pixelate.glsl +++ b/rsc/shaders/filters/pixelate.glsl @@ -1,20 +1,23 @@ +// simple RGBA pixelation with averaging +// by Bruno Herbelin + float Size = 0.5; -float Sharpen = 0.5; +float Sharpen = 0.9; const mat3 G = mat3( 0.0625, 0.125, 0.0625, 0.125, 0.25, 0.125, 0.0625, 0.125, 0.0625); - + void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 size = vec2(3.0 * iResolution.x / iResolution.y, 3.0 ); size = mix( size, iResolution.xy, pow(1.0 - Size, 3.0) ) ; vec2 vUv = size / iResolution.xy; - vec3 blur = vec3(0,0,0); + vec4 blur = vec4(0); for (int i=0; i<3; i++) for (int j=0; j<3; j++) { - blur += G[i][j] * texture(iChannel0, round( (vUv * fragCoord) + vec2(i-1,j-1) ) / size ).rgb; + blur += G[i][j] * texture(iChannel0, round( (vUv * fragCoord) + vec2(i-1,j-1) ) / size ); } - fragColor = vec4( mix( blur, texture(iChannel0, round(vUv * fragCoord) / size ).rgb, Sharpen), 1.0); + fragColor = mix( blur, texture(iChannel0, round(vUv * fragCoord) / size ), Sharpen); } diff --git a/rsc/shaders/filters/resample_double.glsl b/rsc/shaders/filters/resample_double.glsl index 7cdbd43..106d97c 100644 --- a/rsc/shaders/filters/resample_double.glsl +++ b/rsc/shaders/filters/resample_double.glsl @@ -1,3 +1,9 @@ +/* + * This file is part of vimix - video live mixer + * https://github.com/brunoherbelin/vimix + * (C) 2019-2022 Bruno Herbelin + * Distributed under GNU GPL3+ License +**/ //======================================================================================= vec4 CubicHermite (vec4 A, vec4 B, vec4 C, vec4 D, float t) { diff --git a/rsc/shaders/filters/resample_half.glsl b/rsc/shaders/filters/resample_half.glsl index 76a6b27..f7d58e2 100644 --- a/rsc/shaders/filters/resample_half.glsl +++ b/rsc/shaders/filters/resample_half.glsl @@ -1,3 +1,9 @@ +/* + * This file is part of vimix - video live mixer + * https://github.com/brunoherbelin/vimix + * (C) 2019-2022 Bruno Herbelin + * Distributed under GNU GPL3+ License +**/ // inspired by https://www.shadertoy.com/view/fsjBWm (License: MIT) void mainImage( out vec4 fragColor, in vec2 fragCoord ) diff --git a/rsc/shaders/filters/sharp.glsl b/rsc/shaders/filters/sharp.glsl index bd9bb64..e334228 100644 --- a/rsc/shaders/filters/sharp.glsl +++ b/rsc/shaders/filters/sharp.glsl @@ -1,4 +1,10 @@ -uniform float Amount; +/* + * This file is part of vimix - video live mixer + * https://github.com/brunoherbelin/vimix + * (C) 2019-2022 Bruno Herbelin + * Distributed under GNU GPL3+ License +**/ +uniform float Amount; vec4 sharp(sampler2D sampler, vec2 fc, vec2 re) { diff --git a/rsc/shaders/filters/sharpen.glsl b/rsc/shaders/filters/sharpen.glsl index 0d56d6d..092bdb4 100644 --- a/rsc/shaders/filters/sharpen.glsl +++ b/rsc/shaders/filters/sharpen.glsl @@ -1,3 +1,9 @@ +/* + * This file is part of vimix - video live mixer + * https://github.com/brunoherbelin/vimix + * (C) 2019-2022 Bruno Herbelin + * Distributed under GNU GPL3+ License +**/ uniform float Amount; vec4 texSample(const int x, const int y, in vec2 fragCoord) diff --git a/rsc/shaders/filters/sharpen_1.glsl b/rsc/shaders/filters/sharpen_1.glsl index c4ef3ac..677250a 100644 --- a/rsc/shaders/filters/sharpen_1.glsl +++ b/rsc/shaders/filters/sharpen_1.glsl @@ -1,3 +1,9 @@ +/* + * This file is part of vimix - video live mixer + * https://github.com/brunoherbelin/vimix + * (C) 2019-2022 Bruno Herbelin + * Distributed under GNU GPL3+ License +**/ uniform float Amount; #define N 7 diff --git a/rsc/shaders/filters/sharpen_2.glsl b/rsc/shaders/filters/sharpen_2.glsl index 9b8990b..9544dba 100644 --- a/rsc/shaders/filters/sharpen_2.glsl +++ b/rsc/shaders/filters/sharpen_2.glsl @@ -1,3 +1,9 @@ +/* + * This file is part of vimix - video live mixer + * https://github.com/brunoherbelin/vimix + * (C) 2019-2022 Bruno Herbelin + * Distributed under GNU GPL3+ License +**/ uniform float Amount; #define N 7 diff --git a/rsc/shaders/filters/sharpenedge.glsl b/rsc/shaders/filters/sharpenedge.glsl index c3efff7..f2dd790 100644 --- a/rsc/shaders/filters/sharpenedge.glsl +++ b/rsc/shaders/filters/sharpenedge.glsl @@ -1,3 +1,9 @@ +/* + * This file is part of vimix - video live mixer + * https://github.com/brunoherbelin/vimix + * (C) 2019-2022 Bruno Herbelin + * Distributed under GNU GPL3+ License +**/ uniform float Amount; vec3 blurSample(in vec2 uv, in vec2 xoff, in vec2 yoff) diff --git a/rsc/shaders/filters/sigmoid_1.glsl b/rsc/shaders/filters/sigmoid_1.glsl index 0fbd96a..d18e834 100644 --- a/rsc/shaders/filters/sigmoid_1.glsl +++ b/rsc/shaders/filters/sigmoid_1.glsl @@ -1,3 +1,9 @@ +/* + * This file is part of vimix - video live mixer + * https://github.com/brunoherbelin/vimix + * (C) 2019-2022 Bruno Herbelin + * Distributed under GNU GPL3+ License +**/ #define RADIUS 0.2 uniform float Amount; diff --git a/rsc/shaders/filters/sigmoid_2.glsl b/rsc/shaders/filters/sigmoid_2.glsl index dcb228a..85c7c53 100644 --- a/rsc/shaders/filters/sigmoid_2.glsl +++ b/rsc/shaders/filters/sigmoid_2.glsl @@ -1,3 +1,9 @@ +/* + * This file is part of vimix - video live mixer + * https://github.com/brunoherbelin/vimix + * (C) 2019-2022 Bruno Herbelin + * Distributed under GNU GPL3+ License +**/ #define RADIUS 0.2 uniform float Amount; diff --git a/rsc/shaders/filters/sketch.glsl b/rsc/shaders/filters/sketch.glsl index 61901ab..2b34415 100644 --- a/rsc/shaders/filters/sketch.glsl +++ b/rsc/shaders/filters/sketch.glsl @@ -1,4 +1,3 @@ - /** * Sketchy Stippling / Dot-Drawing Effect by Ruofei Du (DuRuofei.com) * Link to demo: https://www.shadertoy.com/view/ldSyzV diff --git a/rsc/shaders/filters/sobel.glsl b/rsc/shaders/filters/sobel.glsl index 0bec9c6..30e7c45 100644 --- a/rsc/shaders/filters/sobel.glsl +++ b/rsc/shaders/filters/sobel.glsl @@ -1,3 +1,9 @@ +/* + * This file is part of vimix - video live mixer + * https://github.com/brunoherbelin/vimix + * (C) 2019-2022 Bruno Herbelin + * Distributed under GNU GPL3+ License +**/ uniform float Factor; const mat3 G[2] = mat3[]( diff --git a/rsc/shaders/filters/stippling.glsl b/rsc/shaders/filters/stippling.glsl index fd242a6..e517887 100644 --- a/rsc/shaders/filters/stippling.glsl +++ b/rsc/shaders/filters/stippling.glsl @@ -1,53 +1,53 @@ -float Factor = 0.3; +// Blue Noise Stippling 2 https://www.shadertoy.com/view/ldyXDd by FabriceNeyret2 +// simplified version of joeedh's https://www.shadertoy.com/view/Md3GWf +// see also https://www.shadertoy.com/view/MdtGD7 +// --- checkerboard noise : to decorelate the pattern between size x size tiles +// Adapted by Bruno Herbelin for vimix -#define SEED1 -0.5775604999999985 -#define SEED2 6.440483302499992 +// simple x-y decorrelated noise seems enough +#define stepnoise0(p, size) rnd( floor(p/size)*size ) +#define rnd(U) fract(sin( 1e3*(U)*mat2(1,-7.131, 12.9898, 1.233) )* 43758.5453) +// joeedh's original noise (cleaned-up) vec2 stepnoise(vec2 p, float size) { - p += 10.0; - float x = floor(p.x/size)*size; - float y = floor(p.y/size)*size; - - x = fract(x*0.1) + 1.0 + x*0.0002; - y = fract(y*0.1) + 1.0 + y*0.0003; - - float a = fract(1.0 / (0.000001*x*y + 0.00001)); - a = fract(1.0 / (0.000001234*a + 0.00001)); - - float b = fract(1.0 / (0.000002*(x*y+x) + 0.00001)); - b = fract(1.0 / (0.0000235*b + 0.00001)); - - return vec2(a, b); -} - -float tent(float f) { - return 1.0 - abs(fract(f)-0.5)*2.0; + p = floor((p+10.)/size)*size; // is p+10. useful ? + p = fract(p*.1) + 1. + p*vec2(2,3)/1e4; + p = fract( 1e5 / (.1*p.x*(p.y+vec2(0,1)) + 1.) ); + p = fract( 1e5 / (p*vec2(.1234,2.35) + 1.) ); + return p; } +// --- stippling mask : regular stippling + per-tile random offset + tone-mapping float mask(vec2 p) { - vec2 r = stepnoise(p, 8.423424); - p[0] += r[0]; - p[1] += r[1]; +#define SEED1 1.705 +#define DMUL 8.12235325 // are exact DMUL and -.5 important ? + p += ( stepnoise0(p, 5.5) - .5 ) *DMUL; // bias [-2,2] per tile otherwise too regular + float f = fract( p.x*SEED1 + p.y/(SEED1+.15555) ); // weights: 1.705 , 0.5375 + //return f; // If you want to skeep the tone mapping + f *= 1.03; // to avoid zero-stipple in plain white ? + // --- indeed, is a tone mapping ( equivalent to do the reciprocal on the image, see tests ) + // returned value in [0,37.2] , but < 0.57 with P=50% + return (pow(f, 150.) + 1.3*f ) / 2.3; // <.98 : ~ f/2, P=50% >.98 : ~f^150, P=50% +} // max = 37.2, int = 0.55 - float f1 = tent(p[0]*SEED1 + p[1]/(SEED1+0.5)); - float f2 = tent(p[1]*SEED2 + p[0]/(SEED2+0.5)); - float f = sqrt( f1*f2 ); +// --- for ramp at screen bottom +#define tent(f) ( 1. - abs(2.*fract(f)-1.) ) +// --- fetch luminance( texture (pixel + offset) ) +#define s(x,y) dot( texture(iChannel0, (U+vec2(x,y))/R ), vec4(.3,.6,.1,0) ) // luminance - return f; -} - -float saturation(vec3 color) { - return (min(color.r, min(color.g, color.b)) + max(color.r, max(color.g, color.b))) * 0.5; -} - -void mainImage( out vec4 fragColor, in vec2 fragCoord ) +void mainImage( out vec4 O, vec2 U ) { - vec2 uv = fragCoord.xy; - vec2 uv2 = fragCoord.xy / iResolution.x; + vec2 R = iResolution.xy; O-=O; + // --- fetch video luminance and enhance the contrast + float f = s(-1,-1) + s(-1,0) + s(-1,1) + + s( 0,-1) + + s( 0,1) + + s( 1,-1) + s( 1,0) + s( 1,1), + f0 = s(0,0); + f = ( .125*f + 8.*f0 ) / 6.; - float f = saturation( texture(iChannel0, fragCoord.xy / iResolution.xy).rgb ); - float c = mask(uv); - c = float( f > mix( 0.6 * c, 1.4 * c, Factor) ); + f = f0 - ( f-f0 ) * 0.5; - fragColor = vec4(c, c, c, texture(iChannel0, fragCoord.xy / iResolution.xy).a ); + // --- stippling + O += step(mask(U), f); } + diff --git a/rsc/shaders/filters/tophat.glsl b/rsc/shaders/filters/tophat.glsl index 0891801..ef8365d 100644 --- a/rsc/shaders/filters/tophat.glsl +++ b/rsc/shaders/filters/tophat.glsl @@ -1,3 +1,9 @@ +/* + * This file is part of vimix - video live mixer + * https://github.com/brunoherbelin/vimix + * (C) 2019-2022 Bruno Herbelin + * Distributed under GNU GPL3+ License +**/ uniform float Radius; #define MAX_SIZE 5