(L) [2014/02/05] [tby mrenneract] [Question about cube mapping and calculating PDFs] Wayback!Hello, I just joined the forum!
I looked at LuxRender's implementation of cube mapping and am a bit confused by the calculation of the PDF.
They basically use:
Code: [LINK # Select all]*pdf = ima * ima * ima / 48.f;
I know that 48 comes from the surface area of the cube map, where each face has an area of 4 and they do rejection sampling which results in 12 squares being sampled.  However I'm not all too clear on the reasoning for multiplying by the ima's, which is the inverse of the length of the vector when sampling based on texel parameters.  In the case of sampling texel values when given a direction vector, ima ends up being the inverse of the magnitude of the largest coordinate value.  I've tried to search for resources on this, but can't seem to find anything.
Here's a link to the relevant part of LuxRender's source:
[LINK http://src.luxrender.net/lux/src/f381b5b7210454c02fff5c239b5af1847a87df5e/core/texture.cpp?at=default#cl-429]
(L) [2014/02/06] [tby ingenious] [Question about cube mapping and calculating PDFs] Wayback!The formula you quote converts the measure of the PDF of the sampled direction from area on the cube to solid angle. You need to do this because the Monte Carlo integrator expects the PDF to be expressed w.r.t. solid angle, and you generate the direction by sampling points on a cube.
In general, the area to solid angle conversion factor has the form
Code: [LINK # Select all]dist_to_cube^2 / |cos(dir, cube_normal)|
which in this particular case simplifies to
Code: [LINK # Select all]1 / |cos(dir, cube_normal)|^3 = ima^3
because the sides of the cube are at distance 1 from the point and thus
Code: [LINK # Select all]dist_to_cube = 1 / |cos(dir, cube_normal)|
Hope this makes it clear.
By the way, this same factor (1 / |cos(dir, cube_normal)|^3) appears in the formula for computing the solid angle PDF of camera rays (which are generated by sampling points on the image plane). I'm lucky to have remembered this factor from that formula. It's sad that people often omit comments nor self-documenting variable names.
EDIT: Fixed the first formula (fraction was inverted).