博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【Shader】扫描网屏幕特效
阅读量:4088 次
发布时间:2019-05-25

本文共 2357 字,大约阅读时间需要 7 分钟。

Shader "Custom/ScannerEffect"{    Properties    {        _MainTex("Texture", 2D) = "white" {}        _ScanDistance("Scan Distance", float) = 0        _ScanWidth("Scan Width", float) = 10        _ScanColor("Scan Color", Color) = (1, 1, 1, 0)    }    SubShader    {        // Cull Off        // ZTest Always        Pass        {            CGPROGRAM            #pragma vertex vert            #pragma fragment frag            #include "UnityCG.cginc"            // 顶点着色器需要的数据类型            struct appdata            {                float4 vertex : POSITION;                float2 uv : TEXCOORD0;            };            // 顶点着色器处理后传递给片段着色器的数据类型            struct v2f            {                float4 vertex : SV_POSITION;                float2 uv : TEXCOORD0;                float2 uv_depth : TEXCOORD1;            };            // 内置变量:相机的世界坐标            float4 _CameraWS;            // 内置变量:主贴图像素尺寸大小,值是Vector4(1 / width, 1 / height, width, height)            float4 _MainTex_TexelSize;            // 顶点着色器            v2f vert(appdata v)            {                v2f o;                o.vertex = UnityObjectToClipPos(v.vertex);                o.uv = v.uv;                o.uv_depth = v.uv;                return o;            }            // 主贴图            sampler2D _MainTex;            // 内置变量:深度图            sampler2D _CameraDepthTexture;            // 扫描距离            float _ScanDistance;            // 扫描网宽度            float _ScanWidth;            // 扫描网的颜色            float4 _ScanColor;            // 指定返回值类型是被SV_Target限定的类型            half4 frag (v2f i) : SV_Target            {                // 片段着色器着色(图像采样)                half4 col = tex2D(_MainTex, i.uv);                // 获取深度信息                float depth = UNITY_SAMPLE_DEPTH(tex2D(_CameraDepthTexture, i.uv));                // 将深度值转换为线性的值 (0~1之间)                float linear01Depth = Linear01Depth(depth);                // 绘制需要变色的扫描区域                if (                    linear01Depth < _ScanDistance &&                     linear01Depth > _ScanDistance - _ScanWidth &&                     linear01Depth < 1)                {                    float diff = 1 - (_ScanDistance - linear01Depth) / (_ScanWidth);                    _ScanColor *= diff;                    return col + _ScanColor;                }                return col;            }            ENDCG        }    }}

转载地址:http://gbkii.baihongyu.com/

你可能感兴趣的文章
课后练习 - 测验3: Python基础语法(下) (第7周)
查看>>
课后练习 - 测验4: 全课程综合测验 (考试周)
查看>>
deeplearning.ai - 自然语言处理与词嵌入
查看>>
deeplearning.ai - 序列模型和注意力机制
查看>>
Python - 网络爬虫规则
查看>>
机器学习基石 - The VC Dimension
查看>>
机器学习基石 - Noise and Error
查看>>
机器学习基石 - Linear Regression
查看>>
机器学习基石 - Logistic Regression
查看>>
机器学习基石 - Linear Models for Classification
查看>>
机器学习基石 - Nonlinear Transformation
查看>>
机器学习基石 - Hazard of Overfitting
查看>>
机器学习基石 - Regularization
查看>>
机器学习基石 - Three Learning Principles
查看>>
细枝末节的小东西
查看>>
numpy处理数据的记录
查看>>
Python 小点
查看>>
Ubantu 10.04.4 是比较老的版本,断网安装后在terminal的窗口中进行更新资源包的时候(apt-get update )会出现忽略相应网址 导致更新失败。
查看>>
工具类关闭流
查看>>
类/对象大小的计算
查看>>