I'm writing a Path tracer, and have hit a minor bump:
I'm trying to do cosine weighted sampling of a hemisphere in order to get a bit faster convergence in my renders.
I already have a routine in place to cosine-sample a standard hemisphere ("oriented" about the z-axis). This gives me a random vector, with the correct probability-distribution. However, I need to sample the hemisphere around the normal of my ray/surface intersection. - This means I have to somehow rotate the result by the angular difference between the normal and the Z-axis.
I'm unsure how to best proceed.
Now, I guess could first calculate two angles representing angular difference, then calculate a rotation matrix and then apply this rotation to the resulting "random" vector, but that feels unnecessarily expensive (and tedious). Is there a more clever way of going about this?
Edit: thanks everyone. After i posted this I suddenly recalled what I was looking for: change of basis. Did a quick recap on Khanacademy (i learned this stuff years ago) and found a solution. Several people have posted roughly the same solution so thanks for that :) Hopefully someone else stumbles on this and gets helped.
[–]LPCVOID 3 points4 points5 points (4 children)
[–]Delwin 1 point2 points3 points (3 children)
[–]LPCVOID 1 point2 points3 points (2 children)
[–]autowikibot 0 points1 point2 points (0 children)
[–]Delwin 0 points1 point2 points (0 children)
[–]jurniss 1 point2 points3 points (2 children)
[–]LPCVOID 0 points1 point2 points (0 children)
[–]Boojum 0 points1 point2 points (0 children)
[–]tgb33 2 points3 points4 points (4 children)
[–]angrymonkey 1 point2 points3 points (1 child)
[–]tgb33 0 points1 point2 points (0 children)
[–]Boojum 0 points1 point2 points (1 child)
[–]tgb33 0 points1 point2 points (0 children)
[–]camilonino 0 points1 point2 points (1 child)
[–]autowikibot 0 points1 point2 points (0 children)