| 81 | } |
| 82 | |
| 83 | Spectrum SampleableSphericalFunction::Sample( |
| 84 | const float u1, const float u2, Vector *w, float *pdf) const { |
| 85 | // Find floating-point $(u,v)$ sample coordinates |
| 86 | float uv[2]; |
| 87 | uvDistrib->SampleContinuous(u1, u2, uv, pdf); |
| 88 | if (*pdf == 0.f) |
| 89 | return Spectrum(); |
| 90 | |
| 91 | // Convert sample point to direction on the unit sphere |
| 92 | const float theta = uv[1] * M_PI; |
| 93 | const float phi = uv[0] * 2.f * M_PI; |
| 94 | const float costheta = cosf(theta), sintheta = sinf(theta); |
| 95 | *w = SphericalDirection(sintheta, costheta, phi); |
| 96 | |
| 97 | // Compute PDF for sampled direction |
| 98 | *pdf /= 2.f * M_PI * M_PI * sintheta; |
| 99 | |
| 100 | // Return value for direction |
| 101 | return Evaluate(phi, theta) / *pdf; |
| 102 | } |
| 103 | |
| 104 | float SampleableSphericalFunction::Pdf(const Vector &w) const { |
| 105 | const float theta = SphericalTheta(w); |