diff --git a/ImGuiVisitor.cpp b/ImGuiVisitor.cpp index 6bfa73a..951e424 100644 --- a/ImGuiVisitor.cpp +++ b/ImGuiVisitor.cpp @@ -360,38 +360,6 @@ void ImGuiVisitor::visit(ImageProcessingShader &n) Action::manager().store(oss.str()); } - if (ImGuiToolkit::IconButton(3, 1)) { - n.lumakey = 0.f; - Action::manager().store("Lumakey 0.0"); - } - ImGui::SameLine(0, IMGUI_SAME_LINE); - ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN); - ImGui::SliderFloat("Lumakey", &n.lumakey, 0.0, 1.0); - if (ImGui::IsItemDeactivatedAfterEdit()){ - std::ostringstream oss; - oss << "Lumakey " << std::setprecision(2) << n.lumakey; - Action::manager().store(oss.str()); - } - - if (ImGuiToolkit::IconButton(13, 4)) { - n.chromakey = glm::vec4(0.f, 0.8f, 0.f, 1.f); - n.chromadelta = 0.f; - Action::manager().store("Chromakey & Color Reset"); - } - ImGui::SameLine(0, IMGUI_SAME_LINE); - ImGui::ColorEdit3("Chroma color", glm::value_ptr(n.chromakey), ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel ) ; - if (ImGui::IsItemDeactivatedAfterEdit()) - Action::manager().store("Chroma color changed"); - ImGui::SameLine(0, 5); - ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN); - ImGui::SliderFloat("Chromakey", &n.chromadelta, 0.0, 1.0, n.chromadelta < 0.001 ? "None" : "Tolerance %.2f"); - if (ImGui::IsItemDeactivatedAfterEdit()){ - std::ostringstream oss; - oss << "Chromakey "; - if (n.chromadelta < 0.001) oss << "None"; else oss << std::setprecision(2) << n.chromadelta; - Action::manager().store(oss.str()); - } - if (ImGuiToolkit::IconButton(6, 16)) { n.invert = 0; Action::manager().store("Invert None"); diff --git a/ImageProcessingShader.cpp b/ImageProcessingShader.cpp index 2933e72..492477f 100644 --- a/ImageProcessingShader.cpp +++ b/ImageProcessingShader.cpp @@ -42,14 +42,11 @@ void ImageProcessingShader::use() program_->setUniform("hueshift", hueshift); program_->setUniform("threshold", threshold); - program_->setUniform("lumakey", lumakey); program_->setUniform("nbColors", nbColors); program_->setUniform("invert", invert); program_->setUniform("gamma", gamma); program_->setUniform("levels", levels); - program_->setUniform("chromakey", chromakey); - program_->setUniform("chromadelta", chromadelta); } @@ -63,13 +60,10 @@ void ImageProcessingShader::reset() saturation = 0.f; hueshift = 0.f; threshold = 0.f; - lumakey = 0.f; nbColors = 0; invert = 0; gamma = glm::vec4(1.f, 1.f, 1.f, 1.f); levels = glm::vec4(0.f, 1.f, 0.f, 1.f); - chromakey = glm::vec4(0.f, 0.8f, 0.f, 0.f); - chromadelta = 0.f; } @@ -80,13 +74,10 @@ void ImageProcessingShader::copy(ImageProcessingShader const& S) saturation = S.saturation; hueshift = S.hueshift; threshold = S.threshold; - lumakey = S.lumakey; nbColors = S.nbColors; invert = S.invert; gamma = S.gamma; levels = S.levels; - chromakey = S.chromakey; - chromadelta = S.chromadelta; } diff --git a/ImageProcessingShader.h b/ImageProcessingShader.h index 71c128c..2c63bf4 100644 --- a/ImageProcessingShader.h +++ b/ImageProcessingShader.h @@ -21,16 +21,12 @@ public: float saturation; // [-1 1] float hueshift; // [0 1] float threshold; // [0 1] - float lumakey; // [0 1] // gamma glm::vec4 gamma; glm::vec4 levels; // discrete operations int nbColors; int invert; - // chroma key - glm::vec4 chromakey; - float chromadelta; }; diff --git a/Interpolator.cpp b/Interpolator.cpp index 63b7a94..7551478 100644 --- a/Interpolator.cpp +++ b/Interpolator.cpp @@ -79,10 +79,6 @@ void SourceInterpolator::interpolateImageProcessing() (1.f - current_cursor_) * from_.processingShader()->threshold + current_cursor_ * to_.processingShader()->threshold; - current_state_.processingShader()->lumakey = - (1.f - current_cursor_) * from_.processingShader()->lumakey - + current_cursor_ * to_.processingShader()->lumakey; - current_state_.processingShader()->nbColors = (1.f - current_cursor_) * from_.processingShader()->nbColors + current_cursor_ * to_.processingShader()->nbColors; @@ -95,14 +91,6 @@ void SourceInterpolator::interpolateImageProcessing() (1.f - current_cursor_) * from_.processingShader()->levels + current_cursor_ * to_.processingShader()->levels; - current_state_.processingShader()->chromakey = - (1.f - current_cursor_) * from_.processingShader()->chromakey - + current_cursor_ * to_.processingShader()->chromakey; - - current_state_.processingShader()->chromadelta = - (1.f - current_cursor_) * from_.processingShader()->chromadelta - + current_cursor_ * to_.processingShader()->chromadelta; - subject_->processingShader()->copy( *current_state_.processingShader() ); // not interpolated : invert , filterid diff --git a/SessionCreator.cpp b/SessionCreator.cpp index 718bb49..600543d 100644 --- a/SessionCreator.cpp +++ b/SessionCreator.cpp @@ -916,10 +916,8 @@ void SessionLoader::visit(ImageProcessingShader &n) uniforms->QueryFloatAttribute("saturation", &n.saturation); uniforms->QueryFloatAttribute("hueshift", &n.hueshift); uniforms->QueryFloatAttribute("threshold", &n.threshold); - uniforms->QueryFloatAttribute("lumakey", &n.lumakey); uniforms->QueryIntAttribute("nbColors", &n.nbColors); uniforms->QueryIntAttribute("invert", &n.invert); - uniforms->QueryFloatAttribute("chromadelta", &n.chromadelta); } XMLElement* gamma = xmlCurrent_->FirstChildElement("gamma"); @@ -928,9 +926,6 @@ void SessionLoader::visit(ImageProcessingShader &n) XMLElement* levels = xmlCurrent_->FirstChildElement("levels"); if (levels) tinyxml2::XMLElementToGLM( levels->FirstChildElement("vec4"), n.levels); - XMLElement* chromakey = xmlCurrent_->FirstChildElement("chromakey"); - if (chromakey) - tinyxml2::XMLElementToGLM( chromakey->FirstChildElement("vec4"), n.chromakey); } void SessionLoader::visit (Source& s) diff --git a/SessionVisitor.cpp b/SessionVisitor.cpp index 7de8a73..ebecfe3 100644 --- a/SessionVisitor.cpp +++ b/SessionVisitor.cpp @@ -494,10 +494,8 @@ void SessionVisitor::visit(ImageProcessingShader &n) filter->SetAttribute("saturation", n.saturation); filter->SetAttribute("hueshift", n.hueshift); filter->SetAttribute("threshold", n.threshold); - filter->SetAttribute("lumakey", n.lumakey); filter->SetAttribute("nbColors", n.nbColors); filter->SetAttribute("invert", n.invert); - filter->SetAttribute("chromadelta", n.chromadelta); xmlCurrent_->InsertEndChild(filter); XMLElement *gamma = xmlDoc_->NewElement("gamma"); @@ -507,10 +505,6 @@ void SessionVisitor::visit(ImageProcessingShader &n) XMLElement *levels = xmlDoc_->NewElement("levels"); levels->InsertEndChild( XMLElementFromGLM(xmlDoc_, n.levels) ); xmlCurrent_->InsertEndChild(levels); - - XMLElement *chromakey = xmlDoc_->NewElement("chromakey"); - chromakey->InsertEndChild( XMLElementFromGLM(xmlDoc_, n.chromakey) ); - xmlCurrent_->InsertEndChild(chromakey); } void SessionVisitor::visit(LineStrip &n) diff --git a/rsc/shaders/filters/chromakey.glsl b/rsc/shaders/filters/chromakey.glsl index efbb8c5..9563965 100644 --- a/rsc/shaders/filters/chromakey.glsl +++ b/rsc/shaders/filters/chromakey.glsl @@ -36,22 +36,43 @@ float colorclose(vec3 yuv, vec3 keyYuv, vec2 tol) { float tmp = sqrt(pow(keyYuv.g - yuv.g, 2.0) + pow(keyYuv.b - yuv.b, 2.0)); if (tmp < tol.x) - return 0.0; - else if (tmp < tol.y) - return (tmp - tol.x)/(tol.y - tol.x); - else - return 1.0; + return 0.0; + else if (tmp < tol.y) + return (tmp - tol.x)/(tol.y - tol.x); + else + return 1.0; } +float alphachromakey(vec3 color, vec3 colorKey, float delta) +{ + // magic values + vec2 tol = vec2(0.5, 0.4*delta); + + //convert from RGB to YCvCr/YUV + vec4 keyYuv = RGBtoYUV * vec4(colorKey, 1.0); + vec4 yuv = RGBtoYUV * vec4(color, 1.0); + + // color distance in the UV (CbCr, PbPr) plane + vec2 dif = yuv.yz - keyYuv.yz; + float d = sqrt(dot(dif, dif)); + + // tolerance clamping + return max( (1.0 - step(d, tol.y)), step(tol.x, d) * (d - tol.x) / (tol.y - tol.x)); +} + + void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec4 texColor0 = texture(iChannel0, fragCoord.xy / iResolution.xy); //convert from RGB to YCvCr/YUV - vec4 keyYUV = RGBtoYUV * chromaKey; - vec4 yuv = RGBtoYUV * texColor0; +// vec4 keyYUV = RGBtoYUV * chromaKey; +// vec4 yuv = RGBtoYUV * texColor0; +// float mask = 1.0 - colorclose(yuv.rgb, keyYUV.rgb, maskRange); +// fragColor = max(texColor0 - mask * chromaKey, 0.0); - float mask = 1.0 - colorclose(yuv.rgb, keyYUV.rgb, maskRange); - fragColor = max(texColor0 - mask * chromaKey, 0.0); + float A = alphachromakey(texColor0.rgb, chromaKey.rgb, Tolerance); + + fragColor = vec4( texColor0.rgb, A ); } diff --git a/rsc/shaders/imageprocessing.fs b/rsc/shaders/imageprocessing.fs index 1fd9f62..e39ad17 100644 --- a/rsc/shaders/imageprocessing.fs +++ b/rsc/shaders/imageprocessing.fs @@ -43,19 +43,10 @@ uniform float saturation; uniform vec4 gamma; uniform vec4 levels; uniform float hueshift; -uniform vec4 chromakey; -uniform float chromadelta; uniform float threshold; -uniform float lumakey; uniform int nbColors; uniform int invert; -// conversion between rgb and YUV -const mat4 RGBtoYUV = mat4(0.257, 0.439, -0.148, 0.0, - 0.504, -0.368, -0.291, 0.0, - 0.098, -0.071, 0.439, 0.0, - 0.0625, 0.500, 0.500, 1.0 ); - /* ** Hue, saturation, luminance <=> Red Green Blue */ @@ -114,24 +105,6 @@ vec3 RGB2HSV( vec3 color ) return hsl; } -float alphachromakey(vec3 color, vec3 colorKey, float delta) -{ - // magic values - vec2 tol = vec2(0.5, 0.4*delta); - - //convert from RGB to YCvCr/YUV - vec4 keyYuv = RGBtoYUV * vec4(colorKey, 1.0); - vec4 yuv = RGBtoYUV * vec4(color, 1.0); - - // color distance in the UV (CbCr, PbPr) plane - vec2 dif = yuv.yz - keyYuv.yz; - float d = sqrt(dot(dif, dif)); - - // tolerance clamping - return max( (1.0 - step(d, tol.y)), step(tol.x, d) * (d - tol.x) / (tol.y - tol.x)); -} - - void main(void) { // adjust UV @@ -145,9 +118,6 @@ void main(void) // read color vec3 transformedRGB = texcolor.rgb; - // chromakey - alpha -= mix( 0.0, 1.0 - alphachromakey( transformedRGB, chromakey.rgb, chromadelta), float(chromadelta > 0.0001) ); - // brightness and contrast transformation transformedRGB = mix(vec3(0.62), transformedRGB, contrast + 1.0) + brightness; @@ -169,10 +139,6 @@ void main(void) // perform reduction of colors transformedHSL = mix( transformedHSL, floor(transformedHSL * vec3(nbColors)) / vec3(nbColors-1), float( nbColors > 0 ) ); - // luma key - alpha -= mix( 0.0, step( transformedHSL.z, lumakey ), float(lumakey > EPSILON)); - alpha = clamp(alpha, 0.0, 1.0); - // level threshold transformedHSL = mix( transformedHSL, vec3(0.0, 0.0, 0.95 - step( transformedHSL.z, threshold )), float(threshold > EPSILON));