aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/app_settings/shaders/class2/lighting/lightV.glsl
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/newview/app_settings/shaders/class2/lighting/lightV.glsl
parentREADME.txt (diff)
downloadmeta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/newview/app_settings/shaders/class2/lighting/lightV.glsl')
-rw-r--r--linden/indra/newview/app_settings/shaders/class2/lighting/lightV.glsl126
1 files changed, 126 insertions, 0 deletions
diff --git a/linden/indra/newview/app_settings/shaders/class2/lighting/lightV.glsl b/linden/indra/newview/app_settings/shaders/class2/lighting/lightV.glsl
new file mode 100644
index 0000000..b15960d
--- /dev/null
+++ b/linden/indra/newview/app_settings/shaders/class2/lighting/lightV.glsl
@@ -0,0 +1,126 @@
1// All lights, no specular highlights
2
3float calcDirectionalLight(vec3 n, vec3 l)
4{
5 float a = max(dot(n,l),0.0);
6 return a;
7}
8
9float calcPointLight(vec3 v, vec3 n, vec4 lp, float la)
10{
11 //get light vector
12 vec3 lv = lp.xyz-v;
13
14 //get distance
15 float d = length(lv);
16
17 //normalize light vector
18 lv *= 1.0/d;
19
20 //distance attenuation
21 float da = clamp(1.0/(la * d), 0.0, 1.0);
22
23 //angular attenuation
24 da *= calcDirectionalLight(n, lv);
25
26 return da;
27}
28
29float calcDirectionalSpecular(vec3 view, vec3 n, vec3 l)
30{
31 return pow(max(dot(reflect(view, n),l), 0.0),8.0);
32}
33
34float calcDirectionalLightSpecular(inout vec4 specular, vec3 view, vec3 n, vec3 l, vec3 lightCol, float da)
35{
36
37 specular.rgb += calcDirectionalSpecular(view,n,l)*lightCol*da;
38 return calcDirectionalLight(n,l);
39}
40
41vec3 calcPointLightSpecular(inout vec4 specular, vec3 view, vec3 v, vec3 n, vec3 l, float r, float pw, vec3 lightCol)
42{
43 //get light vector
44 vec3 lv = l-v;
45
46 //get distance
47 float d = length(lv);
48
49 //normalize light vector
50 lv *= 1.0/d;
51
52 //distance attenuation
53 float da = clamp(1.0/(r * d), 0.0, 1.0);
54
55 //angular attenuation
56
57 da *= calcDirectionalLightSpecular(specular, view, n, lv, lightCol, da);
58
59 return da*lightCol;
60}
61
62vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseLight)
63{
64 vec4 col;
65 col.a = color.a;
66
67 col.rgb = gl_LightModel.ambient.rgb + baseLight.rgb;
68
69 col.rgb += gl_LightSource[0].diffuse.rgb*calcDirectionalLight(norm, gl_LightSource[0].position.xyz);
70 col.rgb += gl_LightSource[1].diffuse.rgb*calcDirectionalLight(norm, gl_LightSource[1].position.xyz);
71 col.rgb += gl_LightSource[2].diffuse.rgb*calcPointLight(pos, norm, gl_LightSource[2].position, gl_LightSource[2].linearAttenuation);
72 col.rgb += gl_LightSource[3].diffuse.rgb*calcPointLight(pos, norm, gl_LightSource[3].position, gl_LightSource[3].linearAttenuation);
73 col.rgb += gl_LightSource[4].diffuse.rgb*calcPointLight(pos, norm, gl_LightSource[4].position, gl_LightSource[4].linearAttenuation);
74 col.rgb += gl_LightSource[5].diffuse.rgb*calcPointLight(pos, norm, gl_LightSource[5].position, gl_LightSource[5].linearAttenuation);
75 col.rgb += gl_LightSource[6].diffuse.rgb*calcPointLight(pos, norm, gl_LightSource[6].position, gl_LightSource[6].linearAttenuation);
76 col.rgb += gl_LightSource[7].diffuse.rgb*calcPointLight(pos, norm, gl_LightSource[7].position, gl_LightSource[7].linearAttenuation);
77
78 col.rgb = min(col.rgb*color.rgb, 1.0);
79
80 gl_FrontColor = vec4(col.rgb, col.a);
81 return col;
82}
83
84vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec3 baseLight)
85{
86 return calcLighting(pos, norm, color, vec4(baseLight, 1.0));
87}
88
89vec4 calcLighting(vec3 pos, vec3 norm, vec4 color)
90{
91 return calcLighting(pos, norm, color, vec3(0.0,0.0,0.0));
92}
93
94vec4 calcLightingSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor, vec4 baseCol)
95{
96 vec4 col;
97 col.a = color.a;
98
99 col.rgb = gl_LightModel.ambient.rgb;
100
101 vec3 view = normalize(pos);
102
103 vec4 specular = specularColor;
104 specularColor.rgb = vec3(0.0, 0.0, 0.0);
105
106 col.rgb += baseCol.a*gl_LightSource[0].diffuse.rgb*calcDirectionalLightSpecular(specularColor, view, norm, gl_LightSource[0].position.xyz,gl_LightSource[0].diffuse.rgb*baseCol.a, 1.0);
107 col.rgb += gl_LightSource[1].diffuse.rgb*calcDirectionalLightSpecular(specularColor, view, norm, gl_LightSource[1].position.xyz,gl_LightSource[1].diffuse.rgb, 1.0);
108 col.rgb += calcPointLightSpecular(specularColor, view, pos, norm, gl_LightSource[2].position.xyz, gl_LightSource[2].linearAttenuation, gl_LightSource[2].quadraticAttenuation,gl_LightSource[2].diffuse.rgb);
109 col.rgb += calcPointLightSpecular(specularColor, view, pos, norm, gl_LightSource[3].position.xyz, gl_LightSource[3].linearAttenuation, gl_LightSource[3].quadraticAttenuation,gl_LightSource[3].diffuse.rgb);
110 col.rgb += calcPointLightSpecular(specularColor, view, pos, norm, gl_LightSource[4].position.xyz, gl_LightSource[4].linearAttenuation, gl_LightSource[4].quadraticAttenuation,gl_LightSource[4].diffuse.rgb);
111 col.rgb += calcPointLightSpecular(specularColor, view, pos, norm, gl_LightSource[5].position.xyz, gl_LightSource[5].linearAttenuation, gl_LightSource[5].quadraticAttenuation,gl_LightSource[5].diffuse.rgb);
112 //col.rgb += calcPointLightSpecular(specularColor, view, pos, norm, gl_LightSource[6].position.xyz, gl_LightSource[6].linearAttenuation, gl_LightSource[6].quadraticAttenuation,gl_LightSource[6].diffuse.rgb);
113 //col.rgb += calcPointLightSpecular(specularColor, view, pos, norm, gl_LightSource[7].position.xyz, gl_LightSource[7].linearAttenuation, gl_LightSource[7].quadraticAttenuation,gl_LightSource[7].diffuse.rgb);
114 col.rgb += baseCol.rgb;
115
116 col.rgb = min(col.rgb*color.rgb, 1.0);
117 specularColor.rgb = min(specularColor.rgb*specular.rgb, 1.0);
118
119 gl_FrontColor = vec4(col.rgb+specularColor.rgb,col.a);
120 return col;
121}
122
123vec4 calcLightingSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor, vec3 baseCol)
124{
125 return calcLightingSpecular(pos, norm, color, specularColor, vec4(baseCol, 1.0));
126}