aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl
diff options
context:
space:
mode:
authorRobin Cornelius2010-10-10 21:53:54 +0100
committerRobin Cornelius2010-10-10 21:53:54 +0100
commitc0034c520c6e61b64822e276316651ec6912bd98 (patch)
tree910442027b6a2c1406d80ca93949755b54badf5c /linden/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl
parentUse all those cores for compile (diff)
parentThickbrick Sleaford, Soft Linden: STORM-164 make gcc-4.4 happy about llvosky.h (diff)
downloadmeta-impy-c0034c520c6e61b64822e276316651ec6912bd98.zip
meta-impy-c0034c520c6e61b64822e276316651ec6912bd98.tar.gz
meta-impy-c0034c520c6e61b64822e276316651ec6912bd98.tar.bz2
meta-impy-c0034c520c6e61b64822e276316651ec6912bd98.tar.xz
Merge branch 'mccabe-plugins' into plugins_merge
Conflicts: linden/doc/contributions.txt linden/indra/cmake/GStreamer.cmake linden/indra/cmake/LLMedia.cmake linden/indra/cmake/OPENAL.cmake linden/indra/llmedia/CMakeLists.txt linden/indra/llprimitive/material_codes.h linden/indra/newview/chatbar_as_cmdline.cpp linden/indra/newview/llappviewer.cpp linden/indra/newview/llfloatertos.cpp linden/indra/newview/llstartup.cpp linden/indra/newview/llviewerwindow.cpp linden/indra/newview/llvoavatar.cpp linden/indra/newview/pipeline.cpp linden/indra/newview/pipeline.h linden/indra/newview/viewer_manifest.py linden/install.xml
Diffstat (limited to 'linden/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl')
-rw-r--r--linden/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl188
1 files changed, 188 insertions, 0 deletions
diff --git a/linden/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl b/linden/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl
new file mode 100644
index 0000000..6519594
--- /dev/null
+++ b/linden/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl
@@ -0,0 +1,188 @@
1/**
2 * @file multiSpotLightF.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_ambient_lod;
30uniform float proj_ambiance;
31uniform float near_clip;
32uniform float far_clip;
33
34uniform vec3 proj_origin; //origin of projection to be used for angular attenuation
35uniform float sun_wash;
36uniform int proj_shadow_idx;
37uniform float shadow_fade;
38
39varying vec4 vary_light;
40
41varying vec4 vary_fragcoord;
42uniform vec2 screen_res;
43
44uniform mat4 inv_proj;
45
46vec4 getPosition(vec2 pos_screen)
47{
48 float depth = texture2DRect(depthMap, pos_screen.xy).a;
49 vec2 sc = pos_screen.xy*2.0;
50 sc /= screen_res;
51 sc -= vec2(1.0,1.0);
52 vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0);
53 vec4 pos = inv_proj * ndc;
54 pos /= pos.w;
55 pos.w = 1.0;
56 return pos;
57}
58
59void main()
60{
61 vec4 frag = vary_fragcoord;
62 frag.xyz /= frag.w;
63 frag.xyz = frag.xyz*0.5+0.5;
64 frag.xy *= screen_res;
65
66 vec3 pos = getPosition(frag.xy).xyz;
67 vec3 lv = vary_light.xyz-pos.xyz;
68 float dist2 = dot(lv,lv);
69 dist2 /= vary_light.w;
70 if (dist2 > 1.0)
71 {
72 discard;
73 }
74
75 float shadow = 1.0;
76
77 if (proj_shadow_idx >= 0)
78 {
79 vec4 shd = texture2DRect(lightMap, frag.xy);
80 float sh[2];
81 sh[0] = shd.b;
82 sh[1] = shd.a;
83 shadow = min(sh[proj_shadow_idx]+shadow_fade, 1.0);
84 }
85
86 vec3 norm = texture2DRect(normalMap, frag.xy).xyz*2.0-1.0;
87
88 norm = normalize(norm);
89 float l_dist = -dot(lv, proj_n);
90
91 vec4 proj_tc = (proj_mat * vec4(pos.xyz, 1.0));
92 if (proj_tc.z < 0.0)
93 {
94 discard;
95 }
96
97 proj_tc.xyz /= proj_tc.w;
98
99 float fa = gl_Color.a+1.0;
100 float dist_atten = min(1.0-(dist2-1.0*(1.0-fa))/fa, 1.0);
101 if (dist_atten <= 0.0)
102 {
103 discard;
104 }
105
106 lv = proj_origin-pos.xyz;
107 lv = normalize(lv);
108 float da = dot(norm, lv);
109
110 vec3 col = vec3(0,0,0);
111
112 vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb;
113
114 float noise = texture2D(noiseMap, frag.xy/128.0).b;
115 if (proj_tc.z > 0.0 &&
116 proj_tc.x < 1.0 &&
117 proj_tc.y < 1.0 &&
118 proj_tc.x > 0.0 &&
119 proj_tc.y > 0.0)
120 {
121 float lit = 0.0;
122 float amb_da = proj_ambiance;
123
124 if (da > 0.0)
125 {
126 float diff = clamp((l_dist-proj_focus)/proj_range, 0.0, 1.0);
127 float lod = diff * proj_lod;
128
129 vec4 plcol = texture2DLod(projectionMap, proj_tc.xy, lod);
130
131 vec3 lcol = gl_Color.rgb * plcol.rgb * plcol.a;
132
133 lit = da * dist_atten * noise;
134
135 col = lcol*lit*diff_tex*shadow;
136 amb_da += (da*0.5)*(1.0-shadow)*proj_ambiance;
137 }
138
139 //float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0);
140 vec4 amb_plcol = texture2DLod(projectionMap, proj_tc.xy, proj_ambient_lod);
141
142 amb_da += (da*da*0.5+0.5)*proj_ambiance;
143
144 amb_da *= dist_atten * noise;
145
146 amb_da = min(amb_da, 1.0-lit);
147
148 col += amb_da*gl_Color.rgb*diff_tex.rgb*amb_plcol.rgb*amb_plcol.a;
149 }
150
151
152 vec4 spec = texture2DRect(specularRect, frag.xy);
153 if (spec.a > 0.0)
154 {
155 vec3 ref = reflect(normalize(pos), norm);
156
157 //project from point pos in direction ref to plane proj_p, proj_n
158 vec3 pdelta = proj_p-pos;
159 float ds = dot(ref, proj_n);
160
161 if (ds < 0.0)
162 {
163 vec3 pfinal = pos + ref * dot(pdelta, proj_n)/ds;
164
165 vec4 stc = (proj_mat * vec4(pfinal.xyz, 1.0));
166
167 if (stc.z > 0.0)
168 {
169 stc.xy /= stc.w;
170
171 if (stc.x < 1.0 &&
172 stc.y < 1.0 &&
173 stc.x > 0.0 &&
174 stc.y > 0.0)
175 {
176 vec4 scol = texture2DLod(projectionMap, stc.xy, proj_lod-spec.a*proj_lod);
177 col += dist_atten*scol.rgb*gl_Color.rgb*scol.a*spec.rgb*shadow;
178 }
179 }
180 }
181 }
182
183 //attenuate point light contribution by SSAO component
184 col *= texture2DRect(lightMap, frag.xy).g;
185
186 gl_FragColor.rgb = col;
187 gl_FragColor.a = 0.0;
188}