From 558eaef3ea09ff560c1fead65f1d1b3b75b4bdc5 Mon Sep 17 00:00:00 2001
From: Geenz <geenz@geenzo.com>
Date: Mon, 1 Apr 2019 23:09:43 -0700
Subject: [PATCH] Make sure that atmospheric calcs aren't done twice. The
 atomospherics were being applied both in the G-buffer and during the sun
 light pass.  This ensures that is not the case. Additionally, re-enable
 specular on the water plane, scale the bloom factor to something more
 reasonable, and also someone broke specular on emissive surfaces.  That's
 fixed too now.

---
 .../shaders/class1/deferred/softenLightF.glsl         |  4 ++--
 .../app_settings/shaders/class1/deferred/waterF.glsl  | 11 ++++-------
 .../shaders/class2/deferred/softenLightF.glsl         |  8 +++-----
 3 files changed, 9 insertions(+), 14 deletions(-)

diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl
index a39a73f1b62..a04a24955ed 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl
@@ -130,11 +130,11 @@ void main()
             
             // add the two types of shiny together
             vec3 spec_contrib = dumbshiny * spec.rgb;
-            bloom = dot(spec_contrib, spec_contrib) / 6;
+            bloom = dot(spec_contrib, spec_contrib) / 32;
             col += spec_contrib;
         }
         
-        col = mix(col.rgb, diffuse.rgb, diffuse.a);
+        col.rgb += diffuse.a * diffuse.rgb;
 
         if (envIntensity > 0.0)
         { //add environmentmap
diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl
index be5e3538a70..9a8a098a195 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl
@@ -153,21 +153,18 @@ void main()
     vec2 distort2 = distort+wavef.xy*refScale * 0.33/max(dmod*df1, 1.0);
         
     vec4 fb = texture2D(screenTex, distort2);
-    
     //mix with reflection
     // Note we actually want to use just df1, but multiplying by 0.999999 gets around an nvidia compiler bug
     color.rgb = mix(fb.rgb, refcol.rgb, df1 * 0.99999);
     
     vec4 pos = vary_position;
     
-    color.rgb += spec * specular;
-    
-    color.rgb = atmosTransport(color.rgb);
-    color.rgb = scaleSoftClipFrag(color.rgb);
+    //color.rgb = atmosTransport(color.rgb);
+    //color.rgb = scaleSoftClipFrag(color.rgb) * 0;
 
     vec3 screenspacewavef = normalize((norm_mat*vec4(wavef, 1.0)).xyz);
 
     frag_data[0] = vec4(color.rgb, 1); // diffuse
-    frag_data[1] = vec4(0);     // speccolor, spec
-    frag_data[2] = vec4(encode_normal(screenspacewavef.xyz*0.5+0.5), 0.05, 0);// normalxy, 0, 0
+    frag_data[1] = vec4(specular, 0.75);     // speccolor, spec
+    frag_data[2] = vec4(encode_normal(screenspacewavef.xyz), 0.05, 0);// normalxy, 0, 0
 }
diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl
index 27532ce458c..39776f17919 100644
--- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl
+++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl
@@ -142,11 +142,11 @@ void main()
             
             // add the two types of shiny together
             vec3 spec_contrib = dumbshiny * spec.rgb;
-            bloom = dot(spec_contrib, spec_contrib) / 6;
+            bloom = dot(spec_contrib, spec_contrib) / 64;
             col += spec_contrib;
         }
         
-        col = mix(col.rgb, diffuse.rgb, diffuse.a);
+        col.rgb += diffuse.a * diffuse.rgb;
 
         if (envIntensity > 0.0)
         { //add environmentmap
@@ -154,9 +154,7 @@ void main()
             vec3 refcol = textureCube(environmentMap, env_vec).rgb;
             col = mix(col.rgb, refcol, envIntensity); 
         }
-                
-
-vec3 a = col.rgb;
+        
         if (norm.w < 0.5)
         {
             col = mix(atmosFragLighting(col, additive, atten), fullbrightAtmosTransportFrag(col, additive, atten), diffuse.a);
-- 
GitLab