Improve the control of shadow_render_power & make it less confusin.

This commit is contained in:
Felix Dick 2022-09-30 23:26:44 +02:00
parent 7579e03b64
commit 4a2ba088ae
3 changed files with 19 additions and 19 deletions

View file

@ -79,7 +79,7 @@ void CConfigManager::setDefaultVars() {
configValues["decoration:no_blur_on_oversized"].intValue = 0;
configValues["decoration:drop_shadow"].intValue = 1;
configValues["decoration:shadow_range"].intValue = 4;
configValues["decoration:shadow_render_power"].intValue = 3;
configValues["decoration:shadow_render_power"].floatValue = 0.5f;
configValues["decoration:shadow_ignore_window"].intValue = 1;
configValues["decoration:shadow_offset"].vecValue = Vector2D();
configValues["decoration:col.shadow"].intValue = 0xee1a1a1a;

View file

@ -1038,9 +1038,9 @@ void CHyprOpenGLImpl::renderRoundedShadow(wlr_box* box, int round, int range, fl
RASSERT((box->width > 0 && box->height > 0), "Tried to render shadow with width/height < 0!");
RASSERT(m_pCurrentWindow, "Tried to render shadow without a window!");
static auto *const PSHADOWPOWER = &g_pConfigManager->getConfigValuePtr("decoration:shadow_render_power")->intValue;
static auto *const PSHADOWPOWER = &g_pConfigManager->getConfigValuePtr("decoration:shadow_render_power")->floatValue;
const auto SHADOWPOWER = std::clamp((int)*PSHADOWPOWER, 1, 4);
const auto SHADOWPOWER = std::max(*PSHADOWPOWER , 0.0f); // TODO: we should do that only once at startup and if the config changed
const auto col = m_pCurrentWindow->m_cRealShadowColor.col();
@ -1069,7 +1069,7 @@ void CHyprOpenGLImpl::renderRoundedShadow(wlr_box* box, int round, int range, fl
glUniform2f(m_RenderData.pCurrentMonData->m_shSHADOW.topLeft, (float)TOPLEFT.x, (float)TOPLEFT.y);
glUniform2f(m_RenderData.pCurrentMonData->m_shSHADOW.bottomRight, (float)BOTTOMRIGHT.x, (float)BOTTOMRIGHT.y);
glUniform2f(m_RenderData.pCurrentMonData->m_shSHADOW.fullSize, (float)FULLSIZE.x, (float)FULLSIZE.y);
glUniform1f(m_RenderData.pCurrentMonData->m_shSHADOW.radius, range + round);
glUniform1f(m_RenderData.pCurrentMonData->m_shSHADOW.radius, round);
glUniform1f(m_RenderData.pCurrentMonData->m_shSHADOW.range, range);
glUniform1f(m_RenderData.pCurrentMonData->m_shSHADOW.shadowPower, SHADOWPOWER);

View file

@ -14,14 +14,14 @@ uniform float radius;
uniform float range;
uniform float shadowPower;
float pixAlphaRoundedDistance(float distanceToCorner) {
if (distanceToCorner > radius) {
return 0.0;
}
float pixAlphaRoundedDistance(float distanceToRadiusCenter) {
float distanceToCorner = distanceToRadiusCenter - radius;
if (distanceToCorner > radius - range) {
return pow((range - (distanceToCorner - radius + range)) / range, shadowPower); // i think?
}
if (distanceToCorner > range)
return 0.0;
if (distanceToCorner > 0.0)
return 1.0 - pow(distanceToCorner / range, shadowPower);
return 1.0;
}
@ -66,15 +66,15 @@ void main() {
float distanceL = pixCoord[0];
float distanceR = fullSize[0] - pixCoord[0];
// get the smallest
float smallest = min(min(distanceT, distanceB), min(distanceL, distanceR));
// get the distance to the closest edge
float distanceToEdge = range - min(min(distanceT, distanceB), min(distanceL, distanceR));
if (smallest < range) {
pixColor[3] = pixColor[3] * pow((smallest / range), shadowPower);
if (distanceToEdge > 0.0) {
pixColor[3] *= 1.0 - pow(distanceToEdge / range, shadowPower);
}
}
if (pixColor[3] == 0.0) {
if (pixColor[3] == 0.0) { // TODO: is this necessary?
discard; return;
}