Sampling a hemisphere using an arbitary distribtuion

情到浓时终转凉″ 提交于 2019-12-08 11:45:09

问题


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:


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.



来源:https://stackoverflow.com/questions/17083173/sampling-a-hemisphere-using-an-arbitary-distribtuion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!