Gaussian Blur

This forum is currently in read-only mode.
From the Asset Store
Basic Running Character useful for all sorts of games, prototyping, and more.
  • Hey guys,

    Is there any chance anyone here can implement a Gaussen blur .fx that can be adjusted through actions in the game? Right now, the horizontal, vertical blurs are pretty limiting in what one can do.

    If I need more blur I'm running two or more blur .fx shaders on a canvas object, which is really inefficient. Also, I'm not able to adjust the strength dynamically, which is really limiting, cause sometimes the camera has to zoom out and if the blur keeps the same strength value the game looks really off.

    All that would be solved if we'd have a single gaussian blur .fx file with an adjustable strength value that could be triggered during the runtime.

    Hope anyone finds some time to block this out.

    Some resources:

    http://vvvv.org/tiki-index.php?page=user+shaders (search for gaussian)

    http://www.grafnet.com.pl/

    http://www.gamasutra.com/features/20040 ... s_03.shtml

    http://digierr.spaces.live.com/blog/cns ... !860.entry

  • The blurmask effect works based on the lightness of the pixel - can you use that instead of blur? Try that, then setting the color filter of the canvas to RGB(mousex, mousex, mousex) and move the mouse from 0 to 255.

  • newt: Madsters blur effect is quite far away from what I get in Photoshop with a simple gaussian blur. I can change the strength alright, but if I raise the value from it's default 2.5 to 5.0 it does some really weird blurring, whereas a blur with a blending mode in Photoshop works great.

    In general, blur horizontal and blur vertical do give me the same effect I get in Photoshop, but there's no way to control their strength settings and I have to add a couple of those on top of one another to get what I want.

    Arima: Not sure I get what you're saying.

  • Photoshop's blur is not realtime. Actually, it usually takes more than one second to calculate, I'm sure you don't want that kind of framerate.

    The reason for photoshop's sluggishness is that it calculates a proper blur with the amount of samples equal to the size of your blur. You can't do that in realtime.

    HOWEVER, the gaussian kernel is separable, which means you can calculate a new blur with the results of the previous and the resould would be the same as taking b^n, where b is the number of samples of the original effect (12 in this case) and n is the number of times you execute the effect. The real size of the final blur will be s*n, where s is the size of the blur you're stacking, asuming they're all the same.

    At this point I feel it's a good idea to point out that ALL AAA 3D games do more than one pass of blur. So this is what you want to do, just like they do it.

    SO, for a pixel-perfect blur, you'd have to use a size of 6 because that means one sample per pixel (6 to each side, total 12 pixels for 12 samples) and then stack as many blurs as you need. Say you want to blur to about 100 pixels as in photoshop. That'd mean s*n = 6*n = 50

    then n= 100/6 = 8.3, you need to stack blur about 8 times on each axis. yeah.

    And yeah, that blur is per-pixel accurate up to size 6.

    Then again... I did say per-pixel accuracy is not feasible in real time. Let's use a blur that's a quarter as accurate, so size = 6*4 = 24. Now 24*n=50 means n=2.0

    Stacking blur two times for each axis will yield a quarter of the accuracy of a per-pixel blur for a 100px wide blur. Inefficient? Just like Bioshock and COD4 (only they use a trick we can't do in Construct to use even less samples, meaning they're even less accurate).

    Then again, if you attempt to stack ANY effect more than twice, CONSTRUCT CRASHES.

    Yeah. Did report it back then, still happens in 995. Wish it didn't.

    All that said, I've never tried blurring with blending. Can I get screenies of what goes wrong?

  • Try this: make a new .cap. Make a sprite, import a background. Next, create a canvas, fill it with white in the picture editor. Give it the blurmask effect.

    Next, make an event to always set the color filter of the canvas to RGB(mousex, mousex, mousex). In case you don't know, you have to right click the bar above the color to use an expression.

    Run it, move the mouse back and forth. The background behind the canvas will be blurred a varying amount depending on the mouse x position. The values for RGB are 0-255, so after that it repeats. The amount the effect blurs is based upon how bright the pixel is, so by using the color filter, it affects the amount of blur. Also, if you want to keep it from crashing, you can layer as many instances of an object with blurmask on top of each other as you want. Hits the framerate hard, though.

  • Thanks guys, some really good input here!

    madster: That might be true, but I guess this should still work:

    Blur Vertical and Blur Horizontal applied twice (means: Blur Vertical + Blur Vertical + Blur Horizontal + Blur Horizontal) gives me pretty much the result I want. So I guess it should be possible to just write one .fx shader that does exactly that - take blur vertical and blur horizontal twice each and give me a global strength that I can set in the effect globally AND still change during the runtime.

    I don't need an exact copy of Photoshops Gaussian Blur, I get something that's good enough with the method described above. The only 'problem', really, is that I have to apply the effects a couple of times and that I can't change the strength of it during the runtime, which sucks if I want to do perspective changes and can't change the blur level that's applied to the canvas object.

    Hope that makes sense now

  • Well then perhaps Arima's suggestion might be best. Although it seems the blur mask fx is limited to about 25 pixels.

  • Blur Vertical and Blur Horizontal applied twice (means: Blur Vertical + Blur Vertical + Blur Horizontal + Blur Horizontal) gives me pretty much the result I want. So I guess it should be possible to just write one .fx shader that does exactly that - take blur vertical and blur horizontal twice each and give me a global strength that I can set in the effect globally AND still change during the runtime.

    I think Ash mentioned that multi pass effects don't work in construct. You can adjust the strength of a blur with a blurmask shader+opacity for now, but hopefully someone will implement a value control for blur horizontal and blur vertical eventually.

  • I think Ash mentioned that multi pass effects don't work in construct.

    Yup. That's the reason. And multipass is the way to go, so the only way currently is stacking them.

    hopefully someone will implement a value control for blur horizontal and blur vertical eventually.

    I did, a good while ago O_O It's in the completed plugins forum.

    It's called "blur motion" and also has runtime angle control, so the horizontal and vertical fx are the same. Which means it crashes if you stack it four times X_x

    I guess you could copy it with another name and use two of each as a workaround.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I have your fx file Madster. I just didn't think it was the same blur quality as blur horizontal and blur vertical. I guess I didn't test it enough. I'll fully experiment with it when I get home.

  • It gave me a different effect than blur horizontal and blur vertical as well, that's why I didn't use it.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)