# Sampling a hemisphere using an arbitary distribtuion

#### Bodes

##### New Member
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** [1]

$$\phi = 2\pi\xi_1$$

$$\alpha = \arccos (1-(1-\cos(\theta))\xi_2)$$

$$x = \sin(\alpha)\cos\phi$$

$$y = \sin(\alpha)\sin\phi$$

$$z = -\cos(\alpha)$$

Where$$\xi$$ 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 [2] and I can draw samples from a piecewise arbitrary distribution. However if I simply say:

$$\alpha = \arccos (1-(1-cos(\theta)) \beta_1)$$

Where $\beta$ 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

[1]: http://postimg.org/image/4wcboqudj/
[2]: http://graphics.ucsd.edu/courses/cse168_s06/ucsd/lecture09.pdf