The Blinn-Phong Normalization Zoo

It is good to see how phys­i­cal­ly based shad­ing is final­ly gain­ing momen­tum in real time graph­ics and games. This is some­thing I have been advo­cat­ing for a long time. Devel­op­ers are spread­ing the word. I was espe­cial­ly sur­prised to learn about Call of Duty: Black Ops join­ing the club [1]. Even a slick 60 Hz shoot­er with no cycles to spare can afford to do PBS today!

This leads me to the top­ic of this post, the nor­mal­iza­tion of the Blinn-Phong spec­u­lar high­light. Why am I writ­ing about it? It came to my mind recent­ly with the cur­rent batch of pub­li­ca­tions from peo­ple adopt­ing phys­i­cal­ly based shad­ing mod­els. This got me check­ing the maths again and I com­piled a list with nor­mal­iza­tion fac­tors for dif­fer­ent shad­ing mod­els, giv­en here in this post. I would also like to elab­o­rate a lit­tle on the mod­el that I wrote about in ShaderX7 [2]. Be aware this post is a large brain dump.

Blinn-Phong Normalization: A paradigm shift for texturing

Let me first devote some lines to empha­size how this nor­mal­iza­tion busi­ness is not only a mat­ter for engine devel­op­ers or shad­er authors, but also for tex­ture artist education.
Nor­mal­iza­tion means, in sim­ple terms, that the shad­ing mod­el scales the inten­si­ty of the spec­u­lar high­light in pro­por­tion to its angu­lar size, such that the total reflect­ed ener­gy remains con­stant with vary­ing sur­face smooth­ness, aka. glossi­ness. This may sound like a minor tech­ni­cal detail, but it real­ly is a par­a­digm shift.

stan­dard blinn-phong nor­mal­ized blinn-phong
Spec­u­lar map has all the details Gloss map has all the details
Glossi­ness constant Spec­u­lar lev­el con­stant (almost)

With stan­dard Blinn-Phong shad­ing, artists were used to paint sur­face vari­a­tion into a tex­ture con­nect­ed to specular/reflective inten­si­ty, while the glossi­ness was only an after­thought, often not tex­tured at all. With a nor­mal­ized shad­ing mod­el, all the detail goes into the glossi­ness tex­ture, while it is the spec­u­lar inten­si­ty that becomes bor­ing. So, is every­thing dif­fer­ent now? In short, yes. And to dri­ve the point home, I’ll give a visu­al example.

Wet and dry parts on an asphalt sur­face, in backlight

Con­sid­er the scene in the image above. The scene shows an an asphalt sur­face in back­light with dra­mat­i­cal­ly dif­fer­ent reflectances for wet and dry parts. Isn’t this para­dox? The refrac­tive index of water is actu­al­ly low­er than that of the asphalt min­er­als, so every­thing else being equal, the water-cov­ered sur­face should have less reflec­tion. But things are not equal, because the water-cov­ered parts have a much smoother sur­face. A smoother sur­face focus­es the reflect­ed sun­light into a nar­row­er range of out­go­ing direc­tions, mak­ing it more intense at the same time. This is the rea­son for the glar­ing parts of the photo.

With this said, I dab­bled a lit­tle bit with GIMP to try and fac­tor the above image into dif­fuse, spec­u­lar and glossi­ness tex­tures, much in the same way as I had advised artists to do when I was tech­ni­cal direc­tor at Replay Stu­dios. The result is shown below.

Fac­tored into dif­fuse, spec­u­lar and glossi­ness textures

The dif­fuse tex­ture is a straight­for­ward ide­al­iza­tion of the sub­sur­face col­or, devoid of any light­ing and reflec­tions. Since this can­not be observed direct­ly, it must be inferred, but it should be much more sat­u­rat­ed than the real-world appear­ance. I may be use­ful to have pho­tos tak­en with a polar­iz­ing fil­ter as a reference.

The spec­u­lar tex­ture defines the reflec­tiv­i­ty for the case when light, view­er and nor­mal are aligned. This is the min­i­mum val­ue, and the shad­ing mod­el will increase the reflec­tiv­i­ty for any oth­er con­fig­u­ra­tion. There is not much artis­tic free­dom here, since this val­ue is con­nect­ed to refrac­tive index of the mate­r­i­al. It is usu­al­ly in the range of 2% to 5% for every­thing which is not a met­al or a crys­tal. In the exam­ple above, there is almost no point in tex­tur­ing it.

Instead, all the sur­face vari­a­tion went into the glossi­ness map. This map is tak­en to be a log­a­rith­mic encod­ing of the Blinn-Phong spec­u­lar expo­nent, which is a mea­sure of sur­face smooth­ness. Black rep­re­sents a sin­gle-dig­it expo­nent, indi­cat­ing a very rough sur­face. White rep­re­sents an expo­nent in the thou­sands, indi­cat­ing a very smooth sur­face. Since the shad­ing mod­el is nor­mal­ized, both the size and the inten­si­ty of the spec­u­lar high­light is con­trolled with this val­ue alone.

Tex­ture Phys­i­cal interpretation
Dif­fuse Col­or due to aver­age sub­sur­face absorption
Spec­u­lar Fres­nel reflectance at nor­mal incidence
Gloss Blinn-Phong expo­nent, a mea­sure of sur­face smoothness

There is more to phys­i­cal­ly-based shad­ing then just a nor­mal­ized Blinn-Phong spec­u­lar term. To get a dra­mat­ic and con­vinc­ing con­tre-jour effect, it is impor­tant to mod­el the behav­ior at graz­ing angles. This was one of the visu­al goals for the Vel­vet Assas­sin engine. See it real­ized, for exam­ple, in this scene, and also pay atten­tion to the wet pud­dles on the floor, which is an effect of vary­ing glossi­ness. Anoth­er play of vary­ing glossi­ness are the wet streaks on the fuel tank here, or the dusty vs non-dusty parts on the car’s wind­screen here. What’s more, it becomes pos­si­ble to paint both metal­lic and non-metal­lic parts onto the same tex­ture, which helps to min­i­mize batch count and num­ber of shad­er vari­ants. (Edit 2018: The old youtube links were dead, so I replaced them with equiv­a­lent scenes from oth­er videos.) As it turned out dur­ing the devel­op­ment, the Fres­nel fac­tor alone does not have enough ‘omph’. It need­ed the com­bi­na­tion of a Fres­nel fac­tor and the micro-facet geo­met­ric vis­i­bil­i­ty fac­tor to get the right effect at graz­ing angles. More on this below.

In the ear­li­er engine for Spell­Force 2, there was only one mate­r­i­al with a per-pix­el vary­ing glossi­ness like that, the ice/crystal mate­r­i­al. It is pos­si­ble to get a hint of how it looked like here and here (note how not only the spec­u­lar high­light , but also the mipmap lev­el of the translu­cent back buffer is var­ied depend­ing on glossi­ness).  Since this game was based on shad­er mod­el 2, I need­ed to sac­ri­fice shad­ow map taps to get the Blinn-Phong nor­mal­iza­tion in (with­out Fres­nel). For all oth­er mate­ri­als, the glossi­ness was fixed and the nor­mal­iza­tion fac­tor was a pre­com­put­ed con­stant. What the engine did have was dif­fuse and spec­u­lar hemi­sphere light­ing. This allowed the artists to leave the dif­fuse tex­ture black for parts of shiny met­al, which is anoth­er impor­tant aspect of PBS. The soldier’s armor in this scene is a good exam­ple of reflect­ing sky- and ground col­ors. After some time, even these rel­a­tive­ly crude, “phys­i­cal­ly inspired” shad­ing mod­els proved to be real­ly pop­u­lar with the team.

Normalization vs Energy Conservation

When I speak about nor­mal­iza­tion I under­stand a dif­fer­ent thing than ener­gy con­ser­va­tion. In ener­gy con­ser­va­tion, one looks at the total hemi­spher­i­cal reflectance for a giv­en BRDF, and guar­an­tees that it is strict­ly bound­ed by uni­ty for all incom­ing light direc­tions. Nor­mal­iza­tion, on the oth­er hand, is just as strong as we define it. We can demand, for instance, that some para­me­ter (the spec­u­lar expo­nent in this case) has no effect the total hemi­spher­i­cal reflectance for a sin­gle, con­ve­nient­ly cho­sen incom­ing light direc­tion. Then we have nor­mal­ized it. In math­e­mat­i­cal terms,

    \[\text{for a given $\omega_i$,} \quad \int \limits _{\Omega} f_r(\omega_i, \omega_o) \cos \theta_o ,\mathrm{d} \omega_o = \text{const} .\]

It is pos­si­ble (and may be even use­ful) to nor­mal­ize BRDFs that are not ener­gy con­serv­ing [8], like the orig­i­nal Phong and Blinn-Phong (the ones with­out the addi­tion­al cosine term). It is also entire­ly pos­si­ble to nor­mal­ize some­thing else than hemi­spher­i­cal reflectance, for instance we can nor­mal­ize the micro-facet dis­tri­b­u­tion function.

The Normalization Zoo

I ver­i­fied the fol­low­ing list of nor­mal­iza­tion fac­tors with the help of MuPAD, which is a great sym­bol­ic alge­bra tool. Unfor­tu­nate­ly this is no longer avail­able as a sep­a­rate prod­uct, which is a real pity. I rate it sec­ond maybe only to Mathematica.

Mod­el RDF/Integrand Nor­mal­iza­tion Lit­er­a­ture
Phong (\vec{R} \cdot \vec{L})^n
\cos^n \theta \sin \theta
\frac{n+1}{2 \pi}
(\vec{R} \cdot \vec{L})^n(\vec{N} \cdot \vec{L})
\cos^n \theta \cos \theta \sin \theta
\frac{n+2}{2 \pi} [3,5,8]
Blinn-Phong (\vec{N} \cdot \vec{H})^n
\cos^n \frac{\theta}{2} \sin \theta
\frac{n+2}{8 \pi} < \frac{n+2}{4 \pi \big( 2-\exp_2(-n/2) \big)} < \frac{n+4}{8 \pi} [6]
(\vec{N} \cdot \vec{H})^n(\vec{N} \cdot \vec{L})
\cos^n \frac{\theta}{2} \cos \theta \sin \theta
\frac{n+6}{8 \pi} < \frac{(n+2)(n+4)}{8 \pi \big( \exp_2(-n/2)+n \big)} < \frac{n+8}{8 \pi} [3,9]
Mod­el NDF/Integrand Nor­mal­iza­tion Lit­er­a­ture
(\vec{N} \cdot \vec{H})^n
\cos^n \alpha \sin \alpha
\frac{n+1}{2 \pi} [2,4,5]
(\vec{N} \cdot \vec{H})^n
\cos^n \alpha \cos \alpha \sin \alpha
\frac{n+2}{2 \pi} [10,11]

The upper part of the table shows the nor­mal­ized reflec­tion den­si­ty func­tion (RDF). This is the prob­a­bil­i­ty den­si­ty that a pho­ton from the incom­ing direc­tion is reflect­ed to the out­go­ing direc­tion, and is the BRDF times \cos \theta. Here, \theta is the angle between \vec{N} and \vec{L}, which is, for the assumed view posi­tion, also the angle between \vec{V} and \vec{L}, resp. \vec{R} and \vec{L}. The lit­er­a­ture col­umn shows where I have seen these nor­mal­iza­tions men­tioned previously.

The low­er part of the table shows the nor­mal­ized nor­mal dis­tri­b­u­tion func­tion (NDF) for a micro-facet mod­el. This is the prob­a­bil­i­ty den­si­ty that the nor­mal of a micro-facet is ori­ent­ed towards \vec{H}. It is the same expres­sion in spher­i­cal coor­di­nates than that for of the Phong RDF, just over a dif­fer­ent vari­able, \alpha, the angle between \vec{N} and \vec{H}. The height­field dis­tri­b­u­tion does it slight­ly dif­fer­ent, it nor­mal­izes the pro­ject­ed area of the micro-facets to the area of the ground plane (adding yet anoth­er cosine term).

Two Pi Or Not Two Pi

This is a good oppor­tu­ni­ty to elab­o­rate on this \pi-busi­ness, because it can be con­fus­ing time and again. The RDFs and NDFs nec­es­sar­i­ly con­tain \pi, as the result of an inte­gra­tion over parts of a sphere. In the shad­er code how­ev­er, \pi does usu­al­ly not appear, because it can­cels out when mul­ti­ply­ing with irra­di­ance, which is itself an inte­gra­tion over parts of a sphere.

Con­sid­er a point light source mod­eled as a small and very far away sphere, at dis­tance r. Let this sphere have radius r_0 and a homo­ge­neous emis­sive sur­face of radi­ance L. From the point of view of the receiv­ing sur­face, the sol­id angle sub­tend­ed by this sphere is a spher­i­cal cap, and so the irra­di­ance inte­grates to E=\pi L (\frac{r_0}{r})^2. So there you have \pi in the for­mu­la for the irra­di­ance of a point light, neat­ly can­cel­ing with the \pi from the RDF resp. NDF. This exer­cise can be done with all oth­er types of illu­mi­na­tion, it should always remove the fac­tor \pi. (See the com­ment sec­tion for an in-depth explanation.)

Minimalist Cook-Torrance (ShaderX7 style)

I wrote ear­li­er in this post how it was impor­tant to cap­ture the effects at graz­ing angles. The orig­i­nal Cook-Tor­rance mod­el [7] has expen­sive fac­tors for the dis­tri­b­u­tion of nor­mals (D), the Fres­nel reflectance (F) and geo­met­ric occlu­sion of micro-facets (G). The nor­mal­ized Blinn-Phong dis­tri­b­u­tion can be used to great­ly sim­pli­fy D. A clever sim­pli­fi­ca­tion for G was giv­en by Kele­men and Szir­may-Kalos [4], by com­bin­ing G with the fore­short­en­ing terms in the denom­i­na­tor; it should then be called the geo­met­ric vis­i­bil­i­ty fac­tor V. The Schlick approx­i­ma­tion is good to sim­pli­fy F, but still with all the ler­p’ing and one-minus’ing that is going on, it gen­er­ates many shad­er instructions.

For Vel­vet Assas­sin, I devised a fur­ther approx­i­ma­tion by com­bin­ing the effect of F and V in a sin­gle expres­sion with a sig­nif­i­cant­ly reduced instruc­tion count, which I would call ‘min­i­mal­ist Cook-Tor­rance’. I looked at graphs and found, that in order to cap­ture the essence, it suf­fices to divide by a high­er pow­er of \vec{L} \cdot \vec{H}, and get rid of F alto­geth­er. This is where the odd pow­er of 3 comes from. In BRDF form, this is

    \[f_r = \frac{k_d}{\pi} + k_s \frac{(n+1) (\vec{N} \cdot \vec{H})^n}{8 \pi (\vec{L} \cdot \vec{H})^3},\]

where k_d is the dif­fuse reflectance, k_s is the spec­u­lar reflectance, and n is the spec­u­lar expo­nent. This is the for­mu­la that was pub­lished in the ShaderX7 arti­cle [2] and the one that shipped with Vel­vet Assas­sin (see here for the code). The for­mu­la can be decom­posed into a con­tri­bu­tion from D (the nor­mal­ized Blinn-Phong NDF, see table above) and a con­tri­bu­tion from the prod­uct of F and V:

    \begin{align*} f_r &= \frac{k_d}{pi} + k_s D F V , & D &= \frac{(n+1)}{2\pi} (\vec{N} \cdot \vec{H})^n , & F V &= \frac{1}{4} (\vec{L} \cdot \vec{H})^{-3} . \end{align*}

It is pos­si­bly the crud­est approx­i­ma­tion to Cook-Tor­rance there is, but an effec­tive one no less. There will be no Fres­nel col­or shift and no explic­it inter­po­la­tion to white (sat­u­ra­tion is sup­posed to take care of that), so the mod­el is lin­ear in k_s, which is a com­pu­ta­tion­al advan­tage of its own. The mod­el will under­es­ti­mate the reflectance at graz­ing angles for low-index mate­ri­als like water, and over­es­ti­mate the reflectance for high-index mate­ri­als like met­als. For the typ­i­cal range of di-electrics how­ev­er, the esti­ma­tion is just right.

The graphs above show the min­i­mal­ist mod­el with the (\vec{L} \cdot \vec{H})^3 denom­i­na­tor (red graph) against the com­bined effect of Schlick and the (\vec{L} \cdot \vec{H})^2 denom­i­na­tor of Kele­men and Szir­may-Kalos (blue graph), for spec­u­lar reflectances of 0.02 (top), 0.05 (mid­dle) and 0.8 (bot­tom), respec­tive­ly. The graphs do not align per­fect­ly, but the ‘omph’ is there. So, what about the instruc­tion count?

Min­i­mal­ist F‑Schlick with Kele­men/Szir­may-Kalos
Mul­ti­ply denom­i­na­tor by \vec{L} \cdot \vec{H} for a third time. Done. Cal­cu­late 1 - \vec{L} \cdot \vec{H}
Raise that to the 4th or 5th power.
Cal­cu­late 1 - k_s.

If you already have (\vec{L} \cdot \vec{H})^2, the sim­pli­fied mod­el just needs one addi­tion­al mul­ti­pli­ca­tion. The com­bi­na­tion of F‑Schlick and Kele­men/Szir­may-Kalos needs 5 or 6 more instruc­tions in a depen­den­cy chain from that point. It does­n’t help if a Fres­nel fac­tor from the envi­ron­ment map already exists, since that is based on \vec{N} \cdot \vec{V}. In terms of bang for the buck, if there are many lights in a loop (and I had a for­ward ren­der­er with up to 8 lights per pass), then I’d rec­om­mend the min­i­mal­ist version.


[1] Dim­i­tar Lazarov, “Phys­i­cal­ly-based light­ing in Call of Duty: Black Ops” SIGGRAPH 2011
[2] Chris­t­ian Schüler, “An Effi­cient and Phys­i­cal­ly Plau­si­ble Real-Time Shad­ing Mod­el.” ShaderX 7, Chap­ter 2.5, pp. 175–187
[3] Fabi­an Giesen, “Phong Nor­mal­iza­tion Fac­tor deriva­tion”
[4] Kele­men and Szir­may-Kalos, “A Micro­facet Based Cou­pled Spec­u­lar-Mat­te BRDF Mod­el with Impor­tance Sam­pling”, Euro­graph­ics 2001
[5] Lafor­tune and Willems, “Using the mod­i­fied Phong reflectance mod­el for phys­i­cal­ly based ren­der­ing”, Tech­ni­cal Report
[6] Yoshi­haru Gotan­da, “Prac­ti­cal Imple­men­ta­tion of Phys­i­cal­ly-Based Shad­ing Mod­els at tri-Ace”, SIGGRAPH 2010
[7] Robert Cook and Ken­neth Tor­rance, “A reflectance mod­el for com­put­er graph­ics”
[8] Robert Lewis, “Mak­ing Shaders More Phys­i­cal­ly Plau­si­ble”, Com­put­er Graph­ics Forum, vol. 13, no. 2 (June, 1994)
[9] Aki­enne-Möller, Haines and Hoff­mann, “Real-Time Ren­der­ing” book
[10] Pharr, Humphreys, “Phys­i­cal­ly-Based Ren­der­ing” book
[11] Nathaniel Hoff­mann, “Craft­ing Phys­i­cal­ly Moti­vat­ed Shad­ing Mod­els for Game Devel­op­ment”, SIGGRAPH 2010

38 Gedanken zu „The Blinn-Phong Normalization Zoo

  1. Pingback: PBR 四 法线分布函数 - 算法网

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht.

Please answer the following anti-spam test

Which thing makes "tick-tock" and if it falls down, the clock is broken?

  1.    ruler
  2.    table
  3.    watch
  4.    pencil
  5.    chair