From 0467d0a62916f045c50c53e12719ca692271326c Mon Sep 17 00:00:00 2001
From: Tofu Linden <tofu.linden@lindenlab.com>
Date: Thu, 28 Jan 2010 18:01:12 -0800
Subject: [PATCH] enable basic directional lighting for basic/atmospheric
 shaders - yay.

next, needs the non-shader GL lighting model to be equally dumb (it's too smart - kill the spot angle.
---
 .../shaders/class1/lighting/lightFuncV.glsl   | 21 +++++++++++++++++++
 .../shaders/class2/lighting/sumLightsV.glsl   |  8 ++++---
 2 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFuncV.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFuncV.glsl
index 3e8fdfb3e48..211de830fae 100644
--- a/indra/newview/app_settings/shaders/class1/lighting/lightFuncV.glsl
+++ b/indra/newview/app_settings/shaders/class1/lighting/lightFuncV.glsl
@@ -28,7 +28,28 @@ float calcPointLight(vec3 v, vec3 n, vec4 lp, float la)
 	
 	//angular attenuation
 	da *= calcDirectionalLight(n, lv);
+
+	return da;	
+}
+
+
+float calcPointLight2(vec3 v, vec3 n, vec4 lp, vec3 ln, float la)
+{
+	//get light vector
+	vec3 lv = lp.xyz-v;
 	
+	//get distance
+	float d = length(lv);
+	
+	//normalize light vector
+	lv *= 1.0/d;
+	
+	//distance attenuation
+	float da = clamp(1.0/(la * d), 0.0, 1.0);
+	
+	//angular attenuation
+	da *= dot(lv, -ln) * calcDirectionalLight(n, lv);
+
 	return da;	
 }
 
diff --git a/indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl b/indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl
index f4c59734a47..fd264b9e747 100644
--- a/indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl
+++ b/indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl
@@ -7,6 +7,7 @@
 
 float calcDirectionalLight(vec3 n, vec3 l);
 float calcPointLight(vec3 v, vec3 n, vec4 lp, float la);
+float calcPointLight2(vec3 v, vec3 n, vec4 lp, vec3 ln, float la);
 
 vec3 atmosAmbient(vec3 light);
 vec3 atmosAffectDirectionalLight(float lightIntensity);
@@ -18,9 +19,10 @@ vec4 sumLights(vec3 pos, vec3 norm, vec4 color, vec4 baseLight)
 	
 	// Collect normal lights (need to be divided by two, as we later multiply by 2)
 	col.rgb += gl_LightSource[1].diffuse.rgb * calcDirectionalLight(norm, gl_LightSource[1].position.xyz);
-	col.rgb += gl_LightSource[2].diffuse.rgb * calcPointLight(pos, norm, gl_LightSource[2].position, gl_LightSource[2].linearAttenuation);
-	col.rgb += gl_LightSource[3].diffuse.rgb * calcPointLight(pos, norm, gl_LightSource[3].position, gl_LightSource[3].linearAttenuation);
-	//col.rgb += gl_LightSource[4].diffuse.rgb * calcPointLight(pos, norm, gl_LightSource[4].position, gl_LightSource[4].linearAttenuation);
+
+	col.rgb += gl_LightSource[2].diffuse.rgb * calcPointLight2(pos, norm, gl_LightSource[2].position, gl_LightSource[2].spotDirection.xyz, gl_LightSource[2].linearAttenuation);
+	col.rgb += gl_LightSource[3].diffuse.rgb * calcPointLight2(pos, norm, gl_LightSource[3].position, gl_LightSource[3].spotDirection.xyz, gl_LightSource[3].linearAttenuation);
+	//col.rgb += gl_LightSource[4].diffuse.rgb * calcPointLight2(pos, norm, gl_LightSource[4].position, gl_LightSource[4].spotDirection.xyz, gl_LightSource[4].linearAttenuation);
 	col.rgb = scaleDownLight(col.rgb);
 
 	// Add windlight lights
-- 
GitLab