Created
September 8, 2017 14:24
-
-
Save mebiusbox/eeb2b4bc07988db022dbe52d59b8dd23 to your computer and use it in GitHub Desktop.
GGX Oren-Nayar for BRDF Explorer
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
analytic | |
# variables go here... | |
# only floats supported right now. | |
# [type] [name] [min val] [max val] [default val] | |
::begin parameters | |
float roughness 0 1 1 | |
float f0 0 1 0.04 | |
::end parameters | |
# Then comes the shader. This should be GLSL code | |
# that defines a function called BRDF (although you can | |
# add whatever other functions you want too). | |
::begin shader | |
const float PI = 3.14159265358979323846; | |
vec3 BRDF( vec3 L, vec3 V, vec3 N, vec3 X, vec3 Y ) | |
{ | |
float VdotN = dot(V,N); | |
float LdotN = dot(L,N); | |
float LdotV = dot(L,V); | |
vec3 H = normalize(L+V); | |
float NdotH = dot(N,H); | |
float VdotH = dot(V,H); | |
float a = roughness*roughness; | |
// float fTheta = f0 + (1.0 - f0) * pow(2.0, -9.60232*pow(VdotH, 8) - 8.58092 * VdotH); | |
float Fr1 = (1.0 - (0.542026*a + 0.303573*roughness) / (a + 1.36053)); | |
float Fr2 = (1.0 - (pow(1.0 - VdotN, 5.0 - 4.0*a)) / (a + 1.36053)); | |
float Fr3 = (-0.733996*a*roughness + 1.50912*a - 1.16402*roughness); | |
float Fr4 = (pow(1.0 - VdotN, 1.0 + (1.0 / (39.0*a*a + 1.0)))); | |
float Fr = Fr1*Fr2*(Fr3*Fr4+1); | |
float Lm1 = (max(1.0 - (2.0*roughness), 0.0)*(1.0 - pow(1.0 - LdotN, 5.0)) + min(2.0*roughness, 1.0)); | |
float Lm2 = ((1.0 - 0.5*roughness)*LdotN + (0.5*roughness)*(pow(LdotN, 2.0))); | |
float Lm = Lm1 * Lm2; | |
float Vd1 = (a / ((a + 0.09)*(1.31072 + 0.995584*VdotN))); | |
float Vd2 = (1.0 - (pow(1.0 - LdotN, (1.0 - 0.3726732*(VdotN*VdotN)) / (0.188566 + 0.38841*VdotN)))); | |
float Vd = Vd1*Vd2; | |
float Bp = LdotV - (VdotN*LdotN); | |
if (Bp < 0.0) Bp *= 1.4*VdotN*LdotN; | |
return vec3((21.0 / (20.0*PI))*(1.0 - f0)*((Fr*Lm) + (Vd*Bp))); | |
} | |
::end shader |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment