BradLarson / GPUImage3

GPUImage 3 is a BSD-licensed Swift framework for GPU-accelerated video and image processing using Metal.
BSD 3-Clause "New" or "Revised" License
2.68k stars 330 forks source link

Reinterpretation of vibrance? #121

Open chenglou opened 2 years ago

chenglou commented 2 years ago

Hello @RedQueenCoder! Followed your blog post http://redqueengraphics.com/2018/08/24/metal-shaders-vibrance/ to here =)

The negative vibrance uniform and the linear interpolation threw me off a bit: https://github.com/BradLarson/GPUImage3/blob/222868e1ba4137a9934b2135635783ef7083eb4d/framework/Source/Operations/Vibrance.metal#L19-L20

If we remove the negative uniform by propagating it into mix, things go from:

a(1 - x) + bx // definition of mix

to:

a(1 + x) - bx
<=> a + ax - bx
<=> a + (a - b)x
<=> a - (b - a)x // a - b is counterintuitive since in context, it'd be a negative delta. See code below

In the context of the code:

half amt = (mx - average) * uniform.vibrance * 3.0;
color.rgb = color.rgb - (mx - color.rgb) * amt;

Which gives an interpretation of vibrance as a function of the original color, minus the deltas (max - self) and (max - average).

I was wondering if this is a bit more intuitive. Or at least, it surfaces a curious mx^2 if we expand amt for some reason. The parallel with saturation's mix is lost though.

Feel free to close if not!