Shader "New_Eye"{ Properties{ //Cornea角膜1 //Iris虹膜 //Sclera巩膜 _Lum("Luminance", Range(0, 10)) = 4 _BaseMap("Base (RGB)", 2D) = "white" {} [MainColor] _BaseColor("Color", Color) = (1,1,1,1) [NoScaleOffset]_BumpMap("NormalIrisTex (RGB)", 2D) = "white" {} [NoScaleOffset]_BumpDetialMap("Iris Detial Tex (RGB)", 2D) = "white" {} [KKBTitle()]_("Specular",Float) = 0.0 _specluarIntensity("Specular Intensity", Range(0, 1)) = 1.0 [NoScaleOffset]_SpecularTex("SpecularTex (RGB), A(Mask)", 2D) = "white" {} _GLCornea("gloss", Range(0, 2)) = 0.5 _GLIris("Iris Gloss", Range(0, 2)) = 0.5 _SPIris("Iris Specular Power", Range(1, 100)) = 20 _SPScleraDetial("Sclera Detial Specular Color and Instance", Color) = (1, 1, 1, 1) [KKBTitle()]_("Reflection", Float) = 0.0 [NoScaleOffset]_SSSMap("reflectTex", 2D) = "white"{} _ReflAmount("ReflAmount", Range(0, 1)) = 1 //_Cubemap("CubeMap", CUBE) = ""{} [KKBTitle()]_("边缘光", Float) = 0.0 _RimColor("边缘光颜色", color) = (0.5, 0.5, 0.5, 1.0) _RimPower("边缘光范围", float) = 15.0 _rimMultiplier("边缘光强度", float) = 1.0 [Header(Mask)] [Space(8)] _MakeUpMask1_RGB("MakeUpMask1_RGB (R: 眼影 G: 腮红 B: 口红 A: 眼线)", 2D) = "black" {} _MakeUpMask2_RGB("MakeUpMask2_RGB (R: 纹身区域)", 2D) = "black" {} _Mask1_Rchannel_TextureAmountA("Mask1_Rchannel_Texture-Amount(A)", 2D) = "black" {} _Mask1_Gchannel_TextureAmountA("Mask1_Gchannel_Texture-Amount(A)", 2D) = "black" {} _Mask1_Bchannel_TextureAmountA("Mask1_Bchannel_Texture-Amount(A)", 2D) = "black" {} _Mask2_Rchannel_TextureAmountA("Mask2_Rchannel_Texture-Amount(A)", 2D) = "black" {} _Mask2_Gchannel_TextureAmountA("Mask2_Gchannel_Texture-Amount(A)", 2D) = "black" {} _Mask2_Bchannel_TextureAmountA("Mask2_Bchannel_Texture-Amount(A)", 2D) = "black" {} _Mask1_Rchannel_ColorAmountA("Mask1_Rchannel_Color-Amount(A)", Color) = (0.7735849, 0.2006942, 0.3233189, 0.7843137) _Mask1_Gchannel_ColorAmountA("Mask1_Gchannel_Color-Amount(A)", Color) = (0.2, 0.772549, 0.4917381, 0.7843137) _Mask1_Bchannel_ColorAmountA("Mask1_Bchannel_Color-Amount(A)", Color) = (0.2, 0.406334, 0.772549, 0.7843137) _Mask1_Achannel_ColorAmountA("Mask1_Achannel_Color-Amount(A)", Color) = (0.2, 0.406334, 0.772549, 0.7843137) _Mask2_Rchannel_ColorAmountA("Mask2_Rchannel_Color-Amount(A)", Color) = (0.2, 0.772549, 0.7071339, 0.7843137) _Mask2_Gchannel_ColorAmountA("Mask2_Gchannel_Color-Amount(A)", Color) = (0.772549, 0.2, 0.6776864, 0.7843137) _Mask2_Bchannel_ColorAmountA("Mask2_Bchannel_Color-Amount(A)", Color) = (0.772549, 0.7037676, 0.2, 0.7843137) // Needed by the inspector [HideInInspector] _Culling("Culling", Float) = 0.0 // Lightmapper and outline selection shader need _MainTex, _Color and _Cutoff [HideInInspector] _MainTex("Albedo", 2D) = "white" {} [HideInInspector] _Color("Color", Color) = (1,1,1,1) [HideInInspector] _Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.0 // URP 10.1. needs this for the depthnormal pass [HideInInspector] _Cutoff(" Threshold", Range(0.0, 1.0)) = 0.5 [HideInInspector] _Surface("__surface", Float) = 0.0 } SubShader { Tags { "RenderPipeline" = "UniversalPipeline" "RenderType" = "Opaque" } pass{ Tags{ "LightMode" = "UniversalForward" } Cull Back CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" CBUFFER_START(UnityPerMaterial) half4 _BaseColor; float4 _SPScleraDetial; float _SPIris; float _Lum; float _ReflAmount; float4 _LightColor0; half _specluarIntensity; float _GLCornea; float _GLIris; fixed _RimPower; fixed3 _RimColor; sampler2D _BaseMap; sampler2D _SpecularTex; sampler2D _BumpMap; sampler2D _BumpDetialMap; sampler2D _SSSMap; sampler2D _MakeUpMask1_RGB; sampler2D _MakeUpMask2_RGB; sampler2D _Mask1_Rchannel_TextureAmountA; sampler2D _Mask1_Gchannel_TextureAmountA; sampler2D _Mask1_Bchannel_TextureAmountA; sampler2D _Mask1_Achannel_TextureAmountA; sampler2D _Mask2_Rchannel_TextureAmountA; sampler2D _Mask2_Gchannel_TextureAmountA; sampler2D _Mask2_Bchannel_TextureAmountA; float _rimMultiplier; float4 _BaseMap_ST; // Mask float4 _MakeUpMask1_RGB_ST; float4 _MakeUpMask2_RGB_ST; float4 _Mask1_Rchannel_ColorAmountA; float4 _Mask1_Gchannel_ColorAmountA; float4 _Mask1_Bchannel_ColorAmountA; float4 _Mask1_Achannel_ColorAmountA; float4 _Mask2_Rchannel_ColorAmountA; float4 _Mask2_Gchannel_ColorAmountA; float4 _Mask2_Bchannel_ColorAmountA; float4 _Mask1_Rchannel_TextureAmountA_ST; float4 _Mask1_Gchannel_TextureAmountA_ST; float4 _Mask1_Bchannel_TextureAmountA_ST; float4 _Mask1_Achannel_TextureAmountA_ST; float4 _Mask2_Rchannel_TextureAmountA_ST; float4 _Mask2_Gchannel_TextureAmountA_ST; float4 _Mask2_Bchannel_TextureAmountA_ST; float4 _EmissionMap_ST; CBUFFER_END struct v2f { float4 pos : SV_POSITION; float3 wNormal : NORMAL; float2 uv : TEXCOORD0; float3 lightDir : TEXCOORD1; float3 viewDir : TEXCOORD2; half3 tspace0 : TEXCOORD3; half3 tspace1 : TEXCOORD4; half3 tspace2 : TEXCOORD5; }; v2f vert(appdata_full v) { v2f o; o.pos = UnityObjectToClipPos(v.vertex); o.lightDir = WorldSpaceLightDir(v.vertex); o.viewDir = WorldSpaceViewDir(v.vertex); o.wNormal = UnityObjectToWorldNormal(v.normal); half3 wTangent = UnityObjectToWorldDir(v.tangent.xyz); half tangentSign = v.tangent.w * unity_WorldTransformParams.w; half3 wBitangent = cross(o.wNormal, wTangent) * tangentSign; o.tspace0 = half3(wTangent.x, wBitangent.x, o.wNormal.x); o.tspace1 = half3(wTangent.y, wBitangent.y, o.wNormal.y); o.tspace2 = half3(wTangent.z, wBitangent.z, o.wNormal.z); o.uv = TRANSFORM_TEX(v.texcoord, _BaseMap); return o; } half4 GetColor(float2 uv) { //half4 albedoAlpha = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, uv) * _BaseColor; half4 albedoAlpha = tex2D(_BaseMap, uv) * _BaseColor; float2 uv_MakeUpMask1_RGB = uv.xy * _MakeUpMask1_RGB_ST.xy + _MakeUpMask1_RGB_ST.zw; //float4 tex2DNode143 = SAMPLE_TEXTURE2D(_MakeUpMask1_RGB, sampler_MakeUpMask1_RGB, uv_MakeUpMask1_RGB); float4 tex2DNode143 = tex2D(_MakeUpMask1_RGB, uv_MakeUpMask1_RGB); float2 uv_Mask1_Rchannel_TextureAmountA = uv.xy * _Mask1_Rchannel_TextureAmountA_ST.xy + _Mask1_Rchannel_TextureAmountA_ST.zw; //float4 tex2D_mask1_R = SAMPLE_TEXTURE2D(_Mask1_Rchannel_TextureAmountA, sampler_Mask1_Rchannel_TextureAmountA, uv_Mask1_Rchannel_TextureAmountA); float4 tex2D_mask1_R = tex2D(_Mask1_Rchannel_TextureAmountA, uv_Mask1_Rchannel_TextureAmountA); float2 uv_Mask1_Gchannel_TextureAmountA = uv.xy * _Mask1_Gchannel_TextureAmountA_ST.xy + _Mask1_Gchannel_TextureAmountA_ST.zw; //float4 tex2D_mask1_G = SAMPLE_TEXTURE2D(_Mask1_Gchannel_TextureAmountA, sampler_Mask1_Gchannel_TextureAmountA, uv_Mask1_Gchannel_TextureAmountA); float4 tex2D_mask1_G = tex2D(_Mask1_Gchannel_TextureAmountA, uv_Mask1_Gchannel_TextureAmountA); float2 uv_Mask1_Bchannel_TextureAmountA = uv.xy * _Mask1_Bchannel_TextureAmountA_ST.xy + _Mask1_Bchannel_TextureAmountA_ST.zw; //float4 tex2D_mask1_B = SAMPLE_TEXTURE2D(_Mask1_Bchannel_TextureAmountA, sampler_Mask1_Bchannel_TextureAmountA, uv_Mask1_Bchannel_TextureAmountA); float4 tex2D_mask1_B = tex2D(_Mask1_Bchannel_TextureAmountA, uv_Mask1_Bchannel_TextureAmountA); float2 uv_Mask1_Achannel_TextureAmountA = uv.xy * _Mask1_Achannel_TextureAmountA_ST.xy + _Mask1_Achannel_TextureAmountA_ST.zw; //float4 tex2D_mask1_A = SAMPLE_TEXTURE2D(_Mask1_Achannel_TextureAmountA, sampler_Mask1_Achannel_TextureAmountA, uv_Mask1_Achannel_TextureAmountA); float4 tex2D_mask1_A = tex2D(_Mask1_Achannel_TextureAmountA, uv_Mask1_Achannel_TextureAmountA); float2 uv_Mask2_Rchannel_TextureAmountA = uv.xy * _Mask2_Rchannel_TextureAmountA_ST.xy + _Mask2_Rchannel_TextureAmountA_ST.zw; //float4 tex2D_mask2_R = SAMPLE_TEXTURE2D(_Mask2_Rchannel_TextureAmountA, sampler_Mask2_Rchannel_TextureAmountA, uv_Mask2_Rchannel_TextureAmountA); float4 tex2D_mask2_R = tex2D(_Mask2_Rchannel_TextureAmountA, uv_Mask2_Rchannel_TextureAmountA); float2 uv_Mask2_Gchannel_TextureAmountA = uv.xy * _Mask2_Gchannel_TextureAmountA_ST.xy + _Mask2_Gchannel_TextureAmountA_ST.zw; //float4 tex2D_mask2_G = SAMPLE_TEXTURE2D(_Mask2_Gchannel_TextureAmountA, sampler_Mask2_Gchannel_TextureAmountA, uv_Mask2_Gchannel_TextureAmountA); float4 tex2D_mask2_G = tex2D(_Mask2_Gchannel_TextureAmountA, uv_Mask2_Gchannel_TextureAmountA); float2 uv_Mask2_Bchannel_TextureAmountA = uv.xy * _Mask2_Bchannel_TextureAmountA_ST.xy + _Mask2_Bchannel_TextureAmountA_ST.zw; //float4 tex2D_mask2_B = SAMPLE_TEXTURE2D(_Mask2_Bchannel_TextureAmountA, sampler_Mask2_Bchannel_TextureAmountA, uv_Mask2_Bchannel_TextureAmountA); float4 tex2D_mask2_B = tex2D(_Mask2_Bchannel_TextureAmountA, uv_Mask2_Bchannel_TextureAmountA); float clampResult295 = clamp((tex2DNode143.r * tex2D_mask1_R.a * _Mask1_Rchannel_ColorAmountA.a), 0.0, 1.0); float4 _Mask1_R_Color = tex2D_mask1_R * _Mask1_Rchannel_ColorAmountA; float4 lerpResult145 = lerp(albedoAlpha, _Mask1_R_Color, clampResult295); float clampResult296 = clamp((tex2DNode143.g * tex2D_mask1_G.a * _Mask1_Gchannel_ColorAmountA.a), 0.0, 1.0); float4 _Mask1_G_Color = tex2D_mask1_G * _Mask1_Gchannel_ColorAmountA; float4 lerpResult160 = lerp(lerpResult145, _Mask1_G_Color, clampResult296); float clampResult297 = clamp((tex2DNode143.b * tex2D_mask1_B.a * _Mask1_Bchannel_ColorAmountA.a), 0.0, 1.0); float4 _Mask1_B_Color = tex2D_mask1_B * _Mask1_Bchannel_ColorAmountA; float4 lerpResult161 = lerp(lerpResult160, _Mask1_B_Color, clampResult297); float clampResult2971 = clamp((tex2DNode143.a * tex2D_mask1_A.a * _Mask1_Achannel_ColorAmountA.a), 0.0, 1.0); float4 _Mask1_A_Color = tex2D_mask1_A * _Mask1_Achannel_ColorAmountA; float4 lerpResult1611 = lerp(lerpResult161, _Mask1_A_Color, clampResult2971); //mask2 float2 uv_MakeUpMask2_RGB = uv.xy * _MakeUpMask2_RGB_ST.xy + _MakeUpMask2_RGB_ST.zw; //float4 tex2DNode144 = SAMPLE_TEXTURE2D(_MakeUpMask2_RGB, sampler_MakeUpMask2_RGB, uv_MakeUpMask2_RGB); float4 tex2DNode144 = tex2D(_MakeUpMask2_RGB, uv_MakeUpMask2_RGB); float clampResult298 = clamp((tex2DNode144.r * tex2D_mask2_R.a * _Mask2_Rchannel_ColorAmountA.a), 0.0, 1.0); float4 _Mask2_R_Color = tex2D_mask2_R * _Mask2_Rchannel_ColorAmountA; float4 lerpResult162 = lerp(lerpResult1611, _Mask2_Rchannel_ColorAmountA, clampResult298); float clampResult299 = clamp((tex2DNode144.g * tex2D_mask2_G.a * _Mask2_Gchannel_ColorAmountA.a), 0.0, 1.0); float4 _Mask2_G_Color = tex2D_mask2_G * _Mask2_Gchannel_ColorAmountA; float4 lerpResult163 = lerp(lerpResult162, _Mask2_Gchannel_ColorAmountA, clampResult299); float clampResult300 = clamp((tex2DNode144.b * tex2D_mask2_B.a * _Mask2_Bchannel_ColorAmountA.a), 0.0, 1.0); float4 _Mask2_B_Color = tex2D_mask2_B * _Mask2_Bchannel_ColorAmountA; float4 lerpResult164 = lerp(lerpResult163, _Mask2_Bchannel_ColorAmountA, clampResult300); albedoAlpha.rgb = half3(lerpResult164.r, lerpResult164.g, lerpResult164.b); return albedoAlpha; } float4 frag(v2f i) :COLOR { float3 viewDir = normalize(i.viewDir); float3 lightDir = normalize(i.lightDir); float3 H = normalize(lightDir + viewDir); float3 N = normalize(i.wNormal); //float3 col = tex2D(_BaseMap, i.uv); float3 col = GetColor(i.uv); fixed4 specularCol = tex2D(_SpecularTex, i.uv); fixed mask = specularCol.a; /* *this common algorithm */ float f = _specluarIntensity + (1 - _specluarIntensity) * pow(2, -10 * dot(H, lightDir)); float VDotH = dot(viewDir, H); /* *this part is compute Cornea's PBR specular */ float _SP = lerp(pow(8192, lerp(0, 0.5, _GLCornea - 0.4)), pow(8192, _GLCornea), mask + 0.005); float d = (_SP + 2) / (8 * UNITY_PI) * pow(max(0.0, dot(N, H)), _SP); //float f = _specluarIntensity + (1 - _specluarIntensity) * pow(2, -10 * dot(H, lightDir)); float k = min(1, _GLCornea + 0.545); float v = 1 / (k * VDotH * VDotH + (1 - k)); float SpecIns = d * f * v; SpecIns = SpecIns * specularCol * (1 - mask) + SpecIns * mask; SpecIns = lerp(0, SpecIns, clamp(mask - 0.3, 0, 1)); /* *this part is compute Iris and Sclera's PBR specular */ half3 tNormalA = UnpackNormal(tex2D(_BumpMap, i.uv)); half3 tNormalB = UnpackNormal(tex2D(_BumpDetialMap, i.uv)); half3 tNormal = normalize(tNormalA * mask + tNormalB * (1 - mask)); half3 normal = half3(dot(i.tspace0, tNormalB), dot(i.tspace1, tNormalB), dot(i.tspace2, tNormalB)); half diff = dot(normal, lightDir) * 0.49 + 0.49; half3 worldNormal; worldNormal.x = dot(i.tspace0, tNormal); worldNormal.y = dot(i.tspace1, tNormal); worldNormal.z = dot(i.tspace2, tNormal); worldNormal = normalize(worldNormal); _SP = pow(8192, _GLIris) * mask + pow(8192, lerp(1.05, 1.8, _GLIris + 0.1)) * (1 - mask); d = (_SP + 2) / (8 * UNITY_PI) * pow(max(0.0, dot(worldNormal, H)), _SP); //f = _specluarIntensity + (1 - _specluarIntensity) * pow(2, -10 * dot(H, lightDir)); k = min(1, _GLIris + 0.545); v = 1 / (k * VDotH * VDotH + (1 - k)); //float3 refDir = reflect(-viewDir, N); //float3 ref = texCUBElod(_Cubemap, float4(refDir, 0.5 - _GLCornea*0.5)).rgb; half3 matnormal = normalize(mul((float3x3)UNITY_MATRIX_V, worldNormal)); half2 matCapUV = matnormal.xy * 0.5 + 0.5; fixed3 ref = tex2D(_SSSMap, matCapUV); float fr = saturate(1.0 - dot(viewDir, worldNormal)); fixed3 rimColor = (saturate(pow(diff * fr , _RimPower) * (1.0 + _RimPower)) * _RimColor).rgb * _rimMultiplier; float roughSpecIns = d * f * v; roughSpecIns = roughSpecIns * _SPScleraDetial.a * mask; float3 roughSpec = roughSpecIns * specularCol; roughSpec = roughSpecIns * _SPScleraDetial.rgb + roughSpecIns; return float4(col * diff * _Lum + rimColor + roughSpec * _SPIris + SpecIns * col + Luminance(ref) * _ReflAmount, 1) * _LightColor0; } ENDCG } } }