SkiaSharp icon indicating copy to clipboard operation
SkiaSharp copied to clipboard

Add RuntimeShader Support.

Open kkwpsv opened this issue 10 months ago • 4 comments

Description of Change

Add RuntimeShader support. See https://github.com/mono/SkiaSharp/issues/3137.

Bugs Fixed

None.

API Changes

Added:

  • SKImageFilter SKImageFilter.CreateRuntimeShader(SKRuntimeShaderBuilder builder, string childShaderName, SKImageFilter? input)
  • SKImageFilter SKImageFilter.CreateRuntimeShader (SKRuntimeShaderBuilder builder, float maxSampleRadius, string childShaderName, SKImageFilter? input)
  • SKImageFilter SKImageFilter.CreateRuntimeShader (SKRuntimeShaderBuilder builder, float maxSampleRadius, string[] childShaderNames, SKImageFilter?[] inputs)
  • SKRuntimeEffectUniforms (SKRuntimeEffectUniforms effectUniforms)
  • SKRuntimeEffectChildren (SKRuntimeEffectChildren effectChildren)
  • SKRuntimeEffectBuilder (SKRuntimeEffectBuilder builder)
  • SKRuntimeShaderBuilder (SKRuntimeShaderBuilder builder)

Behavioral Changes

None.

Required skia PR

https://github.com/mono/skia/pull/145

PR Checklist

  • [ ] Has tests (if omitted, state reason in description)
  • [ ] Rebased on top of main at time of PR
  • [ ] Merged related skia PRs
  • [ ] Changes adhere to coding standard
  • [ ] Updated documentation

kkwpsv avatar Jan 15 '25 09:01 kkwpsv

@dotnet-policy-service agree

kkwpsv avatar Jan 15 '25 09:01 kkwpsv

Here is a demo. https://github.com/kkwpsv/AvaloniaSkiaRuntimeShaderDemo

kkwpsv avatar Jan 16 '25 01:01 kkwpsv

I wonder if instead of putting the code in SKImageFilter, we rather add a SKRuntimeImageFilterBuilder and in fact mirror most of what we do for SKShader but instead of using the word shader like in C++ we use the word ImageFilter. I would even go so far as to add a CreateImageFilter method that just calls into CreateShader. And then also make a BuildImageFilter that then calls that - which would mean it really is just a shader. The Build() method on this would then call the image filter code in the C API and return a new SKImageFilter

I think there is no problem with your idea. What I am doing now is just to make the API close to C++.

kkwpsv avatar Feb 28 '25 02:02 kkwpsv

@kkwpsv are you able to make the changes?

mattleibow avatar Mar 13 '25 17:03 mattleibow

Need any help? This all sounds very exciting!

taublast avatar Jun 21 '25 08:06 taublast

Any updates? I tried the example repo, curious if it could handle the Balatro background effect shader.

https://github.com/kkwpsv/AvaloniaSkiaRuntimeShaderDemo/pull/1

Works super well :)

OptimusPi avatar Jul 03 '25 18:07 OptimusPi