Re: [css3-background] Where we are with Blur value discussion

On Wed, Jul 14, 2010 at 5:30 PM, Brad Kemper <brad.kemper@gmail.com> wrote:
> On Jul 14, 2010, at 5:17 PM, "Tab Atkins Jr." <jackalmage@gmail.com> wrote:
>
>> If we can get everyone to agree that we want to require a gaussian
>> blur, then I'm more than happy to provide the exact equation you can
>> plug the blur length into to get a stdev to hand to the gaussian blur
>> function.  I don't think everyone will agree to that, though.
>
> If you could do that as an example of how to achieve the required results, then maybe we could all be relatively happy.

Welp, as it turns out you can't invert the gaussian blur function with
elementary functions.  Doing it right requires the use of the Lambert
W function, which must be solved numerically for most cases.

The exact answer is given by:

stdev = sqrt( -x^2 / W( -2 * pi * G^2 * x^2 ))

Where X is the blur distance (distance from the edge, so half the
total area affected by the blur) and G is the fraction you're trying
to hit (.01 for 99% transparency).

W() then has to be approximated numerically using Newton's method or
similar.  It's still somewhat expensive, as it involves a couple of
exponentials (though, they're all the same, so I guess it can be
computed once, in which case it turns into ordinary +-*/ math).  Given
an appropriate guess, which is easy to get, I suspect you could
iterate just once or twice to get a usable approximation.

Alternately, we could just ensure that the allowed range was narrow
enough to look the same for "reasonable" shadows, but wide enough for
cheap-and-dirty approximations to safely nestle into it.  Allowing the
99% point to come within +- 2% of the specified length should ensure
that shadows with a blur of less than 10px or so to be guaranteed to
be the same size (modulo rounding), and I suspect allows enough room
for a cheap approximation to be usable.

~TJ

Received on Thursday, 15 July 2010 21:09:34 UTC