您当前的位置: 首页 > 

果冻喜之郎

暂无认证

  • 3浏览

    0关注

    79博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

shader编程7

果冻喜之郎 发布时间:2021-08-16 10:19:54 ,浏览量:3

纹理模糊效果:

实现方法:当前像素点和周围的像素点做平均值,将得到的平均值代替当前像素点

Properties
    {
        _MainTex ("Texture", 2D) = "white" {}
        _Offset ("Offset",Range(0,0.02)) = 0
    }
 fixed4 frag (v2f i) : SV_Target
            {
                fixed4 col = tex2D(_MainTex, i.uv);
                // just invert the colors
                //col.rgb = 1 - col.rgb;
                fixed4 col1 = tex2D(_MainTex, i.uv + (_Offset,0));
                fixed4 col2 = tex2D(_MainTex, i.uv - (_Offset,0));
                fixed4 col3 = tex2D(_MainTex, i.uv + (0,_Offset));
                fixed4 col4 = tex2D(_MainTex, i.uv - (0,_Offset));
                return (col+col1+col2+col3+col4) / 5;
            }

 屏幕模糊效果:

 实现方法:屏幕上的画面通过摄像机渲染,所以只需要对摄像机渲染出来的图片进行处理,通过MonoBehavior中的回调函数调取

给摄像机添加脚本:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class mohu : MonoBehaviour
{
   public Material material;

   private void OnRenderImage(RenderTexture source, RenderTexture destination){
       Graphics.Blit (source, destination, material);
   }
}

将上述材质赋给摄像机 

关注
打赏
1655963140
查看更多评论
立即登录/注册

微信扫码登录

0.0818s