   uniform hemisphere sampling
  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: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));}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?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));}Thank you!   
  After another long search session, and a bit more thinking, I've come to this formula:static inline const vector4<real> SampleUniformHemisphere(const vector2<real> &sample){real phi = Q_2PI * sample.x;real theta = acos(sample.y);return vector4<real>::FromSpherical(theta, phi, real(1));}I suppose that then the equations to limit the theta range becomes:static inline const vector4<real> SampleUniformHemisphereLobe(const vector2<real> &sample, real maxTheta){real maxc = cos(maxTheta);real phi = Q_2PI * sample.x;real theta = acos(real(1) - (sample.y * maxc));return vector4<real>::FromSpherical(theta, phi, real(1));}Anyone can confirm or negate that?   