https://kotlinlang.org logo
#compose-desktop
Title
# compose-desktop
a

Alejandro Rios

07/12/2023, 2:02 AM
Is there any example on how to implement a
floatUniform
effect for a runtime shader in desktop?
I'm looking how to adjust this parts of code using Compose Multiplatform
t

Timo Drick

07/12/2023, 8:18 AM
I am not sure if it is possible to use custom shaders in graphicsLayer yet. But you could use this code which is working:
Copy code
fun Modifier.skslBackground(
    effect: RuntimeEffect,
    uniforms: (RuntimeShaderBuilder) -> Unit = {}
): Modifier = composed {
    val density = LocalDensity.current
    this.drawWithCache {
        val builder = RuntimeShaderBuilder(effect)
        println("size: ${size.width}x${size.height}")
        builder.uniform("iResolution", size.width, size.height, 1f)
        builder.uniform("iDensity", density.density)
        uniforms(builder)
        val shader = builder.makeShader()
        val brush = ShaderBrush(shader)
        onDrawBehind {
            drawRect(brush = brush, topLeft = Offset.Zero, size = size)
        }
    }
}
3 Views