| 170 | } |
| 171 | |
| 172 | Vector 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 | |
| 188 | float PhaseHG(const Vector &w, const Vector &wp, float g) { |
| 189 | const float costheta = Dot(w, wp); |
nothing calls this directly
no test coverage detected