diff --git a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl
index d9e15738ad16edd0a4758f0718e9512302213208..62bb09e94b73c983302104822158a29da311159a 100644
--- a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl
+++ b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl
@@ -44,6 +44,7 @@ vec4 applyWaterFogView(vec3 pos, vec4 color);
 vec3 atmosFragLightingLinear(vec3 l, vec3 additive, vec3 atten);
 vec3 scaleSoftClipFragLinear(vec3 l);
 void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive);
+void calcHalfVectors(vec3 lv, vec3 n, vec3 v, out vec3 h, out vec3 l, out float nh, out float nl, out float nv, out float vh, out float lightDist);
 
 vec3 srgb_to_linear(vec3 cs);
 vec3 linear_to_srgb(vec3 cs);
@@ -359,6 +360,7 @@ void main()
 
     float glare = 0.0;
 
+#if 0 //wrong implementation
     if (glossiness > 0.0)  // specular reflection
     {
         float sa        = dot(normalize(refnormpersp), light_dir.xyz);
@@ -375,6 +377,32 @@ void main()
 
         applyGlossEnv(color, glossenv, spec, pos.xyz, norm.xyz);
     }
+#else //right implementation ported from pointLightF.glsl
+    if (glossiness > 0.0)
+    {
+        vec3  lv = light_dir.xyz;
+        vec3  h, l, v = -normalize(pos.xyz);
+        float nh, nl, nv, vh, lightDist;
+        vec3 n = norm.xyz;
+        calcHalfVectors(lv, n, v, h, l, nh, nl, nv, vh, lightDist);
+
+        if (nl > 0.0 && nh > 0.0)
+        {
+            float lit = min(nl*6.0, 1.0);
+
+            float sa = nh;
+            float fres = pow(1 - vh, 5) * 0.4+0.5;
+            float gtdenom = 2 * nh;
+            float gt = max(0,(min(gtdenom * nv / vh, gtdenom * nl / vh)));
+
+            float scol = shadow*fres*texture2D(lightFunc, vec2(nh, glossiness)).r*gt/(nh*nl);
+            color.rgb += lit*scol*sunlit_linear.rgb*spec.rgb;
+        }
+
+        // add radiance map
+        applyGlossEnv(color, glossenv, spec, pos.xyz, norm.xyz);
+    }
+#endif
 
     color = mix(color.rgb, diffcol.rgb, emissive);
 
diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl
index df3c470a01f191b4720b03638b7b5c2c34cd8359..08e55ece162e1dc8ab10c07d64339d48fee63f7e 100644
--- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl
+++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl
@@ -94,6 +94,7 @@ vec4 applyWaterFogViewLinear(vec3 pos, vec4 color);
 
 uniform float sky_hdr_scale;
 
+void calcHalfVectors(vec3 lv, vec3 n, vec3 v, out vec3 h, out vec3 l, out float nh, out float nl, out float nv, out float vh, out float lightDist);
 void calcDiffuseSpecular(vec3 baseColor, float metallic, inout vec3 diffuseColor, inout vec3 specularColor);
 
 vec3 pbrBaseLight(vec3 diffuseColor,
@@ -244,6 +245,7 @@ void main()
         
         vec3 refnormpersp = reflect(pos.xyz, norm.xyz);
 
+#if 0 // wrong implementation
         if (spec.a > 0.0)  // specular reflection
         {
             float sa        = dot(normalize(refnormpersp), light_dir.xyz);
@@ -256,6 +258,32 @@ void main()
             // add radiance map
             applyGlossEnv(color, glossenv, spec, pos.xyz, norm.xyz);
         }
+#else //right implementation (ported from pointLightF.glsl)
+        if (spec.a > 0.0)
+        {
+            vec3  lv = light_dir.xyz;
+            vec3  h, l, v = -normalize(pos.xyz);
+            float nh, nl, nv, vh, lightDist;
+            vec3 n = norm.xyz;
+            calcHalfVectors(lv, n, v, h, l, nh, nl, nv, vh, lightDist);
+
+            if (nl > 0.0 && nh > 0.0)
+            {
+                float lit = min(nl*6.0, 1.0);
+
+                float sa = nh;
+                float fres = pow(1 - vh, 5) * 0.4+0.5;
+                float gtdenom = 2 * nh;
+                float gt = max(0,(min(gtdenom * nv / vh, gtdenom * nl / vh)));
+
+                scol *= fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*nl);
+                color.rgb += lit*scol*sunlit_linear.rgb*spec.rgb;
+            }
+
+            // add radiance map
+            applyGlossEnv(color, glossenv, spec, pos.xyz, norm.xyz);
+        }
+#endif
 
         color.rgb = mix(color.rgb, baseColor.rgb, baseColor.a);