Variable size blur

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

Post » Fri May 22, 2009 8:08 am

Hello!

Made an effect. This here is the first draft, will be *vastly* improved soon.
Things I'm looking into:
choosing number of samples.
Proper placement of samples.
Time-based randomization of samples.
Size of effect (don't understand it yet).

Things that are working:
-blur amount

Blur.fx:[code:dlvy8o5v]// Variable Blur
// Jorge Fuente-Alba
// PS 2.0

//#CROSS-SAMPLING : reads pixels it may be writing.
//#BORDER-MODE : samples pixels outside bounding box
//#PARAM float blur 2.5 : Blur : amount of blur.



// Foreground texture
texture ForegroundTexture;

// Foreground sampler
sampler2D foreground = sampler_state {
Texture = (ForegroundTexture);
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
};

// Parameter variables
float pixelWidth;
float pixelHeight;
float blur;

// Effect function
float4 EffectProcess( float2 Tex : TEXCOORD0 ) : COLOR0
{
// Add the front and back pixels
float4 here = tex2D(foreground, Tex.xy)*0.25;
float4 left = tex2D(foreground, float2(Tex.x - (pixelWidth*blur), Tex.y))*0.1875;
float4 right = tex2D(foreground, float2(Tex.x + (pixelWidth*blur), Tex.y))*0.1875;
float4 top = tex2D(foreground, float2(Tex.x, Tex.y - (pixelHeight*blur)))*0.1875;
float4 bottom = tex2D(foreground, float2(Tex.x, Tex.y + (pixelHeight*blur)))*0.1875;

return here + left + right + top + bottom;
//float4 src = tex2D(foreground, Tex.xy);

//return result * (1-src.a) + src;

}

// ConstructEffect
technique ConstructEffect
{
pass p0
{
VertexShader = null;
PixelShader = compile ps_2_0 EffectProcess();
}
}
[/code:dlvy8o5v]

Example .cap using it: [url:dlvy8o5v]http://www.udec.cl/~jfuente_alba/blur_example.cap[/url:dlvy8o5v]
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665

Post » Fri May 22, 2009 2:08 pm

Didn't dload yet, but does it support changing blur amount at runtime?

EDIT: It does! sweet! thanks for this madster, will definately come in handy. I also noticed it's not as smooth as the other blur shader, but you said it's vastly unfinished.... so improve it NOW!
B
25
S
3
G
6
Posts: 1,197
Reputation: 5,620

Post » Fri May 22, 2009 8:37 pm

I checked the horizontal and vertical blur and they're 12-tap. I thought they were 3-tap :O
so anyways, that means I should go with a 12-tap poisson disc filter.
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665

Post » Fri May 22, 2009 10:35 pm

Okay.
Turns out the horizontal and vertical blurs are in fact 13-tap gaussian kernels and gaussian is separable, so it's much better to do in two-pass where you end up with 13^2 taps.
So, I present thee Vertical and Horizontal blur plus. All I did was normalize the size then multiply the kernel by a size.

[url:3mko6qqx]http://www.udec.cl/~jfuente_alba/Blur%20Horizontal%20Plus.fx[/url:3mko6qqx]
[url:3mko6qqx]http://www.udec.cl/~jfuente_alba/Blur%20Vertical%20Plus.fx[/url:3mko6qqx]

Also, I made a 13-tap Poisson disc blur kernel. You can see how it looks less smooth. Apply twice and it looks just like gaussian (but distributed as Poisson, natch). Weights are the same as Gaussian right now, I need to do some research and get the right coefficients for a Poisson distribution.
Meanwhile, the unfinished Poisson disc:
[url:3mko6qqx]http://www.udec.cl/~jfuente_alba/Blur%20Disc.fx[/url:3mko6qqx]
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665

Post » Sat May 23, 2009 11:16 am

Hope I'm not getting annoying, but I was really lacking several blur types.

So, here's yet another variable size gaussian blur, only this time you can choose the ANGLE.
Very useful for motion blurring, its faster than doing the fullscreen thing.

Good for ninjas. And stuff.
[url:3txad3mc]http://www.udec.cl/~jfuente_alba/Blur%20Motion.fx[/url:3txad3mc]

It's almost just as fast as horizontal and vertical plus, so I guess it replaces them (just do two passes, one with angle 0 and another with angle 90).

Included example: scirra logo moving with per-sprite motion blur.
[url:3txad3mc]http://www.udec.cl/~jfuente_alba/blur_motion_example.cap[/url:3txad3mc]


Edit: as per Shviller's request: a motion trail effect, similar to motion blur but only in the direction of the angle.
[url:3txad3mc]http://www.udec.cl/~jfuente_alba/Motion%20Trail.fx[/url:3txad3mc]
[url:3txad3mc]http://www.udec.cl/~jfuente_alba/motion_trail_example.cap[/url:3txad3mc]
Edit: bleh fudged the weights in the Motion Trail effect. Will fix tomorrow.

Only one blur type remaining in my list :P
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665

Post » Sat May 23, 2009 2:33 pm

Nice - I've been wanting an angle blur for a while! Thanks!
Moderator
B
87
S
32
G
33
Posts: 3,005
Reputation: 27,397

Post » Sat May 23, 2009 4:06 pm

These are a good idea - but your algorithm is wrong, it's not a true blur. What it's really doing (and it's obvious from the shader code that it does this) is additively blending a set of offset images. This looks like a blur for low radius values, but doesn't work for high blur values. If the sampling points are more than one pixel apart, then a kind of stepped shadow becomes visible.



This is why I haven't added variable blur radius to the existing blur horizontal and blur vertical: if the blur value goes too high, you get shadowing, and if it goes too low, you're sampling the same pixel more than once, which is inefficient. A true blur has to take in to account every single pixel over a range.

They're still useful though, and something like Motion Blur would be cool to adapt in a way like Blur Horizontal works :)
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

Post » Sat May 23, 2009 10:12 pm

[quote="Ashley":1k8hnnsi]...is additively blending a set of offset images.[/quote:1k8hnnsi]
not additive, it's an average. It's just a blur with a low sample count, suitable for real time. This is how current games do it (CoD4, Bioshock, Far Cry 2, etc etc).

[quote="Ashley":1k8hnnsi]if the blur value goes too high, you get shadowing, and if it goes too low, you're sampling the same pixel more than once, which is inefficient. A true blur has to take in to account every single pixel over a range.[/quote:1k8hnnsi]
This *is* a true blur. It's just low quality. Also, Motion Blur at size 25 is *exactly* like Horizontal and Vertical blur, since I modified them (normalized the kernel and introduced a factor). Only now you can smoothly go back to focus... or push it to a larger size, risking it looking bad. Designer's call.

I'll be using it lots, at least. Already managed to cut down on assets on rocket-days by dropping the preblurred and decolored hills and replacing them with instances of the normal assets with shaders.

Do try out the Motion Blur demo. shows how it looks, and it's gooood, specially the pulsating text below:
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665

Post » Sat May 23, 2009 10:29 pm

Yeah, fair enough. True blurs can be done faster by downsampling, blurring the smaller image, then linear filtering the small image up to the original size again, but the rendering engine in the runtime can't support this right now - it'll be included in 2.0 though.
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

Post » Sun May 24, 2009 7:07 am

I love the effect, but it still looks kinda separatey the way regular motion blur does on my machine. Not nearly as bad though, especially at lower settings.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Next

Return to Construct engineering

Who is online

Users browsing this forum: No registered users and 0 guests