MCPcopy Create free account
hub / github.com/TheRealMJP/BakingLab / SampleDirectionGGX

Function SampleDirectionGGX

SampleFramework11/v1.02/Graphics/Sampling.h:121–137  ·  view source on GitHub ↗

Returns a random direction for sampling a GGX distribution. Does everything in world space.

Source from the content-addressed store, hash-verified

119// Returns a random direction for sampling a GGX distribution.
120// Does everything in world space.
121inline Float3 SampleDirectionGGX(const Float3& v, const Float3& n, float roughness,
122 const Float3x3& tangentToWorld, float u1, float u2)
123{
124 float theta = std::atan2(roughness * std::sqrt(u1), std::sqrt(1 - u1));
125 float phi = 2 * Pi * u2;
126
127 Float3 h;
128 h.x = std::sin(theta) * std::cos(phi);
129 h.y = std::sin(theta) * std::sin(phi);
130 h.z = std::cos(theta);
131
132 h = Float3::Normalize(Float3::Transform(h, tangentToWorld));
133
134 float hDotV = std::abs(Float3::Dot(h, v));
135 Float3 sampleDir = 2.0f * hDotV * h - v;
136 return Float3::Normalize(sampleDir);
137}
138
139// Returns the PDF for a particular GGX sample
140inline float GGX_PDF(const Float3& n, const Float3& h, const Float3& v, float roughness)

Callers 2

PathTraceFunction · 0.85

Calls 5

atan2Function · 0.85
sqrtFunction · 0.85
sinFunction · 0.85
cosFunction · 0.85
TransformClass · 0.50

Tested by

no test coverage detected