         if visualizeNormals
           # Visualized normals mode.
           if pixel.normal
-            normal = new THREE.Vector3 pixel.normal.x, pixel.normal.y, pixel.normal.z
-            normal.x *= -1 if flippedHorizontal
-            backward = new THREE.Vector3 0, 0, 1
-
-            horizontalAngle = Math.atan2(normal.y, normal.x) + Math.PI
-            verticalAngle = normal.angleTo backward
+            @_normal.copy pixel.normal
+            @_normal.x *= -1 if flippedHorizontal
+
+            horizontalAngle = Math.atan2(@_normal.y, @_normal.x) + Math.PI
+            verticalAngle = @_normal.angleTo @_backward
 
             hue = horizontalAngle / (2 * Math.PI)
             saturation = verticalAngle / (Math.PI / 2)

              smoothFactor = paletteColor.reflection.smoothFactor or 0

              # Average the normal.
              averageNormal = new THREE.Vector3

              for offsetX in [-smoothFactor..smoothFactor]
                for offsetY in [-smoothFactor..smoothFactor]
                  if sampleNormal = layer._pixelMap[pixel.x + offsetX]?[pixel.y + offsetY]?.normal
                    averageNormal.add sampleNormal

              averageNormal.normalize()
              averageNormal.x *= -1 if flippedHorizontal

              averageNormalLightProduct = THREE.Math.clamp averageNormal.dot(inverseLightDirection), 0, 1

              # Calculate the perfectly reflected ray.
              reflection = averageNormal.clone().multiplyScalar(2 * averageNormalLightProduct).sub inverseLightDirection

              # We assume the inverse view direction to be (0, 0, 1).
              # Dot product is then the equivalent of the z coordinate.
              reflectionViewProduct = THREE.Math.clamp reflection.z, 0, 1

              lightFactor = Math.pow(reflectionViewProduct, shininess) * lightSpecularCoefficient * materialSpecularCoefficient
              lightColor = new THREE.Color(0xffffff).multiplyScalar lightFactor

              shadedColor.add lightColor

            if palette
              # Find the nearest color from the palette to represent the shaded color.


            # Calculate diffuse lighting.
            if pixel.normal
              @_normal.copy pixel.normal
              @_normal.x *= -1 if flippedHorizontal

            else
              @_normal.set 0, 0, 1

            normalLightProduct = THREE.Math.clamp @_normal.dot(inverseLightDirection), 0, 1

            lightDiffuseCoefficient = 0.6
            materialDiffuseCoefficient = 1
