# How to blur part of the screen in the game engine?

I'm making an FPS game, and for some of my guns, i want to be able to zoom in so that i can see farther. This isn't the problem. What i really want is to make the rest of the screen (The part not looking through the scope) blurry so that it looks like the character is focusing through the scope.

I want everything that is not seen directly through the scope to be blurred, for example, refer to the scopes of Crysis 3.

• You can use a 2Dfilter to accomplish this. Probably also with a few custom uniforms so you can pass the information to the shader about when and where to blur. – Mike Pan Aug 5 '14 at 18:34
• Are you looking to simulate DOF (Depth of Field), or do you specifically want to blur everything not in scope, by the same factor, regardless of distance from focus point? – Goran Milovanovic Oct 12 '14 at 4:07
• Does this help at all? – VRM Jan 10 '15 at 2:54
• @GoranMilovanovic I want to blur everything not in the scope – christai Jan 27 '15 at 9:40

How it works: the shader gets the rendered image as a texture its x/y coordinates range from 0 to 1.0

The distance from center is calculated by sqrt(x*x+y*y) > .3 to exclude a circular region from blur.

uniform sampler2D bgl_RenderedTexture;

void main(void)
{
vec4 texcolor = texture2D(bgl_RenderedTexture, gl_TexCoord[0].st);
float x =  gl_TexCoord[0].st.x - .5;
float y =  gl_TexCoord[0].st.y - .5;

if ( sqrt(x*x+y*y) > .3 ) {
float value = 0.0015;
vec4 color = texture2D(bgl_RenderedTexture, vec2(gl_TexCoord[0].st.x + value, gl_TexCoord[0].st.y + value)); // Sample area around current pixel
color += texture2D(bgl_RenderedTexture, vec2(gl_TexCoord[0].st.x - value, gl_TexCoord[0].st.y - value));
color += texture2D(bgl_RenderedTexture, vec2(gl_TexCoord[0].st.x + value, gl_TexCoord[0].st.y - value));
color += texture2D(bgl_RenderedTexture, vec2(gl_TexCoord[0].st.x - value, gl_TexCoord[0].st.y + value));
color /= 4.0;
gl_FragColor = color;
}
else {
gl_FragColor =texcolor;
}
}


Node setup: Add a Filter 2D configure it as Custom Shader and select the above script.

Sample render

Disclaimer: A decent blur needs to incorporate values from a 3x3, 5x5 or bigger matrix, the sample code only uses the left and right neighbor.

• Gosh this was a while back, sorry for not confirming your answer yet :/ Is the float value the blur amount? And how would I incorporate a matrix? – christai Feb 24 '17 at 9:51