Updating shader uniforms for animated effects

61 views
Skip to first unread message

Mike Clifton

unread,
Mar 30, 2024, 8:59:41 AMMar 30
to skia-discuss
I'm working with a SkRuntimeShaderBuilder object, and I want to update the values of some uniforms over time for an animated effect. To create the actual shader to use with the SkPaint object, I call SkRuntimeShaderBuilder::makeShader

It seems I need to call SkRuntimeShaderBuilder::makeShader whenever I change the values of the uniforms, and then I use that new shader. When I do this, it all appears to work as expected, but I want to make sure I'm not doing something horribly inefficient.

Is it appropriate to maintain the same SkRuntimeShaderBuilder object, modify its uniforms, and then call makeShader over and over again? If I try to re-use the result of makeShader to be more efficient, I'm not sure how to change the values of the uniforms.

John Stiles

unread,
Mar 30, 2024, 9:00:41 AMMar 30
to skia-d...@googlegroups.com
You're doing it properly. This should be efficient. 

--
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/91bc7f28-cc35-47a7-a3ad-f291c5065aa5n%40googlegroups.com.

Brian Osman

unread,
Mar 30, 2024, 9:01:47 AMMar 30
to skia-d...@googlegroups.com
Yeah, you're using it right. Many Skia objects (like SkShader) are immutable - once created, they're set in stone. In this case, most of the information about the shader is actually stored on the SkRuntimeEffect (and that's held by reference), so the only thing being copied each time is basically the updated values for all the uniforms - makeShader just creates a snapshot of the uniform and child data.

On Sat, Mar 30, 2024 at 8:59 AM Mike Clifton <mike.o....@gmail.com> wrote:
--

Mike Clifton

unread,
Mar 30, 2024, 2:42:46 PMMar 30
to skia-discuss
Awesome - thanks!
Reply all
Reply to author
Forward
0 new messages