## Marschner Shader Part II

In my last post I mentioned two functions that are needed to represent the hair model as depicted in Marschner’s paper.

*S* = *S _{R} * +

*S*+

_{TT}*S*

_{TRT,}*S _{p} * =

*M*(

_{p}*q*

_{ i },

*q*

_{r }) x

*N*(

_{p}*q*

_{ d },

*f*

_{ d }) for

*P*=

*R*,

*TT*,

*TRT*.

**M component**

This is actually just a probability density function and the best choice here is to use a Gaussian distribution (or normal distribution).

And the M components are as follows:

*M*(_{R}*q*) =_{ h }*g*(*Beta*,_{ R }*q*–_{ h }*Alpha*)._{ R}*M*(_{TT}*q*) =_{ h }*g*(*Beta*,_{ TT }*q*–_{ h }*Alpha*)._{ TT}*M*(_{TRT}*q*) =_{ h }*g*(*Beta*,_{ TRT }*q*–_{ h }*Alpha*)._{ TRT}

**N component**

The N component is actually a bit tricky to compute. Here are all the main steps:

- Convert to Miller-Bravais index.

This is done in order to change the index of refraction to 2D physics, so that the optics of a 3D cylindrical fiber may be reduced to the 2D analysis of the optics of its cross-section.

After looking into Snellâ€™s Law we define the indexes of refraction as:

- Solve a cubic equation

Remember this picture:

We need to find out who the incident angles are, and we can approximate the solution for this equation as:

- Solve Fresnel equation

Fresnel equation is used in order to simulate the reflection model from within the attenuation

- Find out the absorption factor

This is actually quite straightforward, just:

- The attenuation factor

This is obtain combining both the reflection and the absorption factor, hence the “Attenuation by absorption and reflection” model from Marschner’s paper.

where the first derivative is

- The N component (finally)

and the N are

*N*(_{R}*q*_{ d },*f*_{ d }) =_{ }*N*(0,_{P}*q*_{ d },*f*_{ d })._{ }*N*(_{TT}*q*_{ d },*f*_{ d }) =_{ }*N*(1,_{P}*q*_{ d },*f*_{ d })._{ }*N*(_{TRT}*q*_{ d },*f*_{ d )}=*N*(2,_{P}*q*_{ d },*f*_{ d })._{ }

For the last component Marschner proposes a more complex model in order to avoid singularities, but for my implementation I couldn’t tell any improvement so I stuck with the simpler version of *N _{TRT.
}*

**The whole model**

As a sum up this is the whole Marschner hair model in just an equation:

Hope I managed to keep everything simple and explicit alike.