Reputation: 11
An AGSL shader will not animate on a Samsung S21, despite it working in the emulator on Android Studio.
Implementation of the shader is as follows:
val time by produceState(0f) {
while (true) {
withInfiniteAnimationFrameMillis {
launch {
value = if (clockUiState.showAnimations) {
it / 1000f
} else {
delay(1000)
1000f
}
}
}
}
}
val matrixShader = RuntimeShader(MatrixShader)
Canvas(modifier = Modifier
.fillMaxSize()
.onSizeChanged { size ->
matrixShader.setFloatUniform(
"resolution", size.width.toFloat(), size.height.toFloat()
)
}
.graphicsLayer {
matrixShader.setFloatUniform("time", time)
renderEffect = RenderEffect
.createRuntimeShaderEffect(
matrixShader,
"contents"
)
.asComposeRenderEffect()
}
) {
drawRect(Color.Red)
}
The actual shader code is irrelevant here as other shaders do not seem to work with this implementation either on the S21.
I'm attempting to implement an animated AGSL shader as a background in my app (yes I know it is power heavy , it will be for an app designed to use on a desk in a cradle). The shader works and animates correctly on the Android Studio Resizable emulator at API level 34. However when attempting to load it on my phone, a Samsung S21 with the same API level, the shader does not animate with time and just stops after 1 frame.
Based on the fact that it works on the emulator I would assume it is a hardware problem/limitation, however due to AGSL's lack of debugging/logging I have no way to know. Has anyone run into the same issue and know a work around or if it will just never work?
Upvotes: 1
Views: 45