Physically Based Shading in Unity
float4 MyFragmentProgram(VertexToFragment v2f) :SV_TARGET{
float3 lightDir = _WorldSpaceLightPos0.xyz;
float3 viewDir = normalize(_WorldSpaceCameraPos - v2f.worldpos);
float3 lightColor = _LightColor0.rgb;
float3 albedo = tex2D(_MainTex, v2f.uv).rgb * _Color;
float oneMinusReflectivity;
albedo = EnergyConservationBetweenDiffuseAndSpecular(albedo,
_SpecularColor, oneMinusReflectivity);
UnityLight light;
light.color = lightColor;
light.dir = lightDir;
light.ndotl = DotClamped(normalize(v2f.normal),
lightDir);
UnityIndirect indirectLight;
indirectLight.diffuse = 0;
indirectLight.specular = 0;
return UNITY_BRDF_PBS(albedo, _SpecularColor, oneMinusReflectivity,
_
Smoothness, normalize(v2f.normal), viewDir,
light, indirectLight);
}