这是我的脚本
Shader "Custom/Eyeball" {
Properties
{
_Color ("Base Color", Color) = (1,1,1,0.5)
_MainTex ("Base (RGB)", 2D) = "white" {}
_EyeTex ("Eye Texture (RGB)", 2D) = "white" {}
_EyeColor1 ("Eye Color 1", Color) = (1,1,1,0.5)
_EyeColor2 ("Eye Color 2", Color) = (1,1,1,0.5)
_ReflectColor ("Reflection Color", Color) = (1,1,1,0.5)
_RimPower ("Rim Power", float) = 3.0
_Cube ("Reflection Cubemap", Cube) = "_Skybox" { TexGen CubeReflect }
[MaterialToggle] RampColor ("Ramp Color", Float) = 0
[MaterialToggle] CreatePupil ("Create Pupil", Float) = 0
[HideInInspector]EyeSize ("Eye Size", float) = 3.0
[HideInInspector]PupilSize ("Pupil Size", float) = 3.0
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert vertex:vert
#pragma multi_compile DUMMY RAMPCOLOR_ON
#pragma multi_compile DUMMY2 CREATEPUPIL_ON
sampler2D _MainTex;
sampler2D _EyeTex;
samplerCUBE _Cube;
fixed4 _Color;
fixed4 _EyeColor1;
fixed4 _EyeColor2;
fixed4 _ReflectColor;
uniform float4x4 EyeMatrix;
half _RimPower;
half EyeSize;
half PupilSize;
struct Input {
float2 uv_MainTex;
float4 eyeCoords;
float3 worldRefl;
float3 viewDir;
};
void vert (inout appdata_full v, out Input o)
{
o.eyeCoords = mul(EyeMatrix, mul(_Object2World, v.vertex));
}
void surf (Input IN, inout SurfaceOutput o)
{
half4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
if (IN.eyeCoords.z > 0)
{
half4 irisTex = tex2D (_EyeTex, saturate(IN.eyeCoords.xy/EyeSize+0.5));
fixed irisBoundary = saturate((0.99 - irisTex.a)/0.05);
#ifdef CREATEPUPIL_ON
fixed pupilBoundary = saturate(saturate(irisTex.a - PupilSize) / 0.05);
#endif
#ifdef RAMPCOLOR_ON
#ifdef CREATEPUPIL_ON
o.Albedo = lerp(fixed3(0,0,0), lerp(c.rgb, lerp(_EyeColor1.rgb, _EyeColor2.rgb, irisTex.r), irisBoundary), pupilBoundary) * c.a;
#else
o.Albedo = lerp(c.rgb, lerp(_EyeColor1.rgb, _EyeColor2.rgb, irisTex.r), irisBoundary)* c.a;
#endif
#else
#ifdef CREATEPUPIL_ON
o.Albedo = lerp(fixed3(0,0,0), lerp(c.rgb, irisTex, irisBoundary), pupilBoundary)* c.a;
#else
o.Albedo = lerp(c.rgb, irisTex, irisBoundary)* c.a;
#endif
#endif
}
else
o.Albedo = c.rgb;
//o.Albedo *= _Color.rgb;
fixed4 reflcol = texCUBE (_Cube, IN.worldRefl) * _ReflectColor * c.a * _Color.a;
half rim = 1.0 - saturate(dot (normalize(IN.viewDir), o.Normal));
//o.Emission = _ReflectColor.rgb * pow (rim, _RimPower);
o.Emission = (_Color.a * o.Albedo* c.a + reflcol.rgb) * pow (rim, _RimPower);
o.Alpha = 1;
}
ENDCG
}
FallBack "Diffuse"
}