Skip to content

Commit

Permalink
Merge pull request #113 from Semper-Viventem/update-fluted-glass-shader
Browse files Browse the repository at this point in the history
Update fluted glass shader
  • Loading branch information
Semper-Viventem authored Feb 20, 2024
2 parents 42985a6 + 26f24c2 commit 6ea62ad
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 10 deletions.
8 changes: 2 additions & 6 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ android {
minSdk = 29
targetSdk = 34

// This version code will be applied only for F-Droid builds, for other flavors version code will be generated by gradle dynamically
// F-Droid requires version code to be hardcoded in the build.gradle file
versionCode = 1705859024
versionName = "0.22.8-beta"
versionCode = 1708449099
versionName = "0.22.9-beta"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

Expand Down Expand Up @@ -83,7 +81,6 @@ android {
create("github") {
isDefault = true
dimension = "distribution"
versionCode = (System.currentTimeMillis() / 1000).toInt()

buildConfigField("String", "DISTRIBUTION", "\"Github\"")
buildConfigField("Boolean", "STORE_RATING_IS_APPLICABLE", "false")
Expand All @@ -92,7 +89,6 @@ android {
create("googlePlay") {
isDefault = false
dimension = "distribution"
versionCode = (System.currentTimeMillis() / 1000).toInt()

buildConfigField("String", "DISTRIBUTION", "\"Google play\"")
buildConfigField("Boolean", "STORE_RATING_IS_APPLICABLE", "true")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.zIndex
import f.cking.software.dpToPx
import kotlin.math.max

@Composable
fun GlassBottomNavBar(
modifier: Modifier = Modifier,
blur: Float = 3f,
glassCurveSizeDp: Float = 3f,
fallbackColor: Color = MaterialTheme.colorScheme.surfaceContainerHighest,
overlayColor: Color = MaterialTheme.colorScheme.surfaceContainerHighest.copy(alpha = 0.3f),
overlayColor: Color = MaterialTheme.colorScheme.surfaceContainerHighest.copy(alpha = 0.35f),
content: @Composable () -> Unit,
) {
GlassBottomSpace(
Expand Down Expand Up @@ -79,7 +80,7 @@ fun GlassBottomSpace(
glassCurveSizeDp: Float = 3f,
zIndex: Float = 1f,
fallbackColor: Color = MaterialTheme.colorScheme.surfaceContainerHighest,
overlayColor: Color = MaterialTheme.colorScheme.surfaceContainerHighest.copy(alpha = 0.3f),
overlayColor: Color = MaterialTheme.colorScheme.surfaceContainerHighest.copy(alpha = 0.35f),
bottomContent: @Composable () -> Unit,
globalContent: @Composable () -> Unit,
) {
Expand Down Expand Up @@ -144,7 +145,6 @@ fun Modifier.blurBottom(heightPx: Float, blur: Float, glassCurveSizeDp: Float):
contentShader.setFloatUniform("blurredHeight", heightPx)
blurredShader.setFloatUniform("blurredHeight", heightPx)
glassShader.setFloatUniform("blurredHeight", heightPx)
glassShader.setFloatUniform("horizontalSquareSize", context.dpToPx(glassCurveSizeDp).toFloat())

this
.onSizeChanged {
Expand All @@ -163,6 +163,10 @@ fun Modifier.blurBottom(heightPx: Float, blur: Float, glassCurveSizeDp: Float):
it.width.toFloat(),
it.height.toFloat(),
)

val minCurveSizePx: Float = it.width / 100f
val glassCurveSizePx = max(minCurveSizePx, context.dpToPx(glassCurveSizeDp).toFloat())
glassShader.setFloatUniform("horizontalSquareSize", glassCurveSizePx)
}
.then(
graphicsLayer {
Expand Down
53 changes: 52 additions & 1 deletion app/src/main/java/f/cking/software/utils/graphic/Shaders.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,49 @@ object Shaders {
return color;
}
float4 colorDistortion(float2 fragCoord) {
// uv (0 to 1)
float2 uv = fragCoord.xy / iResolution.xy;
float chromo_x = 0.025;
float chromo_y = 0.025;
return float4(content.eval(float2(uv.x - chromo_x * 0.016, uv.y - chromo_y * 0.009) * iResolution.xy).r, content.eval(float2(uv.x + chromo_x * 0.0125, uv.y - chromo_y * 0.004) * iResolution.xy).g, content.eval(float2(uv.x - chromo_x * 0.0045, uv.y + chromo_y * 0.0085) * iResolution.xy).b, 1.0);
}
float2 sphericalTransformation(
float u,
float v,
float uCenter,
float vCenter,
float lensRadius,
float tau
) {
u -= uCenter;
v -= vCenter;
float l = sqrt(u * u + v * v);
float z = sqrt(lensRadius * lensRadius - l * l);
float sphereRadius = sqrt(u * u + v * v + z * z);
float uAlpha = (1.0 - (1.0 / tau)) * sin(u / sphereRadius / 2);
float vAlpha = (1.0 - (1.0 / tau)) * sin(v / sphereRadius);
u = l <= lensRadius ?
u + uCenter - z * tan(uAlpha) :
u + uCenter;
v = l <= lensRadius ?
v + vCenter - z * tan(vAlpha) :
v + vCenter;
return float2(u, v);
}
float4 main(float2 fragCoord) {
float2 offset = float2(horizontalOffset, verticalOffset);
float2 squares = float2(iResolution.x / horizontalSquareSize, verticalSquares);
float2 uv = fragCoord.xy / iResolution.xy;
Expand All @@ -78,8 +119,18 @@ object Shaders {
tc.x *= iResolution.x / iResolution.y;
float2 tile = fract(tc * squares);
uv = sphericalTransformation(
uv.x,
uv.y,
(uv + (tile * amt) - offset).x,
1.0,
(blurredHeight / iResolution.y * 1.5),
1.5
);
float4 color = content.eval((uv + (tile * amt) - offset) * iResolution.xy);
float2 flutedGlassCoordinate = (uv + (tile * amt) - offset) * iResolution.xy;
float4 color = colorDistortion(flutedGlassCoordinate);
float4 white = float4(1.0, 1.0, 1.0, 1.0);
float4 colorModificator = 0.04 * gradient((uv + (tile * amt) - offset) * iResolution.xy);
return min(color + colorModificator, white);
Expand Down

0 comments on commit 6ea62ad

Please sign in to comment.