1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
| Shader "KajiyaKayAnisotropic" { Properties { _ShiftMap("ShiftMap", 2D) = "black" {} _PrimaryShift("PrimaryShift", float) = 1.0 _SecondaryShift("SecondaryShift", float) = 1.0
_AlbedoMap("AlbedoMap", 2D) = "gray" {} _SpecMask("SpecMask", 2D) = "white" {} _SpecularColor1("SpecularColor1", Color) = (1,1,1,1) _SpecularColor2("SpecularColor2", Color) = (1,1,1,1) _SpecExp1("SpecExp1", float) = 100.0 _SpecExp2("SpecExp2", float) = 100.0 } SubShader { Pass { Tags { "LightMode" = "ForwardBase" }
CGPROGRAM #pragma vertex vert #pragma fragment frag #pragma multi_compile_fwdbase #include "UnityCG.cginc" #include "AutoLight.cginc"
struct appdata { float4 vertex : POSITION; float2 uv : TEXCOORD0; float3 normal : NORMAL; float4 tangent : TANGENT; };
struct v2f { float4 vertex : SV_POSITION; float2 uv : TEXCOORD0; float3 normal : TEXCOORD1; float3 tangent : TEXCOORD2; float3 binormal : TEXCOORD3; float3 worldPos : TEXCOORD4; };
float4 _LightColor0;
sampler2D _ShiftMap; float4 _ShiftMap_ST;
float _PrimaryShift; float _SecondaryShift;
sampler2D _AlbedoMap; float4 _AlbedoMap_ST;
sampler2D _SpecMask; float4 _SpecMask_ST;
fixed4 _SpecularColor1; fixed4 _SpecularColor2;
float _SpecExp1; float _SpecExp2;
float3 ShiftTangent(float3 T, float3 N, float shift) { float3 shiftedT = T + (shift * N); return normalize(shiftedT); }
float StrandSpecular(float3 T, float3 V, float L, float exponent) { float3 H = normalize(L + V); float dotTH = dot(T, H); float sinTH = sqrt(1.0 - dotTH*dotTH); float dirAtten = smoothstep(-1.0, 0.0, dot(T, H));
return dirAtten * pow(sinTH, exponent); }
v2f vert (appdata v) { v2f o; o.vertex = UnityObjectToClipPos(v.vertex); o.uv = v.uv; o.normal = normalize(mul(float4(v.normal, 0.0), unity_WorldToObject).xyz); o.tangent = normalize(mul(unity_ObjectToWorld, float4(v.tangent.xyz, 0.0)).xyz); o.binormal = normalize(cross(o.normal,o.tangent)) * v.tangent.w; o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz; return o; }
fixed4 frag (v2f i) : SV_Target { half3 lightDir = normalize(_WorldSpaceLightPos0.xyz); half3 viewDir = normalize(_WorldSpaceCameraPos.xyz - i.worldPos);
half3 normal = normalize(i.normal); half3 tangen = normalize(i.tangent); half3 binormal = normalize(i.binormal);
half3 shiftDir = binormal;
float3 diffuse = saturate(lerp(0.25, 1.0, dot(normal, lightDir)));
float shiftTex = tex2D(_ShiftMap, i.uv) - 0.5; float3 t1 = ShiftTangent(shiftDir, normal, _PrimaryShift + shiftTex); float3 specular = _SpecularColor1 * StrandSpecular(t1, viewDir, lightDir, _SpecExp1);
float3 t2 = ShiftTangent(shiftDir, normal, _SecondaryShift + shiftTex); float specMask = tex2D(_SpecMask, i.uv); specular += _SpecularColor2 * specMask * StrandSpecular(t2, viewDir, lightDir, _SpecExp2);
fixed4 o; o.rgb = (diffuse + specular) * tex2D(_AlbedoMap, i.uv) * _LightColor0.xyz; o.a = 1;
return o; } ENDCG } } Fallback "Diffuse" }
|