SkImageFilters::Shader examples?

Skip to first unread message


May 3, 2022, 1:35:49 PMMay 3
to skia-discuss

Is there an example somewhere about the SkImageFilters::Shader?

I need to build an image filter with a custom shader that applies a motion blur, so I'm looking for some examples, especially about the uniforms the image filter might pass to the shader, containing the surface content.

I already built an SkRuntimeShader which works correctly, but now I need an imageFilter, because I need to apply it to a paint object passed to the saveLayer function.

Thank you!

Brian Osman

May 3, 2022, 1:47:53 PMMay 3
There are two examples in:

The second one (rtif_unsharp) is fairly minimal so might be the easiest to work from. The basic idea is that if you already have a runtime shader that does what you want, you can have the "content" that you're filtering be a `uniform shader` input to that shader. When you make the SkImageFilters::RuntimeShader call, you can give it a SkRuntimeShaderBuilder that already has any uniform values you want populated. You also specify two parallel arrays. One has the names of `uniform shader` variables in your SkSL. The other has `SkImageFilter` nodes that are bound to those child shaders when the filter is evaluated. Any child that's left as `nullptr` is bound to the "implicit" image filter input (eg, the layer contents, if you're applying the filter as part of a saveLayer call).

You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit


May 5, 2022, 2:58:09 AMMay 5
to skia-discuss
Thanks! It's exactly what I needed
Reply all
Reply to author
0 new messages