aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl')
-rw-r--r--linden/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl199
1 files changed, 199 insertions, 0 deletions
diff --git a/linden/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl b/linden/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl
new file mode 100644
index 0000000..d653408
--- /dev/null
+++ b/linden/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl
@@ -0,0 +1,199 @@
1/**
2 * @file spotLightF.glsl
3 *
4 * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
5 * $License$
6 */
7
8#version 120
9
10#extension GL_ARB_texture_rectangle : enable
11
12uniform sampler2DRect diffuseRect;
13uniform sampler2DRect specularRect;
14uniform sampler2DRect depthMap;
15uniform sampler2DRect normalMap;
16uniform samplerCube environmentMap;
17uniform sampler2DRect lightMap;
18uniform sampler2D noiseMap;
19uniform sampler2D lightFunc;
20uniform sampler2D projectionMap;
21
22uniform mat4 proj_mat; //screen space to light space
23uniform float proj_near; //near clip for projection
24uniform vec3 proj_p; //plane projection is emitting from (in screen space)
25uniform vec3 proj_n;
26uniform float proj_focus; //distance from plane to begin blurring
27uniform float proj_lod; //(number of mips in proj map)
28uniform float proj_range; //range between near clip and far clip plane of projection
29uniform float proj_ambiance;
30uniform float near_clip;
31uniform float far_clip;
32
33uniform vec3 proj_origin; //origin of projection to be used for angular attenuation
34uniform float sun_wash;
35uniform int proj_shadow_idx;
36uniform float shadow_fade;
37
38varying vec4 vary_light;
39
40varying vec4 vary_fragcoord;
41uniform vec2 screen_res;
42
43uniform mat4 inv_proj;
44
45vec4 getPosition(vec2 pos_screen)
46{
47 float depth = texture2DRect(depthMap, pos_screen.xy).a;
48 vec2 sc = pos_screen.xy*2.0;
49 sc /= screen_res;
50 sc -= vec2(1.0,1.0);
51 vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0);
52 vec4 pos = inv_proj * ndc;
53 pos /= pos.w;
54 pos.w = 1.0;
55 return pos;
56}
57
58void main()
59{
60 vec4 frag = vary_fragcoord;
61 frag.xyz /= frag.w;
62 frag.xyz = frag.xyz*0.5+0.5;
63 frag.xy *= screen_res;
64
65 float shadow = 1.0;
66
67 if (proj_shadow_idx >= 0)
68 {
69 vec4 shd = texture2DRect(lightMap, frag.xy);
70 float sh[2];
71 sh[0] = shd.b;
72 sh[1] = shd.a;
73 shadow = min(sh[proj_shadow_idx]+shadow_fade, 1.0);
74 }
75
76 vec3 pos = getPosition(frag.xy).xyz;
77 vec3 lv = vary_light.xyz-pos.xyz;
78 float dist2 = dot(lv,lv);
79 dist2 /= vary_light.w;
80 if (dist2 > 1.0)
81 {
82 discard;
83 }
84
85 vec3 norm = texture2DRect(normalMap, frag.xy).xyz*2.0-1.0;
86
87 norm = normalize(norm);
88 float l_dist = -dot(lv, proj_n);
89
90 vec4 proj_tc = (proj_mat * vec4(pos.xyz, 1.0));
91 if (proj_tc.z < 0.0)
92 {
93 discard;
94 }
95
96 proj_tc.xyz /= proj_tc.w;
97
98 float fa = gl_Color.a+1.0;
99 float dist_atten = clamp(1.0-(dist2-1.0*(1.0-fa))/fa, 0.0, 1.0);
100
101 lv = proj_origin-pos.xyz;
102 lv = normalize(lv);
103 float da = dot(norm, lv);
104
105 vec3 col = vec3(0,0,0);
106
107 vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb;
108
109 float noise = texture2D(noiseMap, frag.xy/128.0).b;
110 if (proj_tc.z > 0.0 &&
111 proj_tc.x < 1.0 &&
112 proj_tc.y < 1.0 &&
113 proj_tc.x > 0.0 &&
114 proj_tc.y > 0.0)
115 {
116 float lit = 0.0;
117 if (da > 0.0)
118 {
119 float diff = clamp((l_dist-proj_focus)/proj_range, 0.0, 1.0);
120 float lod = diff * proj_lod;
121
122 vec4 plcol = texture2DLod(projectionMap, proj_tc.xy, lod);
123
124 vec3 lcol = gl_Color.rgb * plcol.rgb * plcol.a;
125
126 lit = da * dist_atten * noise;
127
128 col = lcol*lit*diff_tex*shadow;
129 }
130
131 float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0);
132 float lod = diff * proj_lod;
133 vec4 amb_plcol = texture2DLod(projectionMap, proj_tc.xy, lod);
134 //float amb_da = mix(proj_ambiance, proj_ambiance*max(-da, 0.0), max(da, 0.0));
135 float amb_da = proj_ambiance;
136 if (da > 0.0)
137 {
138 amb_da += (da*0.5)*(1.0-shadow)*proj_ambiance;
139 }
140
141 amb_da += (da*da*0.5+0.5)*proj_ambiance;
142
143 amb_da *= dist_atten * noise;
144
145 amb_da = min(amb_da, 1.0-lit);
146
147 col += amb_da*gl_Color.rgb*diff_tex.rgb*amb_plcol.rgb*amb_plcol.a;
148 }
149
150
151 vec4 spec = texture2DRect(specularRect, frag.xy);
152 if (spec.a > 0.0)
153 {
154 vec3 ref = reflect(normalize(pos), norm);
155
156 //project from point pos in direction ref to plane proj_p, proj_n
157 vec3 pdelta = proj_p-pos;
158 float ds = dot(ref, proj_n);
159
160 if (ds < 0.0)
161 {
162 vec3 pfinal = pos + ref * dot(pdelta, proj_n)/ds;
163
164 vec3 stc = (proj_mat * vec4(pfinal.xyz, 1.0)).xyz;
165
166 if (stc.z > 0.0)
167 {
168 stc.xy /= stc.z+proj_near;
169
170 if (stc.x < 1.0 &&
171 stc.y < 1.0 &&
172 stc.x > 0.0 &&
173 stc.y > 0.0)
174 {
175 vec4 scol = texture2DLod(projectionMap, stc.xy, proj_lod-spec.a*proj_lod);
176 col += dist_atten*scol.rgb*gl_Color.rgb*scol.a*spec.rgb*shadow;
177 }
178 }
179 }
180 }
181
182 /*if (spec.a > 0.0)
183 {
184 //vec3 ref = reflect(normalize(pos), norm);
185 float sa = dot(normalize(lv-normalize(pos)),norm);;
186 //sa = max(sa, 0.0);
187 //sa = pow(sa, 128.0 * spec.a*spec.a/dist_atten)*min(dist_atten*4.0, 1.0);
188 sa = texture2D(lightFunc, vec2(sa, spec.a)).a * min(dist_atten*4.0, 1.0);
189 sa *= noise;
190 col += da*sa*lcol*spec.rgb;
191 }*/
192
193 //attenuate point light contribution by SSAO component
194 col *= texture2DRect(lightMap, frag.xy).g;
195
196
197 gl_FragColor.rgb = col;
198 gl_FragColor.a = 0.0;
199}