mrdoob/three.js — Issue #677: Bug in the 'normal' Blinn-Phong and 'phong' fragment shaders
Author: WestLangley
Created: 2011-10-22 19:22:04+00:00
State: open

As it is currently written, the half-vector in camera space is computed as the normalized sum of
(1) the un-normalized light direction, and
(2) the normalized view direction.

However, both vectors need to be normalized before adding them.

So, in the point lights calculation,

```javascript
"vec3 pointVector = normalize( vPointLight[ i ].xyz );",
"vec3 pointHalfVector = normalize( vPointLight[ i ].xyz + viewPosition );",
```

should be replaced by

```javascript
"vec3 pointVector = normalize( vPointLight[ i ].xyz );",
"vec3 pointHalfVector = normalize( pointVector + viewPosition );",
```

And likewise, in the directional lights calculation,

```javascript
"vec3 dirVector = normalize( lDirection.xyz );",
"vec3 dirHalfVector = normalize( lDirection.xyz + viewPosition );",
```

should be replaced by

```javascript
"vec3 dirVector = normalize( lDirection.xyz );",
"vec3 dirHalfVector = normalize( dirVector + viewPosition );",
```

As an aside, it happens that for the point lights calculation, `vPointLight[i].xyz` was already normalized in the vertex shader, so the 'bug' turns out to not be a bug after all. But for the sake of clarity, I think the change is warranted.

The directional lights calculation, however, is incorrect -- except in the special case where the user passes in a normalized vector to begin with.

WestLangley