Skip to content

Commit cf3952a

Browse files
author
Alexander Gauggel
committed
Use non-italic font in math equations where appropriate: sine, cosine, sign and names
1 parent bea4a2c commit cf3952a

File tree

1 file changed

+58
-58
lines changed

1 file changed

+58
-58
lines changed

docs/_posts/2023-10-21-study-notes-on-the-marschner-hair-shading-model.md

Lines changed: 58 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ These functions are defined once for each path:
3838
$$ M_R $$, $$ M_{TT} $$ and $$ M_{TRT} $$ and their counterparts $$ N_R $$, $$ N_{TT} $$ and $$ N_{TRT} $$. The entire scattering function is defined as:
3939

4040
\begin{equation}
41-
S = M_R N_R / cos^2(\theta_d) + M_{TT} N_{TT} / cos^2(\theta_d) + M_{TRT} N_{TRT} / cos^2(\theta_d)
41+
S = M_R N_R / \cos^2(\theta_d) + M_{TT} N_{TT} / \cos^2(\theta_d) + M_{TRT} N_{TRT} / \cos^2(\theta_d)
4242
\end{equation}
4343

44-
Note that I omitted the parameters from the Marschner paper for brevity. The division by $$cos^2(\theta_d)$$ is a normalization factor that accounts for the projected solid
44+
Note that I omitted the parameters from the Marschner paper for brevity. The division by $$\cos^2(\theta_d)$$ is a normalization factor that accounts for the projected solid
4545
angle of the specular cone. However, this assumes $$\theta_i=\theta_r$$. This does not hold when taking surface roughness into
4646
account and is therefore only an approximation, as noted in **[3]**.
4747

@@ -115,22 +115,22 @@ We want to calculate the change of $$\phi$$ in regard to $$h$$, so we have to re
115115
The relationship between the two is directly taken from the definition of the unit circle:
116116

117117
\begin{equation}
118-
sin(\gamma_i) = h \label{eq:gamma_i_to_h}
118+
\sin(\gamma_i) = h \label{eq:gamma_i_to_h}
119119
\end{equation}
120120

121121
It follows:
122122

123123
\begin{equation}
124-
\gamma_i = arcsin(h) \label{eq:gamma_i}
124+
\gamma_i = \arcsin(h) \label{eq:gamma_i}
125125
\end{equation}
126126

127127
Putting this back into equation \eqref{eq:phi_gamma}:
128128

129129
\begin{equation}
130-
\phi = -2 arcsin(h)
130+
\phi = -2 \arcsin(h)
131131
\end{equation}
132132

133-
Taking the derivative in regard to $$h$$, keeping in mind that $$\frac d{dx} arcsin(x) = \frac1{\sqrt{1-x^2}}$$:
133+
Taking the derivative in regard to $$h$$, keeping in mind that $$\frac d{dx} \arcsin(x) = \frac1{\sqrt{1-x^2}}$$:
134134

135135
\begin{equation}
136136
\frac{d\phi}{dh} = -2 \frac1{\sqrt{1-h^2}}
@@ -139,49 +139,49 @@ Taking the derivative in regard to $$h$$, keeping in mind that $$\frac d{dx} arc
139139
The next step is to express this in regards to our shading input $$\phi$$. We will use our previous definition \eqref{eq:gamma_i_to_h} to replace $$h$$ by $$\gamma_i$$ again:
140140

141141
\begin{equation}
142-
\frac{d\phi}{dh} = -2 \frac1{\sqrt{1-sin^2(\gamma_i)}}
142+
\frac{d\phi}{dh} = -2 \frac1{\sqrt{1-\sin^2(\gamma_i)}}
143143
\end{equation}
144144

145-
We can simplify this using the trigonometric identity $$cos(x) = \sqrt{1-sin^2(x)}$$:
145+
We can simplify this using the trigonometric identity $$\cos(x) = \sqrt{1-\sin^2(x)}$$:
146146

147147
\begin{equation}
148-
\frac{d\phi}{dh} = -2 \frac1{cos(\gamma_i)}
148+
\frac{d\phi}{dh} = -2 \frac1{\cos(\gamma_i)}
149149
\end{equation}
150150

151151
Now we solve our initial function \eqref{eq:phi_gamma} for $$\phi$$, which is simply $$\gamma_i = - \frac \phi 2$$, and plug this in:
152152

153153
\begin{equation}
154-
\frac{d\phi}{dh} = -2 \frac1{cos(-\frac \phi 2)}
154+
\frac{d\phi}{dh} = -2 \frac1{\cos(-\frac \phi 2)}
155155
\end{equation}
156156

157-
Since $$cos(x) = cos(-x)$$ we drop the minus sign inside the cosine:
157+
Since $$\cos(x) = \cos(-x)$$ we drop the minus sign inside the cosine:
158158

159159
\begin{equation}
160-
\frac{d\phi}{dh} = -2 \frac1{cos(\frac \phi 2)}
160+
\frac{d\phi}{dh} = -2 \frac1{\cos(\frac \phi 2)}
161161
\end{equation}
162162

163163
We can plug this into our initial definition of $$N$$ \eqref{eq:azimuthal_scattering}:
164164

165165
\begin{equation}
166-
N_R = A_R |2 (-2 \frac1{cos(\frac \phi 2)}) |^{-1}
166+
N_R = A_R |2 (-2 \frac1{\cos(\frac \phi 2)}) |^{-1}
167167
\end{equation}
168168

169169
We simplify this by multiplying out the constant factors and dropping the minus sign inside the absolute value:
170170

171171
\begin{equation}
172-
N_R = A_R |4 \frac1{cos(\frac \phi 2)}) |^{-1}
172+
N_R = A_R |4 \frac1{\cos(\frac \phi 2)}) |^{-1}
173173
\end{equation}
174174

175175
Then we apply the power of minus one:
176176

177177
\begin{equation}
178-
N_R = A_R |\frac1 4 cos(\frac \phi 2))|
178+
N_R = A_R |\frac1 4 \cos(\frac \phi 2))|
179179
\end{equation}
180180

181181
Finally, pulling out the fraction outside the absolute value gives:
182182

183183
\begin{equation}
184-
N_R = A_R \frac1 4 |cos(\frac \phi 2))|
184+
N_R = A_R \frac1 4 |\cos(\frac \phi 2))|
185185
\end{equation}
186186

187187
This matches equation *(6)* from the Weta paper **[3]**. Note that they leave $$A_R$$ out of their equation, since they list it in the context of analyzing energy conservation
@@ -193,39 +193,39 @@ The Marschner paper includes a fairly detailed derivation of the Bravais Index t
193193
some minor errors. Luckily, there is an extended version of the appendix **[6]**. The paper appendix incorrectly states:
194194

195195
\begin{equation}
196-
\eta cos \gamma = \eta' cos \delta \label{eq:gamma_delta_incorrect}
196+
\eta \cos \gamma = \eta' \cos \delta \label{eq:gamma_delta_incorrect}
197197
\end{equation}
198198

199199
$$\gamma$$ is the inclination of the incoming vector with regard to the normal plane. $$\delta$$ is the corresponding inclination of the refracted vector.
200200
Solving equation \eqref{eq:gamma_delta_incorrect} for $$\eta'$$, we get:
201201

202202
\begin{equation}
203-
\eta' = \frac{\eta cos \gamma}{cos \delta} \label{eq:eta_prime_incorrect}
203+
\eta' = \frac{\eta \cos \gamma}{\cos \delta} \label{eq:eta_prime_incorrect}
204204
\end{equation}
205205

206206
Compare this to the extended appendix **[6]** that states:
207207

208208
\begin{equation}
209-
\eta' = \frac{\eta cos \delta}{cos \gamma} \label{eq:eta_prime_correct}
209+
\eta' = \frac{\eta \cos \delta}{\cos \gamma} \label{eq:eta_prime_correct}
210210
\end{equation}
211211

212212
$$ \gamma $$ and $$ \delta $$ are swapped. Initially, I was unsure which version was correct. I wrote a small Octave script to manually compute
213213
some refraction vectors and their projections to confirm that the extended appendix is the correct one.
214214
Using the script to check the paper equations used for deriving equation \eqref{eq:eta_prime_incorrect}, I found the following two statements to be incorrect as well:
215215

216216
\begin{equation}
217-
\sin \theta_i' = sin \theta_i cos \gamma
217+
\sin \theta_i' = \sin \theta_i \cos \gamma
218218
\end{equation}
219219

220220
\begin{equation}
221-
\sin \theta_t' = sin \theta_t cos \delta
221+
\sin \theta_t' = \sin \theta_t \cos \delta
222222
\end{equation}
223223

224224
The extended appendix does not go into great detail how it arrives at equation \eqref{eq:eta_prime_correct}. Let's look into this next.
225225
As stated in the paper appendix, Snell's law applies in the vertical normal plane:
226226

227227
\begin{equation}
228-
sin \theta_i' = \eta' sin \theta_t' \label{eq:snells_law_projected}
228+
\sin \theta_i' = \eta' \sin \theta_t' \label{eq:snells_law_projected}
229229
\end{equation}
230230

231231
$$\theta_i'$$ and $$\theta_t'$$ are the inclinations of the incoming and refracted vectors after projecting them onto the normal plane.
@@ -247,73 +247,73 @@ Looking at the geometry of *Figure 16 (c)* in the paper appendix **[4]**, we can
247247
is a direction and therefore a unit vector, so $$||v_i|| = 1$$. We can use this to compute the length of the projection of $$v_i$$ on the normal plane, denoted $$v_i'$$:
248248

249249
\begin{equation}
250-
cos\gamma = \frac{||v_i'||}{||v_i||}
250+
\cos\gamma = \frac{||v_i'||}{||v_i||}
251251
\end{equation}
252252

253253
\begin{equation}
254-
cos\gamma = ||v_i'||
254+
\cos\gamma = ||v_i'||
255255
\end{equation}
256256

257257
The top of the triangle between $$v_i'$$ and it's projection on the normal $$n$$ is equal to $$s_i'$$. This gives us:
258258

259259
\begin{equation}
260-
sin \theta_i' = \frac{s_i'}{||v_i'||}
260+
\sin \theta_i' = \frac{s_i'}{||v_i'||}
261261
\end{equation}
262262

263263
\begin{equation}
264-
sin \theta_i' = \frac{s_i'}{cos \gamma} \label{eq:incoming_projection_and_inclination}
264+
\sin \theta_i' = \frac{s_i'}{\cos \gamma} \label{eq:incoming_projection_and_inclination}
265265
\end{equation}
266266

267267
We can apply the equivalent steps to the refracted vector to obtain:
268268

269269
\begin{equation}
270-
sin \theta_t' = \frac{s_t'}{cos \delta} \label{eq:refracted_projection_and_inclination}
270+
\sin \theta_t' = \frac{s_t'}{\cos \delta} \label{eq:refracted_projection_and_inclination}
271271
\end{equation}
272272

273273
Substituting \eqref{eq:incoming_projection_and_inclination} and \eqref{eq:refracted_projection_and_inclination} into equation \eqref{eq:snells_law_projected}:
274274

275275
\begin{equation}
276-
\eta' \frac{s_t'}{cos \delta} = \frac{s_i'}{cos \gamma}
276+
\eta' \frac{s_t'}{\cos \delta} = \frac{s_i'}{\cos \gamma}
277277
\end{equation}
278278

279279
\begin{equation}
280-
\eta' = \frac{s_i'}{s_t'} \frac{cos \delta}{cos \gamma}
280+
\eta' = \frac{s_i'}{s_t'} \frac{\cos \delta}{\cos \gamma}
281281
\end{equation}
282282

283283
Substituting $$\eta$$ into this using equation \eqref{eq:eta_ratio} yields equation \eqref{eq:eta_prime_correct}. As a reminder:
284284

285285
$$
286-
\eta' = \eta \frac{cos \delta}{cos \gamma}
286+
\eta' = \eta \frac{\cos \delta}{\cos \gamma}
287287
$$
288288

289-
The next step is to get rid of the $$cos\delta$$ term. The extended appendix observes:
289+
The next step is to get rid of the $$\cos\delta$$ term. The extended appendix observes:
290290

291291
\begin{equation}
292-
\eta sin \delta = sin \gamma
292+
\eta \sin \delta = \sin \gamma
293293
\end{equation}
294294

295-
We transform this for substitution by using the trigonometric identity $$ sin(x) = \sqrt{1 - cos^2(x)} $$:
295+
We transform this for substitution by using the trigonometric identity $$\sin(x) = \sqrt{1 - \cos^2(x)} $$:
296296

297297
$$
298298
\begin{aligned}
299-
\eta sin \delta &= sin \gamma \\
300-
\eta \sqrt{1 - cos^2 \delta} &= sin \gamma \\
301-
\eta^2(1 - cos^2 \delta) &= sin^2 \gamma \\
302-
\eta^2 - \eta^2 cos^2 \delta &= sin^2 \gamma \\
303-
\eta^2 cos^2 \delta &= \eta^2 - sin^2 \gamma
299+
\eta \sin \delta &= \sin \gamma \\
300+
\eta \sqrt{1 - \cos^2 \delta} &= \sin \gamma \\
301+
\eta^2(1 - \cos^2 \delta) &= \sin^2 \gamma \\
302+
\eta^2 - \eta^2 \cos^2 \delta &= \sin^2 \gamma \\
303+
\eta^2 \cos^2 \delta &= \eta^2 - \sin^2 \gamma
304304
\end{aligned}
305305
$$
306306

307307
This intermediate result is also listed in the extended appendix. When we take the square root of this, we get:
308308

309309
\begin{equation}
310-
\eta cos \delta = \sqrt{\eta^2 - sin^2 \gamma}
310+
\eta \cos \delta = \sqrt{\eta^2 - \sin^2 \gamma}
311311
\end{equation}
312312

313313
Finally, we substitute this term into equation \eqref{eq:eta_prime_correct} to obtain:
314314

315315
\begin{equation}
316-
\eta'(\gamma) = \frac{\sqrt{\eta^2 - sin^2 \gamma}}{cos \gamma}
316+
\eta'(\gamma) = \frac{\sqrt{\eta^2 - \sin^2 \gamma}}{\cos \gamma}
317317
\end{equation}
318318

319319
# Angle for computing $$\eta'$$
@@ -340,44 +340,44 @@ As noted in **[7]**, the internal path segment length $$l$$ is incorrect in the
340340
There it is incorrectly stated:
341341

342342
\begin{equation}
343-
l_{Marschner}(\gamma_t) = 2 + 2cos(2\gamma_t) \label{eq:path_length_marschner}
343+
l_{\mathrm{Marschner}}(\gamma_t) = 2 + 2\cos(2\gamma_t) \label{eq:path_length_marschner}
344344
\end{equation}
345345

346346
We can derive the correct term using the law of cosines. The law of cosines relates the length of the triangle sides using the cosine of the angle:
347347

348348
\begin{equation}
349-
c^2 = a^2 + b^2 - 2ab cos \gamma \label{eq:law_of_cosines}
349+
c^2 = a^2 + b^2 - 2ab \cos \gamma \label{eq:law_of_cosines}
350350
\end{equation}
351351

352352
As seen in *Figure 9* in **[4]**, $$a=1$$ and $$b=1$$, since this is the radius of the unit circle. We require the angle opposite of $$l$$.
353353
Since we know that the sum of all angles in a triangle is $$\pi$$, we know $$\gamma= \pi - 2 \gamma_t$$. Inserting these values into \eqref{eq:law_of_cosines} we get:
354354

355355
$$
356356
\begin{aligned}
357-
l^2 &= 1^2 + 1^2 - 2 cos(\pi - 2 \gamma_t) \\
358-
l^2 &= 2 - 2 cos(\pi - 2 \gamma_t)
357+
l^2 &= 1^2 + 1^2 - 2 \cos(\pi - 2 \gamma_t) \\
358+
l^2 &= 2 - 2 \cos(\pi - 2 \gamma_t)
359359
\end{aligned}
360360
$$
361361

362-
Then we simplify this using $$cos(x) = cos(-x)$$ and $$cos(x) = -cos(x - \pi)$$:
362+
Then we simplify this using $$\cos(x) = \cos(-x)$$ and $$\cos(x) = -\cos(x - \pi)$$:
363363

364364
$$
365365
\begin{aligned}
366-
l^2 &= 2 - 2 cos( 2 \gamma - \pi) \\
367-
l^2 &= 2 + 2 cos(2 \gamma_t)
366+
l^2 &= 2 - 2 \cos( 2 \gamma - \pi) \\
367+
l^2 &= 2 + 2 \cos(2 \gamma_t)
368368
\end{aligned}
369369
$$
370370

371371
Taking the square root, the final path segment length is:
372372

373373
\begin{equation}
374-
l = \sqrt{2 + 2 cos(2 \gamma_t)} \label{eq:path_length_derived}
374+
l = \sqrt{2 + 2 \cos(2 \gamma_t)} \label{eq:path_length_derived}
375375
\end{equation}
376376

377377
Comparing this to equation \eqref{eq:path_length_marschner}, it is clear that the latter is missing the square root. In **[7]**, the path length is given as:
378378

379379
\begin{equation}
380-
l_{Zinke} = 2 cos(\gamma_t) \label{eq:path_length_zinke}
380+
l_{\mathrm{Zinke}} = 2 \cos(\gamma_t) \label{eq:path_length_zinke}
381381
\end{equation}
382382

383383
Note that my notation differs slightly from **[7]**. For one, I assume that the fiber radius is one, so I omitted $$r=1$$ . Furthermore, they relate the
@@ -390,35 +390,35 @@ or when taking their absolute value. We can show that they are equal. First, we
390390

391391
$$
392392
\begin{aligned}
393-
l &= \sqrt{2 + 2 cos(2 \gamma_t)} \\
394-
l &= \sqrt{2} \sqrt{1 + cos(2 \gamma_t)} \\
395-
l &= \sqrt{2} \sqrt{2} \sqrt{\frac{1 + cos(2 \gamma_t)}{2}} \\
396-
l &= 2 \sqrt{\frac{1 + cos(2 \gamma_t)}{2}}
393+
l &= \sqrt{2 + 2 \cos(2 \gamma_t)} \\
394+
l &= \sqrt{2} \sqrt{1 + \cos(2 \gamma_t)} \\
395+
l &= \sqrt{2} \sqrt{2} \sqrt{\frac{1 + \cos(2 \gamma_t)}{2}} \\
396+
l &= 2 \sqrt{\frac{1 + \cos(2 \gamma_t)}{2}}
397397
\end{aligned}
398398
$$
399399

400-
Then we use the trigonometric identity $$cos(\frac{x}{2}) = sign(cos\frac{x}{2})\sqrt{\frac{1+cos(x)}{2}}$$ to arrive at:
400+
Then we use the trigonometric identity $$\cos(\frac{x}{2}) = \mathrm{sign}(\cos\frac{x}{2})\sqrt{\frac{1+\cos(x)}{2}}$$ to arrive at:
401401

402402
\begin{equation}
403-
sign(cos(\gamma_t)) l = 2 cos(\gamma_t)
403+
\mathrm{sign}(\cos(\gamma_t)) l = 2 \cos(\gamma_t)
404404
\end{equation}
405405

406406
Taking the absolute value of this equation gives:
407407

408408
\begin{equation}
409-
|sign(cos(\gamma_t)) l| = |2 cos(\gamma_t)|
409+
|\mathrm{sign}(\cos(\gamma_t)) l| = |2 \cos(\gamma_t)|
410410
\end{equation}
411411

412412
From equation \eqref{eq:path_length_derived}, we know that $$l \geq 0$$ and $$l$$ is zero when $$cos(\gamma_t)$$ is zero, so we can drop the sign:
413413

414414
\begin{equation}
415-
|l| = |2 cos(\gamma_t)|
415+
|l| = |2 \cos(\gamma_t)|
416416
\end{equation}
417417

418418
Since we know that $$l$$ is never negative, we can drop the absolute value on the left side of the equation as well:
419419

420420
\begin{equation}
421-
l = |2 cos(\gamma_t)|
421+
l = |2 \cos(\gamma_t)|
422422
\end{equation}
423423

424424
This matches \eqref{eq:path_length_zinke}, except for the absolute value.

0 commit comments

Comments
 (0)