7

I'm currently learning mathemetical concepts of distribution and the way to use them in a ray tracer with the book "Physically Based Rendering".

Let's start by uniformly sampling an hemisphere:

As you probably know, a way to generate the uniformly distributed direction is to use the inversion method.

Let us denote by $p$ our uniform probability density function:

$p(\omega) = \cfrac{1}{2\pi}$ and so $p(\theta, \phi) = \sin(\theta)p(\omega)$.

Then you compute $p(\theta)$, $p(\phi | \theta)$, you integrate your cumulative distribution function and you invert the function.

My questions are:

  • What does $p(\theta, \phi)$ really mean?

  • What is the transformation between $p(\omega)$ and $p(\theta, \phi)$?

  • In the book, to find $p(\theta,\phi)$ they state that $p(\theta, \phi) d\theta d\phi = p(\omega)d\omega$, but why?

I know that for $p(\omega)$, our random variable is a given $\omega$ (a direction), so the function represents a relative probability for this direction (so a solid angle, because the relative term implies a direction and a delta area around this direction).

But for $p(\theta,\phi)$, our random variable is now the couple $(\theta,\phi)$. To what extent is it different from a direction?

Qzaac
  • 73
  • 5

1 Answers1

5

I'm not sure I've correctly understood the question, but here goes.

You're trying to sample directions uniformly, so you've got $p(\omega)$, which is the probability of getting a particular direction. But what is a direction? You actually need your probability distribution to produce numbers in some representation, and the easiest representation to deal with is lat-long (i.e. two angles). So the thing you actually need to sample from is the probability distribution of pairs of angles. This is what $p(\theta, \phi)$ is: the joint probability of two variables.

$p(\omega)$ and $p(\theta, \phi)$ mean the same thing geometrically, but the former gives you an abstract direction you can't sample from directly, while the latter more usefully gives you two numbers that represent a direction.

The reason for your third bullet point is to do with the point you've made about how it isn't just a single direction. These aren't really functions: they're distributions. A direction is infinitesimal, so you can't have a probability of just one direction. What you actually need to do is integrate it over the directions you're interested in. $$ \int p(\omega)d\omega = \int_0^{2\pi}\int_0^\pi p(\theta, \phi)d\theta d\phi = 1 $$

Whichever representation you use, the integral over the hemisphere has to be 1, because it's a probability distribution.


I'm not sure if I need to explain this or if you already understood, but here's the origin of the $sin(\theta)$. When you do the double-integral on the right, you're splitting the problem up into a series of rings, or slices of the unit sphere. Each ring has constant $\theta$ while $\phi$ goes from $0$ to $2\pi$. Also, the area of each individual ring decreases as $\theta$ increases: the ring at the equator is huge, while the last "ring" at the pole is tiny. The area decreases as $sin(\theta)$. Because we want each unit of area of the sphere to have the same probability, we need the smaller rings to get a smaller share of the probability.

As Florian R. explains, you can do that by including the $sin(\theta)$ factor in the integral, or you can put it inside the definition of $p(\theta, \phi)$ like the book does.

Dan Hulme
  • 6,780
  • 1
  • 16
  • 35
  • In your equation, you transform from integration in cartesian coordinates to integration in sphere coordinates. Shouldn't you add sin(ϕ) there to account for this coordinate transformation? Alternatively, you might define p(θ, ϕ)=sin(ϕ)p(sin(ϕ)cos(θ), sin(ϕ)sin(θ), cos(ϕ)), but I think it will be more clear if the sin(ϕ) factor is distinct from p(θ, ϕ). – Florian R. Jun 28 '17 at 10:07
  • 1
    @FlorianR. The question already describes that sin(θ) is inside p(θ, ϕ). The questioner didn't seem to have trouble with it and it's a bit of a side issue, so I didn't really pay any attention to it. – Dan Hulme Jun 28 '17 at 11:32
  • @DanHulme Thanks for your answer. Ok it's good to see p(w) as an abstract representation. In my question, I didn't understand how to compute $p(\theta, \phi)$. According to your answer, to calculate $p(\theta, \phi)$ you state that integrals equality involves integrands equality so $p(\omega)d\omega$ = $p(\theta, \phi)d\theta d\phi$, am I right ? But is it still right if in this case integration domains are not the same for the two integrals? – Qzaac Jun 29 '17 at 21:58
  • @FlorianR do you state that the transformation from $p(\omega)$ to $p(\theta, \phi)$ is the transformation from cartesian coordinates to spherical coordinates ? – Qzaac Jun 29 '17 at 22:03
  • 2
    @Yoo Rather the transformation from integrating over ω to integrating over θ and ϕ is the transformation from integrating in cartesian to integrating in spherical coordinates. While you already define p(ω) = sin(θ)p(θ,ϕ), I'd rather not change p at all, using ω=(sin(ϕ)cos(θ), sin(ϕ)sin(θ), cos(ϕ)) and using dω = sin(θ)dθdϕ. I think that should make it clear that p stays the same, we are just transforming the coordinate system of the integration. This is, however, subjective and if you redefine p to include sin(θ) like you did, the resulting equation will be the exact same. – Florian R. Jun 30 '17 at 04:41
  • @FlorianR You are right to precise that p is the same thing no matter its starting set ($\omega$, or {\theta, \phi}). It's the probability density function, used to find the relative probability of a direction, am I right ?

    I think you are misunderstanding what I understand and what I don't (my bad, my question can be confusing). Even though I state that $p(\omega) = \sin(\theta)p(\theta, \phi)$, i don't know why it is true. (That's why I asked the third question in my post), and because I don't know why is true, I can't plainly understand what is the transformation.

    – Qzaac Jun 30 '17 at 11:40
  • @Yoo Is my edit helpful? At first I thought I had understood what you understand and what you don't, but I'm not so sure now. – Dan Hulme Jun 30 '17 at 12:21
  • 1
    @Yoo Ah, I'm sorry. Dan just added an explanation and maybe to help you visualize it, think of a map using latitude/longitude. The south pole appears enormous, and if you were to integrate something along latitude and longitude, the poles would be overrepresented. The sin(θ) factor removes this bias towards the poles. Also, you might want to read up on integration by substitution for the general case. – Florian R. Jun 30 '17 at 12:25
  • @FlorianR. Oh, that's a good way of describing it. I might use that one in future. – Dan Hulme Jun 30 '17 at 12:29
  • @DanHulme yes your edit is helpful, it is always good to restart from scratch to be sure that everything is understood. – Qzaac Jul 01 '17 at 14:43
  • @FlorianR.Thanks, it's useful to have a "viewable" way of what the integral means. – Qzaac Jul 01 '17 at 14:44
  • @DanHulme

    However, Florian and you explained why $d(\omega) = \sin(\theta)d(\theta)d(\phi)$, am I right ?

    Let me ask the question: Why can we state that $p(\omega)d(\omega) = p(\theta,\phi)d(\theta)d(\phi)$ ? An equality that is in the book. This is the equality I want to prove, because it would infer that $p(\omega) = p(\theta, \phi) \sin(\theta)$, the questions I asked in my post.

    Is it because the integrals (in the Dan's answer) are equals so their integrands are equals ? I'm looking for a concrete, and rigorous proof of the equality.

    – Qzaac Jul 01 '17 at 14:56
  • @DanHulme To be clear, in th book they state that:

    $$p(\omega)d(\omega) = p(\theta, \phi)d(\theta)d(\phi)$$ so $$p(\omega)\sin(\theta)d(\theta)d(\phi) = p(\theta, \phi)d(\theta)d(\phi)$$ so $$p(\omega)\sin(\theta) = p(\theta, \phi)$$.

    And I can't rigorously demonstrate the first equality.

    – Qzaac Jul 01 '17 at 15:06
  • 1
    That wouldn't generally be true, but it is true here because of the extra constraint that the distribution is uniform. Any probability distribution has to integrate to 1, but this one also has the same value everywhere. (Or to put it another way, the two integrals have to be equal for every region you integrate over.) – Dan Hulme Jul 01 '17 at 18:22