It was a hard night for me yesterday ,I was coding like maniac, searching for the reasons that made my path tracer render looks so ugly!I did fixed a bug related to the luminaries(objects below a luminaire ,like the ceiling, receives much light when they are supposed to be in shadow (thanks to neos for pointing this out))…
But now , I had a much more serious problem , It is how to pick a random direction on the unit hemisphere centered at the normal of the intersected point.At first ,I didn’t bother at searching for a good approach ,I just used the classic method which is :
-Pick two random number between 0 and 1 (say n1 and n2)
-theta=2*PI*n1
-phi=0.5*PI*n2
And then the random direction is :
x=cos(theta)*sin(phi)
y=sin(theta)*sin(phi)
z=cos(phi)
But this method turns out to be not efficient as I thought , a “strange” shadow in the back of the sphere has appeared , take a look:

So I looked over the internet to find another method for hemispherical sampling and I end up with this one:
pick two random numbers (e1 ,e2) the spherical angles (theta and phi) are then given by :
theta=2.0*PI*e1,phi=arccos(sq rt(e2)).
The shadow thing is somehow fixed but another bug has appeared , check it out:

I know that it is less probably that someone is visiting my blog right now but if you passed by and have a solution , please let me know!
Thanks
Edit:
After some searching , I found out that my problem was that I’m not actually constructing a coordinate system such as the unit hemisphere is centered around the normal at the intersected point so the good way is to sample the hemisphere using a pdf then creating the random direction by multiplying each component of the random direction (on the unit hemisphere) by the axis u,v,w respectively with w set to be the normal at the intersected point (must be normalized) , u=CrossProduct(t,w)/length(CrossProduct(t,w)) , t is a vector equal to w except that the smallest absolute value component of t (x,y or z) is set to 1 and finally v=CrossProduct(w,u).
Now the Cornell Box looks much more better:

Thanks for reading!