diff options
Diffstat (limited to 'linden/indra/newview/app_settings/shaders/class1/deferred/sunLightF.glsl')
-rw-r--r-- | linden/indra/newview/app_settings/shaders/class1/deferred/sunLightF.glsl | 111 |
1 files changed, 86 insertions, 25 deletions
diff --git a/linden/indra/newview/app_settings/shaders/class1/deferred/sunLightF.glsl b/linden/indra/newview/app_settings/shaders/class1/deferred/sunLightF.glsl index d43fe6c..22bdd2c 100644 --- a/linden/indra/newview/app_settings/shaders/class1/deferred/sunLightF.glsl +++ b/linden/indra/newview/app_settings/shaders/class1/deferred/sunLightF.glsl | |||
@@ -7,17 +7,21 @@ | |||
7 | 7 | ||
8 | #extension GL_ARB_texture_rectangle : enable | 8 | #extension GL_ARB_texture_rectangle : enable |
9 | 9 | ||
10 | uniform sampler2DRect positionMap; | ||
11 | uniform sampler2DRect normalMap; | ||
12 | uniform sampler2DRect depthMap; | 10 | uniform sampler2DRect depthMap; |
13 | uniform sampler2DShadow shadowMap0; | 11 | uniform sampler2DRect normalMap; |
14 | uniform sampler2DShadow shadowMap1; | 12 | uniform sampler2DRectShadow shadowMap0; |
15 | uniform sampler2DShadow shadowMap2; | 13 | uniform sampler2DRectShadow shadowMap1; |
16 | uniform sampler2DShadow shadowMap3; | 14 | uniform sampler2DRectShadow shadowMap2; |
15 | uniform sampler2DRectShadow shadowMap3; | ||
16 | uniform sampler2DRectShadow shadowMap4; | ||
17 | uniform sampler2DRectShadow shadowMap5; | ||
17 | uniform sampler2D noiseMap; | 18 | uniform sampler2D noiseMap; |
18 | 19 | ||
20 | uniform sampler2D lightFunc; | ||
21 | |||
22 | |||
19 | // Inputs | 23 | // Inputs |
20 | uniform mat4 shadow_matrix[4]; | 24 | uniform mat4 shadow_matrix[6]; |
21 | uniform vec4 shadow_clip; | 25 | uniform vec4 shadow_clip; |
22 | uniform float ssao_radius; | 26 | uniform float ssao_radius; |
23 | uniform float ssao_max_radius; | 27 | uniform float ssao_max_radius; |
@@ -27,6 +31,25 @@ uniform float ssao_factor_inv; | |||
27 | varying vec2 vary_fragcoord; | 31 | varying vec2 vary_fragcoord; |
28 | varying vec4 vary_light; | 32 | varying vec4 vary_light; |
29 | 33 | ||
34 | uniform mat4 inv_proj; | ||
35 | uniform vec2 screen_res; | ||
36 | |||
37 | uniform float shadow_bias; | ||
38 | uniform float shadow_offset; | ||
39 | |||
40 | vec4 getPosition(vec2 pos_screen) | ||
41 | { | ||
42 | float depth = texture2DRect(depthMap, pos_screen.xy).a; | ||
43 | vec2 sc = pos_screen.xy*2.0; | ||
44 | sc /= screen_res; | ||
45 | sc -= vec2(1.0,1.0); | ||
46 | vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); | ||
47 | vec4 pos = inv_proj * ndc; | ||
48 | pos /= pos.w; | ||
49 | pos.w = 1.0; | ||
50 | return pos; | ||
51 | } | ||
52 | |||
30 | //calculate decreases in ambient lighting when crowded out (SSAO) | 53 | //calculate decreases in ambient lighting when crowded out (SSAO) |
31 | float calcAmbientOcclusion(vec4 pos, vec3 norm) | 54 | float calcAmbientOcclusion(vec4 pos, vec3 norm) |
32 | { | 55 | { |
@@ -54,7 +77,7 @@ float calcAmbientOcclusion(vec4 pos, vec3 norm) | |||
54 | for (int i = 0; i < 8; i++) | 77 | for (int i = 0; i < 8; i++) |
55 | { | 78 | { |
56 | vec2 samppos_screen = pos_screen + scale * reflect(kern[i], noise_reflect); | 79 | vec2 samppos_screen = pos_screen + scale * reflect(kern[i], noise_reflect); |
57 | vec3 samppos_world = texture2DRect(positionMap, samppos_screen).xyz; | 80 | vec3 samppos_world = getPosition(samppos_screen).xyz; |
58 | 81 | ||
59 | vec3 diff = pos_world - samppos_world; | 82 | vec3 diff = pos_world - samppos_world; |
60 | float dist2 = dot(diff, diff); | 83 | float dist2 = dot(diff, diff); |
@@ -74,14 +97,18 @@ float calcAmbientOcclusion(vec4 pos, vec3 norm) | |||
74 | 97 | ||
75 | angle_hidden = min(ssao_factor*angle_hidden/float(points), 1.0); | 98 | angle_hidden = min(ssao_factor*angle_hidden/float(points), 1.0); |
76 | 99 | ||
77 | return 1.0 - (float(points != 0) * angle_hidden); | 100 | return (1.0 - (float(points != 0) * angle_hidden)); |
78 | } | 101 | } |
79 | 102 | ||
80 | void main() | 103 | void main() |
81 | { | 104 | { |
82 | vec2 pos_screen = vary_fragcoord.xy; | 105 | vec2 pos_screen = vary_fragcoord.xy; |
83 | vec4 pos = vec4(texture2DRect(positionMap, pos_screen).xyz, 1.0); | 106 | |
84 | vec3 norm = texture2DRect(normalMap, pos_screen).xyz; | 107 | //try doing an unproject here |
108 | |||
109 | vec4 pos = getPosition(pos_screen); | ||
110 | |||
111 | vec3 norm = texture2DRect(normalMap, pos_screen).xyz*2.0-1.0; | ||
85 | 112 | ||
86 | /*if (pos.z == 0.0) // do nothing for sky *FIX: REMOVE THIS IF/WHEN THE POSITION MAP IS BEING USED AS A STENCIL | 113 | /*if (pos.z == 0.0) // do nothing for sky *FIX: REMOVE THIS IF/WHEN THE POSITION MAP IS BEING USED AS A STENCIL |
87 | { | 114 | { |
@@ -90,35 +117,45 @@ void main() | |||
90 | }*/ | 117 | }*/ |
91 | 118 | ||
92 | float shadow = 1.0; | 119 | float shadow = 1.0; |
93 | float dp_directional_light = max(0.0, dot(norm, vary_light.xyz)); | 120 | float dp_directional_light = max(0.0, dot(norm, vary_light.xyz)); |
94 | 121 | ||
122 | vec4 spos = vec4(pos.xyz + norm.xyz * (-pos.z/64.0*shadow_offset+shadow_bias), 1.0); | ||
123 | |||
124 | //vec3 debug = vec3(0,0,0); | ||
125 | |||
95 | if (dp_directional_light == 0.0) | 126 | if (dp_directional_light == 0.0) |
96 | { | 127 | { |
97 | // if we know this point is facing away from the sun then we know it's in shadow without having to do a squirrelly shadow-map lookup | 128 | // if we know this point is facing away from the sun then we know it's in shadow without having to do a squirrelly shadow-map lookup |
98 | shadow = 0.0; | 129 | shadow = 0.0; |
99 | } | 130 | } |
100 | else if (pos.z > -shadow_clip.w) | 131 | else if (spos.z > -shadow_clip.w) |
101 | { | 132 | { |
102 | if (pos.z < -shadow_clip.z) | 133 | vec4 lpos; |
134 | |||
135 | if (spos.z < -shadow_clip.z) | ||
103 | { | 136 | { |
104 | vec4 lpos = shadow_matrix[3]*pos; | 137 | lpos = shadow_matrix[3]*spos; |
105 | shadow = shadow2DProj(shadowMap3, lpos).x; | 138 | lpos.xy *= screen_res; |
139 | shadow = shadow2DRectProj(shadowMap3, lpos).x; | ||
106 | shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); | 140 | shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); |
107 | } | 141 | } |
108 | else if (pos.z < -shadow_clip.y) | 142 | else if (spos.z < -shadow_clip.y) |
109 | { | 143 | { |
110 | vec4 lpos = shadow_matrix[2]*pos; | 144 | lpos = shadow_matrix[2]*spos; |
111 | shadow = shadow2DProj(shadowMap2, lpos).x; | 145 | lpos.xy *= screen_res; |
146 | shadow = shadow2DRectProj(shadowMap2, lpos).x; | ||
112 | } | 147 | } |
113 | else if (pos.z < -shadow_clip.x) | 148 | else if (spos.z < -shadow_clip.x) |
114 | { | 149 | { |
115 | vec4 lpos = shadow_matrix[1]*pos; | 150 | lpos = shadow_matrix[1]*spos; |
116 | shadow = shadow2DProj(shadowMap1, lpos).x; | 151 | lpos.xy *= screen_res; |
152 | shadow = shadow2DRectProj(shadowMap1, lpos).x; | ||
117 | } | 153 | } |
118 | else | 154 | else |
119 | { | 155 | { |
120 | vec4 lpos = shadow_matrix[0]*pos; | 156 | lpos = shadow_matrix[0]*spos; |
121 | shadow = shadow2DProj(shadowMap0, lpos).x; | 157 | lpos.xy *= screen_res; |
158 | shadow = shadow2DRectProj(shadowMap0, lpos).x; | ||
122 | } | 159 | } |
123 | 160 | ||
124 | // take the most-shadowed value out of these two: | 161 | // take the most-shadowed value out of these two: |
@@ -126,6 +163,17 @@ void main() | |||
126 | // * an unblurred dot product between the sun and this norm | 163 | // * an unblurred dot product between the sun and this norm |
127 | // the goal is to err on the side of most-shadow to fill-in shadow holes and reduce artifacting | 164 | // the goal is to err on the side of most-shadow to fill-in shadow holes and reduce artifacting |
128 | shadow = min(shadow, dp_directional_light); | 165 | shadow = min(shadow, dp_directional_light); |
166 | |||
167 | /*debug.r = lpos.y / (lpos.w*screen_res.y); | ||
168 | |||
169 | lpos.xy /= lpos.w*32.0; | ||
170 | if (fract(lpos.x) < 0.1 || fract(lpos.y) < 0.1) | ||
171 | { | ||
172 | debug.gb = vec2(0.5, 0.5); | ||
173 | } | ||
174 | |||
175 | debug += (1.0-shadow)*0.5;*/ | ||
176 | |||
129 | } | 177 | } |
130 | else | 178 | else |
131 | { | 179 | { |
@@ -135,5 +183,18 @@ void main() | |||
135 | 183 | ||
136 | gl_FragColor[0] = shadow; | 184 | gl_FragColor[0] = shadow; |
137 | gl_FragColor[1] = calcAmbientOcclusion(pos, norm); | 185 | gl_FragColor[1] = calcAmbientOcclusion(pos, norm); |
138 | //gl_FragColor[2] is unused as of August 2008, may be used for debugging | 186 | |
187 | //spotlight shadow 1 | ||
188 | vec4 lpos = shadow_matrix[4]*spos; | ||
189 | lpos.xy *= screen_res; | ||
190 | gl_FragColor[2] = shadow2DRectProj(shadowMap4, lpos).x; | ||
191 | |||
192 | //spotlight shadow 2 | ||
193 | lpos = shadow_matrix[5]*spos; | ||
194 | lpos.xy *= screen_res; | ||
195 | gl_FragColor[3] = shadow2DRectProj(shadowMap5, lpos).x; | ||
196 | |||
197 | //gl_FragColor.rgb = pos.xyz; | ||
198 | //gl_FragColor.b = shadow; | ||
199 | //gl_FragColor.rgb = debug; | ||
139 | } | 200 | } |