Sampling a hemisphere using an arbitary distribtui

2019-06-11 15:18发布

I am writing a ray tracer and I wish to fire rays from a point p into a hemisphere above that point according to some distribution.

1) I have derived a method to uniformly sample within a solid angle (defined by theta) above p Image

phi = 2*pi*X_1

alpha = arccos (1-(1-cos(theta))*X_2)

x = sin(alpha)*cos(phi)

y = sin(alpha)*sin*phi

z = -cos(alpha)

Where X is a uniform random number

That works and Im pretty happy with that. But my question is what happens if I do not want a uniform distribution.

I have used the algorithm on page 27 from here and I can draw samples from a piecewise arbitrary distribution. However if I simply say:

alpha = arccos (1-(1-cos(theta)) B1)

Where B is a random number generated from an arbiatry distribution. It doesn't behave nicely...What am I doing wrong? Thanks in advance. I really really need help on this

Additional: Perhaps I am asking a leading question. Taking a step back: Is there a way to generate points on a hemisphere according to an arbitrary distribution. I have a method for uniformly sampling a hemisphere and one for cosine-weighted hemisphere sampling. (pg 663-669 pbrt.org)

1条回答
淡お忘
2楼-- · 2019-06-11 15:41

With an uniform distribution, you can just average the sample results and obtain the correct result. This is equivalent to divide each sample result by the sample Probability Density Function (PDF) and, in the case of an uniform distribution, it is just 1 / sample_count (i.e. the same of averaging the results).

With an arbitrary distribution, you have still to divide the sample result by the sample PDF however the PDF now depends on the arbitrary distribution you are using. I assume your error is here.

查看更多
登录 后发表回答