# Relationship between Phong and Blinn lighting model

version : 1.1 – Living blog – First version was 29 March 2012

Phong and Blinn are the two most used lighting models in game development. The properties of the two have been debate a lot of time and I won’t discuss this here. See [1] to know why you should use Blinn rather  than Phong when you do physically based rendering. The point of interest I would discuss is the relationship between Phong lobe shape and Blinn lobe shape. This relationship matter when you use image based lighting (IBL). In this case you generally have only one cubemap sample and can only emulate Phong shape highlight (see AMD Cubemapgen for physically based rendering). The problem come when you want to use IBL and try to match it with analytic Blinn lighting model use for direct lighting. The highlight shape don’t match. Here is a comparison between an analytic Phong (Left) and Blinn (Right) highlight with the same specular power (Click for high rez).

This post will study what we can do to better match Blinn and Phong highligh. There is really few paper about this subject [2] [3]. About Phong and Blinn relationship, it can be show that the Phong angle is twice the Blinn angle [3]:

$cos^{-1}(R.E) = 2 cos^{-1}(N.H)$

This relation allows to write

$cos^\rho(\theta) = cos^{x \rho} (\frac{\theta}{2})$

Where $\rho$ is the specular power, $\theta$ is the Phong angle ( $cos^{-1}(R.E)$ ) and $x$ is our unknown parameter. Finding the value of $x$ which best fit this equation will provide our relationship between Phong and Blinn.

Yoshiharu Gotanda give 4.2 for the value of $x$ in [2]. Frederick Fisher and Andrew Woo give 4 in [3]. Following sections will discuss these results.

## Solving the equation

To solve the equation I used Mathematica [4]. Mathematica is one of those tools which became important to learn for modern graphic programmers. I provide all the Mathematica code I use in this post, so you can play with it.
Mathematica has a powerful language which allow to do a lot of thing. Solving our unknown parameter $x$ can be done in a single line:

F[SpecPower_]:=x /. FindFit[Table[{a,Cos[a]^SpecPower},{a,0,\[Pi]/2,0.01}],Cos[b/2]^(SpecPower*x),{x},b];

Step by step, we create a table of data with equation $cos^{SpecPower}(x)$ for x varying from $0$ to $\frac{\Pi}{2}$ (as advice in [3], no need to go further than 90°). Then we use the FindFit method with our Phong/Blinn equation to try to find the $x$ value which best match our data.
Then we can create a graph which will display best fit $x$ value for SpecularPower from 1 to 500.

DiscretePlot[F[SpecPower], {SpecPower, 1, 500}, PlotRange -> {0, 6},  Filling -> None, Joined -> True]

As we can see, there is a slope near SpecularPower 1 then the solution rapidly converge to 4. The SpecularPower of 0 is a degenerate case and is not handled here.

DiscretePlot[{F[SpecPower], 4}, {SpecPower, 1, 20},  PlotRange -> {0, 6}, Filling -> None, Joined -> True]

We see on these graphs than we don’t have a unique value for $x$. But 4 is a very good candidate when SpecularPower is high. Let’s try to find a simple function which approximate this solution curve.
For this we will apply FindFit again. The solution curve looks like a hyperbolic function of the form $a/x + b$. This is a good candidate to give to FindFit. After some trial, I find the following hyperbolic function.

data = Table[{SpecularPower, F[SpecularPower]}, {SpecularPower, 1, 500, 1}];
G[X_] = a/X^3 + b/X^2 + c/X + d /. FindFit[data, a/x^3 + b/x^2 + c/x + d, {a, b, c,d}, x];

The result is

$G(X)=4.00012 -\frac{0.624042}{X^3}+\frac{0.728329}{X^2}+\frac{1.22792}{X}$

Following graph show the comparison between the solution curve and this approximate solution curve

DiscretePlot[{F[SpecularPower], G[SpecularPower]}, {SpecularPower, 1,500}, PlotRange -> {0, 6}, Filling -> None, Joined -> True]
DiscretePlot[{F[SpecularPower], G[SpecularPower]}, {SpecularPower, 1, 10}, PlotRange -> {0, 6}, Filling -> None, Joined -> True]

Rather good approximation (Curves match, so you see only one on the graphs).

## Result comparison

In the previous section we have found an approximate curve for the Phong and Blinn relationship.

$cos^\rho(\theta) = cos^{\rho(4.00012 -\frac{0.624042}{\rho^3}+\frac{0.728329}{\rho^2}+\frac{1.22792}{\rho})} (\frac{\theta}{2})$

Here is a comparison between the reference, [2], [3] and this curve.
First some numerical value from the approximate curve for the first 20 SpecularPower, to compare with the 4 and 4.2 value of [2] and [3].

Then the graph for few SpecularPower (Red: Reference, green : x set with approximate solution curve, blue : x set to 4.2 like in [2], Purple : x set to 4.0 like in [3], click for high rez):

DrawComparison[N_] :=  Plot[{Cos[x]^N,  Cos[x/2]^(N*G[N]), Cos[x/2]^(4.2*N),  Cos[x/2]^(4*N)}, {x, 0, \[Pi]/2},  PlotStyle -> {Red, Green, Blue, Purple}];

DrawComparison[1]

DrawComparison[3]

DrawComparison[10]

DrawComparison[500]

The only noticeable difference appear when SpecularPower < 5. But should we care about this in practice ?
Following are teapot rendered with Phong, Blinn, Blinn with approximate solution curve, Blinn with 4.0, Blinn with 4.2 (Click for high rez).
Specular power 1

Specular Power 3

Specular Power 5

Specular Power 10

Specular Power 100

Specular Power 1000

For details, I use the following code (Note that I boost specular to get visible highligh and I don’t use energy conserving factor):

#define METHOD 0
float p_value = 10.0;
float multiplier_spec = 3.0;
(...)
#if METHOD == 0
// Phong
vec3 r = reflect(-light, n);
float rdotv = saturate(dot(r, view));
float spec  = multiplier_spec * pow(rdotv, p_value);
#elif METHOD == 1
// Blinn-Phong
float ndoth = saturate(dot(n, h));
float spec  = multiplier_spec * pow(ndoth, p_value);
#elif METHOD == 2
// approximate curve
float p_value_2 = p_value * p_value;
float p_value_3 = p_value_2 * p_value;
float factor = 4.00012  - (0.624042  / p_value_3)
+ (0.728329  / p_value_2)
+ (1.22792   / p_value);
float ndoth = saturate(dot(n, h));
float spec  = multiplier_spec * pow(ndoth, factor * p_value);
#elif METHOD == 3
// Fisher and Woo
float ndoth = saturate(dot(n, h));
float spec  = multiplier_spec * pow(ndoth, 4.0 * p_value);
#elif METHOD == 4
// Gotanda
float ndoth = saturate(dot(n, h));
float spec  = multiplier_spec * pow(ndoth, 4.2 * p_value);
#endif
(...)

Final result:
– For Specular power > 10 there is almost no difference between candidates (with bright highligh as the teapot sample you can see small variation). And all candidates are good approximation.
– For very low specular < 5, the result is bad anyway, whatever the candidate. This is due to the size of the highligh. Still the result usable as an approximation.
– Compare theorical result is good but compare visual result is better

The takeaway :
– Just use the simplest factor $(R.E)^\rho = (N.H)^{4 \rho}$
– Mathematica skill achievement (PDF link of Mathematica code from this post)

## Reference

[2] Gotanda, “Real-time Physically Based Rendering – Implementation”, http://research.tri-ace.com/Data/cedec2011_RealtimePBR_Implementation.pptx
[3] Fisher, Woo, “R.E Versus N.H Specular Highlights” in. Graphics Gems IV
[4] Mathematica, http://www.wolfram.com/mathematica/

### 8 Responses to Relationship between Phong and Blinn lighting model

1. Robin Green says:

Next try a Minimax Polynomial fit (or even a Rational Minimax). You’ve got a bounded range, it should work fine.

• seblagarde says:

Hey,
can you provide some hint on this ? I think I miss something 🙂
I try to play with RationalInterpolation/MiniMaxApproximation in mathematica, but didn’t get it to work with my function (at least, I don’t understand how to make them work)…
Thank you

2. seblagarde says:

Small update: Add screenshot for specular power 5, 10, 1000, provide code and affine final result.

3. Charles de Rousiers says:

If I may, those two models are strongly different from a conceptual point of view: one models the BRDF shape, the other one models the NDF. At grazing angle, a “Phong” lobe is completely istropic and a “Blinn-Phong lobe” is highly anisotropic. This should give you major visual differences even for medium specular power >5.

You can easily see that on Wang’s paper (http://research.microsoft.com/en-us/um/people/jpwang/paper_stuffs/ppsg.pdf), especially on the supplement material (http://research.microsoft.com/en-us/um/people/jpwang/paper_stuffs/sg_supp.pdf), figure 9, where they try to approximate a “Blinn-Phong lobe” with an isotropic lobe (spherical gaussian lobe). The differences are obvious for grazing angles.

As you said, it’s not only a power issue, it’s mainly a visual difference issue! 🙂

4. seblagarde says:

Totally agree, people should use Blinn anyway. I use this trick only to try to match preconvolved cubemap (with isotropic lobe) with analytic Blinn like Tri-Ace (http://research.tri-ace.com/Data/cedec2011_RealtimePBR_Implementation_e.pptx). Fail at grazing angle of course, but better than nothing 🙂

5. Pingback: Confluence: Art

6. Pingback: Real-Time Rendering · New CRC Books