float4 _GlobalLightDir, _GlobalLightDir1; float4 _GlobalDirColor, _GlobalPointColor0, _GlobalPointColor1, _GlobalPointColor2, _GlobalPointColor3; float4 _GlobalPointX, _GlobalPointY, _GlobalPointZ, _GlobalPointAtten; //Èܽâ bool CheckDissolve(fixed modelVertexX, sampler2D _DissolveMap, float2 uv, fixed _Max, fixed _Min, fixed _DissolveThreshold, fixed _ColorFactorA, fixed4 _DissolveColorA) { fixed4 dissolveValue = tex2D(_DissolveMap, uv); fixed range = _Max - _Min; fixed mapping = (modelVertexX - _Min) / range; fixed finalThreshold = lerp(_DissolveThreshold, _DissolveThreshold / 10, saturate(mapping)); if (dissolveValue.r < finalThreshold) { discard; return false; } fixed lerpValue = finalThreshold / dissolveValue.r; return lerpValue > _ColorFactorA; } half GGX_Mobile(half Roughness, half NoH) { float OneMinusNoHSqr = 1.0 - NoH * NoH; half a = Roughness * Roughness; float n = NoH * a; float p = a / (OneMinusNoHSqr + n * n); float d = min(32, p * p); return d; } half3 EnvBRDFApprox(half3 SpecularColor, half Roughness, half NoV) { const half4 c0 = { -1, -0.0275, -0.572, 0.022 }; const half4 c1 = { 1, 0.0425, 1.04, -0.04 }; half4 r = Roughness * c0 + c1; half a004 = min(r.x * r.x, exp2(-9.28 * NoV)) * r.x + r.y; half2 AB = half2(-1.04, 1.04) * a004 + r.zw; AB.y *= saturate(50.0 * SpecularColor.g); return SpecularColor * AB.x + AB.y; } float BRDFSpec(float noh, float loh, float r4, float r) { float a = (noh * noh) * (r4 - 1) + 1; a *= loh; float a2 = a * a; return min(32, r4 / (4 * UNITY_PI * a2 * (r + 0.5))); } float3 BRDFPointLights(float3 pos, float3 V, float3 N, float3 DiffuseColor, float3 SpecularColor, float Roughness) { float4 toLightX = _GlobalPointX - pos.x; float4 toLightY = _GlobalPointY - pos.y; float4 toLightZ = _GlobalPointZ - pos.z; float4 lengthSq = 0; lengthSq = toLightX * toLightX + toLightY * toLightY + toLightZ * toLightZ; lengthSq = max(lengthSq, 0.0001); float4 corr = rsqrt(lengthSq); toLightX *= corr; toLightY *= corr; toLightZ *= corr; float4 ndotl = 0; ndotl = toLightX * N.x + toLightY * N.y + toLightZ * N.z; ndotl = max(float4(0, 0, 0, 0), ndotl); float4 atten = clamp(1.0 - lengthSq * _GlobalPointAtten, 0, 1) / (1 + lengthSq); float4 diff = ndotl * atten; float3 col0 = _GlobalPointColor0.rgb * diff.x; float3 col1 = _GlobalPointColor1.rgb * diff.y; float3 col2 = _GlobalPointColor2.rgb * diff.z; float3 col3 = _GlobalPointColor3.rgb * diff.w; float3 col = (col0 + col1 + col2 + col3) * DiffuseColor / UNITY_PI; float4 HX = toLightX + V.x; float4 HY = toLightY + V.y; float4 HZ = toLightZ + V.z; lengthSq = 0; lengthSq = HX * HX + HY * HY + HZ * HZ; lengthSq = max(lengthSq, 0.000001); corr = rsqrt(lengthSq); HX *= corr; HY *= corr; HZ *= corr; float4 noh = 0, loh = 0; noh = HX * N.x + HY * N.y + HZ * N.z; noh = max(float4(0.01, 0.01, 0.01, 0.01), noh); loh = HX * toLightX + HY * toLightY + HZ * toLightZ; loh = max(float4(0.01, 0.01, 0.01, 0.01), loh); float r4 = Roughness * Roughness; r4 *= r4; col += BRDFSpec(noh.x, loh.x, r4, Roughness) * SpecularColor * col0; col += BRDFSpec(noh.y, loh.y, r4, Roughness) * SpecularColor * col1; col += BRDFSpec(noh.z, loh.z, r4, Roughness) * SpecularColor * col2; col += BRDFSpec(noh.w, loh.w, r4, Roughness) * SpecularColor * col3; return col; } half EnvBRDFApproxNonmetal(half Roughness, half NoV) { const half2 c0 = { -1, -0.0275 }; const half2 c1 = { 1, 0.0425 }; half2 r = Roughness * c0 + c1; return min(r.x * r.x, exp2(-9.28 * NoV)) * r.x + r.y; } float3 mod2D289(float3 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; } float2 mod2D289(float2 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; } float3 permute(float3 x) { return mod2D289(((x * 34.0) + 1.0) * x); } float Snoise(float2 v) { const float4 C = float4(0.211324865405187, 0.366025403784439, -0.577350269189626, 0.024390243902439); float2 i = floor(v + dot(v, C.yy)); float2 x0 = v - i + dot(i, C.xx); float2 i1; i1 = (x0.x > x0.y) ? float2(1.0, 0.0) : float2(0.0, 1.0); float4 x12 = x0.xyxy + C.xxzz; x12.xy -= i1; i = mod2D289(i); float3 p = permute(permute(i.y + float3(0.0, i1.y, 1.0)) + i.x + float3(0.0, i1.x, 1.0)); float3 m = max(0.5 - float3(dot(x0, x0), dot(x12.xy, x12.xy), dot(x12.zw, x12.zw)), 0.0); m = m * m; m = m * m; float3 x = 2.0 * frac(p * C.www) - 1.0; float3 h = abs(x) - 0.5; float3 ox = floor(x + 0.5); float3 a0 = x - ox; m *= 1.79284291400159 - 0.85373472095314 * (a0 * a0 + h * h); float3 g; g.x = a0.x * x0.x + h.x * x0.y; g.yz = a0.yz * x12.xz + h.yz * x12.yw; return 130.0 * dot(m, g); }