0

I can get Compose to render a fragment shader:

fun main() = singleWindowApplication(title = "Shaaaderrrs") {
    val runtimeEffect = remember {
        RuntimeEffect.makeForShader(
            """
                uniform vec3 iResolution;
                vec4 main(in vec2 fragCoord) {
                    return vec4(fragCoord / iResolution.xy, 0, 1); 
                }
            """.trimIndent()
        )
    }

    val shader by derivedStateOf {
        val builder = RuntimeShaderBuilder(runtimeEffect)
        builder.uniform("iResolution", 800.0f, 600.0f, 1.0f)
        builder.makeShader()
    }

    val brush by derivedStateOf {
        ShaderBrush(shader)
    }

    Surface(modifier = Modifier.background(MaterialTheme.colors.surface)) {
        Canvas(modifier = Modifier.fillMaxSize()) {
            drawRect(brush = brush, size = Size(800.0f, 600.0f))
        }
    }
}

From here, I'm trying to get some real pieces from ShaderToy to work.

Skia's shader language is SkSL, but it's similar enough to GLSL that many ShaderToy shaders work with very little modification.

Sometimes I am greeted by this exception:

java.lang.RuntimeException: error: program is too large
1 error
    at org.jetbrains.skia.RuntimeEffectKt._nMakeForShader(Native Method)
    at org.jetbrains.skia.RuntimeEffectKt.access$_nMakeForShader(RuntimeEffect.kt:1)
    at org.jetbrains.skia.RuntimeEffect$Companion.makeForShader(RuntimeEffect.kt:11)
    at com.example.common.ShaderToyKt.ShaderToy(ShaderToy.kt:46)
    at com.example.common.AppKt.App(App.kt:8)

This happens particularly often for raymarching shaders which tend to contain large loops. This is a pain for me, as I was particularly interested in using this to run raymarching demos.

So, how do I get this limit increased? The shader I'm trying works fine with GLSL in the browser, so I think it's completely reasonable to expect it to work here.

Hakanai
  • 12,010
  • 10
  • 62
  • 132

0 Answers0