diff --git a/es-core/src/ThemeData.cpp b/es-core/src/ThemeData.cpp index b4a9704b5..568c5c01e 100644 --- a/es-core/src/ThemeData.cpp +++ b/es-core/src/ThemeData.cpp @@ -275,6 +275,9 @@ std::map> {"gameselector", STRING}, {"audio", BOOLEAN}, {"interpolation", STRING}, + {"color", COLOR}, + {"colorEnd", COLOR}, + {"gradientType", STRING}, {"pillarboxes", BOOLEAN}, {"pillarboxThreshold", NORMALIZED_PAIR}, {"scanlines", BOOLEAN}, diff --git a/es-core/src/components/VideoComponent.cpp b/es-core/src/components/VideoComponent.cpp index 5bde60c27..fc08db3ec 100644 --- a/es-core/src/components/VideoComponent.cpp +++ b/es-core/src/components/VideoComponent.cpp @@ -22,6 +22,9 @@ VideoComponent::VideoComponent() : mVideoWidth {0} , mVideoHeight {0} + , mColorShift {0xFFFFFFFF} + , mColorShiftEnd {0xFFFFFFFF} + , mColorGradientHorizontal {true} , mTargetSize {0.0f, 0.0f} , mVideoAreaPos {0.0f, 0.0f} , mVideoAreaSize {0.0f, 0.0f} @@ -254,6 +257,29 @@ void VideoComponent::applyTheme(const std::shared_ptr& theme, } } + if (elem->has("color")) { + mColorShift = elem->get("color"); + mColorShiftEnd = mColorShift; + } + if (elem->has("colorEnd")) + mColorShiftEnd = elem->get("colorEnd"); + + if (elem->has("gradientType")) { + const std::string& gradientType {elem->get("gradientType")}; + if (gradientType == "horizontal") { + mColorGradientHorizontal = true; + } + else if (gradientType == "vertical") { + mColorGradientHorizontal = false; + } + else { + mColorGradientHorizontal = true; + LOG(LogWarning) << "VideoComponent: Invalid theme configuration, property " + "\"gradientType\" for element \"" + << element.substr(6) << "\" defined as \"" << gradientType << "\""; + } + } + if (elem->has("pillarboxes")) mDrawPillarboxes = elem->get("pillarboxes"); @@ -355,6 +381,12 @@ void VideoComponent::renderSnapshot(const glm::mat4& parentTrans) if (mStaticImagePath != "") { mStaticImage.setOpacity(mOpacity * mThemeOpacity); mStaticImage.setSaturation(mSaturation * mThemeSaturation); + if (mColorShift != 0xFFFFFFFF) + mStaticImage.setColorShift(mColorShift); + if (mColorShift != mColorShiftEnd) + mStaticImage.setColorShiftEnd(mColorShiftEnd); + if (!mColorGradientHorizontal) + mStaticImage.setColorGradientHorizontal(mColorGradientHorizontal); mStaticImage.setDimming(mDimming); mStaticImage.render(parentTrans); } diff --git a/es-core/src/components/VideoComponent.h b/es-core/src/components/VideoComponent.h index d214dead5..ef590cee9 100644 --- a/es-core/src/components/VideoComponent.h +++ b/es-core/src/components/VideoComponent.h @@ -101,6 +101,9 @@ protected: unsigned mVideoWidth; unsigned mVideoHeight; + unsigned int mColorShift; + unsigned int mColorShiftEnd; + bool mColorGradientHorizontal; glm::vec2 mTargetSize; glm::vec2 mVideoAreaPos; glm::vec2 mVideoAreaSize; diff --git a/es-core/src/components/VideoFFmpegComponent.cpp b/es-core/src/components/VideoFFmpegComponent.cpp index b78994535..08279e73d 100644 --- a/es-core/src/components/VideoFFmpegComponent.cpp +++ b/es-core/src/components/VideoFFmpegComponent.cpp @@ -164,6 +164,11 @@ void VideoFFmpegComponent::render(const glm::mat4& parentTrans) vertices[3] = {{mSize.x + mRectangleOffset.x, mSize.y + + mRectangleOffset.y}, {1.0f, 1.0f}, 0xFFFFFFFF}; // clang-format on + vertices[0].color = mColorShift; + vertices[1].color = mColorGradientHorizontal ? mColorShift : mColorShiftEnd; + vertices[2].color = mColorGradientHorizontal ? mColorShiftEnd : mColorShift; + vertices[3].color = mColorShiftEnd; + // Round vertices. for (int i = 0; i < 4; ++i) vertices[i].position = glm::round(vertices[i].position); diff --git a/resources/shaders/glsl/scanlines.glsl b/resources/shaders/glsl/scanlines.glsl index 9e9bc62f0..cbc2cb60b 100644 --- a/resources/shaders/glsl/scanlines.glsl +++ b/resources/shaders/glsl/scanlines.glsl @@ -30,10 +30,13 @@ precision mediump float; uniform mat4 MVPMatrix; in vec2 positionVertex; in vec2 texCoordVertex; +in vec4 colorVertex; uniform vec2 textureSize; + out vec2 texCoord; out vec2 onex; out vec2 oney; +out vec4 colorShift; #define SourceSize vec4(textureSize, 1.0 / textureSize) @@ -43,6 +46,7 @@ void main() texCoord = texCoordVertex; onex = vec2(SourceSize.z, 0.0); oney = vec2(0.0, SourceSize.w); + colorShift.abgr = colorVertex.rgba; } // Fragment section of code: @@ -59,6 +63,7 @@ uniform sampler2D textureSampler; in vec2 texCoord; in vec2 onex; in vec2 oney; +in vec4 colorShift; out vec4 FragColor; #define SourceSize vec4(textureSize, 1.0 / textureSize) @@ -158,6 +163,10 @@ void main() colorTemp = vec4(blendedColor, colorTemp.a); } + // Color shift. + colorTemp.rgb *= colorShift.rgb; + colorTemp.a *= colorShift.a; + FragColor = vec4(colorTemp.rgb, colorTemp.a * opacity); } #endif