<p>I think it is a mistake in the book.</p>
<p>Pick random points uniformly on a sphere offset by the normal, you will get a
distribution of rays proportional to <span class="math-container">$\cos{\theta} \sin{\theta}$</span>, rather than <span class="math-container">$\cos{\theta}$</span> as the book written.</p>
<p><span class="math-container">$$
ds = \frac{(2r \cdot \cos{\theta} \cdot d\theta) }{\cos{\theta}}
\cdot (2 \pi \cdot 2r \cdot \cos{\theta} \sin{\theta)} 
$$</span>
where <span class="math-container">$ds$</span> is the differential area on the shifted sphere's surface with respect to <span class="math-container">$\theta$</span>. Integrate <span class="math-container">$\theta$</span> from 0 to <span class="math-container">$\pi/2$</span>, you'll get <span class="math-container">$4 \pi r^2$</span>.</p>
<p>And pick random points uniformly inside a sphere offset by the normal, you obtain a distribution of rays proportional to <span class="math-container">$\cos{\theta}^3 \sin{\theta}$</span>.</p>
<p><span class="math-container">$$
dv = (2r \cos{\theta} d\theta) \cdot(2\pi \cdot 2r \cos{\theta} \sin{\theta})
\cdot(2r \cos{\theta} \cdot \frac{1}{3})
$$</span>
where <span class="math-container">$dv$</span> is the differential volume (whitch is a
quadrangular pyramid) with respect to <span class="math-container">$\theta$</span> inside the sphere. You can readily integrate it to <span class="math-container">$\frac{4}{3} \pi r^3$</span>.</p>

CC BY-SA 4.0
2022-09-07T16:28:32.300Z
2022-09-07T16:28:32.300Z
Gin Zhuang
<p>There are two different methods of computing a random ray bounce being compared in this section of the online book, the first one is: Pick a point <span class="math-container">$s$</span> anywhere <em>inside</em> the sphere, then compute a vector from a point <span class="math-container">$p$</span> on the surface to the point <span class="math-container">$s$</span> <em>inside</em> the sphere.</p>
<p>The second method is: Pick a point <span class="math-container">$s$</span> anywhere <em>on the surface</em> of the sphere, then compute a vector from the point <span class="math-container">$p$</span> to the point <span class="math-container">$s$</span> <em>on the surface</em> of the sphere.</p>
<p>After computing the random vector, compute the angle <span class="math-container">$\phi$</span> between the given normal vector and random vector. That angle is then used in the lighting computations.</p>
<p>Given the two methods of computing a random vector the question arises: &quot;Are these two methods equivalent and how do we show that they are or are not?&quot;  To show that we have to somehow compute every possible angle using the two different methods which should result in a function they are equivalent to. The bit of language &quot;every possible angle&quot; suggests using integrals over a volume for the first method and integrals over a surface for the second method. And that is where these two approaches diverge, the integration over the volume gives a different answer then the integration over the surface.</p>
<p>...skipping all the math...</p>
<p>The first method it turns out, after doing a bunch of calculus, is equivalent to <span class="math-container">$cos^3(\phi)$</span> suggesting that all those points on the interior of the sphere are skewing the random vector angle towards the center of the sphere which are close to the normal vector.</p>
<p>The second method, after a bit more calculus, gives the result <span class="math-container">$cos(\phi)$</span> which is the answer we were hoping for.</p>

CC BY-SA 4.0
2021-10-06T15:47:40.573Z
Thank you so much for your explanation. It's exactly what I want.
veggieg
CC BY-SA 4.0
2021-10-05T14:36:35.053Z
2021-10-05T14:36:35.053Z
pmw1234
<p>I have a question about Peter Shirley's Ray tracing in one weekend. In the <a href="https://raytracing.github.io/books/RayTracingInOneWeekend.html#diffusematerials/truelambertianreflection" rel="nofollow noreferrer">True Lambertian Reflection section</a>, when talking about rejection method, he said</p>
<blockquote>
<p>This distribution scales by the cos^3(ϕ) where ϕ is the angle from normal</p>
</blockquote>
<p>Can anyone please tell me where the exponent 3 comes from?
Thanks!</p>

CC BY-SA 4.0
2021-09-26T15:59:52.143Z
See the following (it may be fairly confusing however): https://github.com/vchizhov/Derivations/blob/master/Probability%20density%20functions%20of%20the%20projected%20offset%20disk%2C%20circle%2C%20ball%2C%20and%20sphere.pdf
lightxbulb
CC BY-SA 4.0
2021-09-29T10:15:39.810Z
@lightxbulb Thanks for the link. But yes, it is a bit confusing...
veggieg
<raytracing><diffuse>
question about true Lambertian reflection in Ray tracing in one weekend
veggieg
# question about true Lambertian reflection in Ray tracing in one weekend

(Asked by: username_0 on 2021-09-26)

I have a question about Peter Shirley's Ray tracing in one weekend. In the [True Lambertian Reflection section](https://raytracing.github.io/books/RayTracingInOneWeekend.html#diffusematerials/truelambertianreflection), when talking about rejection method, he said

> This distribution scales by the cos^3(ϕ) where ϕ is the angle from normal

Can anyone please tell me where the exponent 3 comes from?
Thanks!

**Tags:** raytracing, diffuse

> **Comments:**
> **username_1**: See the following (it may be fairly confusing however): https://github.com/vchizhov/Derivations/blob/master/Probability%20density%20functions%20of%20the%20projected%20offset%20disk%2C%20circle%2C%20ball%2C%20and%20sphere.pdf  
> **username_0**: @username_1 Thanks for the link. But yes, it is a bit confusing...  

---

## 2 answers

### Answer by username_3 on 2021-10-05. Score: 2

There are two different methods of computing a random ray bounce being compared in this section of the online book, the first one is: Pick a point $s$ anywhere *inside* the sphere, then compute a vector from a point $p$ on the surface to the point $s$ *inside* the sphere.

The second method is: Pick a point $s$ anywhere *on the surface* of the sphere, then compute a vector from the point $p$ to the point $s$ *on the surface* of the sphere.

After computing the random vector, compute the angle $\phi$ between the given normal vector and random vector. That angle is then used in the lighting computations.

Given the two methods of computing a random vector the question arises: "Are these two methods equivalent and how do we show that they are or are not?" To show that we have to somehow compute every possible angle using the two different methods which should result in a function they are equivalent to. The bit of language "every possible angle" suggests using integrals over a volume for the first method and integrals over a surface for the second method. And that is where these two approaches diverge, the integration over the volume gives a different answer then the integration over the surface.

...skipping all the math...

The first method it turns out, after doing a bunch of calculus, is equivalent to $cos^3(\phi)$ suggesting that all those points on the interior of the sphere are skewing the random vector angle towards the center of the sphere which are close to the normal vector.

The second method, after a bit more calculus, gives the result $cos(\phi)$ which is the answer we were hoping for.

> **Comments:**
> **username_0**: Thank you so much for your explanation. It's exactly what I want.  

---

### Answer by username_2 on 2022-09-07. Score: 0

I think it is a mistake in the book.

Pick random points uniformly on a sphere offset by the normal, you will get a
distribution of rays proportional to $\cos{\theta} \sin{\theta}$, rather than $\cos{\theta}$ as the book written.

$$
ds = \frac{(2r \cdot \cos{\theta} \cdot d\theta) }{\cos{\theta}}
\cdot (2 \pi \cdot 2r \cdot \cos{\theta} \sin{\theta)}
$$
where $ds$ is the differential area on the shifted sphere's surface with respect to $\theta$. Integrate $\theta$ from 0 to $\pi/2$, you'll get $4 \pi r^2$.

And pick random points uniformly inside a sphere offset by the normal, you obtain a distribution of rays proportional to $\cos{\theta}^3 \sin{\theta}$.

$$
dv = (2r \cos{\theta} d\theta) \cdot(2\pi \cdot 2r \cos{\theta} \sin{\theta})
\cdot(2r \cos{\theta} \cdot \frac{1}{3})
$$
where $dv$ is the differential volume (whitch is a
quadrangular pyramid) with respect to $\theta$ inside the sphere. You can readily integrate it to $\frac{4}{3} \pi r^3$.


---

