Rename eccentricFactor to depthEffect
This commit is contained in:
1 parent
645a014c3b
commit
f9688b348d
9 files changed
+21
-19
No files matched your search
@@ -46,7 +46,7 @@ android {
|
||||
compilerOptions {
|
||||
jvmTarget = JvmTarget.JVM_21
|
||||
freeCompilerArgs.addAll(
|
||||
"-jvm-default=no-compatibility"
|
||||
"-jvm-default=no-compatibility",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -31,7 +31,7 @@ android {
|
||||
compilerOptions {
|
||||
jvmTarget = JvmTarget.JVM_21
|
||||
freeCompilerArgs.addAll(
|
||||
"-jvm-default=no-compatibility"
|
||||
"-jvm-default=no-compatibility",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -161,7 +161,7 @@ private class LiquidGlassElement(
|
||||
private class LiquidGlassNode(
|
||||
var state: LiquidGlassProviderState,
|
||||
var style: () -> GlassStyle,
|
||||
val luminanceSampler: LuminanceSampler?
|
||||
var luminanceSampler: LuminanceSampler?
|
||||
) : GlobalPositionAwareModifierNode, ObserverModifierNode, DelegatingNode() {
|
||||
|
||||
override val shouldAutoInvalidate: Boolean = false
|
||||
@@ -183,7 +183,7 @@ private class LiquidGlassNode(
|
||||
private var _cornerRadiusPx: Float = Float.NaN
|
||||
private var _innerRefractionHeight: Float = Float.NaN
|
||||
private var _innerRefractionAmount: Float = Float.NaN
|
||||
private var _eccentricFactor: Float = Float.NaN
|
||||
private var _depthEffect: Float = Float.NaN
|
||||
private var _innerRefractionRenderEffect: RenderEffect? = null
|
||||
|
||||
private var _renderEffect: androidx.compose.ui.graphics.RenderEffect? = null
|
||||
@@ -242,16 +242,16 @@ private class LiquidGlassNode(
|
||||
|
||||
val innerRefractionHeight = style.innerRefraction.height.toPx(size, this)
|
||||
val innerRefractionAmount = style.innerRefraction.amount.toPx(size, this)
|
||||
val eccentricFactor = style.innerRefraction.eccentricFactor
|
||||
val depthEffect = style.innerRefraction.depthEffect
|
||||
val innerRefractionChanged =
|
||||
sizeChanged || cornerRadiusChanged ||
|
||||
_innerRefractionHeight != innerRefractionHeight ||
|
||||
_innerRefractionAmount != innerRefractionAmount ||
|
||||
_eccentricFactor != eccentricFactor
|
||||
_depthEffect != depthEffect
|
||||
if (innerRefractionChanged) {
|
||||
_innerRefractionHeight = innerRefractionHeight
|
||||
_innerRefractionAmount = innerRefractionAmount
|
||||
_eccentricFactor = eccentricFactor
|
||||
_depthEffect = depthEffect
|
||||
_innerRefractionRenderEffect =
|
||||
RenderEffect.createRuntimeShaderEffect(
|
||||
refractionShader.apply {
|
||||
@@ -260,7 +260,7 @@ private class LiquidGlassNode(
|
||||
|
||||
setFloatUniform("refractionHeight", innerRefractionHeight)
|
||||
setFloatUniform("refractionAmount", innerRefractionAmount)
|
||||
setFloatUniform("eccentricFactor", eccentricFactor)
|
||||
setFloatUniform("depthEffect", depthEffect)
|
||||
},
|
||||
"image"
|
||||
)
|
||||
@@ -319,13 +319,13 @@ private class LiquidGlassNode(
|
||||
compositingStrategy = androidx.compose.ui.graphics.layer.CompositingStrategy.Offscreen
|
||||
}
|
||||
|
||||
if (luminanceSampler != null) {
|
||||
luminanceSampler?.let { sampler ->
|
||||
samplerJob =
|
||||
coroutineScope.launch {
|
||||
while (isActive) {
|
||||
delay(luminanceSampler.sampleIntervalMillis)
|
||||
delay(sampler.sampleIntervalMillis)
|
||||
graphicsLayer?.let { layer ->
|
||||
luminanceSampler.sample(layer)
|
||||
sampler.sample(layer)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -356,6 +356,7 @@ private class LiquidGlassNode(
|
||||
) {
|
||||
this.state = state
|
||||
this.style = style
|
||||
this.luminanceSampler = luminanceSampler
|
||||
updateStyle()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ private class LiquidGlassProviderElement(
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.TIRAMISU)
|
||||
internal class LiquidGlassProviderNode(
|
||||
private class LiquidGlassProviderNode(
|
||||
var state: LiquidGlassProviderState
|
||||
) : DrawModifierNode, GlobalPositionAwareModifierNode, Modifier.Node() {
|
||||
|
||||
|
||||
@@ -18,15 +18,16 @@ import androidx.compose.ui.unit.dp
|
||||
* It is a **negative** value that determines how much the content is distorted.
|
||||
* To create a full refraction effect, use `RefractionValue.Full`.
|
||||
*
|
||||
* @param eccentricFactor
|
||||
* The shift factor for the refraction effect.
|
||||
* 0 means no shift, 1 will shift the content towards the corners.
|
||||
* @param depthEffect
|
||||
* The level of depth effect applied to the refraction.
|
||||
* 0 means no depth effect, creating a flat style.
|
||||
* 1 will shift the content towards the corners, creating a full depth effect.
|
||||
*/
|
||||
@Immutable
|
||||
data class InnerRefraction(
|
||||
override val height: RefractionHeight,
|
||||
override val amount: RefractionAmount,
|
||||
@param:FloatRange(from = 0.0, to = 1.0) val eccentricFactor: Float = 1f
|
||||
@param:FloatRange(from = 0.0, to = 1.0) val depthEffect: Float = 1f
|
||||
) : Refraction {
|
||||
|
||||
companion object {
|
||||
@@ -36,7 +37,7 @@ data class InnerRefraction(
|
||||
InnerRefraction(
|
||||
height = RefractionHeight(8.dp),
|
||||
amount = RefractionAmount((-16).dp),
|
||||
eccentricFactor = 1f
|
||||
depthEffect = 1f
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,7 @@ uniform float cornerRadius;
|
||||
|
||||
uniform float refractionHeight;
|
||||
uniform float refractionAmount;
|
||||
uniform float eccentricFactor;
|
||||
uniform float depthEffect;
|
||||
|
||||
$sdRectangleShaderUtils
|
||||
|
||||
@@ -61,7 +61,7 @@ half4 main(float2 coord) {
|
||||
float2 normal = gradSdRoundedRectangle(centeredCoord, halfSize, gradRadius);
|
||||
|
||||
float refractedDistance = circleMap(1.0 - -sd / refractionHeight) * refractionAmount;
|
||||
float2 refractedDirection = normalize(normal + eccentricFactor * normalize(centeredCoord));
|
||||
float2 refractedDirection = normalize(normal + depthEffect * normalize(centeredCoord));
|
||||
float2 refractedCoord = coord + refractedDistance * refractedDirection;
|
||||
/*if (refractedCoord.x < 0.0 || refractedCoord.x >= size.x ||
|
||||
refractedCoord.y < 0.0 || refractedCoord.y >= size.y) {
|
||||
|
||||
Reference in new issue
Block a user