summaryrefslogtreecommitdiff
path: root/indra/newview/app_settings/shaders/class1/lighting/lightFuncV.glsl
blob: 4525bf80b289b4744ec709dd91e8b9871aa8d58d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/** 
 * @file lightFuncV.glsl
 *
 * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
 * $License$
 */


float calcDirectionalLight(vec3 n, vec3 l)
{
	float a = max(dot(n,l),0.0);
	return a;
}

float calcPointLight(vec3 v, vec3 n, vec4 lp, 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 *= calcDirectionalLight(n, lv);

	return da;	
}


float calcPointLight2(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float is_omnidirectional)
{
	//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 *= max(dot(-ln, lv),is_omnidirectional) * calcDirectionalLight(n, lv);

	return da;	
}