From 4f06f3dae6d35b142f57e07c41e0a8abcd296fcb Mon Sep 17 00:00:00 2001
From: Tofu Buzzard <no-email>
Date: Sun, 16 Jan 2011 13:36:44 +0000
Subject: [PATCH] FIX VWR-24509 Fix SSAO speckling artifacts at distance,
 re-enable distant SSAO (transplanted from
 ef938dea0504b12fcf802f38fcf5457ba566c468)

---
 doc/contributions.txt                                      | 1 +
 .../app_settings/shaders/class1/deferred/blurLightF.glsl   | 7 +++++--
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/doc/contributions.txt b/doc/contributions.txt
index b5158b37921..313cc113418 100644
--- a/doc/contributions.txt
+++ b/doc/contributions.txt
@@ -752,6 +752,7 @@ tiamat bingyi
 Tofu Buzzard
 	CTS-411
 	STORM-546
+	VWR-24509
 TraductoresAnonimos Alter
 	CT-324
 Tue Torok
diff --git a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl
index ad4d700b991..6859f72a9c2 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl
@@ -51,6 +51,9 @@ void main()
 	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;
 
+	// relax tolerance according to distance to avoid speckling artifacts, as angles and distances are a lot more abrupt within a small screen area at larger distances
+	float pointplanedist_tolerance_pow2 = pos.z*pos.z*0.00005;
+
 	// 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 );
 
@@ -59,7 +62,7 @@ void main()
 		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)
+		if (d*d <= pointplanedist_tolerance_pow2)
 		{
 			col += texture2DRect(lightMap, samptc)*kern[i].xyxx;
 			defined_weight += kern[i].xy;
@@ -70,7 +73,7 @@ void main()
 		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)
+		if (d*d <= pointplanedist_tolerance_pow2)
 		{
 			col += texture2DRect(lightMap, samptc)*kern[i].xyxx;
 			defined_weight += kern[i].xy;
-- 
GitLab