How to use Shader Derivative to add sharpness on Spark AR?

I’m trying to find a faster way of creating sharpness effect on Spark AR.

Hi @jepharaujo,
Maybe you could try to use the safe derivatives patch that Josh released in this thread:
and then use the output to overlay blend with the base texture.
because overlay blend makes the everything below 0.5 or 50% grey or #808080 darker, and above it lighter, then the edge contrast will be enhanced. I’d suggest to keep it subtle because if the camera is in lowlight or noisy, then it will also create sharper noise.
So I think you could adapt some photography retouching technique called high frequency separation,
So, before you put the the shader derivative patch, try to blur it a little bit to avoid noisy output.
You can check out Popul-ar new blur kit on Sugar:

to keep it fast performance, you could downsample the texture using shader render pass and reduce the size, so the convolution or averaging sample area is smaller before the blur.
Try using 2 layer of directional blur for x and y for faster blur, or gaussian if you prefer smoother blur, or use median blur to averaging the area but it would remove small details.
I hope you find it helpful. good luck :slight_smile:


The safe derivative has some tradeoffs, but it should work roughly the same as shader derivatives. Mainly, there’s something like 5% of phones that don’t support shader derivatives, so your effect won’t work on those devices if you use derivatives.

The safe derivative will be less efficient than the actual derivatives, but you can support that extra 5% if reach is a concern.

The actual derivatives will also be higher quality than the safe derivative, so that’s another thing to keep in mind.

One thing to note about the derivatives is that for some reason it doesn’t come with alpha, so you will need to swizzle it. Here’s an example, building off @Adi_Satrio’s comments:

1 Like