Skip to content

Instantly share code, notes, and snippets.

@mebiusbox
Created September 8, 2017 14:22
Show Gist options
  • Save mebiusbox/c51ae40a398c5ed5534689eb8bb3b7d7 to your computer and use it in GitHub Desktop.
Save mebiusbox/c51ae40a398c5ed5534689eb8bb3b7d7 to your computer and use it in GitHub Desktop.
Normalized Oren-Nayar for BRDF explorer.
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
bool fresnel 1
::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 fdiff = 1.05 * (1.0 - f0) * (1.0 - pow(1.0 - LdotN, 5.0)) * (1.0 - pow(1.0 - VdotN, 5.0));
float A = 1.0 - 0.5 * (a / (a + 0.65));
float B = 0.45 * (a / (a + 0.09));
float Bp = LdotV - (VdotN * LdotN);
float Bm = min(1.0, LdotN / VdotN);
if (fresnel) {
return vec3((1.0/PI) * (1.0 - f0) * (fdiff * LdotN * A + B * Bp * Bm));
}
if (Bp >= 0.0) {
return vec3((1.0/PI)*(LdotN*A + B*Bp*Bm));
}
return vec3((1.0/PI)*(LdotN*A + B*Bp));
}
::end shader
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment