Shader "MyShader/TransShader"
{
Properties
{
_RimColor ("Rim Color", Color) = (0.5,0.5,0.5,0.5)
_InnerColor ("Inner Color", Color) = (0.5,0.5,0.5,0.5)
_InnerColorPower ("Inner Color Power", Range(0.0,1.0)) = 0.5
_RimPower ("Rim Power", Range(0.0,10.0)) = 2.5
_AlphaPower ("Alpha Rim Power", Range(0.0,16.0)) = 4.0
_AllPower ("All Power", Range(0.0, 20.0)) = 1.0
}
SubShader
{
Tags { "RenderType"="Transparent" "IgnoreProjector"="True" "Queue"="Transparent" }
LOD 100
Blend SrcAlpha OneMinusSrcAlpha
ZWrite On
Pass
{
ZWrite On
ColorMask 0 //用于设置颜色通道的写掩码,0表示不写入任何通道
}
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#include "Lighting.cginc"
#include "AutoLight.cginc"
struct appdata
{
float3 normal:NORMAL;
float4 vertex : POSITION;
};
struct v2f
{
float3 worldNormal : TEXCOORD0;
float3 worldPos : TEXCOORD1;
float4 pos : SV_POSITION;
};
float4 _RimColor;
float _RimPower;
float _AlphaPower;
float _AlphaMin;
float _InnerColorPower;
float _AllPower;
float4 _InnerColor;
v2f vert (appdata v)
{
v2f o;
o.worldNormal = UnityObjectToWorldNormal(v.normal);
o.pos = UnityObjectToClipPos(v.vertex);
o.worldPos = mul(unity_ObjectToWorld,v.vertex).xyz;
return o;
}
fixed4 frag (v2f i) : SV_Target
{
fixed3 worldNormal = normalize(i.worldNormal);
fixed3 worldLightDir = normalize(UnityWorldSpaceLightDir(i.worldPos));
fixed3 worldViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos));
// fixed3 albedo = _Color.rgb;
// fixed3 ambient = UNITY_LIGHTMODEL_AMBIENT.xyz * albedo;
// fixed3 diffuse = _LightColor0.rgb * albedo * max(0,dot(worldNormal,worldLightDir)
half rim = 1.0 - saturate(dot(worldViewDir, worldNormal));
fixed3 c = _RimColor.rgb * pow(rim, _RimPower) * _AllPower + (_InnerColor.rgb * 2 * _InnerColorPower);
return fixed4(c, (pow(rim, _AlphaPower)) * _AllPower);
}
ENDCG
}
}
Fallback "Transparent/VertexLit"
}
网友评论