Adding Inner Shadow in Skia

I came across this code to create inner shadow in Skia. I replicated it in vvvv:

trying-inner-shadow.vl (31.9 KB)

You’d notice that in my replica DropShadowOnly works but DropShadowAndForeground doesn’t. When I choose DropShadowAndForeground, I expected to see a pink rectangle with some shadow at its sides but I’m seeing a black rectangle instead.

I suspect it is not working because in the code sourceGraphic is defined like so:

auto sourceGraphic = SkImageFilters::ColorFilter(
        SkColorFilters::Blend(SK_ColorBLACK, SkBlendMode::kDst), nullptr);

But if I do the same in vvvv I get a null error:

I had to put an AvoidNULL node in between to suppress the exception. But putting it also meant I’ll get the fallback value and not the value I actually wanted.

How do I solve this? I want the error to go away while keeping the actual functionality.

TL;DR: waiting for a better inner shadow implementation.


Turns out this can be solved by removing all nodes preceding sourceGraphic. We won’t even keep CreateColorFilter there for sourceGraphic as it by default applies some filter that affects the output.

The error was occuring because SkiaSharp shim has placed some null checks in between.

That being said, this isn’t the final solution. The inner shadow implementation I referenced is imperfect, as it doesn’t properly puts shadow on a shape which has some opacity in it. I have raised a ticket about it.