From a6e8026de00248bf6be5cf608bea6c7d94c4e07c Mon Sep 17 00:00:00 2001
From: Tofu Buzzard <no-email>
Date: Wed, 15 Dec 2010 13:40:28 +0000
Subject: [PATCH] CTS-411 edge ghosting in deferred rendering (w/shadows and
 shadow smoothing enabled) (transplanted from
 c698ce37c0502597aafc75fcf9c37ff2970b7faf) (transplanted from
 ae92e806703a0c03ec2ab76d74906c7465285aaf)

---
 doc/contributions.txt                         |  1 +
 .../shaders/class1/deferred/blurLightF.glsl   | 27 +++---
 .../shaders/class2/deferred/blurLightF.glsl   | 83 -------------------
 .../shaders/class2/deferred/blurLightV.glsl   | 19 -----
 4 files changed, 15 insertions(+), 115 deletions(-)
 delete mode 100644 indra/newview/app_settings/shaders/class2/deferred/blurLightF.glsl
 delete mode 100644 indra/newview/app_settings/shaders/class2/deferred/blurLightV.glsl

diff --git a/doc/contributions.txt b/doc/contributions.txt
index 4c59e703eee..b5158b37921 100644
--- a/doc/contributions.txt
+++ b/doc/contributions.txt
@@ -750,6 +750,7 @@ Thraxis Epsilon
 tiamat bingyi
 	CT-246
 Tofu Buzzard
+	CTS-411
 	STORM-546
 TraductoresAnonimos Alter
 	CT-324
diff --git a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl
index ea2df4b51a1..ad4d700b991 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl
@@ -39,43 +39,44 @@ vec4 getPosition(vec2 pos_screen)
 
 void main() 
 {
-	vec3 norm = texture2DRect(normalMap, vary_fragcoord.xy).xyz;
+        vec2 tc = vary_fragcoord.xy;
+	vec3 norm = texture2DRect(normalMap, tc).xyz;
 	norm = vec3((norm.xy-0.5)*2.0,norm.z); // unpack norm
-	vec3 pos = getPosition(vary_fragcoord.xy).xyz;
-	vec4 ccol = texture2DRect(lightMap, vary_fragcoord.xy).rgba;
+	vec3 pos = getPosition(tc).xyz;
+	vec4 ccol = texture2DRect(lightMap, tc).rgba;
 	
 	vec2 dlt = kern_scale * delta / (1.0+norm.xy*norm.xy);
-	
 	dlt /= max(-pos.z*dist_factor, 1.0);
 	
 	vec2 defined_weight = kern[0].xy; // special case the first (centre) sample's weight in the blur; we have to sample it anyway so we get it for 'free'
 	vec4 col = defined_weight.xyxx * ccol;
-	
+
+	// perturb sampling origin slightly in screen-space to hide edge-ghosting artifacts where smoothing radius is quite large
+	tc += ( (int(tc.x+tc.y)%2 - 0.5) * kern[1].z * dlt * 0.5 );
+
 	for (int i = 1; i < 4; i++)
 	{
-		vec2 tc = vary_fragcoord.xy + kern[i].z*dlt;
-	        vec3 samppos = getPosition(tc).xyz; 
+		vec2 samptc = tc + kern[i].z*dlt;
+	        vec3 samppos = getPosition(samptc).xyz; 
 		float d = dot(norm.xyz, samppos.xyz-pos.xyz);// dist from plane
 		if (d*d <= 0.003)
 		{
-			col += texture2DRect(lightMap, tc)*kern[i].xyxx;
+			col += texture2DRect(lightMap, samptc)*kern[i].xyxx;
 			defined_weight += kern[i].xy;
 		}
 	}
 	for (int i = 1; i < 4; i++)
 	{
-		vec2 tc = vary_fragcoord.xy - kern[i].z*dlt;
-	        vec3 samppos = getPosition(tc).xyz; 
+		vec2 samptc = tc - kern[i].z*dlt;
+	        vec3 samppos = getPosition(samptc).xyz; 
 		float d = dot(norm.xyz, samppos.xyz-pos.xyz);// dist from plane
 		if (d*d <= 0.003)
 		{
-			col += texture2DRect(lightMap, tc)*kern[i].xyxx;
+			col += texture2DRect(lightMap, samptc)*kern[i].xyxx;
 			defined_weight += kern[i].xy;
 		}
 	}
 
-
-
 	col /= defined_weight.xyxx;
 	
 	gl_FragColor = col;
diff --git a/indra/newview/app_settings/shaders/class2/deferred/blurLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/blurLightF.glsl
deleted file mode 100644
index ea2df4b51a1..00000000000
--- a/indra/newview/app_settings/shaders/class2/deferred/blurLightF.glsl
+++ /dev/null
@@ -1,83 +0,0 @@
-/** 
- * @file blurLightF.glsl
- *
- * $LicenseInfo:firstyear=2007&license=viewerlgpl$
- * $/LicenseInfo$
- */
- 
-#version 120
-
-#extension GL_ARB_texture_rectangle : enable
-
-uniform sampler2DRect depthMap;
-uniform sampler2DRect normalMap;
-uniform sampler2DRect lightMap;
-
-uniform float dist_factor;
-uniform float blur_size;
-uniform vec2 delta;
-uniform vec3 kern[4];
-uniform float kern_scale;
-
-varying vec2 vary_fragcoord;
-
-uniform mat4 inv_proj;
-uniform vec2 screen_res;
-
-vec4 getPosition(vec2 pos_screen)
-{
-	float depth = texture2DRect(depthMap, pos_screen.xy).a;
-	vec2 sc = pos_screen.xy*2.0;
-	sc /= screen_res;
-	sc -= vec2(1.0,1.0);
-	vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0);
-	vec4 pos = inv_proj * ndc;
-	pos /= pos.w;
-	pos.w = 1.0;
-	return pos;
-}
-
-void main() 
-{
-	vec3 norm = texture2DRect(normalMap, vary_fragcoord.xy).xyz;
-	norm = vec3((norm.xy-0.5)*2.0,norm.z); // unpack norm
-	vec3 pos = getPosition(vary_fragcoord.xy).xyz;
-	vec4 ccol = texture2DRect(lightMap, vary_fragcoord.xy).rgba;
-	
-	vec2 dlt = kern_scale * delta / (1.0+norm.xy*norm.xy);
-	
-	dlt /= max(-pos.z*dist_factor, 1.0);
-	
-	vec2 defined_weight = kern[0].xy; // special case the first (centre) sample's weight in the blur; we have to sample it anyway so we get it for 'free'
-	vec4 col = defined_weight.xyxx * ccol;
-	
-	for (int i = 1; i < 4; i++)
-	{
-		vec2 tc = vary_fragcoord.xy + kern[i].z*dlt;
-	        vec3 samppos = getPosition(tc).xyz; 
-		float d = dot(norm.xyz, samppos.xyz-pos.xyz);// dist from plane
-		if (d*d <= 0.003)
-		{
-			col += texture2DRect(lightMap, tc)*kern[i].xyxx;
-			defined_weight += kern[i].xy;
-		}
-	}
-	for (int i = 1; i < 4; i++)
-	{
-		vec2 tc = vary_fragcoord.xy - kern[i].z*dlt;
-	        vec3 samppos = getPosition(tc).xyz; 
-		float d = dot(norm.xyz, samppos.xyz-pos.xyz);// dist from plane
-		if (d*d <= 0.003)
-		{
-			col += texture2DRect(lightMap, tc)*kern[i].xyxx;
-			defined_weight += kern[i].xy;
-		}
-	}
-
-
-
-	col /= defined_weight.xyxx;
-	
-	gl_FragColor = col;
-}
-
diff --git a/indra/newview/app_settings/shaders/class2/deferred/blurLightV.glsl b/indra/newview/app_settings/shaders/class2/deferred/blurLightV.glsl
deleted file mode 100644
index c2d05c601a8..00000000000
--- a/indra/newview/app_settings/shaders/class2/deferred/blurLightV.glsl
+++ /dev/null
@@ -1,19 +0,0 @@
-/** 
- * @file blurLightF.glsl
- *
- * $LicenseInfo:firstyear=2007&license=viewerlgpl$
- * $/LicenseInfo$
- */
- 
-#version 120
-
-varying vec2 vary_fragcoord;
-uniform vec2 screen_res;
-
-void main()
-{
-	//transform vertex
-	gl_Position = ftransform(); 
-	vec4 pos = gl_ModelViewProjectionMatrix * gl_Vertex;
-	vary_fragcoord = (pos.xy*0.5+0.5)*screen_res;
-}
-- 
GitLab