There's a few (here, and here) gaussian blur tutorials out there suggesting that you can essentially cut the number of texture lookups in a gaussian blur shader in half by exploiting the GPU's hardware linear filtering.
Essentially turning this:
Into this:
It sounds good in theory, but after attempting to implement this, I've come to the conclusion that it can't be done correctly, and I'd like someone to prove me wrong :)
My beef lies with the weights. Take the far left 2 texels in the first image. Their overall contribution to the shader equals:
t1 * w1 + t2 * w2
In the image, their weights 1 and 4, respectively. Now let us assign abitrary color values to the texels... 10 and 20. This gives their overall contribution, according to the formula, of 90. Great.
Now let us try to work this out with linear filtering.
What we want is essentially a new sampling location and a new weight, such that the value sampled at this new location, multiplied by the new weight, equals our original formula.
((t1 - t2 * new_offset) + t2) * w3 = t1 * w1 + t2 * w2
Let's make it easy and choose a sampling location halfway between texels 1 and 2, so that the value sampled is 15 (((10 - 20) * .5) + 20). So the new weight MUST be 6, so that 15 * 6 = 90. Ok great.
Now what happens when you change the values...instead of 10 and 20, you use 10 and 30. With the first way, you get 10 * 1 + 30 * 4 = 130. But with the linear sampling way, you get a linear sampled value of 20 ((10 + 30) / 2), times the weight of 6...120! It doesn't match!
Can anyone shed any light on why the linear sampling optimization is thought to work, and what I'm misunderstanding about it? I would be more than thrilled to be wrong about this :)