diff --git a/es-core/src/GuiComponent.cpp b/es-core/src/GuiComponent.cpp index d66849627..4edf89f6b 100644 --- a/es-core/src/GuiComponent.cpp +++ b/es-core/src/GuiComponent.cpp @@ -29,6 +29,7 @@ GuiComponent::GuiComponent() , mOrigin {0.0f, 0.0f} , mRotationOrigin {0.5f, 0.5f} , mSize {0.0f, 0.0f} + , mBrightness {0.0f} , mOpacity {1.0f} , mSaturation {1.0f} , mDimming {1.0f} @@ -183,6 +184,16 @@ const int GuiComponent::getChildIndex() const return -1; } +void GuiComponent::setBrightness(float brightness) +{ + if (mBrightness == brightness) + return; + + mBrightness = brightness; + for (auto it = mChildren.cbegin(); it != mChildren.cend(); ++it) + (*it)->setBrightness(brightness); +} + void GuiComponent::setOpacity(float opacity) { if (mOpacity == opacity) @@ -371,6 +382,9 @@ void GuiComponent::applyTheme(const std::shared_ptr& theme, else setZIndex(getDefaultZIndex()); + if (properties & ThemeFlags::BRIGHTNESS && elem->has("brightness")) + mBrightness = glm::clamp(elem->get("brightness"), -2.0f, 2.0f); + if (properties & ThemeFlags::OPACITY && elem->has("opacity")) mThemeOpacity = glm::clamp(elem->get("opacity"), 0.0f, 1.0f); diff --git a/es-core/src/GuiComponent.h b/es-core/src/GuiComponent.h index 8727af152..968a5e9c3 100644 --- a/es-core/src/GuiComponent.h +++ b/es-core/src/GuiComponent.h @@ -222,8 +222,10 @@ public: virtual void stopGamelistFadeAnimations() {} virtual bool isListScrolling() { return false; } virtual void stopListScrolling() {} + virtual const float getBrightness() const { return mBrightness; } virtual const float getOpacity() const { return mOpacity; } virtual const float getColorOpacity() const { return 1.0f; } + virtual void setBrightness(float brightness); virtual void setOpacity(float opacity); virtual float getSaturation() const { return static_cast(mColor); } virtual void setSaturation(float saturation) { mSaturation = saturation; } @@ -336,6 +338,7 @@ protected: glm::vec2 mRotationOrigin; glm::vec2 mSize; + float mBrightness; float mOpacity; float mSaturation; float mDimming; diff --git a/es-core/src/ThemeData.cpp b/es-core/src/ThemeData.cpp index 6b1f40af1..3d25696c6 100644 --- a/es-core/src/ThemeData.cpp +++ b/es-core/src/ThemeData.cpp @@ -133,6 +133,7 @@ std::map> {"imageColor", COLOR}, {"imageColorEnd", COLOR}, {"imageGradientType", STRING}, + {"imageBrightness", FLOAT}, {"imageSaturation", FLOAT}, {"itemTransitions", STRING}, {"itemHorizontalAlignment", STRING}, @@ -185,6 +186,7 @@ std::map> {"imageColor", COLOR}, {"imageColorEnd", COLOR}, {"imageGradientType", STRING}, + {"imageBrightness", FLOAT}, {"imageSaturation", FLOAT}, {"backgroundImage", PATH}, {"backgroundRelativeScale", FLOAT}, @@ -260,6 +262,7 @@ std::map> {"colorEnd", COLOR}, {"gradientType", STRING}, {"scrollFadeIn", BOOLEAN}, + {"brightness", FLOAT}, {"opacity", FLOAT}, {"saturation", FLOAT}, {"visible", BOOLEAN}, @@ -286,6 +289,7 @@ std::map> {"delay", FLOAT}, {"fadeInTime", FLOAT}, {"scrollFadeIn", BOOLEAN}, + {"brightness", FLOAT}, {"opacity", FLOAT}, {"saturation", FLOAT}, {"visible", BOOLEAN}, @@ -304,6 +308,7 @@ std::map> {"direction", STRING}, {"keepAspectRatio", BOOLEAN}, {"interpolation", STRING}, + {"brightness", FLOAT}, {"opacity", FLOAT}, {"saturation", FLOAT}, {"visible", BOOLEAN}, diff --git a/es-core/src/ThemeData.h b/es-core/src/ThemeData.h index b912593f9..42af83e25 100644 --- a/es-core/src/ThemeData.h +++ b/es-core/src/ThemeData.h @@ -57,9 +57,10 @@ namespace ThemeFlags DELAY = 0x00002000, Z_INDEX = 0x00004000, ROTATION = 0x00008000, - OPACITY = 0x00010000, - SATURATION = 0x00020000, - VISIBLE = 0x00040000, + BRIGHTNESS = 0x00010000, + OPACITY = 0x00020000, + SATURATION = 0x00040000, + VISIBLE = 0x00080000, ALL = 0xFFFFFFFF }; // clang-format on diff --git a/es-core/src/components/GIFAnimComponent.cpp b/es-core/src/components/GIFAnimComponent.cpp index ccadfcb03..e6f39f9a6 100644 --- a/es-core/src/components/GIFAnimComponent.cpp +++ b/es-core/src/components/GIFAnimComponent.cpp @@ -495,6 +495,7 @@ void GIFAnimComponent::render(const glm::mat4& parentTrans) for (int i = 0; i < 4; ++i) vertices[i].position = glm::round(vertices[i].position); + vertices->brightness = mBrightness; vertices->saturation = mSaturation * mThemeSaturation; vertices->opacity = mOpacity * mThemeOpacity; vertices->dimming = mDimming; diff --git a/es-core/src/components/ImageComponent.cpp b/es-core/src/components/ImageComponent.cpp index 489cb6092..9fec9d6e2 100644 --- a/es-core/src/components/ImageComponent.cpp +++ b/es-core/src/components/ImageComponent.cpp @@ -394,8 +394,9 @@ void ImageComponent::render(const glm::mat4& parentTrans) else fadeIn(mTexture->bind()); - mVertices->saturation = mSaturation * mThemeSaturation; + mVertices->brightness = mBrightness; mVertices->opacity = mThemeOpacity; + mVertices->saturation = mSaturation * mThemeSaturation; mVertices->dimming = mDimming; mVertices->reflectionsFalloff = mReflectionsFalloff; diff --git a/es-core/src/components/LottieAnimComponent.cpp b/es-core/src/components/LottieAnimComponent.cpp index fe32254c8..2c673478c 100644 --- a/es-core/src/components/LottieAnimComponent.cpp +++ b/es-core/src/components/LottieAnimComponent.cpp @@ -484,6 +484,7 @@ void LottieAnimComponent::render(const glm::mat4& parentTrans) for (int i = 0; i < 4; ++i) vertices[i].position = glm::round(vertices[i].position); + vertices->brightness = mBrightness; vertices->saturation = mSaturation * mThemeSaturation; vertices->opacity = mOpacity * mThemeOpacity; vertices->dimming = mDimming; diff --git a/es-core/src/components/VideoComponent.cpp b/es-core/src/components/VideoComponent.cpp index fc08db3ec..b996481d8 100644 --- a/es-core/src/components/VideoComponent.cpp +++ b/es-core/src/components/VideoComponent.cpp @@ -381,6 +381,8 @@ void VideoComponent::renderSnapshot(const glm::mat4& parentTrans) if (mStaticImagePath != "") { mStaticImage.setOpacity(mOpacity * mThemeOpacity); mStaticImage.setSaturation(mSaturation * mThemeSaturation); + if (mBrightness != 0.0f) + mStaticImage.setBrightness(mBrightness); if (mColorShift != 0xFFFFFFFF) mStaticImage.setColorShift(mColorShift); if (mColorShift != mColorShiftEnd) diff --git a/es-core/src/components/VideoFFmpegComponent.cpp b/es-core/src/components/VideoFFmpegComponent.cpp index 08279e73d..ab4c0ad4f 100644 --- a/es-core/src/components/VideoFFmpegComponent.cpp +++ b/es-core/src/components/VideoFFmpegComponent.cpp @@ -176,6 +176,7 @@ void VideoFFmpegComponent::render(const glm::mat4& parentTrans) if (mFadeIn < 1.0f || mThemeOpacity < 1.0f) vertices->opacity = mFadeIn * mThemeOpacity; + vertices->brightness = mBrightness; vertices->saturation = mSaturation * mThemeSaturation; vertices->dimming = mDimming; diff --git a/es-core/src/components/primary/CarouselComponent.h b/es-core/src/components/primary/CarouselComponent.h index 6d2467fe9..2ddfc63ab 100644 --- a/es-core/src/components/primary/CarouselComponent.h +++ b/es-core/src/components/primary/CarouselComponent.h @@ -147,6 +147,7 @@ private: unsigned int mImageColorShift; unsigned int mImageColorShiftEnd; bool mImageColorGradientHorizontal; + float mImageBrightness; float mImageSaturation; bool mInstantItemTransitions; Alignment mItemHorizontalAlignment; @@ -200,6 +201,7 @@ CarouselComponent::CarouselComponent() , mImageColorShift {0xFFFFFFFF} , mImageColorShiftEnd {0xFFFFFFFF} , mImageColorGradientHorizontal {true} + , mImageBrightness {0.0f} , mImageSaturation {1.0f} , mInstantItemTransitions {false} , mItemHorizontalAlignment {ALIGN_CENTER} @@ -265,6 +267,8 @@ void CarouselComponent::addEntry(Entry& entry, const std::shared_ptrsetMaxSize(glm::round(mItemSize * (mItemScale >= 1.0f ? mItemScale : 1.0f))); item->setImage(entry.data.imagePath); item->applyTheme(theme, "system", "", ThemeFlags::ALL); + if (mImageBrightness != 0.0) + item->setBrightness(mImageBrightness); if (mImageSaturation != 1.0) item->setSaturation(mImageSaturation); if (mImageColorShift != 0xFFFFFFFF) @@ -285,6 +289,8 @@ void CarouselComponent::addEntry(Entry& entry, const std::shared_ptr= 1.0f ? mItemScale : 1.0f))); defaultImage->setImage(entry.data.defaultImagePath); defaultImage->applyTheme(theme, "system", "", ThemeFlags::ALL); + if (mImageBrightness != 0.0) + defaultImage->setBrightness(mImageBrightness); if (mImageSaturation != 1.0) defaultImage->setSaturation(mImageSaturation); if (mImageColorShift != 0xFFFFFFFF) @@ -354,6 +360,8 @@ void CarouselComponent::updateEntry(Entry& entry, const std::shared_ptrsetMaxSize(glm::round(mItemSize * (mItemScale >= 1.0f ? mItemScale : 1.0f))); item->setImage(entry.data.imagePath); item->applyTheme(theme, "system", "", ThemeFlags::ALL); + if (mImageBrightness != 0.0) + item->setBrightness(mImageBrightness); if (mImageSaturation != 1.0) item->setSaturation(mImageSaturation); if (mImageColorShift != 0xFFFFFFFF) @@ -1124,6 +1132,9 @@ void CarouselComponent::applyTheme(const std::shared_ptr& theme, } } + if (elem->has("imageBrightness")) + mImageBrightness = glm::clamp(elem->get("imageBrightness"), -2.0f, 2.0f); + if (elem->has("imageSaturation")) mImageSaturation = glm::clamp(elem->get("imageSaturation"), 0.0f, 1.0f); diff --git a/es-core/src/components/primary/GridComponent.h b/es-core/src/components/primary/GridComponent.h index a9b4c48ca..0ee7b24df 100644 --- a/es-core/src/components/primary/GridComponent.h +++ b/es-core/src/components/primary/GridComponent.h @@ -148,6 +148,7 @@ private: unsigned int mImageColor; unsigned int mImageColorEnd; bool mImageColorGradientHorizontal; + float mImageBrightness; float mImageSaturation; std::unique_ptr mBackgroundImage; std::string mBackgroundImagePath; @@ -205,6 +206,7 @@ GridComponent::GridComponent() , mImageColor {0xFFFFFFFF} , mImageColorEnd {0xFFFFFFFF} , mImageColorGradientHorizontal {true} + , mImageBrightness {0.0f} , mImageSaturation {1.0f} , mBackgroundRelativeScale {1.0f} , mBackgroundColor {0xFFFFFFFF} @@ -258,6 +260,8 @@ void GridComponent::addEntry(Entry& entry, const std::shared_ptr& item->setCroppedSize(mItemSize * mImageRelativeScale); item->setImage(entry.data.imagePath); item->applyTheme(theme, "system", "", ThemeFlags::ALL); + if (mImageBrightness != 0.0) + item->setBrightness(mImageBrightness); if (mImageSaturation != 1.0) item->setSaturation(mImageSaturation); if (mImageColor != 0xFFFFFFFF) @@ -284,6 +288,8 @@ void GridComponent::addEntry(Entry& entry, const std::shared_ptr& defaultImage->setCroppedSize(mItemSize * mImageRelativeScale); defaultImage->setImage(entry.data.defaultImagePath); defaultImage->applyTheme(theme, "system", "", ThemeFlags::ALL); + if (mImageBrightness != 0.0) + defaultImage->setBrightness(mImageBrightness); if (mImageSaturation != 1.0) defaultImage->setSaturation(mImageSaturation); if (mImageColor != 0xFFFFFFFF) @@ -335,6 +341,8 @@ void GridComponent::updateEntry(Entry& entry, const std::shared_ptrsetCroppedSize(mItemSize * mImageRelativeScale); item->setImage(entry.data.imagePath); item->applyTheme(theme, "system", "", ThemeFlags::ALL); + if (mImageBrightness != 0.0) + item->setBrightness(mImageBrightness); if (mImageSaturation != 1.0) item->setSaturation(mImageSaturation); if (mImageColor != 0xFFFFFFFF) @@ -1027,6 +1035,9 @@ void GridComponent::applyTheme(const std::shared_ptr& theme, } } + if (elem->has("imageBrightness")) + mImageBrightness = glm::clamp(elem->get("imageBrightness"), -2.0f, 2.0f); + if (elem->has("imageSaturation")) mImageSaturation = glm::clamp(elem->get("imageSaturation"), 0.0f, 1.0f); diff --git a/es-core/src/renderers/Renderer.h b/es-core/src/renderers/Renderer.h index 8295b9f0f..4e51f2cd6 100644 --- a/es-core/src/renderers/Renderer.h +++ b/es-core/src/renderers/Renderer.h @@ -61,6 +61,7 @@ public: glm::vec2 texcoord; unsigned int color; glm::vec4 clipregion; + float brightness; float opacity; float saturation; float dimming; @@ -69,7 +70,8 @@ public: unsigned int shaderFlags; Vertex() - : opacity {1.0f} + : brightness {0.0f} + , opacity {1.0f} , saturation {1.0f} , dimming {1.0f} , reflectionsFalloff {0.0f} @@ -86,6 +88,7 @@ public: , texcoord(textureCoord) , color(color) , clipregion(clipRegion) + , brightness {0.0f} , opacity {1.0f} , saturation {1.0f} , dimming {1.0f} diff --git a/es-core/src/renderers/RendererOpenGL.cpp b/es-core/src/renderers/RendererOpenGL.cpp index cb7d611d7..adaa1dbff 100644 --- a/es-core/src/renderers/RendererOpenGL.cpp +++ b/es-core/src/renderers/RendererOpenGL.cpp @@ -443,6 +443,7 @@ void RendererOpenGL::drawTriangleStrips(const Vertex* vertices, GL_CHECK_ERROR(glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex) * numVertices, vertices, GL_DYNAMIC_DRAW)); mCoreShader->setClipRegion(vertices->clipregion); + mCoreShader->setBrightness(vertices->brightness); mCoreShader->setOpacity(vertices->opacity); mCoreShader->setSaturation(vertices->saturation); mCoreShader->setDimming(vertices->dimming); @@ -517,6 +518,7 @@ void RendererOpenGL::drawTriangleStrips(const Vertex* vertices, GL_CHECK_ERROR(glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex) * numVertices, vertices, GL_DYNAMIC_DRAW)); mScanlinelShader->setOpacity(vertices->opacity); + mScanlinelShader->setBrightness(vertices->brightness); mScanlinelShader->setSaturation(vertices->saturation); mScanlinelShader->setTextureSize({shaderWidth, shaderHeight}); GL_CHECK_ERROR(glDrawArrays(GL_TRIANGLE_STRIP, 0, numVertices)); diff --git a/es-core/src/renderers/ShaderOpenGL.cpp b/es-core/src/renderers/ShaderOpenGL.cpp index ec119407f..7d04d8c71 100644 --- a/es-core/src/renderers/ShaderOpenGL.cpp +++ b/es-core/src/renderers/ShaderOpenGL.cpp @@ -19,6 +19,7 @@ ShaderOpenGL::ShaderOpenGL() , mShaderTextureCoord {0} , mShaderColor {0} , mShaderTextureSize {0} + , mShaderBrightness {0} , mShaderOpacity {0} , mShaderSaturation {0} , mShaderDimming {0} @@ -122,6 +123,7 @@ void ShaderOpenGL::getVariableLocations(GLuint programID) mShaderColor = glGetAttribLocation(mProgramID, "colorVertex"); mShaderTextureSize = glGetUniformLocation(mProgramID, "textureSize"); mShaderClipRegion = glGetUniformLocation(mProgramID, "clipRegion"); + mShaderBrightness = glGetUniformLocation(mProgramID, "brightness"); mShaderOpacity = glGetUniformLocation(mProgramID, "opacity"); mShaderSaturation = glGetUniformLocation(mProgramID, "saturation"); mShaderDimming = glGetUniformLocation(mProgramID, "dimming"); @@ -166,6 +168,12 @@ void ShaderOpenGL::setClipRegion(glm::vec4 clipRegion) clipRegion[3])); } +void ShaderOpenGL::setBrightness(GLfloat brightness) +{ + if (mShaderBrightness != -1) + GL_CHECK_ERROR(glUniform1f(mShaderBrightness, brightness)); +} + void ShaderOpenGL::setOpacity(GLfloat opacity) { if (mShaderOpacity != -1) diff --git a/es-core/src/renderers/ShaderOpenGL.h b/es-core/src/renderers/ShaderOpenGL.h index 48a13daae..f8f594d3e 100644 --- a/es-core/src/renderers/ShaderOpenGL.h +++ b/es-core/src/renderers/ShaderOpenGL.h @@ -69,6 +69,7 @@ public: void setAttribPointers(); void setTextureSize(std::array shaderVec2); void setClipRegion(glm::vec4 clipRegion); + void setBrightness(GLfloat brightness); void setOpacity(GLfloat opacity); void setSaturation(GLfloat saturation); void setDimming(GLfloat dimming); @@ -95,6 +96,7 @@ private: GLint mShaderColor; GLint mShaderClipRegion; GLint mShaderTextureSize; + GLint mShaderBrightness; GLint mShaderOpacity; GLint mShaderSaturation; GLint mShaderDimming; diff --git a/resources/shaders/glsl/core.glsl b/resources/shaders/glsl/core.glsl index b918fe969..32de8cd6f 100644 --- a/resources/shaders/glsl/core.glsl +++ b/resources/shaders/glsl/core.glsl @@ -4,7 +4,7 @@ // core.glsl // // Core shader functionality: -// Clipping, saturation, opacity, dimming and reflections falloff. +// Clipping, brightness, saturation, opacity, dimming and reflections falloff. // // Vertex section of code: @@ -39,6 +39,7 @@ in vec2 texCoord; in vec4 color; uniform vec4 clipRegion; +uniform float brightness; uniform float saturation; uniform float opacity; uniform float dimming; @@ -70,6 +71,10 @@ void main() vec4 sampledColor = texture(textureSampler, texCoord); + // Brightness. + if (brightness != 0.0) + sampledColor.rgb = sampledColor.rgb * pow(2.0, brightness); + // Saturation. if (saturation != 1.0) { vec3 grayscale; diff --git a/resources/shaders/glsl/scanlines.glsl b/resources/shaders/glsl/scanlines.glsl index 2be2e9b71..aa24780e1 100644 --- a/resources/shaders/glsl/scanlines.glsl +++ b/resources/shaders/glsl/scanlines.glsl @@ -58,6 +58,7 @@ precision mediump float; uniform vec2 textureSize; uniform float opacity; +uniform float brightness; uniform float saturation; uniform sampler2D textureSampler; in vec2 texCoord; @@ -155,6 +156,10 @@ void main() vec4 colorTemp = clamp(GAMMA_OUT(color), 0.0, 1.0); + // Brightness. + if (brightness != 0.0) + colorTemp.rgb = colorTemp.rgb * pow(2.0, brightness); + // Saturation. if (saturation != 1.0) { vec3 grayscale;