Gaussian Blur

Forum for plugin, effect and behavior programmers. Please use the Help & Support forum for help using Construct.

Post » Sun Oct 18, 2009 8:17 pm

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
B
6
S
2
G
3
Posts: 520
Reputation: 2,690

Post » Sun Oct 18, 2009 8:53 pm

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.
Moderator
B
88
S
32
G
33
Posts: 3,005
Reputation: 27,432

Post » Sun Oct 18, 2009 10:39 pm

[url:3epx9aou]http://www.scirra.com/phpBB3/viewtopic.php?f=7&t=3719&st=0&sk=t&sd=a[/url:3epx9aou]
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Mon Oct 19, 2009 1:02 am

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.
B
6
S
2
G
3
Posts: 520
Reputation: 2,690

Post » Mon Oct 19, 2009 2:25 am

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?
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665

Post » Mon Oct 19, 2009 3:40 am

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.
Moderator
B
88
S
32
G
33
Posts: 3,005
Reputation: 27,432

Post » Mon Oct 19, 2009 4:51 am

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 :)
B
6
S
2
G
3
Posts: 520
Reputation: 2,690

Post » Mon Oct 19, 2009 8:40 am

Well then perhaps Arima's suggestion might be best. Although it seems the blur mask fx is limited to about 25 pixels.
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Mon Oct 19, 2009 1:56 pm

[quote="thomasmahler":ukdbameq]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.
[/quote:ukdbameq]
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.
B
25
S
3
G
6
Posts: 1,197
Reputation: 5,620

Post » Tue Oct 20, 2009 12:22 am

[quote="Davioware":6d8rhzq9]I think Ash mentioned that multi pass effects don't work in construct.[/quote:6d8rhzq9]
Yup. That's the reason. And multipass is the way to go, so the only way currently is stacking them.

[quote="Davioware":6d8rhzq9]hopefully someone will implement a value control for blur horizontal and blur vertical eventually.[/quote:6d8rhzq9]
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.
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665

Next

Return to Construct engineering

Who is online

Users browsing this forum: No registered users and 0 guests