shader代码:Shader "Unlit/Test"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Transparent" "Queue"="AlphaTest" "IgnoreProjector"="True" }
LOD 100Cull Off
ZWrite OffPass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 3.0
#pragma multi_compile _ Use_Vigent#include "UnityCG.cginc"struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};sampler2D _MainTex;
sampler2D _CameraTex;
float4 _MainTex_ST;
float4 _NVColor;
float4 _TargetColor;
float _BaseLight;
float _Light;v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
}fixed4 frag (v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.uv);
fixed4 dif=tex2D(_CameraTex,i.uv);
//得到灰度值
float lum=Luminance(col.rgb);col=dot(col,_NVColor);col.rgb=lerp(col.rgb,_TargetColor,lum*_Light);col.rgb=lerp(col.rgb,dif.rgb,lum+_BaseLight);#if Use_Vigent
float dist=distance(i.uv,float2(0.5f,0.5f));
col*=smoothstep(0.5,0.45,dist);
#endifcol.rb=max(col.r-0.75,0)*4;
return col;
}
ENDCG
}
}}C#代码:using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[ExecuteInEditMode]
public class Shader_TouShi : MonoBehaviour {public Shader test_20;Material mat;[SerializeField]public Color m_NVColor = new Color(0f, 1f, 0.1724138f, 0f);[SerializeField]public Color m_TargetColor = new Color(1f, 1f, 1f, 0f);[Range(0f, 0.1f)]public float m_BaseLight = 0;[Range(0f, 128f)]public float m_Light = 0;public bool UsingVigent;private void Awake(){if (mat == null){mat = CreatMat(test_20);}}Material CreatMat(Shader shader){if (shader == null){return null;}if (shader.isSupported == false){return null;}mat = new Material(shader);mat.hideFlags = HideFlags.DontSave;return mat;}private void OnRenderImage(RenderTexture source, RenderTexture destination){mat.SetColor("_NVColor", m_NVColor);mat.SetColor("_TargetColor", m_TargetColor);mat.SetFloat("_BaseLight", m_BaseLight);mat.SetFloat("_Light", m_Light);if (UsingVigent == true){mat.EnableKeyword("Use_Vigent");}else{mat.DisableKeyword("Use_Vigent");}Graphics.Blit(source, destination, mat);}}