|
|
|
|
|
|
#define LIGHTWEIGHT_LINEAR_TO_GAMMA(color) color |
|
|
|
#endif |
|
|
|
|
|
|
|
#ifdef _SPECULAR_SETUP |
|
|
|
#define SAMPLE_METALLICSPECULAR(uv) tex2D(_SpecGlossMap, uv) |
|
|
|
#else |
|
|
|
#define SAMPLE_METALLICSPECULAR(uv) tex2D(_MetallicGlossMap, uv) |
|
|
|
#endif |
|
|
|
|
|
|
|
CBUFFER_START(_PerObject) |
|
|
|
half4 unity_LightIndicesOffsetAndCount; |
|
|
|
half4 unity_4LightIndices0; |
|
|
|
half4 unity_4LightIndices1; |
|
|
|
half _Shininess; |
|
|
|
CBUFFER_END |
|
|
|
|
|
|
|
CBUFFER_START(_PerCamera) |
|
|
|
float4 _MainLightPosition; |
|
|
|
half4 _MainLightColor; |
|
|
|
float4 _MainLightAttenuationParams; |
|
|
|
half4 _MainLightSpotDir; |
|
|
|
|
|
|
|
half4 _AdditionalLightCount; |
|
|
|
float4 _AdditionalLightPosition[MAX_VISIBLE_LIGHTS]; |
|
|
|
half4 _AdditionalLightColor[MAX_VISIBLE_LIGHTS]; |
|
|
|
float4 _AdditionalLightAttenuationParams[MAX_VISIBLE_LIGHTS]; |
|
|
|
half4 _AdditionalLightSpotDir[MAX_VISIBLE_LIGHTS]; |
|
|
|
CBUFFER_END |
|
|
|
|
|
|
|
CBUFFER_START(_PerFrame) |
|
|
|
half4 _GlossyEnvironmentColor; |
|
|
|
sampler2D _AttenuationTexture; |
|
|
|
CBUFFER_END |
|
|
|
void OutputTangentToWorld(half4 vertexTangent, half3 vertexNormal, out half3 tangentWS, out half3 binormalWS, out half3 normalWS) |
|
|
|
{ |
|
|
|
half sign = vertexTangent.w * unity_WorldTransformParams.w; |
|
|
|
normalWS = normalize(UnityObjectToWorldNormal(vertexNormal)); |
|
|
|
tangentWS = normalize(mul((half3x3)unity_ObjectToWorld, vertexTangent.xyz)); |
|
|
|
binormalWS = cross(normalWS, tangentWS) * sign; |
|
|
|
} |
|
|
|
|
|
|
|
half3 TangentToWorldNormal(half3 normalTangent, half3 tangent, half3 binormal, half3 normal) |
|
|
|
{ |
|
|
|
|
|
|
return half4(LIGHTWEIGHT_LINEAR_TO_GAMMA(color), 1); |
|
|
|
#endif |
|
|
|
} |
|
|
|
|
|
|
|
inline half Alpha(half albedoAlpha) |
|
|
|
{ |
|
|
|
#if defined(_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A) |
|
|
|
half alpha = _Color.a; |
|
|
|
#else |
|
|
|
half alpha = albedoAlpha * _Color.a; |
|
|
|
#endif |
|
|
|
|
|
|
|
#if defined(_ALPHATEST_ON) |
|
|
|
clip(alpha - _Cutoff); |
|
|
|
#endif |
|
|
|
|
|
|
|
return alpha; |
|
|
|
} |
|
|
|
|
|
|
|
half3 Normal(float2 uv) |
|
|
|
{ |
|
|
|
#if _NORMALMAP |
|
|
|
return UnpackNormal(tex2D(_BumpMap, uv)); |
|
|
|
#else |
|
|
|
return half3(0.0h, 0.0h, 1.0h); |
|
|
|
#endif |
|
|
|
} |
|
|
|
|
|
|
|
inline void SpecularGloss(half2 uv, half alpha, out half4 specularGloss) |
|
|
|
{ |
|
|
|
specularGloss = half4(0, 0, 0, 1); |
|
|
|
#ifdef _SPECGLOSSMAP |
|
|
|
specularGloss = tex2D(_SpecGlossMap, uv); |
|
|
|
specularGloss.rgb = LIGHTWEIGHT_GAMMA_TO_LINEAR(specularGloss.rgb); |
|
|
|
#elif defined(_SPECULAR_COLOR) |
|
|
|
specularGloss = _SpecColor; |
|
|
|
#endif |
|
|
|
|
|
|
|
#ifdef _GLOSSINESS_FROM_BASE_ALPHA |
|
|
|
specularGloss.a = alpha; |
|
|
|
#endif |
|
|
|
} |
|
|
|
|
|
|
|
half4 MetallicSpecGloss(float2 uv, half albedoAlpha) |
|
|
|
{ |
|
|
|
half4 specGloss; |
|
|
|
|
|
|
|
#ifdef _METALLICSPECGLOSSMAP |
|
|
|
specGloss = specGloss = SAMPLE_METALLICSPECULAR(uv); |
|
|
|
#ifdef _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A |
|
|
|
specGloss.a = albedoAlpha * _GlossMapScale; |
|
|
|
#else |
|
|
|
specGloss.a *= _GlossMapScale; |
|
|
|
#endif |
|
|
|
|
|
|
|
#else // _METALLICSPECGLOSSMAP |
|
|
|
#if _METALLIC_SETUP |
|
|
|
specGloss.rgb = _Metallic.rrr; |
|
|
|
#else |
|
|
|
specGloss.rgb = _SpecColor.rgb; |
|
|
|
#endif |
|
|
|
|
|
|
|
#ifdef _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A |
|
|
|
specGloss.a = albedoAlpha * _GlossMapScale; |
|
|
|
#else |
|
|
|
specGloss.a = _Glossiness; |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
return specGloss; |
|
|
|
} |
|
|
|
|
|
|
|
half OcclusionLW(float2 uv) |
|
|
|
{ |
|
|
|
#ifdef _OCCLUSIONMAP |
|
|
|
#if (SHADER_TARGET < 30) |
|
|
|
// SM20: instruction count limitation |
|
|
|
// SM20: simpler occlusion |
|
|
|
return tex2D(_OcclusionMap, uv).g; |
|
|
|
#else |
|
|
|
half occ = tex2D(_OcclusionMap, uv).g; |
|
|
|
return LerpOneTo(occ, _OcclusionStrength); |
|
|
|
#endif |
|
|
|
#else |
|
|
|
return 1.0; |
|
|
|
#endif |
|
|
|
} |
|
|
|
|
|
|
|
half3 EmissionLW(float2 uv) |
|
|
|
{ |
|
|
|
#ifndef _EMISSION |
|
|
|
return 0; |
|
|
|
#else |
|
|
|
return LIGHTWEIGHT_GAMMA_TO_LINEAR(tex2D(_EmissionMap, uv).rgb) * _EmissionColor.rgb; |
|
|
|
#endif |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif |