shader 高斯模糊

//高斯模糊第一版:取原像素及上下左右共五个像素的平均值设为原像素的值

   fixed tmpOffset =0.01 ;//模糊度(像素偏移度)
   fixed4 frag (v2f i) : SV_Target
   {
    fixed2 tmpUV =i.uv;  //这一步 看一下
    fixed4 col = tex2D(_MainTex, i.uv);
    //步骤一:定义上下左右四个像素,并定义一个模糊度(像素偏移程度)
    
    fixed4 col2 =tex2D(_MainTex,tmpUV+fixed2(-tmpOffset,0));//提取偏右1%的像素
    fixed4 col3 =tex2D(_MainTex,tmpUV+fixed2(tmpOffset,0));//提取偏左1%的像素
    fixed4 col4 =tex2D(_MainTex,tmpUV+fixed2(0,tmpOffset));//提取偏上1%的像素
    fixed4 col5 =tex2D(_MainTex,tmpUV+fixed2(0,-tmpOffset));//提取偏下1%的像素                
    //步骤二:取这五个像素的平均值,使之成为原像素。
    col =(col+col2+col3+col4+col5)/5;
    return col;
   }




   //高斯模糊 第二版 取九个点像素平均值 并分配权重
   //原理:将一个像素的值变为此像素及上、下、左、右像素的平均值;
   int _For =1;
   float _Weifht1 =0.5;
   float _Weight2 =0.075;
   float _Weifht3 =0.05;
   fixed tmpOffset =0.01 ;//模糊度(像素偏移度)
   fixed4 frag (v2f i) : SV_Target
   {
    fixed2 tmpUV =i.uv;  //这一步 看一下
    fixed4 col = tex2D(_MainTex, i.uv);
    //步骤一:定义上下左右四个像素,并定义一个模糊度(像素偏移程度)
    
    fixed4 col2 =tex2D(_MainTex,tmpUV+fixed2(-tmpOffset,0));//提取偏右1%的像素
    fixed4 col3 =tex2D(_MainTex,tmpUV+fixed2(tmpOffset,0));//提取偏左1%的像素
    fixed4 col4 =tex2D(_MainTex,tmpUV+fixed2(0,tmpOffset));//提取偏上1%的像素
    fixed4 col5 =tex2D(_MainTex,tmpUV+fixed2(0,-tmpOffset));//提取偏下1%的像素            
    //加左上 左下 右上 右下 四个角的像素
    fixed4 col6 =tex2D(_MainTex,tmpUV+fixed2(-tmpOffset,-tmpOffset));          //   权重示意图:  0.5   0.75   0.5
    fixed4 col7 =tex2D(_MainTex,tmpUV+fixed2(tmpOffset,-tmpOffset));          //                           0.75   4     0.75
    fixed4 col8 =tex2D(_MainTex,tmpUV+fixed2(-tmpOffset,tmpOffset));          //                           0.5   0.75   0.5
    fixed4 col9 =tex2D(_MainTex,tmpUV+fixed2(tmpOffset,tmpOffset));                //
    col =(col * 4+(col2+col3+col4+col5) *0.75           //权重: 最中心的是4 上下左右是3 四个角是2
    +(col6+col7+col8+col9)*0.5)/9;         //
    return col;
}

   //高斯模糊  第三版:  13个像素的平均值(九宫格+4),无权重
   //                 。
   //            。   。   。
   //      。   。   。   。   。
   //            。   。   。
   //                  。
   //原理:将一个像素的值变为此像素及上、下、左、右像素的平均值;
   int _For =1;
   
   fixed tmpOffset =0.01 ;//模糊度(像素偏移度)
   fixed4 frag (v2f i) : SV_Target
   {
    fixed2 tmpUV =i.uv;  //这一步 看一下
    fixed4 col = tex2D(_MainTex, i.uv);
    //步骤一:定义上下左右四个像素,并定义一个模糊度(像素偏移程度)
    
    fixed4 col2 =tex2D(_MainTex,tmpUV+fixed2(-tmpOffset,0));//提取偏右1%的像素     shader 1
    fixed4 col3 =tex2D(_MainTex,tmpUV+fixed2(tmpOffset,0));//提取偏左1%的像素   shader 1
    fixed4 col4 =tex2D(_MainTex,tmpUV+fixed2(0,tmpOffset));//提取偏上1%的像素   shader 1
    fixed4 col5 =tex2D(_MainTex,tmpUV+fixed2(0,-tmpOffset));//提取偏下1%的像素          sahder 1 
    //加左上 左下 右上 右下 四个角的像素
    fixed4 col6 =tex2D(_MainTex,tmpUV+fixed2(-tmpOffset,-tmpOffset));     //shader 2
    fixed4 col7 =tex2D(_MainTex,tmpUV+fixed2(tmpOffset,-tmpOffset));     //shader 2
    fixed4 col8 =tex2D(_MainTex,tmpUV+fixed2(-tmpOffset,tmpOffset));     //shader 2
    fixed4 col9 =tex2D(_MainTex,tmpUV+fixed2(tmpOffset,tmpOffset));       //shader 2
    //加上 原像素 上上 下下 左左 右右的像素
    fixed4 col10 =tex2D(_MainTex,tmpUV+fixed2(-tmpOffset,-tmpOffset));        // sahder 3
    fixed4 col11 =tex2D(_MainTex,tmpUV+fixed2(tmpOffset,-tmpOffset));        // sahder 3
    fixed4 col12=tex2D(_MainTex,tmpUV+fixed2(-tmpOffset,tmpOffset));        // sahder 3
    fixed4 col13 =tex2D(_MainTex,tmpUV+fixed2(tmpOffset,tmpOffset));          // sahder 3
    col =(col+col2+col3+col4+col5+col6+col7+col8+col9 +
    + col10 +col11+col12+col13)/13;
    return col;
   }

 


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值