Skip to Main Content
Learning XNA 3.0
book

Learning XNA 3.0

by Aaron Reed
November 2008
Beginner content levelBeginner
510 pages
16h 24m
English
O'Reilly Media, Inc.
Content preview from Learning XNA 3.0

HLSL Effects: Blur

Another very simple effect is blurring the image. To do this, you grab the color of each pixel in the texture and add to it the colors from the pixels adjacent to the target pixel. To try this, replace the pixel shader in your game with the following code:

float4 PixelShader(VertexOut input) : COLOR0
{
    float4 Color;
    Color =  tex2D(ColoredTextureSampler, input.textureCoordinates.xy);
    Color += tex2D(ColoredTextureSampler, input.textureCoordinates.xy + (0.01));
    Color += tex2D(ColoredTextureSampler, input.textureCoordinates.xy − (0.01));
    Color = Color / 3;

    return Color;
}

This effect will require pixel shader 1.4 or higher, so change the line in your technique that defines the pixel shader to:

PixelShader = compile ps_1_4 PixelShader(  );

Tip

Wouldn't you always want to use the latest and greatest pixel shader? Why even bother with pixel shader 1.1?

In fact, you should always use the lowest-version pixel shader that you can, depending on the functions that you are going to implement. The reason? Graphics cards only support certain pixel shader and vertex shader versions. If you don't need to use version 1.4, but you tell HLSL to use that version anyway, some users might not be able to run your game because their graphics cards might only support pixel shader 1.1 (even though they ought to be able to run your game because you're not actually using any of the functions in pixel shader 1.4).

The result will be a blurred image, as shown in Figure 13-8.

Figure 13-8. Blurred image ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning XNA 4.0

Learning XNA 4.0

Aaron Reed
Beginning C# 7 Programming with Visual Studio 2017

Beginning C# 7 Programming with Visual Studio 2017

Benjamin Perkins, Jacob Vibe Hammer, Jon D. Reid

Publisher Resources

ISBN: 9780596154905Supplemental ContentErrata Page