 
 #endif
 
-transformedNormal = normalize( transformedNormal );
-
-#if MAX_DIR_LIGHTS > 0
-
-for( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {
-
-	vec3 dirVector = transformDirection( directionalLightDirection[ i ], viewMatrix );
-
-	float dotProduct = dot( transformedNormal, dirVector );
-	vec3 directionalLightWeighting = vec3( max( dotProduct, 0.0 ) );
-
-	#ifdef DOUBLE_SIDED
-
-		vec3 directionalLightWeightingBack = vec3( max( -dotProduct, 0.0 ) );
-
-	#endif
-
-	vLightFront += directionalLightColor[ i ] * directionalLightWeighting;
-
-	#ifdef DOUBLE_SIDED
-
-		vLightBack += directionalLightColor[ i ] * directionalLightWeightingBack;
-
-	#endif
-
-}
-
-#endif
+vec3 normal = normalize( transformedNormal );
 
 #if MAX_POINT_LIGHTS > 0
 
-	for( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {
+	for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {
+
+		vec3 lightColor = pointLightColor[ i ];
 
 		vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );
 		vec3 lVector = lPosition.xyz - mvPosition.xyz;
+		vec3 lightDir = normalize( lVector );
+
+		// attenuation
 
 		float attenuation = calcLightAttenuation( length( lVector ), pointLightDistance[ i ], pointLightDecay[ i ] );
 
-		lVector = normalize( lVector );
-		float dotProduct = dot( transformedNormal, lVector );
+		// diffuse
 
-		vec3 pointLightWeighting = vec3( max( dotProduct, 0.0 ) );
+		float dotProduct = dot( normal, lightDir );
+
+		vLightFront += lightColor * attenuation * saturate( dotProduct );
 
 		#ifdef DOUBLE_SIDED
 
-			vec3 pointLightWeightingBack = vec3( max( -dotProduct, 0.0 ) );
-
-		#endif
-
-		vLightFront += pointLightColor[ i ] * pointLightWeighting * attenuation;
-
-		#ifdef DOUBLE_SIDED
-
-			vLightBack += pointLightColor[ i ] * pointLightWeightingBack * attenuation;
+			vLightBack += lightColor * attenuation * saturate( - dotProduct );
 
 		#endif
 


#endif

#if MAX_HEMI_LIGHTS > 0

	for( int i = 0; i < MAX_HEMI_LIGHTS; i ++ ) {

		vec3 lVector = transformDirection( hemisphereLightDirection[ i ], viewMatrix );

		float dotProduct = dot( transformedNormal, lVector );

		float hemiDiffuseWeight = 0.5 * dotProduct + 0.5;
		float hemiDiffuseWeightBack = -0.5 * dotProduct + 0.5;

		vLightFront += mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight );

		#ifdef DOUBLE_SIDED

			vLightBack += mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeightBack );



#if MAX_SPOT_LIGHTS > 0

	for ( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {

		vec3 lightColor = spotLightColor[ i ];

		vec3 lightPosition = spotLightPosition[ i ];
		vec4 lPosition = viewMatrix * vec4( lightPosition, 1.0 );
		vec3 lVector = lPosition.xyz - mvPosition.xyz;
		vec3 lightDir = normalize( lVector );

		float spotEffect = dot( spotLightDirection[ i ], normalize( lightPosition - worldPosition.xyz ) );

		if ( spotEffect > spotLightAngleCos[ i ] ) {

			spotEffect = saturate( pow( saturate( spotEffect ), spotLightExponent[ i ] ) );

			// attenuation

			float attenuation = calcLightAttenuation( length( lVector ), spotLightDistance[ i ], spotLightDecay[ i ] );

			attenuation *= spotEffect;

			// diffuse

			float dotProduct = dot( normal, lightDir );

			vLightFront += lightColor * attenuation * saturate( dotProduct );

			#ifdef DOUBLE_SIDED

				vLightBack += lightColor * attenuation * saturate( - dotProduct );

			#endif

