Skip to content

Commit

Permalink
Add natural shadows using parametric blend (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
matinlotfali authored Dec 24, 2023
1 parent 63907e5 commit ebaf328
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ This effect started as a fork of [shapecorners](https://sourceforge.net/projects
- Disable effect when window gets maximized - by [matinlotfali](https://github.com/matinlotfali)
- Cleanups for the plugin logic, remove unneeded dependencies from CMakeLists.txt file - by [alex1701c](https://github.com/alex1701c)
- Separate outline color for active and inactive windows - by [OrkenWhite](https://github.com/OrkenWhite)
- Add natural shadows using parametric blend - by [paletteOvO](https://github.com/paletteOvO)

# How to build from source code:

Expand Down
7 changes: 7 additions & 0 deletions src/shaders_110/shapecorners.frag
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ varying vec2 texcoord0; // The XY location of the rendering pixel. Star
bool isDrawingShadows() { return windowSize != windowExpandedSize && shadowColor.a > 0.0; }
bool isDrawingOutline() { return outlineColor.a > 0.0 && outlineThickness > 0.0; }

float parametricBlend(float t) {
float sqt = t * t;
return sqt / (2.0 * (sqt - t) + 1.0);
}

/*
* \brief This function generates the shadow color based on the distance_from_center
* \param distance_from_center: Distance of the rendering point and the reference point that is being used for rounding corners.
Expand All @@ -33,6 +38,8 @@ vec4 getShadowColor(float distance_from_center) {
if(!isDrawingShadows())
return vec4(0.0, 0.0, 0.0, 0.0);
float percent = -distance_from_center/shadowSize + 1.0;
percent = clamp(percent, 0.0, 1.0);
percent = parametricBlend(percent);
if (percent < 0.0)
return vec4(0.0, 0.0, 0.0, 0.0);
else
Expand Down
7 changes: 7 additions & 0 deletions src/shaders_140/shapecorners.frag
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ out vec4 fragColor; // The RGBA color that can be rendered
bool isDrawingShadows() { return windowSize != windowExpandedSize && shadowColor.a > 0.0; }
bool isDrawingOutline() { return outlineColor.a > 0.0 && outlineThickness > 0.0; }

float parametricBlend(float t) {
float sqt = t * t;
return sqt / (2.0 * (sqt - t) + 1.0);
}

/*
* \brief This function generates the shadow color based on the distance_from_center
* \param distance_from_center: Distance of the rendering point and the reference point that is being used for rounding corners.
Expand All @@ -32,6 +37,8 @@ vec4 getShadowColor(float distance_from_center) {
if(!isDrawingShadows())
return vec4(0,0,0,0);
float percent = -distance_from_center/shadowSize + 1;
percent = clamp(percent, 0, 1);
percent = parametricBlend(percent);
if(percent < 0)
return vec4(0,0,0,0);
else
Expand Down

0 comments on commit ebaf328

Please sign in to comment.