前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >径向模糊效果

径向模糊效果

作者头像
逍遥剑客
发布2018-05-23 15:32:51
6780
发布2018-05-23 15:32:51
举报

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

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

原理:

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

代码翻译成HLSL:

代码语言:javascript
复制
// This texture should hold the image to blur. 
sampler2D Texture0;  
// some const, tweak for best look 
const float fSampleDist;  
const float fSampleStrength;   
// some sample positions 
float samples[10] =   
{  
   -0.08,  
   -0.05,  
   -0.03,  
   -0.02,  
   -0.01,  
   0.01,  
   0.02,  
   0.03,  
   0.05,  
   0.08  
};  
float4 ps_main( float2 texCoord  : TEXCOORD0 ) : COLOR  
{  
 // 0.5,0.5 is the center of the screen 
 // so substracting uv from it will result in 
 // a vector pointing to the middle of the screen 
   float2 dir = 0.5 - texCoord;  
 // calculate the distance to the center of the screen 
 float dist = length(dir);  
 // normalize the direction (reuse the distance) 
   dir /= dist;  
 // this is the original colour of this pixel 
 // using only this would result in a nonblurred version 
   float4 color = tex2D(Texture0, texCoord);  
   float4 sum = color;  
 // take 10 additional blur samples in the direction towards 
 // the center of the screen 
 for (int i = 0; i < 10; ++i)  
   {  
      sum += tex2D(Texture0, texCoord + dir * samples[i] * fSampleDist);  
   }  
 // we have taken eleven samples 
   sum /= 11.0;  
 // weighten the blur effect with the distance to the 
 // center of the screen ( further out is blurred more) 
 float t = saturate(dist * fSampleStrength);  
 //Blend the original color with the averaged pixels 
 return lerp(color, sum, t);  
}  

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

这是RM里的效果:

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2010年01月06日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档