Hey! I'm experimenting with shaders and SKSL/AGSL ...
# compose-web
m
Hey! I'm experimenting with shaders and SKSL/AGSL in a Compose Multiplatform project and have encountered an issue with shaders and uniforms. I'm using a bitmap as a uniform in shader code to manipulate it, and while it works fine on all platforms, it doesn't behave as expected on Kotlin/Wasm. Is this a known issue, or is it not supported at the moment?
This is a simplified version of the shader I'm using:
Copy code
uniform float2 iResolution;
uniform shader iBitmap; 

half4 main(vec2 fragCoord) {
    half4 col = iBitmap.eval(fragCoord);
    return half4(col.rgb, 1.); 
}
And I'm setting uniform by calling
child
function:
Copy code
child("iBitmap", ImageShader(imageBitmap))
k
Maybe I missed something when I added those bindings. The JS pipeline has different bindings from everything else
m
Not sure, but I've tried also Kotlin/JS and same issue happens there
More finding: using color-based shader works fine:
Copy code
child(it.name, Shader.Companion.makeColor(Color.RED))
Could it be something related to colour space mapping?
k
I’d first check that your image shader is doing the right thing as a standalone shader - something along the lines of https://github.com/android/snippets/blob/07b51c299a4a7c443060fa924b284b31de48307a/[…]a/com/example/compose/snippets/graphics/BrushExampleSnippets.kt but with your source image. Then, after you verify that, file a bug with a fully reproducible code that can be copy-pasted without modifications.
gratitude thank you 1
m
I found the issue: I was loading an image from
composeResources
using
imageResource
. After adding some logs around the returned bitmap, I realised that the image size was 1x1. Probably some asynchronous loading mechanism is in place for the web. I tried to load and decode the image explicitly, and the issue is now sorted out. This is the code I'm using for loading and decoding it:
Copy code
var bitmap by remember { mutableStateOf<Image?>(null) }
LaunchedEffect(Unit) {
    val byteArray = getDrawableResourceBytes(
        getSystemResourceEnvironment(),
        Res.drawable.img_03
    )
    bitmap = makeFromEncoded(byteArray)
}
Not the best code but works fine on my use case.
👍 1