You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/_posts/2023-10-21-study-notes-on-the-marschner-hair-shading-model.md
+58-58Lines changed: 58 additions & 58 deletions
Original file line number
Diff line number
Diff line change
@@ -38,10 +38,10 @@ These functions are defined once for each path:
38
38
$$ M_R $$, $$ M_{TT} $$ and $$ M_{TRT} $$ and their counterparts $$ N_R $$, $$ N_{TT} $$ and $$ N_{TRT} $$. The entire scattering function is defined as:
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
45
45
angle of the specular cone. However, this assumes $$\theta_i=\theta_r$$. This does not hold when taking surface roughness into
46
46
account and is therefore only an approximation, as noted in **[3]**.
47
47
@@ -115,22 +115,22 @@ We want to calculate the change of $$\phi$$ in regard to $$h$$, so we have to re
115
115
The relationship between the two is directly taken from the definition of the unit circle:
116
116
117
117
\begin{equation}
118
-
sin(\gamma_i) = h \label{eq:gamma_i_to_h}
118
+
\sin(\gamma_i) = h \label{eq:gamma_i_to_h}
119
119
\end{equation}
120
120
121
121
It follows:
122
122
123
123
\begin{equation}
124
-
\gamma_i = arcsin(h) \label{eq:gamma_i}
124
+
\gamma_i = \arcsin(h) \label{eq:gamma_i}
125
125
\end{equation}
126
126
127
127
Putting this back into equation \eqref{eq:phi_gamma}:
128
128
129
129
\begin{equation}
130
-
\phi = -2 arcsin(h)
130
+
\phi = -2 \arcsin(h)
131
131
\end{equation}
132
132
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}}$$:
134
134
135
135
\begin{equation}
136
136
\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
139
139
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:
We simplify this by multiplying out the constant factors and dropping the minus sign inside the absolute value:
170
170
171
171
\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}
173
173
\end{equation}
174
174
175
175
Then we apply the power of minus one:
176
176
177
177
\begin{equation}
178
-
N_R = A_R |\frac1 4 cos(\frac \phi 2))|
178
+
N_R = A_R |\frac1 4 \cos(\frac \phi 2))|
179
179
\end{equation}
180
180
181
181
Finally, pulling out the fraction outside the absolute value gives:
182
182
183
183
\begin{equation}
184
-
N_R = A_R \frac1 4 |cos(\frac \phi 2))|
184
+
N_R = A_R \frac1 4 |\cos(\frac \phi 2))|
185
185
\end{equation}
186
186
187
187
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
193
193
some minor errors. Luckily, there is an extended version of the appendix **[6]**. The paper appendix incorrectly states:
194
194
195
195
\begin{equation}
196
-
\eta cos \gamma = \eta' cos \delta \label{eq:gamma_delta_incorrect}
$$\gamma$$ is the inclination of the incoming vector with regard to the normal plane. $$\delta$$ is the corresponding inclination of the refracted vector.
200
200
Solving equation \eqref{eq:gamma_delta_incorrect} for $$\eta'$$, we get:
201
201
202
202
\begin{equation}
203
-
\eta' = \frac{\eta cos \gamma}{cos \delta} \label{eq:eta_prime_incorrect}
$$ \gamma $$ and $$ \delta $$ are swapped. Initially, I was unsure which version was correct. I wrote a small Octave script to manually compute
213
213
some refraction vectors and their projections to confirm that the extended appendix is the correct one.
214
214
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:
215
215
216
216
\begin{equation}
217
-
\sin \theta_i' = sin \theta_i cos \gamma
217
+
\sin \theta_i' = \sin \theta_i \cos \gamma
218
218
\end{equation}
219
219
220
220
\begin{equation}
221
-
\sin \theta_t' = sin \theta_t cos \delta
221
+
\sin \theta_t' = \sin \theta_t \cos \delta
222
222
\end{equation}
223
223
224
224
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.
225
225
As stated in the paper appendix, Snell's law applies in the vertical normal plane:
226
226
227
227
\begin{equation}
228
-
sin \theta_i' = \eta' sin \theta_t' \label{eq:snells_law_projected}
$$\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
247
247
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'$$:
248
248
249
249
\begin{equation}
250
-
cos\gamma = \frac{||v_i'||}{||v_i||}
250
+
\cos\gamma = \frac{||v_i'||}{||v_i||}
251
251
\end{equation}
252
252
253
253
\begin{equation}
254
-
cos\gamma = ||v_i'||
254
+
\cos\gamma = ||v_i'||
255
255
\end{equation}
256
256
257
257
The top of the triangle between $$v_i'$$ and it's projection on the normal $$n$$ is equal to $$s_i'$$. This gives us:
258
258
259
259
\begin{equation}
260
-
sin \theta_i' = \frac{s_i'}{||v_i'||}
260
+
\sin \theta_i' = \frac{s_i'}{||v_i'||}
261
261
\end{equation}
262
262
263
263
\begin{equation}
264
-
sin \theta_i' = \frac{s_i'}{cos \gamma} \label{eq:incoming_projection_and_inclination}
Substituting \eqref{eq:incoming_projection_and_inclination} and \eqref{eq:refracted_projection_and_inclination} into equation \eqref{eq:snells_law_projected}:
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$$.
353
353
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:
354
354
355
355
$$
356
356
\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)
359
359
\end{aligned}
360
360
$$
361
361
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)$$:
363
363
364
364
$$
365
365
\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)
368
368
\end{aligned}
369
369
$$
370
370
371
371
Taking the square root, the final path segment length is:
372
372
373
373
\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}
375
375
\end{equation}
376
376
377
377
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:
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
390
390
391
391
$$
392
392
\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}}
397
397
\end{aligned}
398
398
$$
399
399
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:
401
401
402
402
\begin{equation}
403
-
sign(cos(\gamma_t)) l = 2 cos(\gamma_t)
403
+
\mathrm{sign}(\cos(\gamma_t)) l = 2 \cos(\gamma_t)
0 commit comments