canvaskit-wasm 0.39 build 2026-04-29

RuntimeEffect

Compile your own SkSL shader source at runtime, get back a RuntimeEffect, instantiate Shader instances from it. SkSL is Skia's GLSL-like shading language — same syntax for vertex / fragment math, same uniforms model.

const sksl = ` uniform float u_time; uniform float2 u_resolution; half4 main(float2 xy) { float2 uv = xy / u_resolution; float r = 0.5 + 0.5 * sin(u_time + uv.x * 6.28); float g = 0.5 + 0.5 * sin(u_time + uv.y * 6.28 + 2.0); float b = 0.5 + 0.5 * sin(u_time + (uv.x + uv.y) * 6.28 + 4.0); return half4(r, g, b, 1.0); } `; const effect = CK.RuntimeEffect.Make(sksl); const paint = new CK.Paint(); let t = 0; loop(() => { t += 0.02; const shader = effect.makeShader([t, w, h]); paint.setShader(shader); canvas.drawRect(CK.LTRBRect(0, 0, w, h), paint); shader.delete(); surface.flush(); });

effect.makeShader(uniforms) allocates a new Shader per call — delete inside the loop or you'll leak one shader per frame. Uniforms are passed as a flat number[]; their order matches the uniform declarations in the SkSL source.

Members

MemberArgsReturnsNotes
deletevoidFree the WASM memory. Required.
getUniformCountnumberNumber of uniforms in the program.
getUniformFloatCountnumberTotal float slots across all uniforms (the array length you pass to makeShader).
getUniformi: numberSkSLUniformMetadata for the i-th uniform.
getUniformNamei: numberstringName of the i-th uniform.
makeShaderuniforms: number[] | Float32Array, localMatrix?: MatrixShaderInstantiate a shader with these uniform values.
makeShaderWithChildrenuniforms, children: Shader[], localMatrix?: MatrixShaderInstantiate with child shaders that the SkSL program samples (declared as uniform shader in source).

Static factories

FactoryArgsReturnsNotes
CK.RuntimeEffect.Makesksl: string, errorCallback?: (msg: string) => voidRuntimeEffect | nullCompile SkSL source. Returns null on compile error; errorCallback receives the diagnostic.
CK.RuntimeEffect.MakeForBlendersksl: string, errorCallback?RuntimeEffect | nullCompile a SkSL blender (operates on src+dst rather than just src).

See also