|
1 // We store vertex coordinates and the quad shape in a constant buffer, this is |
|
2 // easy to update and allows us to use a single call to set the x, y, w, h of |
|
3 // the quad. |
|
4 // The QuadDesc and TexCoords both work as follows: |
|
5 // The x component is the quad left point, the y component is the top point |
|
6 // the z component is the width, and the w component is the height. The quad |
|
7 // are specified in viewport coordinates, i.e. { -1.0f, 1.0f, 2.0f, -2.0f } |
|
8 // would cover the entire viewport (which runs from <-1.0f, 1.0f> left to right |
|
9 // and <-1.0f, 1.0f> -bottom- to top. The TexCoords desc is specified in texture |
|
10 // space <0, 1.0f> left to right and top to bottom. The input vertices of the |
|
11 // shader stage always form a rectangle from {0, 0} - {1, 1} |
|
12 cbuffer cb0 |
|
13 { |
|
14 float4 QuadDesc; |
|
15 float4 TexCoords; |
|
16 float4 MaskTexCoords; |
|
17 float4 TextColor; |
|
18 } |
|
19 |
|
20 cbuffer cb1 |
|
21 { |
|
22 float4 BlurOffsetsH[3]; |
|
23 float4 BlurOffsetsV[3]; |
|
24 float4 BlurWeights[3]; |
|
25 float4 ShadowColor; |
|
26 } |
|
27 |
|
28 cbuffer cb2 |
|
29 { |
|
30 float3x3 DeviceSpaceToUserSpace; |
|
31 float2 dimensions; |
|
32 // Precalculate as much as we can! |
|
33 float3 diff; |
|
34 float2 center1; |
|
35 float A; |
|
36 float radius1; |
|
37 float sq_radius1; |
|
38 } |
|
39 |
|
40 struct VS_OUTPUT |
|
41 { |
|
42 float4 Position : SV_Position; |
|
43 float2 TexCoord : TEXCOORD0; |
|
44 float2 MaskTexCoord : TEXCOORD1; |
|
45 }; |
|
46 |
|
47 struct VS_RADIAL_OUTPUT |
|
48 { |
|
49 float4 Position : SV_Position; |
|
50 float2 MaskTexCoord : TEXCOORD0; |
|
51 float2 PixelCoord : TEXCOORD1; |
|
52 }; |
|
53 |
|
54 struct PS_TEXT_OUTPUT |
|
55 { |
|
56 float4 color; |
|
57 float4 alpha; |
|
58 }; |
|
59 |
|
60 Texture2D tex; |
|
61 Texture2D bcktex; |
|
62 Texture2D mask; |
|
63 uint blendop; |
|
64 |
|
65 sampler sSampler = sampler_state { |
|
66 Filter = MIN_MAG_MIP_LINEAR; |
|
67 Texture = tex; |
|
68 AddressU = Clamp; |
|
69 AddressV = Clamp; |
|
70 }; |
|
71 |
|
72 sampler sBckSampler = sampler_state { |
|
73 Filter = MIN_MAG_MIP_LINEAR; |
|
74 Texture = bcktex; |
|
75 AddressU = Clamp; |
|
76 AddressV = Clamp; |
|
77 }; |
|
78 |
|
79 sampler sWrapSampler = sampler_state { |
|
80 Filter = MIN_MAG_MIP_LINEAR; |
|
81 Texture = tex; |
|
82 AddressU = Wrap; |
|
83 AddressV = Wrap; |
|
84 }; |
|
85 |
|
86 sampler sMirrorSampler = sampler_state { |
|
87 Filter = MIN_MAG_MIP_LINEAR; |
|
88 Texture = tex; |
|
89 AddressU = Mirror; |
|
90 AddressV = Mirror; |
|
91 }; |
|
92 |
|
93 sampler sMaskSampler = sampler_state { |
|
94 Filter = MIN_MAG_MIP_LINEAR; |
|
95 Texture = mask; |
|
96 AddressU = Clamp; |
|
97 AddressV = Clamp; |
|
98 }; |
|
99 |
|
100 sampler sShadowSampler = sampler_state { |
|
101 Filter = MIN_MAG_MIP_LINEAR; |
|
102 Texture = tex; |
|
103 AddressU = Border; |
|
104 AddressV = Border; |
|
105 BorderColor = float4(0, 0, 0, 0); |
|
106 }; |
|
107 |
|
108 RasterizerState TextureRast |
|
109 { |
|
110 ScissorEnable = True; |
|
111 CullMode = None; |
|
112 }; |
|
113 |
|
114 BlendState ShadowBlendH |
|
115 { |
|
116 BlendEnable[0] = False; |
|
117 RenderTargetWriteMask[0] = 0xF; |
|
118 }; |
|
119 |
|
120 BlendState ShadowBlendV |
|
121 { |
|
122 BlendEnable[0] = True; |
|
123 SrcBlend = One; |
|
124 DestBlend = Inv_Src_Alpha; |
|
125 BlendOp = Add; |
|
126 SrcBlendAlpha = One; |
|
127 DestBlendAlpha = Inv_Src_Alpha; |
|
128 BlendOpAlpha = Add; |
|
129 RenderTargetWriteMask[0] = 0xF; |
|
130 }; |
|
131 |
|
132 BlendState bTextBlend |
|
133 { |
|
134 AlphaToCoverageEnable = FALSE; |
|
135 BlendEnable[0] = TRUE; |
|
136 SrcBlend = Src1_Color; |
|
137 DestBlend = Inv_Src1_Color; |
|
138 BlendOp = Add; |
|
139 SrcBlendAlpha = Src1_Alpha; |
|
140 DestBlendAlpha = Inv_Src1_Alpha; |
|
141 BlendOpAlpha = Add; |
|
142 RenderTargetWriteMask[0] = 0x0F; // All |
|
143 }; |
|
144 |
|
145 VS_OUTPUT SampleTextureVS(float3 pos : POSITION) |
|
146 { |
|
147 VS_OUTPUT Output; |
|
148 Output.Position.w = 1.0f; |
|
149 Output.Position.x = pos.x * QuadDesc.z + QuadDesc.x; |
|
150 Output.Position.y = pos.y * QuadDesc.w + QuadDesc.y; |
|
151 Output.Position.z = 0; |
|
152 Output.TexCoord.x = pos.x * TexCoords.z + TexCoords.x; |
|
153 Output.TexCoord.y = pos.y * TexCoords.w + TexCoords.y; |
|
154 Output.MaskTexCoord.x = pos.x * MaskTexCoords.z + MaskTexCoords.x; |
|
155 Output.MaskTexCoord.y = pos.y * MaskTexCoords.w + MaskTexCoords.y; |
|
156 return Output; |
|
157 } |
|
158 |
|
159 VS_RADIAL_OUTPUT SampleRadialVS(float3 pos : POSITION) |
|
160 { |
|
161 VS_RADIAL_OUTPUT Output; |
|
162 Output.Position.w = 1.0f; |
|
163 Output.Position.x = pos.x * QuadDesc.z + QuadDesc.x; |
|
164 Output.Position.y = pos.y * QuadDesc.w + QuadDesc.y; |
|
165 Output.Position.z = 0; |
|
166 Output.MaskTexCoord.x = pos.x * MaskTexCoords.z + MaskTexCoords.x; |
|
167 Output.MaskTexCoord.y = pos.y * MaskTexCoords.w + MaskTexCoords.y; |
|
168 |
|
169 // For the radial gradient pixel shader we need to pass in the pixel's |
|
170 // coordinates in user space for the color to be correctly determined. |
|
171 |
|
172 Output.PixelCoord.x = ((Output.Position.x + 1.0f) / 2.0f) * dimensions.x; |
|
173 Output.PixelCoord.y = ((1.0f - Output.Position.y) / 2.0f) * dimensions.y; |
|
174 Output.PixelCoord.xy = mul(float3(Output.PixelCoord.x, Output.PixelCoord.y, 1.0f), DeviceSpaceToUserSpace).xy; |
|
175 return Output; |
|
176 } |
|
177 |
|
178 float Screen(float a, float b) |
|
179 { |
|
180 return 1 - ((1 - a)*(1 - b)); |
|
181 } |
|
182 |
|
183 static float RedLuminance = 0.3f; |
|
184 static float GreenLuminance = 0.59f; |
|
185 static float BlueLuminance = 0.11f; |
|
186 |
|
187 float Lum(float3 C) |
|
188 { |
|
189 return RedLuminance * C.r + GreenLuminance * C.g + BlueLuminance * C.b; |
|
190 } |
|
191 |
|
192 float3 ClipColor(float3 C) |
|
193 { |
|
194 float L = Lum(C); |
|
195 float n = min(min(C.r, C.g), C.b); |
|
196 float x = max(max(C.r, C.g), C.b); |
|
197 |
|
198 if(n < 0) |
|
199 C = L + (((C - L) * L) / (L - n)); |
|
200 |
|
201 if(x > 1) |
|
202 C = L + ((C - L) * (1 - L) / (x - L)); |
|
203 |
|
204 return C; |
|
205 } |
|
206 |
|
207 float3 SetLum(float3 C, float l) |
|
208 { |
|
209 float d = l - Lum(C); |
|
210 C = C + d; |
|
211 return ClipColor(C); |
|
212 } |
|
213 |
|
214 float Sat(float3 C) |
|
215 { |
|
216 return max(C.r, max(C.g, C.b)) - min(C.r, min(C.g, C.b)); |
|
217 } |
|
218 |
|
219 void SetSatComponents(inout float minComp, inout float midComp, inout float maxComp, in float satVal) |
|
220 { |
|
221 midComp -= minComp; |
|
222 maxComp -= minComp; |
|
223 minComp = 0.0; |
|
224 if (maxComp > 0.0) |
|
225 { |
|
226 midComp *= satVal/maxComp; |
|
227 maxComp = satVal; |
|
228 } |
|
229 } |
|
230 |
|
231 float3 SetSat(float3 color, in float satVal) |
|
232 { |
|
233 if (color.x <= color.y) { |
|
234 if (color.y <= color.z) { |
|
235 // x <= y <= z |
|
236 SetSatComponents(color.x, color.y, color.z, satVal); |
|
237 } |
|
238 else { |
|
239 if (color.x <= color.z) { |
|
240 // x <= z <= y |
|
241 SetSatComponents(color.x, color.z, color.y, satVal); |
|
242 } |
|
243 else { |
|
244 // z <= x <= y |
|
245 SetSatComponents(color.z, color.x, color.y, satVal); |
|
246 } |
|
247 } |
|
248 } |
|
249 else { |
|
250 if (color.x <= color.z) { |
|
251 // y <= x <= z |
|
252 SetSatComponents(color.y, color.x, color.z, satVal); |
|
253 } |
|
254 else { |
|
255 if (color.y <= color.z) { |
|
256 // y <= z <= x |
|
257 SetSatComponents(color.y, color.z, color.x, satVal); |
|
258 } |
|
259 else { |
|
260 // z <= y <= x |
|
261 SetSatComponents(color.z, color.y, color.x, satVal); |
|
262 } |
|
263 } |
|
264 } |
|
265 |
|
266 return color; |
|
267 } |
|
268 |
|
269 float4 SampleBlendTextureSeparablePS_1( VS_OUTPUT In) : SV_Target |
|
270 { |
|
271 float4 output = tex.Sample(sSampler, In.TexCoord); |
|
272 float4 background = bcktex.Sample(sBckSampler, In.TexCoord); |
|
273 if((output.a == 0) || (background.a == 0)) |
|
274 return output; |
|
275 |
|
276 output.rgb /= output.a; |
|
277 background.rgb /= background.a; |
|
278 |
|
279 float4 retval = output; |
|
280 |
|
281 if(blendop == 1) { // multiply |
|
282 retval.rgb = output.rgb * background.rgb; |
|
283 } else if(blendop == 2) { |
|
284 retval.rgb = output.rgb + background.rgb - output.rgb * background.rgb; |
|
285 } else if(blendop == 3) { |
|
286 if(background.r <= 0.5) |
|
287 retval.r = 2*background.r * output.r; |
|
288 else |
|
289 retval.r = Screen(output.r, 2 * background.r - 1); |
|
290 if(background.g <= 0.5) |
|
291 retval.g = 2 * background.g * output.g; |
|
292 else |
|
293 retval.g = Screen(output.g, 2 * background.g - 1); |
|
294 if(background.b <= 0.5) |
|
295 retval.b = 2 * background.b * output.b; |
|
296 else |
|
297 retval.b = Screen(output.b, 2 * background.b - 1); |
|
298 } else if(blendop == 4) { |
|
299 retval.rgb = min(output.rgb, background.rgb); |
|
300 } else if(blendop == 5) { |
|
301 retval.rgb = max(output.rgb, background.rgb); |
|
302 } else { |
|
303 if(background.r == 0) |
|
304 retval.r = 0; |
|
305 else |
|
306 if(output.r == 1) |
|
307 retval.r = 1; |
|
308 else |
|
309 retval.r = min(1, background.r / (1 - output.r)); |
|
310 if(background.g == 0) |
|
311 retval.g = 0; |
|
312 else |
|
313 if(output.g == 1) |
|
314 retval.g = 1; |
|
315 else |
|
316 retval.g = min(1, background.g / (1 - output.g)); |
|
317 if(background.b == 0) |
|
318 retval.b = 0; |
|
319 else |
|
320 if(output.b == 1) |
|
321 retval.b = 1; |
|
322 else |
|
323 retval.b = min(1, background.b / (1 - output.b)); |
|
324 } |
|
325 |
|
326 output.rgb = ((1 - background.a) * output.rgb + background.a * retval.rgb) * output.a; |
|
327 return output; |
|
328 } |
|
329 |
|
330 float4 SampleBlendTextureSeparablePS_2( VS_OUTPUT In) : SV_Target |
|
331 { |
|
332 float4 output = tex.Sample(sSampler, In.TexCoord); |
|
333 float4 background = bcktex.Sample(sBckSampler, In.TexCoord); |
|
334 if((output.a == 0) || (background.a == 0)) |
|
335 return output; |
|
336 |
|
337 output.rgb /= output.a; |
|
338 background.rgb /= background.a; |
|
339 |
|
340 float4 retval = output; |
|
341 |
|
342 if(blendop == 7) { |
|
343 if(background.r == 1) |
|
344 retval.r = 1; |
|
345 else |
|
346 if(output.r == 0) |
|
347 retval.r = 0; |
|
348 else |
|
349 retval.r = 1 - min(1, (1 - background.r) / output.r); |
|
350 if(background.g == 1) |
|
351 retval.g = 1; |
|
352 else |
|
353 if(output.g == 0) |
|
354 retval.g = 0; |
|
355 else |
|
356 retval.g = 1 - min(1, (1 - background.g) / output.g); |
|
357 if(background.b == 1) |
|
358 retval.b = 1; |
|
359 else |
|
360 if(output.b == 0) |
|
361 retval.b = 0; |
|
362 else |
|
363 retval.b = 1 - min(1, (1 - background.b) / output.b); |
|
364 } else if(blendop == 8) { |
|
365 if(output.r <= 0.5) |
|
366 retval.r = 2 * output.r * background.r; |
|
367 else |
|
368 retval.r = Screen(background.r, 2 * output.r -1); |
|
369 if(output.g <= 0.5) |
|
370 retval.g = 2 * output.g * background.g; |
|
371 else |
|
372 retval.g = Screen(background.g, 2 * output.g -1); |
|
373 if(output.b <= 0.5) |
|
374 retval.b = 2 * output.b * background.b; |
|
375 else |
|
376 retval.b = Screen(background.b, 2 * output.b -1); |
|
377 } else if(blendop == 9){ |
|
378 float D; |
|
379 if(background.r <= 0.25) |
|
380 D = ((16 * background.r - 12) * background.r + 4) * background.r; |
|
381 else |
|
382 D = sqrt(background.r); |
|
383 if(output.r <= 0.5) |
|
384 retval.r = background.r - (1 - 2 * output.r) * background.r * (1 - background.r); |
|
385 else |
|
386 retval.r = background.r + (2 * output.r - 1) * (D - background.r); |
|
387 |
|
388 if(background.g <= 0.25) |
|
389 D = ((16 * background.g - 12) * background.g + 4) * background.g; |
|
390 else |
|
391 D = sqrt(background.g); |
|
392 if(output.g <= 0.5) |
|
393 retval.g = background.g - (1 - 2 * output.g) * background.g * (1 - background.g); |
|
394 else |
|
395 retval.g = background.g + (2 * output.g - 1) * (D - background.g); |
|
396 |
|
397 if(background.b <= 0.25) |
|
398 D = ((16 * background.b - 12) * background.b + 4) * background.b; |
|
399 else |
|
400 D = sqrt(background.b); |
|
401 |
|
402 if(output.b <= 0.5) |
|
403 retval.b = background.b - (1 - 2 * output.b) * background.b * (1 - background.b); |
|
404 else |
|
405 retval.b = background.b + (2 * output.b - 1) * (D - background.b); |
|
406 } else if(blendop == 10) { |
|
407 retval.rgb = abs(output.rgb - background.rgb); |
|
408 } else { |
|
409 retval.rgb = output.rgb + background.rgb - 2 * output.rgb * background.rgb; |
|
410 } |
|
411 |
|
412 output.rgb = ((1 - background.a) * output.rgb + background.a * retval.rgb) * output.a; |
|
413 return output; |
|
414 } |
|
415 |
|
416 float4 SampleBlendTextureNonSeparablePS( VS_OUTPUT In) : SV_Target |
|
417 { |
|
418 float4 output = tex.Sample(sSampler, In.TexCoord); |
|
419 float4 background = bcktex.Sample(sBckSampler, In.TexCoord); |
|
420 if((output.a == 0) || (background.a == 0)) |
|
421 return output; |
|
422 |
|
423 output.rgb /= output.a; |
|
424 background.rgb /= background.a; |
|
425 |
|
426 float4 retval = output; |
|
427 |
|
428 if(blendop == 12) { |
|
429 retval.rgb = SetLum(SetSat(output.rgb, Sat(background.rgb)), Lum(background.rgb)); |
|
430 } else if(blendop == 13) { |
|
431 retval.rgb = SetLum(SetSat(background.rgb, Sat(output.rgb)), Lum(background.rgb)); |
|
432 } else if(blendop == 14) { |
|
433 retval.rgb = SetLum(output.rgb, Lum(background.rgb)); |
|
434 } else { |
|
435 retval.rgb = SetLum(background.rgb, Lum(output.rgb)); |
|
436 } |
|
437 |
|
438 output.rgb = ((1 - background.a) * output.rgb + background.a * retval.rgb) * output.a; |
|
439 return output; |
|
440 } |
|
441 |
|
442 |
|
443 float4 SampleTexturePS( VS_OUTPUT In) : SV_Target |
|
444 { |
|
445 return tex.Sample(sSampler, In.TexCoord); |
|
446 } |
|
447 |
|
448 float4 SampleMaskTexturePS( VS_OUTPUT In) : SV_Target |
|
449 { |
|
450 return tex.Sample(sSampler, In.TexCoord) * mask.Sample(sMaskSampler, In.MaskTexCoord).a; |
|
451 } |
|
452 |
|
453 float4 SampleRadialGradientPS(VS_RADIAL_OUTPUT In, uniform sampler aSampler) : SV_Target |
|
454 { |
|
455 // Radial gradient painting is defined as the set of circles whose centers |
|
456 // are described by C(t) = (C2 - C1) * t + C1; with radii |
|
457 // R(t) = (R2 - R1) * t + R1; for R(t) > 0. This shader solves the |
|
458 // quadratic equation that arises when calculating t for pixel (x, y). |
|
459 // |
|
460 // A more extensive derrivation can be found in the pixman radial gradient |
|
461 // code. |
|
462 |
|
463 float2 p = In.PixelCoord; |
|
464 float3 dp = float3(p - center1, radius1); |
|
465 |
|
466 // dpx * dcx + dpy * dcy + r * dr |
|
467 float B = dot(dp, diff); |
|
468 |
|
469 float C = pow(dp.x, 2) + pow(dp.y, 2) - sq_radius1; |
|
470 |
|
471 float det = pow(B, 2) - A * C; |
|
472 |
|
473 if (det < 0) { |
|
474 return float4(0, 0, 0, 0); |
|
475 } |
|
476 |
|
477 float sqrt_det = sqrt(abs(det)); |
|
478 |
|
479 float2 t = (B + float2(sqrt_det, -sqrt_det)) / A; |
|
480 |
|
481 float2 isValid = step(float2(-radius1, -radius1), t * diff.z); |
|
482 |
|
483 if (max(isValid.x, isValid.y) <= 0) { |
|
484 return float4(0, 0, 0, 0); |
|
485 } |
|
486 |
|
487 float upper_t = lerp(t.y, t.x, isValid.x); |
|
488 |
|
489 float4 output = tex.Sample(aSampler, float2(upper_t, 0.5)); |
|
490 // Premultiply |
|
491 output.rgb *= output.a; |
|
492 // Multiply the output color by the input mask for the operation. |
|
493 output *= mask.Sample(sMaskSampler, In.MaskTexCoord).a; |
|
494 return output; |
|
495 }; |
|
496 |
|
497 float4 SampleRadialGradientA0PS( VS_RADIAL_OUTPUT In, uniform sampler aSampler ) : SV_Target |
|
498 { |
|
499 // This simpler shader is used for the degenerate case where A is 0, |
|
500 // i.e. we're actually solving a linear equation. |
|
501 |
|
502 float2 p = In.PixelCoord; |
|
503 float3 dp = float3(p - center1, radius1); |
|
504 |
|
505 // dpx * dcx + dpy * dcy + r * dr |
|
506 float B = dot(dp, diff); |
|
507 |
|
508 float C = pow(dp.x, 2) + pow(dp.y, 2) - pow(radius1, 2); |
|
509 |
|
510 float t = 0.5 * C / B; |
|
511 |
|
512 if (-radius1 >= t * diff.z) { |
|
513 return float4(0, 0, 0, 0); |
|
514 } |
|
515 |
|
516 float4 output = tex.Sample(aSampler, float2(t, 0.5)); |
|
517 // Premultiply |
|
518 output.rgb *= output.a; |
|
519 // Multiply the output color by the input mask for the operation. |
|
520 output *= mask.Sample(sMaskSampler, In.MaskTexCoord).a; |
|
521 return output; |
|
522 }; |
|
523 |
|
524 float4 SampleShadowHPS( VS_OUTPUT In) : SV_Target |
|
525 { |
|
526 float outputStrength = 0; |
|
527 |
|
528 outputStrength += BlurWeights[0].x * tex.Sample(sShadowSampler, float2(In.TexCoord.x + BlurOffsetsH[0].x, In.TexCoord.y)).a; |
|
529 outputStrength += BlurWeights[0].y * tex.Sample(sShadowSampler, float2(In.TexCoord.x + BlurOffsetsH[0].y, In.TexCoord.y)).a; |
|
530 outputStrength += BlurWeights[0].z * tex.Sample(sShadowSampler, float2(In.TexCoord.x + BlurOffsetsH[0].z, In.TexCoord.y)).a; |
|
531 outputStrength += BlurWeights[0].w * tex.Sample(sShadowSampler, float2(In.TexCoord.x + BlurOffsetsH[0].w, In.TexCoord.y)).a; |
|
532 outputStrength += BlurWeights[1].x * tex.Sample(sShadowSampler, float2(In.TexCoord.x + BlurOffsetsH[1].x, In.TexCoord.y)).a; |
|
533 outputStrength += BlurWeights[1].y * tex.Sample(sShadowSampler, float2(In.TexCoord.x + BlurOffsetsH[1].y, In.TexCoord.y)).a; |
|
534 outputStrength += BlurWeights[1].z * tex.Sample(sShadowSampler, float2(In.TexCoord.x + BlurOffsetsH[1].z, In.TexCoord.y)).a; |
|
535 outputStrength += BlurWeights[1].w * tex.Sample(sShadowSampler, float2(In.TexCoord.x + BlurOffsetsH[1].w, In.TexCoord.y)).a; |
|
536 outputStrength += BlurWeights[2].x * tex.Sample(sShadowSampler, float2(In.TexCoord.x + BlurOffsetsH[2].x, In.TexCoord.y)).a; |
|
537 |
|
538 return ShadowColor * outputStrength; |
|
539 }; |
|
540 |
|
541 float4 SampleShadowVPS( VS_OUTPUT In) : SV_Target |
|
542 { |
|
543 float4 outputColor = float4(0, 0, 0, 0); |
|
544 |
|
545 outputColor += BlurWeights[0].x * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[0].x)); |
|
546 outputColor += BlurWeights[0].y * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[0].y)); |
|
547 outputColor += BlurWeights[0].z * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[0].z)); |
|
548 outputColor += BlurWeights[0].w * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[0].w)); |
|
549 outputColor += BlurWeights[1].x * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[1].x)); |
|
550 outputColor += BlurWeights[1].y * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[1].y)); |
|
551 outputColor += BlurWeights[1].z * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[1].z)); |
|
552 outputColor += BlurWeights[1].w * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[1].w)); |
|
553 outputColor += BlurWeights[2].x * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[2].x)); |
|
554 |
|
555 return outputColor; |
|
556 }; |
|
557 |
|
558 float4 SampleMaskShadowVPS( VS_OUTPUT In) : SV_Target |
|
559 { |
|
560 float4 outputColor = float4(0, 0, 0, 0); |
|
561 |
|
562 outputColor += BlurWeights[0].x * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[0].x)); |
|
563 outputColor += BlurWeights[0].y * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[0].y)); |
|
564 outputColor += BlurWeights[0].z * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[0].z)); |
|
565 outputColor += BlurWeights[0].w * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[0].w)); |
|
566 outputColor += BlurWeights[1].x * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[1].x)); |
|
567 outputColor += BlurWeights[1].y * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[1].y)); |
|
568 outputColor += BlurWeights[1].z * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[1].z)); |
|
569 outputColor += BlurWeights[1].w * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[1].w)); |
|
570 outputColor += BlurWeights[2].x * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[2].x)); |
|
571 |
|
572 return outputColor * mask.Sample(sMaskSampler, In.MaskTexCoord).a; |
|
573 }; |
|
574 |
|
575 PS_TEXT_OUTPUT SampleTextTexturePS( VS_OUTPUT In) : SV_Target |
|
576 { |
|
577 PS_TEXT_OUTPUT output; |
|
578 output.color = float4(TextColor.r, TextColor.g, TextColor.b, 1.0); |
|
579 output.alpha.rgba = tex.Sample(sSampler, In.TexCoord).bgrg * TextColor.a; |
|
580 return output; |
|
581 }; |
|
582 |
|
583 PS_TEXT_OUTPUT SampleTextTexturePSMasked( VS_OUTPUT In) : SV_Target |
|
584 { |
|
585 PS_TEXT_OUTPUT output; |
|
586 |
|
587 float maskValue = mask.Sample(sMaskSampler, In.MaskTexCoord).a; |
|
588 |
|
589 output.color = float4(TextColor.r, TextColor.g, TextColor.b, 1.0); |
|
590 output.alpha.rgba = tex.Sample(sSampler, In.TexCoord).bgrg * TextColor.a * maskValue; |
|
591 |
|
592 return output; |
|
593 }; |
|
594 |
|
595 technique10 SampleTexture |
|
596 { |
|
597 pass P0 |
|
598 { |
|
599 SetRasterizerState(TextureRast); |
|
600 SetVertexShader(CompileShader(vs_4_0_level_9_3, SampleTextureVS())); |
|
601 SetGeometryShader(NULL); |
|
602 SetPixelShader(CompileShader(ps_4_0_level_9_3, SampleTexturePS())); |
|
603 } |
|
604 } |
|
605 |
|
606 technique10 SampleTextureForSeparableBlending_1 |
|
607 { |
|
608 pass P0 |
|
609 { |
|
610 SetRasterizerState(TextureRast); |
|
611 SetVertexShader(CompileShader(vs_4_0_level_9_3, SampleTextureVS())); |
|
612 SetGeometryShader(NULL); |
|
613 SetPixelShader(CompileShader(ps_4_0_level_9_3, SampleBlendTextureSeparablePS_1())); |
|
614 } |
|
615 } |
|
616 |
|
617 technique10 SampleTextureForSeparableBlending_2 |
|
618 { |
|
619 pass P0 |
|
620 { |
|
621 SetRasterizerState(TextureRast); |
|
622 SetVertexShader(CompileShader(vs_4_0_level_9_3, SampleTextureVS())); |
|
623 SetGeometryShader(NULL); |
|
624 SetPixelShader(CompileShader(ps_4_0_level_9_3, SampleBlendTextureSeparablePS_2())); |
|
625 } |
|
626 } |
|
627 |
|
628 technique10 SampleTextureForNonSeparableBlending |
|
629 { |
|
630 pass P0 |
|
631 { |
|
632 SetRasterizerState(TextureRast); |
|
633 SetVertexShader(CompileShader(vs_4_0_level_9_3, SampleTextureVS())); |
|
634 SetGeometryShader(NULL); |
|
635 SetPixelShader(CompileShader(ps_4_0_level_9_3, SampleBlendTextureNonSeparablePS())); |
|
636 } |
|
637 } |
|
638 |
|
639 technique10 SampleRadialGradient |
|
640 { |
|
641 pass APos |
|
642 { |
|
643 SetRasterizerState(TextureRast); |
|
644 SetVertexShader(CompileShader(vs_4_0_level_9_3, SampleRadialVS())); |
|
645 SetGeometryShader(NULL); |
|
646 SetPixelShader(CompileShader(ps_4_0_level_9_3, SampleRadialGradientPS( sSampler ))); |
|
647 } |
|
648 pass A0 |
|
649 { |
|
650 SetRasterizerState(TextureRast); |
|
651 SetVertexShader(CompileShader(vs_4_0_level_9_3, SampleRadialVS())); |
|
652 SetGeometryShader(NULL); |
|
653 SetPixelShader(CompileShader(ps_4_0_level_9_3, SampleRadialGradientA0PS( sSampler ))); |
|
654 } |
|
655 pass APosWrap |
|
656 { |
|
657 SetRasterizerState(TextureRast); |
|
658 SetVertexShader(CompileShader(vs_4_0_level_9_3, SampleRadialVS())); |
|
659 SetGeometryShader(NULL); |
|
660 SetPixelShader(CompileShader(ps_4_0_level_9_3, SampleRadialGradientPS( sWrapSampler ))); |
|
661 } |
|
662 pass A0Wrap |
|
663 { |
|
664 SetRasterizerState(TextureRast); |
|
665 SetVertexShader(CompileShader(vs_4_0_level_9_3, SampleRadialVS())); |
|
666 SetGeometryShader(NULL); |
|
667 SetPixelShader(CompileShader(ps_4_0_level_9_3, SampleRadialGradientA0PS( sWrapSampler ))); |
|
668 } |
|
669 pass APosMirror |
|
670 { |
|
671 SetRasterizerState(TextureRast); |
|
672 SetVertexShader(CompileShader(vs_4_0_level_9_3, SampleRadialVS())); |
|
673 SetGeometryShader(NULL); |
|
674 SetPixelShader(CompileShader(ps_4_0_level_9_3, SampleRadialGradientPS( sMirrorSampler ))); |
|
675 } |
|
676 pass A0Mirror |
|
677 { |
|
678 SetRasterizerState(TextureRast); |
|
679 SetVertexShader(CompileShader(vs_4_0_level_9_3, SampleRadialVS())); |
|
680 SetGeometryShader(NULL); |
|
681 SetPixelShader(CompileShader(ps_4_0_level_9_3, SampleRadialGradientA0PS( sMirrorSampler ))); |
|
682 } |
|
683 } |
|
684 |
|
685 technique10 SampleMaskedTexture |
|
686 { |
|
687 pass P0 |
|
688 { |
|
689 SetRasterizerState(TextureRast); |
|
690 SetVertexShader(CompileShader(vs_4_0_level_9_3, SampleTextureVS())); |
|
691 SetGeometryShader(NULL); |
|
692 SetPixelShader(CompileShader(ps_4_0_level_9_3, SampleMaskTexturePS())); |
|
693 } |
|
694 } |
|
695 |
|
696 technique10 SampleTextureWithShadow |
|
697 { |
|
698 // Horizontal pass |
|
699 pass P0 |
|
700 { |
|
701 SetRasterizerState(TextureRast); |
|
702 SetBlendState(ShadowBlendH, float4(1.0f, 1.0f, 1.0f, 1.0f), 0xffffffff); |
|
703 SetVertexShader(CompileShader(vs_4_0_level_9_3, SampleTextureVS())); |
|
704 SetGeometryShader(NULL); |
|
705 SetPixelShader(CompileShader(ps_4_0_level_9_3, SampleShadowHPS())); |
|
706 } |
|
707 // Vertical pass |
|
708 pass P1 |
|
709 { |
|
710 SetRasterizerState(TextureRast); |
|
711 SetBlendState(ShadowBlendV, float4(1.0f, 1.0f, 1.0f, 1.0f), 0xffffffff); |
|
712 SetVertexShader(CompileShader(vs_4_0_level_9_3, SampleTextureVS())); |
|
713 SetGeometryShader(NULL); |
|
714 SetPixelShader(CompileShader(ps_4_0_level_9_3, SampleShadowVPS())); |
|
715 } |
|
716 // Vertical pass - used when using a mask |
|
717 pass P2 |
|
718 { |
|
719 SetRasterizerState(TextureRast); |
|
720 SetBlendState(ShadowBlendV, float4(1.0f, 1.0f, 1.0f, 1.0f), 0xffffffff); |
|
721 SetVertexShader(CompileShader(vs_4_0_level_9_3, SampleTextureVS())); |
|
722 SetGeometryShader(NULL); |
|
723 SetPixelShader(CompileShader(ps_4_0_level_9_3, SampleMaskShadowVPS())); |
|
724 } |
|
725 } |
|
726 |
|
727 technique10 SampleTextTexture |
|
728 { |
|
729 pass Unmasked |
|
730 { |
|
731 SetRasterizerState(TextureRast); |
|
732 SetBlendState(bTextBlend, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF ); |
|
733 SetVertexShader(CompileShader(vs_4_0_level_9_3, SampleTextureVS())); |
|
734 SetGeometryShader(NULL); |
|
735 SetPixelShader(CompileShader(ps_4_0_level_9_3, SampleTextTexturePS())); |
|
736 } |
|
737 pass Masked |
|
738 { |
|
739 SetRasterizerState(TextureRast); |
|
740 SetBlendState(bTextBlend, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF ); |
|
741 SetVertexShader(CompileShader(vs_4_0_level_9_3, SampleTextureVS())); |
|
742 SetGeometryShader(NULL); |
|
743 SetPixelShader(CompileShader(ps_4_0_level_9_3, SampleTextTexturePSMasked())); |
|
744 } |
|
745 } |
|
746 |