|
|
|
|
|
|
#endif |
|
|
|
} |
|
|
|
|
|
|
|
half3 MetallicSetup(float2 uv, Surface s, /*half3 albedo, half albedoAlpha, */out half3 specular, out half smoothness, out half oneMinusReflectivity) |
|
|
|
half3 MetallicSetup(float2 uv, SurfacePBR s, /*half3 albedo, half albedoAlpha, */out half3 specular, out half smoothness, out half oneMinusReflectivity) |
|
|
|
{ |
|
|
|
//half2 metallicGloss = MetallicSpecGloss(uv, albedoAlpha).ra; |
|
|
|
//half metallic = metallicGloss.r; |
|
|
|
|
|
|
return s.Albedo * oneMinusReflectivity; |
|
|
|
} |
|
|
|
|
|
|
|
half3 SpecularSetup(float2 uv, Surface s, /*half3 albedo, half albedoAlpha, */out half3 specular, out half smoothness, out half oneMinusReflectivity) |
|
|
|
half3 SpecularSetup(float2 uv, SurfacePBR s, /*half3 albedo, half albedoAlpha, */out half3 specular, out half smoothness, out half oneMinusReflectivity) |
|
|
|
{ |
|
|
|
half4 specGloss = float4(s.Specular, s.Smoothness);// MetallicSpecGloss(uv, albedoAlpha); |
|
|
|
|
|
|
|
|
|
|
return o; |
|
|
|
} |
|
|
|
|
|
|
|
Surface InitializeSurface() |
|
|
|
SurfacePBR InitializeSurfacePBR() |
|
|
|
Surface s; |
|
|
|
s.Albedo = float3(1, 1, 1); |
|
|
|
SurfacePBR s; |
|
|
|
s.Albedo = float3(0.5, 0.5, 0.5); |
|
|
|
s.Specular = float3(0, 0, 0); |
|
|
|
s.Metallic = 0; |
|
|
|
s.Normal = float3(.5, .5, 1); |
|
|
|
|
|
|
s.Alpha = 1; |
|
|
|
return s; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
SurfaceFastBlinn InitializeSurfaceFastBlinn() |
|
|
|
{ |
|
|
|
SurfaceFastBlinn s; |
|
|
|
s.Diffuse = float3(0.5, 0.5, 0.5); |
|
|
|
s.Specular = float3(0, 0, 0); |
|
|
|
s.Normal = float3(.5, .5, 1); |
|
|
|
s.Emission = 0; |
|
|
|
s.Glossiness = 0; |
|
|
|
s.Alpha = 1; |
|
|
|
return s; |
|
|
|
} |
|
|
|
void DefineSurface(LightweightVertexOutput i, inout Surface s); |
|
|
|
void DefineSurface(LightweightVertexOutput i, inout SurfacePBR s); |
|
|
|
void DefineSurface(LightweightVertexOutput i, inout SurfaceFastBlinn s); |
|
|
|
Surface s = InitializeSurface(); |
|
|
|
SurfacePBR s = InitializeSurfacePBR(); |
|
|
|
DefineSurface(i, s); |
|
|
|
|
|
|
|
float2 uv = i.uv01.xy; |
|
|
|
|
|
|
|
|
|
|
half4 LightweightFragmentFastBlinn(LightweightVertexOutput i) : SV_Target |
|
|
|
{ |
|
|
|
half4 diffuseAlpha = tex2D(_MainTex, i.uv01.xy); |
|
|
|
half3 diffuse = LIGHTWEIGHT_GAMMA_TO_LINEAR(diffuseAlpha.rgb) * _Color.rgb; |
|
|
|
half alpha = diffuseAlpha.a * _Color.a; |
|
|
|
SurfaceFastBlinn s = InitializeSurfaceFastBlinn(); |
|
|
|
DefineSurface(i, s); |
|
|
|
clip(alpha - _Cutoff); |
|
|
|
clip(s.Alpha - _Cutoff); |
|
|
|
half3 normalMap = UnpackNormal(tex2D(_BumpMap, i.uv01.xy)); |
|
|
|
CalculateNormal(normalMap, i, normal); |
|
|
|
|
|
|
|
half4 specularGloss; |
|
|
|
SpecularGloss(i.uv01.xy, alpha, specularGloss); |
|
|
|
CalculateNormal(s.Normal, i, normal); |
|
|
|
|
|
|
|
half3 viewDir = i.viewDir.xyz; |
|
|
|
float3 worldPos = i.posWS.xyz; |
|
|
|
|
|
|
half4 specularGloss = half4(s.Specular, s.Glossiness); |
|
|
|
#ifndef _MULTIPLE_LIGHTS |
|
|
|
LightInput lightInput; |
|
|
|
INITIALIZE_MAIN_LIGHT(lightInput); |
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
half3 color = LightingBlinnPhong(diffuse, specularGloss, lightDirection, normal, viewDir, lightAtten) * lightInput.color; |
|
|
|
half3 color = LightingBlinnPhong(s.Diffuse, specularGloss, lightDirection, normal, viewDir, lightAtten) * lightInput.color; |
|
|
|
half3 color = LightingLambert(diffuse, lightDirection, normal, lightAtten) * lightInput.color; |
|
|
|
half3 color = LightingLambert(s.Diffuse, lightDirection, normal, lightAtten) * lightInput.color; |
|
|
|
#endif |
|
|
|
|
|
|
|
#else |
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
#ifdef LIGHTWEIGHT_SPECULAR_HIGHLIGHTS |
|
|
|
color += LightingBlinnPhong(diffuse, specularGloss, lightDirection, normal, viewDir, lightAtten) * lightData.color; |
|
|
|
color += LightingBlinnPhong(s.Diffuse, specularGloss, lightDirection, normal, viewDir, lightAtten) * lightData.color; |
|
|
|
color += LightingLambert(diffuse, lightDirection, normal, lightAtten) * lightData.color; |
|
|
|
color += LightingLambert(s.Diffuse, lightDirection, normal, lightAtten) * lightData.color; |
|
|
|
#ifdef _EMISSION |
|
|
|
color += LIGHTWEIGHT_GAMMA_TO_LINEAR(tex2D(_EmissionMap, i.uv01.xy).rgb) * _EmissionColor; |
|
|
|
#else |
|
|
|
color += _EmissionColor; |
|
|
|
#endif |
|
|
|
color += CalculateEmissionFastBlinn(i.uv01.xy); |
|
|
|
color += (DecodeLightmap(UNITY_SAMPLE_TEX2D(unity_Lightmap, i.uv01.zw)) + i.fogCoord.yzw) * diffuse; |
|
|
|
color += (DecodeLightmap(UNITY_SAMPLE_TEX2D(unity_Lightmap, i.uv01.zw)) + i.fogCoord.yzw) * s.Diffuse; |
|
|
|
color += i.fogCoord.yzw * diffuse; |
|
|
|
color += i.fogCoord.yzw * s.Diffuse; |
|
|
|
color += texCUBE(_Cube, reflectVec).rgb * specularGloss.rgb; |
|
|
|
color += texCUBE(_Cube, reflectVec).rgb * s.Specular; |
|
|
|
color += reflectionProbe.rgb * (reflectionProbe.a * unity_SpecCube0_HDR.x) * specularGloss.rgb; |
|
|
|
color += reflectionProbe.rgb * (reflectionProbe.a * unity_SpecCube0_HDR.x) * s.Specular; |
|
|
|
return OutputColor(color, alpha); |
|
|
|
return OutputColor(color, s.Alpha); |
|
|
|
}; |
|
|
|
|
|
|
|
#endif |