2
\$\begingroup\$

I am currently trying to implement shadows into my game, and after a lot of searching in the interwebs I came to the conclusion that drawing hard edged shadows to a low resolution pass combined with a Gaussian blur effect would fit best and make a good compromise between performance and looks - even though theyre not 100% physically accurate.

Now my problem is, that I dont really know how to implement the Gaussian blur part. Its not difficult to draw shadows to a low resolutions buffer image and then stretch it which makes it more smooth, but I need to add the Gaussian blur effect.

I have searched a lot on that and found some approachs for GLSL, some even here, but none of them really helped it.

My game is written in Java using Slick2D/LWJGL and I would appreciate any help or approaches for an algorithm or maybe even an existing library to achieve that effect.

Thanks for any help in advance.

\$\endgroup\$
1
  • \$\begingroup\$ Maybe I misunderstand the question but calculate a new image from your old one using a kernel that smooth out the values. Or is there some other part that hinders you? \$\endgroup\$ Jun 8, 2014 at 20:27

2 Answers 2

2
\$\begingroup\$

I tackled almost an Identical problem about a year ago. Since then I've figured out how to add gaussian blur to create better shadows. I'm assuming you're starting from a point like this: Shadow Blog Post, Image of Shadows With No Blur. And this is what you're after Image of Shadows WITH Blur.

My lighting system code that included shadows can be found here: Lighting Manager. I ended up using a Shader "Wrapper" by Jeremy Klix here: Shader Wrapper.

The shaders I used are here: Shaders. Take a look at the bassicBlur.vrt, blurHorz.frg and blurVert.frg. Combined they are a simple 2 pass (X then Y) gaussian blur. I define the 2 (horizontal and vertical) shader objects around line 66. Then during rendering, I use the shaders around 135. The shader takes two parameters: radius of the blur and the resolution of the rendered area. The idea is that you:

  1. Enable the shader
  2. Enable a multiple blend function
  3. Draw the shadow map
  4. Revert the blend function
  5. Disable the shader

Let me know if you'd like more details.

\$\endgroup\$
0
\$\begingroup\$

The good news is that constant width Gaussian filter is separable thus you can gain good performance even for large kernel sizes, i.e this cuts the computation from the naive O(n^2) cost down to O(2n). The separable Gaussian filter is implemented by having two passes over the image: First performing 1D horizontal Gaussian blur, followed by 1D vertical Gaussian blur. This is pretty much the standard way to implement Gaussian filter nowadays. Here is an explanation how to implement it in GLSL,

\$\endgroup\$

You must log in to answer this question.