径向模糊效果

最先在这里看到:http://www.gamerendering.com/2008/12/20/radial-blur-filter/

这效果在鬼泣4中切换场景时见过, 极品飞车12的运动模糊也有这种感觉.

原理:

    确定一个中心点(如0.5, 0.5), 跟当前像素连一条线. 以当前像素为中心, 在线上的附近像素进行采样, 最后取一下平均值.

代码翻译成HLSL:

  1. // This texture should hold the image to blur.   
  2. sampler2D Texture0;  
  3.   
  4. // some const, tweak for best look   
  5. const float fSampleDist;  
  6. const float fSampleStrength;   
  7.   
  8.   
  9. // some sample positions   
  10. float samples[10] =   
  11. {  
  12.    -0.08,  
  13.    -0.05,  
  14.    -0.03,  
  15.    -0.02,  
  16.    -0.01,  
  17.    0.01,  
  18.    0.02,  
  19.    0.03,  
  20.    0.05,  
  21.    0.08  
  22. };  
  23.   
  24.   
  25. float4 ps_main( float2 texCoord  : TEXCOORD0 ) : COLOR  
  26. {  
  27.    // 0.5,0.5 is the center of the screen   
  28.    // so substracting uv from it will result in   
  29.    // a vector pointing to the middle of the screen   
  30.    float2 dir = 0.5 - texCoord;  
  31.    // calculate the distance to the center of the screen   
  32.    float dist = length(dir);  
  33.    // normalize the direction (reuse the distance)   
  34.    dir /= dist;  
  35.      
  36.    // this is the original colour of this pixel   
  37.    // using only this would result in a nonblurred version   
  38.    float4 color = tex2D(Texture0, texCoord);  
  39.      
  40.    float4 sum = color;  
  41.    // take 10 additional blur samples in the direction towards   
  42.    // the center of the screen   
  43.    for (int i = 0; i < 10; ++i)  
  44.    {  
  45.       sum += tex2D(Texture0, texCoord + dir * samples[i] * fSampleDist);  
  46.    }  
  47.   
  48.    // we have taken eleven samples   
  49.    sum /= 11.0;  
  50.      
  51.    // weighten the blur effect with the distance to the   
  52.    // center of the screen ( further out is blurred more)   
  53.    float t = saturate(dist * fSampleStrength);  
  54.      
  55.    //Blend the original color with the averaged pixels   
  56.    return lerp(color, sum, t);  
  57. }  
  1. // This texture should hold the image to blur.  
  2. sampler2D Texture0;  
  3.   
  4. // some const, tweak for best look  
  5. const float fSampleDist;  
  6. const float fSampleStrength;   
  7.   
  8.   
  9. // some sample positions  
  10. float samples[10] =   
  11. {  
  12.    -0.08,  
  13.    -0.05,  
  14.    -0.03,  
  15.    -0.02,  
  16.    -0.01,  
  17.    0.01,  
  18.    0.02,  
  19.    0.03,  
  20.    0.05,  
  21.    0.08  
  22. };  
  23.   
  24.   
  25. float4 ps_main( float2 texCoord  : TEXCOORD0 ) : COLOR  
  26. {  
  27.    // 0.5,0.5 is the center of the screen  
  28.    // so substracting uv from it will result in  
  29.    // a vector pointing to the middle of the screen  
  30.    float2 dir = 0.5 - texCoord;  
  31.    // calculate the distance to the center of the screen  
  32.    float dist = length(dir);  
  33.    // normalize the direction (reuse the distance)  
  34.    dir /= dist;  
  35.      
  36.    // this is the original colour of this pixel  
  37.    // using only this would result in a nonblurred version  
  38.    float4 color = tex2D(Texture0, texCoord);  
  39.      
  40.    float4 sum = color;  
  41.    // take 10 additional blur samples in the direction towards  
  42.    // the center of the screen  
  43.    for (int i = 0; i < 10; ++i)  
  44.    {  
  45.       sum += tex2D(Texture0, texCoord + dir * samples[i] * fSampleDist);  
  46.    }  
  47.   
  48.    // we have taken eleven samples  
  49.    sum /= 11.0;  
  50.      
  51.    // weighten the blur effect with the distance to the  
  52.    // center of the screen ( further out is blurred more)  
  53.    float t = saturate(dist * fSampleStrength);  
  54.      
  55.    //Blend the original color with the averaged pixels  
  56.    return lerp(color, sum, t);  
  57. }  

两个参数, 动态调整的话可以产生极品飞车12那种速度感(也算是第一人称运动模糊的简单实现吧).

这是RM里的效果:

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值