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 cheapest car insurance Fargo ND on 27 de setembro de 2016 - 4:19 am

    бате по работе понадобился безпроводной интернет на ноут… Из всех модемов ему больше всего советовали мегафон. Купил этот модем по акциии 2 месяца безлимитка бесплатно… ну и чёт я немогу понять… изначально на счету было 999р… один день открл… через несколько дней смотрю а там уже 199р. чё за фигня? куда вс девается? боюсь щас деньги в минус уйдут и чё?

  2. #2 by emergency towing colorado springs on 27 de setembro de 2016 - 4:36 am

    I appreciate you sharing this post.Really looking forward to read more. Really Great.

  3. #3 by apply singapore pr on 27 de setembro de 2016 - 5:26 am

    Nice post!

  4. #4 by uniform on 27 de setembro de 2016 - 5:38 am

    Really fantastic info can be found on site. The fundamental defect of fathers is that they want their children to be a credit to them. by Bertrand Russell.

1 110 111 112
(não será publicado)