-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBrdf.cpp
More file actions
35 lines (27 loc) · 914 Bytes
/
Brdf.cpp
File metadata and controls
35 lines (27 loc) · 914 Bytes
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
#include "Math.h"
#include "Brdf.h"
float TestGGX(const float alpha, const float theta_o, const float theta, const float phi)
{
// view vector
const float3 v(sin(theta_o), 0.0f, cos(theta_o));
// masking
const float a = 1.0f / (alpha * tan(theta_o));
const float Lambda = (-1.0f + sqrt(1.0f + 1.0f / a * a)) / 2.0f;
const float G = 1.0f / (1.0f + Lambda);
// reflected vector
const float3 l(cos(phi)*sin(theta), sin(phi)*sin(theta), cos(theta));
// half vector
const float3 h = (v + l) / normalize(v + l);
// GGX distribution
float D = 0.0f;
if (h.z > 0.0f)
{
// angle associated with H
const float theta_h = acos(h.z);
D = 1.0F / powf(1.0F + powf(tan(theta_h) / alpha, 2.0F), 2.0F);
D = D / (PI * alpha*alpha * powf(h.z, 4));
}
// display integral (should be 1)
const float color = sin(theta) * D * G / abs(4.0f * v.z);
return color;
}