9
\$\begingroup\$

I'm using libGDX for an android game; as far as I can tell, it doesn't have an API for blurring.

Reading on Wikipedia, it seems like blur is formed by setting each pixels RGB values to the average of all adjacent values. Which doesn't seem easily possible in libGDX -- setting pixel data.

So my question is simple:

Is it possible to fake (a decent) blur using only images?

I can potentially overlay multiple (in number, transparency, type) images; but can I create a convincing blur like this?

I'm tempted to say "no," but maybe someone else has achieved something similar. For clarity, I want a set of 1+ generic images I can render on top of ANY image to generate a blur-like effect.

\$\endgroup\$
8
  • \$\begingroup\$ good question! I've thought of the same thing, myself! \$\endgroup\$
    – Daniel
    Oct 20, 2011 at 1:21
  • \$\begingroup\$ @DantheMan on which platform? \$\endgroup\$
    – ashes999
    Oct 20, 2011 at 1:40
  • \$\begingroup\$ Unity3d or the CG shading language. \$\endgroup\$
    – Daniel
    Oct 20, 2011 at 1:56
  • \$\begingroup\$ You suggest overlaying transparent images over one another. If you slightly offset them, you're going to be averaging the pixels, achieving blur \$\endgroup\$
    – Jeff
    Oct 20, 2011 at 2:30
  • 1
    \$\begingroup\$ @ashes999, if you're looking for a "magic image" that can be overlaid on things to make them appear blurry, that doesn't exist. Alpha-blending (overlaying) isn't remotely the same thing as blurring, sorry. \$\endgroup\$ Oct 20, 2011 at 2:51

2 Answers 2

7
\$\begingroup\$

If you're able to additively blend images and multiply them by a constant while doing so, then you can do a blur. Instead of averaging the pixels in a neighborhood, you'd average several copies of the image displaced by a small number of pixels from each other. Or more generally, you could do a Gaussian blur or whatever kind of blur, by controlling the weights - that is, multiplying each displaced copy of the image by a constant as it's being added onto the rest.

Algorithmically, it would look something like this:

clear output_image to 0
foreach offset, weight in filter_kernel:
    output_image += input_image * weight, shifted by offset

You'd use the same offsets and weights as in the standard way of doing a blur. There are plenty of articles on the Web on how to generate the weights for a Gaussian blur, for instance.

\$\endgroup\$
1
  • \$\begingroup\$ +1 nice answer. In my case, I don't have additive ability. \$\endgroup\$
    – ashes999
    Oct 20, 2011 at 2:57
0
\$\begingroup\$

Blurring can be an expensive operation, perhaps a different approach could work, e.g.:

  1. Store multiple copies of the image blurred in several different directions (e.g. multiples of 45 degrees), then display the closest matching image at runtime. This will offer the highest performance, at the cost of memory usage.
  2. Scale the image down and then back to full-size with anti-aliasing/smoothing. Often this can be done with graphics hardware with very little performance impact.
\$\endgroup\$
1
  • \$\begingroup\$ It won't work, because it has to be dynamic, i.e. I can't know the exact setup of the screen ahead of time. \$\endgroup\$
    – ashes999
    Oct 20, 2011 at 15:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .