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

   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;
   }

 


 shader 高斯模糊

相关文章:

  • 2022-12-23
  • 2021-11-21
  • 2021-05-06
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-22
  • 2021-12-04
  • 2021-04-10
  • 2022-01-07
相关资源
相似解决方案