     // Include tint mask
     vec4 c0 = blend.x * color0 * interpolateTint(0, g_vColorTint0, g_vColorTintB0, g_flTexCoordScale0, g_flTexCoordRotate0);
     vec4 c1 = blend.y * color1 * interpolateTint(1, g_vColorTint1, g_vColorTintB1, g_flTexCoordScale1, g_flTexCoordRotate1);
-    vec4 c2 = blend.z * color2 * interpolateTint(2, g_vColorTint2, g_vColorTintB2, g_flTexCoordScale2, g_flTexCoordRotate2);
-    vec4 c3 = blend.w * color3 * interpolateTint(3, g_vColorTint3, g_vColorTintB3, g_flTexCoordScale3, g_flTexCoordRotate3);
+    #if param_F_TWO_LAYER_BLEND == 0
+        vec4 c2 = blend.z * color2 * interpolateTint(2, g_vColorTint2, g_vColorTintB2, g_flTexCoordScale2, g_flTexCoordRotate2);
+        vec4 c3 = blend.w * color3 * interpolateTint(3, g_vColorTint3, g_vColorTintB3, g_flTexCoordScale3, g_flTexCoordRotate3);
+    #endif
 #else
     vec4 c0 = blend.x * color0;
     vec4 c1 = blend.y * color1;
-    vec4 c2 = blend.z * color2;
-    vec4 c3 = blend.w * color3;
-#endif
-
+    #if param_F_TWO_LAYER_BLEND == 0
+        // TODO: this blending is probably wrong
+        vec4 c2 = blend.z * color2;
+        vec4 c3 = blend.w * color3;
+    #endif
+#endif
+
+#if param_F_TWO_LAYER_BLEND == 0
     //Add up the result
     vec4 finalColor = c0 + c1 + c2 + c3;
+#else
+    //Add up the result
+    vec4 finalColor = c0 + c1;
+#endif
 
 #if param_F_NORMAL_MAP
-    //calculate blended normal
-    vec4 bumpNormal = blend.x * normal0 + blend.y * normal1 + blend.z * normal2 + blend.w * normal3;
+    #if param_F_TWO_LAYER_BLEND == 0
+        //calculate blended normal
+        vec4 bumpNormal = blend.x * normal0 + blend.y * normal1 + blend.z * normal2 + blend.w * normal3;
+    #else
+        //calculate blended normal
+        vec4 bumpNormal = blend.x * normal0 + blend.y * normal1;
+    #endif
 
     //Reconstruct the tangent vector from the map
     vec2 temp = vec2(bumpNormal.w, bumpNormal.y) * 2 - 1;

    //Calculate coordinates
    vec2 coord0 = getTexCoord(g_flTexCoordScale0, g_flTexCoordRotate0);
    vec2 coord1 = getTexCoord(g_flTexCoordScale1, g_flTexCoordRotate1);
    vec2 coord2 = getTexCoord(g_flTexCoordScale2, g_flTexCoordRotate2);
    vec2 coord3 = getTexCoord(g_flTexCoordScale3, g_flTexCoordRotate3);

    //Get the ambient color from the color texture
    vec4 color0 = texture2D(g_tColor0, coord0);
    vec4 color1 = texture2D(g_tColor1, coord1);
    vec4 color2 = texture2D(g_tColor2, coord2);
    vec4 color3 = texture2D(g_tColor3, coord3);

    //Get normal
    vec4 normal0 = texture2D(g_tNormal0, coord0);
    vec4 normal1 = texture2D(g_tNormal1, coord1);
    vec4 normal2 = texture2D(g_tNormal2, coord2);
    vec4 normal3 = texture2D(g_tNormal3, coord3);

    //Get specular
    vec4 specular0 = texture2D(g_tSpecular0, coord0);
    vec4 specular1 = texture2D(g_tSpecular1, coord1);
    vec4 specular2 = texture2D(g_tSpecular2, coord2);
    vec4 specular3 = texture2D(g_tSpecular3, coord3);

    //calculate blend
    vec4 blend = vec4(max(0, 1 - vBlendWeights.x - vBlendWeights.y - vBlendWeights.z), vBlendWeights.x, max(0, vBlendWeights.y - vBlendWeights.x), max(0, vBlendWeights.z - vBlendWeights.w - vBlendWeights.y));

    illumination = min(illumination + 0.3, 1.0);
#endif

#if param_F_TWO_LAYER_BLEND == 0
    //Calculate specular
    vec4 blendSpecular = blend.x * specular0 + blend.y * specular1 + blend.z * specular2 + blend.w * specular3;
#else
    //Calculate specular
    vec4 blendSpecular = blend.x * specular0 + blend.y * specular1;
#endif

    float specular = blendSpecular.x * pow(max(0,dot(lightDirection, finalNormal)), 6);

    //Apply ambient occlusion
