Created
August 1, 2015 12:11
-
-
Save linniksergey/440d9d11cdb01c72d01d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "math.h" | |
vector Schlick (float cosT; vector Fi) | |
{ | |
return (Fi + (1-Fi) * pow(1-cosT, 5)); | |
} | |
vector cookTorrance(vector nN; string category; vector Fi; float roughness) | |
{ | |
vector out = {0,0,0}; | |
vector nV = normalize(-I); //normalized I | |
float r2 = roughness * roughness; | |
illuminance(P, nN, M_PI, bouncemask("reflect"), "category", category) | |
{ | |
vector nL = normalize(L); //normalized dir to light | |
vector H = normalize(nV + nL); // half vector | |
float NdotH = dot(nN, H); | |
float NdotL = dot(nN, nL); | |
float VdotH = dot(nV, H); | |
float NdotV = dot(nN, nV); | |
//fresnel | |
vector kr = Schlick(NdotV, Fi); | |
// Geometry function | |
float G = min(1, (2*NdotH*NdotV/VdotH), (2*NdotH*NdotL/VdotH)); | |
// beckman | |
float roughness_a = 1.0f / ( 4.0f * r2 * pow( NdotH, 4 ) ); | |
float roughness_b = NdotH * NdotH - 1.0f; | |
float roughness_c = r2 * NdotH * NdotH; | |
float D = roughness_a * exp( roughness_b / roughness_c ); | |
out += shadow(Cl) * (kr * D * G) / (M_PI * NdotV); | |
} | |
return out; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment