Unity Shader中将指定颜色过滤成透明
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
Shader "Unlit/MakeSpecifiedColorTransparent"
{
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {} //在这里填入过滤之后保留的底色或基低贴图
_FilterfColor("Ridof (RGB)",Color)=(0,0,0,1) //在这里填写自己需要过滤的颜色
}
SubShader {
Tags { "RenderType"="Opaque" }
Blend SrcAlpha OneMinusSrcAlpha
pass
{
CGPROGRAM
#pragma vertex vertext_convert
#pragma fragment fragment_convert
#include "UnityCG.cginc"
sampler2D _MainTex;
sampler2D _MainTex1;
float4 _FilterfColor;
struct Inputvrite
{
float4 vertex : POSITION;
float4 texcoord : TEXCOORD0;
};
struct Inputfragment
{
float4 pos : SV_POSITION;
float4 uv : TEXCOORD0;
};
float ColorLerp(float3 tmp_nowcolor,float3 tmp_FilterfColor)
{
float3 dis = float3(abs(tmp_nowcolor.x - tmp_FilterfColor.x),abs(tmp_nowcolor.y - tmp_FilterfColor.y),abs(tmp_nowcolor.z - tmp_FilterfColor.z));
float dis0 =sqrt(pow(dis.x,2)+pow(dis.y,2)+pow(dis.z,2));
float maxdis = sqrt(3);
float dis1 = lerp(0,maxdis,dis0);
return dis1;
}
Inputfragment vertext_convert(Inputvrite i)
{
Inputfragment o;
o.pos = UnityObjectToClipPos(i.vertex);
o.uv = float4(i.texcoord.xy,1,1);
return o;
}
float4 fragment_convert(Inputfragment o) : COLOR
{
float4 c = tex2D(_MainTex,o.uv);
c.a *=ColorLerp(c.rgb,_FilterfColor.rgb);
return c;
}
ENDCG
}
}
FallBack "Diffuse"
}
作者:艾孜尔江
本文来自博客园,作者:艾孜尔江,转载请注明原文链接:https://www.cnblogs.com/ezhar/p/13432289.html