SkImageFilters::Shader examples?

48 views
Skip to first unread message

Giuseppe

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

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

unread,
May 3, 2022, 1:47:53 PMMay 3
to skia-d...@googlegroups.com
There are two examples in: https://source.chromium.org/chromium/chromium/src/+/main:third_party/skia/gm/runtimeimagefilter.cpp

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 skia-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/80565085-30b5-46ac-b412-1c1f0e872902n%40googlegroups.com.

Giuseppe

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