vec3 p;
do
{
p = 2.0f * vec3(rand.getRandom(), rand.getRandom(), rand.getRandom()) - vec3(1, 1, 1);
}while(dot(p, p) >= 1.0f);
const vec3 p = 2.0f * vec3(rand.getRandom(), rand.getRandom(), rand.getRandom()) - vec3(1, 1, 1);
if (dot(p, p) >= 1.0f)
return unit_vector(p);
return p;
vec3 direction;
do
{
direction = random_in_unit_sphere(rand);
}while(dot(direction, rec.normal) < 0);
vec3 direction = random_in_unit_sphere(rand);
if (dot(direction, rec.normal) < 0)
direction *= -1.0f;
NB: This was for a 500x500px Cornell Box rendered at 1000 samples per pixel; if there is a difference, I can't see it.