Skip to content

Instantly share code, notes, and snippets.

@mebiusbox
Created September 8, 2017 14:25
Show Gist options
  • Save mebiusbox/32995b0d133a82a05b4023e512addb77 to your computer and use it in GitHub Desktop.
Save mebiusbox/32995b0d133a82a05b4023e512addb77 to your computer and use it in GitHub Desktop.
GGX Approximation Diffuse for BRDF Explorer
analytic
# variables go here...
# only floats supported right now.
# [type] [name] [min val] [max val] [default val]
::begin parameters
float albedo 0 1 1
float roughness 0 1 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 a = roughness*roughness;
float facing = 0.5 + 0.5 * LdotV;
float rough = facing * (0.9 - 0.4 * facing) * ((0.5 + NdotH)/NdotH);
float Smooth = 1.05 * (1 - pow(1-LdotN, 5)) * (1-pow(1-VdotN, 5));
float single = 1/PI * mix(Smooth, rough, a);
float multi = 0.1159 * a;
float contrib = albedo * (single + albedo*multi);
return vec3(contrib);
}
::end shader
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment