@@ -24,8 +24,7 @@ PS_OUTPUT main(BASIC_PS_INPUT input)
2424 float3 blinn_phong = diffuse * d + s;*/
2525
2626 // blend between dielectric and metal
27- const float f0 = 0.03 ;
28- float3 specularColor = lerp (float3 (1.0 , 1.0 , 1.0 ), albedo, metalness);
27+ float3 specularColor = metalness * lerp (metalness.xxx, albedo, metalness);
2928 float3 finalAlbedo = albedo * (1.0 - metalness);
3029
3130 // precompute all cosines
@@ -38,7 +37,7 @@ PS_OUTPUT main(BASIC_PS_INPUT input)
3837 float3 diffuse = dotNL * finalAlbedo;
3938
4039 // schlick fresnel approximation
41- float fresnel = f0 + (1.0 - f0 ) * pow (1.0 - dotNV, 5.0 );
40+ float3 fresnel = specularColor + (1.0 - specularColor ) * pow (1.0 - dotNV, 5.0 );
4241
4342 float alpha = roughness * roughness;
4443 float alphaSquared = alpha * alpha;
@@ -49,12 +48,12 @@ PS_OUTPUT main(BASIC_PS_INPUT input)
4948
5049 // schlick approximation for geometry factor
5150 float k = alpha * 0.5 ;
52- float geometryFactor = g1v (dotNL, k) * g1v (dotNV, k);
51+ float visibility = g1v (dotNL, k) * g1v (dotNV, k);
5352
5453 // cook-torrance microfacet model
55- float3 specular = specularColor * dotNL * fresnel * normalDistribution * geometryFactor ;
54+ float3 specular = fresnel * normalDistribution * visibility ;
5655
57- output.color = float4 (( diffuse + specular) * 10.0 , 1.0 );
56+ output.color = float4 (diffuse + specular, 1.0 );
5857
5958 return output;
6059}
0 commit comments