Code Snippet: Radial Blur shader

This short code snipped will show how to make a simple radial blur as a post effect pass. The effect is cool and the code is preeeetty simple.

If you are in XNA, you can use it in spritebatch (make a shader with a pixel shader only, set it and call the classic spritebatch to draw the image) or you can use in DirectX, Opengl (minor changes)

sampler TextureSampler : register(s0);

float2 Center = { 0.5, 0.5 }; ///center of the screen (could be any place)
float BlurStart = 1.0f; /// blur offset
float BlurWidth = -0.1; ///how big it should be
int nsamples = 10;

float4 PS_RadialBlur(float2 UV	: TEXCOORD0 ) : COLOR
    UV -= Center;
    float4 c = 0;
    for(int i=0; i <nsamples; i++) {
    	float scale = BlurStart + BlurWidth*(i/(float) (nsamples-1));
    	c += tex2D(TextureSampler, UV * scale + Center );
   	c /= nsamples;
    return c;

Experiment changing the nsamples parameter. You can also put it as a uniform variable and force the compiler to unroll the for loop =P

Enjoy !


  1. #1 by tack mats on 23 de julho de 2017 - 1:42 pm

    that could be the end of this report. Right here you will locate some web pages that we think you will appreciate, just click the links over

  2. #2 by on 23 de julho de 2017 - 2:13 pm

    I every time spent my half an hour to read this website’s articles or reviews daily along with a cup of

  3. #3 by Pet friendly Biloxi Rentals on 23 de julho de 2017 - 4:48 pm

    Every the moment inside a even though we select blogs that we study. Listed beneath would be the most recent internet sites that we pick

  4. #4 by Home Improvement on 23 de julho de 2017 - 5:33 pm

    I like this website so much, bookmarked. “I don’t care what is written about me so long as it isn’t true.” by Dorothy Parker.

  5. #5 by Pascagoula rentals on 23 de julho de 2017 - 5:51 pm

    just beneath, are quite a few completely not associated websites to ours, having said that, they are certainly worth going over

  6. #6 by Biloxi HVAC services on 23 de julho de 2017 - 6:26 pm

    Sites of interest we’ve a link to

  7. #7 by Mississippi vacation on 23 de julho de 2017 - 7:22 pm

    Wonderful story, reckoned we could combine several unrelated information, nonetheless genuinely worth taking a appear, whoa did a single learn about Mid East has got much more problerms at the same time

1 345 346 347
(não será publicado)