forked from autodesk-forks/MaterialX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmx_sheen_brdf.glsl
55 lines (44 loc) · 1.7 KB
/
mx_sheen_brdf.glsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "pbrlib/genglsl/lib/mx_bsdfs.glsl"
void mx_sheen_brdf_reflection(vec3 L, vec3 V, float weight, vec3 color, float roughness, vec3 N, BSDF base, out BSDF result)
{
if (weight < M_FLOAT_EPS)
{
result = base;
return;
}
float NdotL = dot(N,L);
float NdotV = dot(N,V);
if (NdotL <= 0.0 || NdotV <= 0.0)
{
result = base;
return;
}
vec3 H = normalize(L + V);
float NdotH = dot(N, H);
float alpha = clamp(roughness, M_FLOAT_EPS, 1.0);
float D = mx_microfacet_sheen_NDF(NdotH, alpha);
vec3 F = color * weight;
// Geometry term is skipped and we use a smoother denominator, as in:
// https://blog.selfshadow.com/publications/s2013-shading-course/rad/s2013_pbs_rad_notes.pdf
vec3 fr = D * F / (4.0 * (NdotL + NdotV - NdotL*NdotV));
// Get sheen directional albedo for attenuating base layer
// in order to be energy conserving.
float albedo = weight * mx_microfacet_sheen_albedo(NdotV, alpha);
// We need to include NdotL from the light integral here
// as in this case it's not cancelled out by the BRDF denominator.
result = fr * NdotL // Top layer reflection
+ base * (1.0 - albedo); // Base layer reflection attenuated by top layer
}
void mx_sheen_brdf_indirect(vec3 V, float weight, vec3 color, float roughness, vec3 N, BSDF base, out vec3 result)
{
if (weight <= 0.0)
{
result = base;
return;
}
float NdotV = abs(dot(N,V));
float alpha = clamp(roughness, M_FLOAT_EPS, 1.0);
float albedo = weight * mx_microfacet_sheen_albedo(NdotV, alpha);
vec3 Li = mx_environment_irradiance(N);
result = Li * color * albedo + base * (1.0 - albedo);
}