MCPcopy Create free account
hub / github.com/LuxCoreRender/LuxCore / SampleHG

Function SampleHG

src/luxrays/utils/mc.cpp:172–186  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

170}
171
172Vector SampleHG(const Vector &w, float g, const float u1, const float u2) {
173 float costheta;
174 if (fabsf(g) < 1e-3f)
175 costheta = 1.f - 2.f * u1;
176 else {
177 // NOTE - lordcrc - Bugfix, pbrt tracker id 0000082: bug in SampleHG
178 const float sqrTerm = (1.f - g * g) / (1.f - g + 2.f * g * u1);
179 costheta = (1.f + g * g - sqrTerm * sqrTerm) / (2.f * g);
180 }
181 const float sintheta = sqrtf(Max(0.f, 1.f - costheta * costheta));
182 const float phi = 2.f * M_PI * u2;
183 Vector v1, v2;
184 CoordinateSystem(w, &v1, &v2);
185 return SphericalDirection(sintheta, costheta, phi, v1, v2, w);
186}
187
188float PhaseHG(const Vector &w, const Vector &wp, float g) {
189 const float costheta = Dot(w, wp);

Callers

nothing calls this directly

Calls 3

MaxFunction · 0.85
CoordinateSystemFunction · 0.85
SphericalDirectionFunction · 0.85

Tested by

no test coverage detected