Original Post
Hi, I wasn't able to find what I need, so I thought to try here. I need to uniformly sample a hemisphere, and I went as follows: All the formulas I've found do the conversion spherical->cartesian togheter with the phi and theta calculation, so they mix everything and I can't figure out if my code is correct or not. Could someone more skilled confirm that this code does the sampling right? In addition, if I wanted to limit the sampling range (providing a max theta), I just need to change the code as follows, right? Thank you!
static inline const vector4<real> SampleUniformHemisphere(const vector2<real> &sample)
{
real phi = Q_2PI * sample.x;
real theta = (Q_PI / real(2)) * sample.y;
return vector4<real>::FromSpherical(theta, phi, real(1));
}
static inline const vector4<real> SampleUniformHemisphereLobe(const vector2<real> &sample, real maxTheta)
{
real phi = Q_2PI * sample.x;
real theta = maxTheta * sample.y;
return vector4<real>::FromSpherical(theta, phi, real(1));
}