gfx/2d/ShadersD2D.fx

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

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

mercurial