Hey guys, I've been trying to implement a phsically based metal kind of shader and I was wondering if what I'm doing is correct.
Have a look at my shader:
// Compute half-way-vector float3 H = (V + L); H = normalize(H); // normalize // Specular Fresnel Term approximation by Schlick float LdotH = saturate(dot(L, H)); float3 Fresnel_spec_multiplier = 1.0f - FresnelReflectance; float3 Fresnel_spec = FresnelReflectance + exp2(log2(1.0f - LdotH) * 5 + log2(Fresnel_spec_multiplier)); // Normalized Blinn-Phong NDF (D) float D = 0.0f; float NdotH = saturate(dot(N, H)); float NormalizationFactor = ((glossiness + 2) / 2); D = exp2(log2(NdotH) * glossiness + log2(NormalizationFactor)); // NormalizationFactor * pow(NdotH, glossiness) // Cook-Torrance geometry term approximation by Kelemen & Szirmay-Kalos float G = 1.0f / (LdotH * LdotH + 0.0000001f); // Microfacet BRDF f(l,v) float3 f_microfacet = (Fresnel_spec * G * D) / 4.0f; Radiance += f_microfacet * Li * Cosine; Radiance += ReflectionColor * Fresnel_spec;
As you can see I'm already using a custom microfacet brdf using an approximation of the cook-torrance geometry term and the fresnel factor but for the NDF just a regular blinn-phong model. Is the cook-torrance NDF actually the beckmann distribution function or is it something different ? If yes then should I rather use a precomputed distribution texture for this like it's found on here: http://http.developer.nvidia.com/GPUGems3/gpugems3_ch14.html ?
I've found this code segment for the cook-torrance NDF on pixars renderman page:
float alpha = acos(NdotH); float D = gaussConstant*exp(-(alpha*alpha)/(m*m));
alpha in this case would be NdotH and m is the microfacet H ? And the guassian constant would be something like 0.8346...? (according to what I found on wikipedia).
This is a screenshot of how it looks using fresnel of gold:
here's another one using a different normal map:
I think it's wrong to tint the environment color with the specular fresnel again after I've multiplied it before by the fresnel using NdotV ?
It's just that it looks very "blueish" to me if I don't do that, have a look:
Edited by lipsryme, 30 April 2013 - 10:26 AM.