PBRT_V2 总结记录 <94> 2D Sampling With Multidimensional Transformations

概述:

Suppose we have a 2D joint density function p(x, y) that we wish to draw samples (X, Y)
from. Sometimes multidimensional densities are separable and can be expressed as the
product of 1D densities, for example,

for some px and py. In this case, random variables (X, Y) can be found by independently
sampling X from px and Y from py. Many useful densities aren’t separable, however, so
we will introduce the theory of how to sample from multidimensional distributions in
the general case.

 

Given a 2D density function, the marginal density function p(x) is obtained by “integrating
out” one of the dimensions:

This can be thought of as the density function forX alone.More precisely, it is the average
density for a particular x over all possible y values.

 

The conditional density function p(y|x) is the density function for y given that some
particular x has been chosen (it is read “p of y given x”):

The basic idea for 2D sampling from joint distributions is to first compute the marginal
density to isolate(隔离) one particular variable and draw a sample from that density using standard
1D techniques. Once that sample is drawn, one can then compute the conditional

density function given that value and draw a sample from that distribution, again using
standard 1D sampling techniques.

(基本思路:第一先计算 the marginal density,第二再计算  the conditional density function

 

EXAMPLE: UNIFORMLY SAMPLING A HEMISPHERE

As an example, consider the task of choosing a direction on the hemisphere uniformly
with respect to solid angle. Remember that a uniform distribution means that the density
function is a constant, so we know that p(ω) = c. In conjunction with(连同) the fact that the
density function must integrate to one over its domain, we have

This tells us that p(ω) = 1/(2π), or p(θ , φ) = sin θ/(2π) (using a result from the previous
example about spherical coordinates)(这里可以参考 《PBRT_V2 总结记录 <93> Transforming Between Distributions In Multiple Dimensions》). Note that this density function is separable.
Nevertheless, we will use the marginal and conditional densities to illustrate the multidimensional
sampling technique.

Consider sampling θ first. To do so, we need θ’s marginal density function p(θ):

Now, compute the conditional density for φ:

Notice that the density function for φ is itself uniform; this should make intuitive sense
given the symmetry of the hemisphere.Now, we use the 1D inversion technique to sample
each of these PDFs in turn:

(注意,这里是 CDF,并不是 PDF)

 

Inverting these functions is straightforward, and again noting that we can safely replace
1− ξ with ξ since these are both uniformly distributed random numbers over [0, 1],
we get

Converting these back to Cartesian coordinates, we get the final sampling formulae:

This sampling strategy is implemented in the following code. Two uniform random
numbers u1 and u2 are passed in, and a vector on the hemisphere is returned.

Vector UniformSampleHemisphere(float u1, float u2) {
    float z = u1;
    float r = sqrtf(max(0.f, 1.f - z*z));
    float phi = 2 * M_PI * u2;
    float x = r * cosf(phi);
    float y = r * sinf(phi);
    return Vector(x, y, z);
}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值