Add RuntimeShader Support.#3141
Conversation
|
@dotnet-policy-service agree |
|
Here is a demo. |
There was a problem hiding this comment.
Thanks for this PR. This looks like a good feature to get in. Sorry about the long wait for a review @kkwpsv. 😞
I know the C++ API has this different way to make the "shader", but it always felt a bit odd to have this in sort of separate locations when the Shader, Blender and ColorFilter were all in SKRuntimeEffect.
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
They dropped the different builders in C++, so we might avoid exposing this at all in the C API: https://github.com/google/skia/blob/main/include/effects/SkImageFilters.h#L458. I would think we could rather do what we did for all the others and just pass the values all in as args:
sk_shader_t* sk_runtimeeffect_make_shader(sk_runtimeeffect_t* effect, sk_data_t* uniforms, sk_flattenable_t** children, size_t childCount, const sk_matrix_t* localMatrix)They have this PR where they removed the builders and just have the base one: google/skia@0b776ce. I don't think we should do that as the separate builders are OK and also allow for a more fluent style code. But, that is also up for discussion.
Let me know what you think about these ideas!
I think there is no problem with your idea. |
|
@kkwpsv are you able to make the changes? |
|
Need any help? This all sounds very exciting! |
|
Any updates? I tried the example repo, curious if it could handle the Balatro background effect shader. kkwpsv/AvaloniaSkiaRuntimeShaderDemo#1 Works super well :) |
|
Closing — superseded by #3778 which implements the full SkSL image filter API (ToImageFilter + SKRuntimeImageFilterBuilder) with the updated m147 Skia APIs. Thank you for the contribution! |
Description of Change
Add RuntimeShader support.
See #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
mono/skia#145
PR Checklist