1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/2d/ShadersD2D.fx Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,746 @@ 1.4 +// We store vertex coordinates and the quad shape in a constant buffer, this is 1.5 +// easy to update and allows us to use a single call to set the x, y, w, h of 1.6 +// the quad. 1.7 +// The QuadDesc and TexCoords both work as follows: 1.8 +// The x component is the quad left point, the y component is the top point 1.9 +// the z component is the width, and the w component is the height. The quad 1.10 +// are specified in viewport coordinates, i.e. { -1.0f, 1.0f, 2.0f, -2.0f } 1.11 +// would cover the entire viewport (which runs from <-1.0f, 1.0f> left to right 1.12 +// and <-1.0f, 1.0f> -bottom- to top. The TexCoords desc is specified in texture 1.13 +// space <0, 1.0f> left to right and top to bottom. The input vertices of the 1.14 +// shader stage always form a rectangle from {0, 0} - {1, 1} 1.15 +cbuffer cb0 1.16 +{ 1.17 + float4 QuadDesc; 1.18 + float4 TexCoords; 1.19 + float4 MaskTexCoords; 1.20 + float4 TextColor; 1.21 +} 1.22 + 1.23 +cbuffer cb1 1.24 +{ 1.25 + float4 BlurOffsetsH[3]; 1.26 + float4 BlurOffsetsV[3]; 1.27 + float4 BlurWeights[3]; 1.28 + float4 ShadowColor; 1.29 +} 1.30 + 1.31 +cbuffer cb2 1.32 +{ 1.33 + float3x3 DeviceSpaceToUserSpace; 1.34 + float2 dimensions; 1.35 + // Precalculate as much as we can! 1.36 + float3 diff; 1.37 + float2 center1; 1.38 + float A; 1.39 + float radius1; 1.40 + float sq_radius1; 1.41 +} 1.42 + 1.43 +struct VS_OUTPUT 1.44 +{ 1.45 + float4 Position : SV_Position; 1.46 + float2 TexCoord : TEXCOORD0; 1.47 + float2 MaskTexCoord : TEXCOORD1; 1.48 +}; 1.49 + 1.50 +struct VS_RADIAL_OUTPUT 1.51 +{ 1.52 + float4 Position : SV_Position; 1.53 + float2 MaskTexCoord : TEXCOORD0; 1.54 + float2 PixelCoord : TEXCOORD1; 1.55 +}; 1.56 + 1.57 +struct PS_TEXT_OUTPUT 1.58 +{ 1.59 + float4 color; 1.60 + float4 alpha; 1.61 +}; 1.62 + 1.63 +Texture2D tex; 1.64 +Texture2D bcktex; 1.65 +Texture2D mask; 1.66 +uint blendop; 1.67 + 1.68 +sampler sSampler = sampler_state { 1.69 + Filter = MIN_MAG_MIP_LINEAR; 1.70 + Texture = tex; 1.71 + AddressU = Clamp; 1.72 + AddressV = Clamp; 1.73 +}; 1.74 + 1.75 +sampler sBckSampler = sampler_state { 1.76 + Filter = MIN_MAG_MIP_LINEAR; 1.77 + Texture = bcktex; 1.78 + AddressU = Clamp; 1.79 + AddressV = Clamp; 1.80 +}; 1.81 + 1.82 +sampler sWrapSampler = sampler_state { 1.83 + Filter = MIN_MAG_MIP_LINEAR; 1.84 + Texture = tex; 1.85 + AddressU = Wrap; 1.86 + AddressV = Wrap; 1.87 +}; 1.88 + 1.89 +sampler sMirrorSampler = sampler_state { 1.90 + Filter = MIN_MAG_MIP_LINEAR; 1.91 + Texture = tex; 1.92 + AddressU = Mirror; 1.93 + AddressV = Mirror; 1.94 +}; 1.95 + 1.96 +sampler sMaskSampler = sampler_state { 1.97 + Filter = MIN_MAG_MIP_LINEAR; 1.98 + Texture = mask; 1.99 + AddressU = Clamp; 1.100 + AddressV = Clamp; 1.101 +}; 1.102 + 1.103 +sampler sShadowSampler = sampler_state { 1.104 + Filter = MIN_MAG_MIP_LINEAR; 1.105 + Texture = tex; 1.106 + AddressU = Border; 1.107 + AddressV = Border; 1.108 + BorderColor = float4(0, 0, 0, 0); 1.109 +}; 1.110 + 1.111 +RasterizerState TextureRast 1.112 +{ 1.113 + ScissorEnable = True; 1.114 + CullMode = None; 1.115 +}; 1.116 + 1.117 +BlendState ShadowBlendH 1.118 +{ 1.119 + BlendEnable[0] = False; 1.120 + RenderTargetWriteMask[0] = 0xF; 1.121 +}; 1.122 + 1.123 +BlendState ShadowBlendV 1.124 +{ 1.125 + BlendEnable[0] = True; 1.126 + SrcBlend = One; 1.127 + DestBlend = Inv_Src_Alpha; 1.128 + BlendOp = Add; 1.129 + SrcBlendAlpha = One; 1.130 + DestBlendAlpha = Inv_Src_Alpha; 1.131 + BlendOpAlpha = Add; 1.132 + RenderTargetWriteMask[0] = 0xF; 1.133 +}; 1.134 + 1.135 +BlendState bTextBlend 1.136 +{ 1.137 + AlphaToCoverageEnable = FALSE; 1.138 + BlendEnable[0] = TRUE; 1.139 + SrcBlend = Src1_Color; 1.140 + DestBlend = Inv_Src1_Color; 1.141 + BlendOp = Add; 1.142 + SrcBlendAlpha = Src1_Alpha; 1.143 + DestBlendAlpha = Inv_Src1_Alpha; 1.144 + BlendOpAlpha = Add; 1.145 + RenderTargetWriteMask[0] = 0x0F; // All 1.146 +}; 1.147 + 1.148 +VS_OUTPUT SampleTextureVS(float3 pos : POSITION) 1.149 +{ 1.150 + VS_OUTPUT Output; 1.151 + Output.Position.w = 1.0f; 1.152 + Output.Position.x = pos.x * QuadDesc.z + QuadDesc.x; 1.153 + Output.Position.y = pos.y * QuadDesc.w + QuadDesc.y; 1.154 + Output.Position.z = 0; 1.155 + Output.TexCoord.x = pos.x * TexCoords.z + TexCoords.x; 1.156 + Output.TexCoord.y = pos.y * TexCoords.w + TexCoords.y; 1.157 + Output.MaskTexCoord.x = pos.x * MaskTexCoords.z + MaskTexCoords.x; 1.158 + Output.MaskTexCoord.y = pos.y * MaskTexCoords.w + MaskTexCoords.y; 1.159 + return Output; 1.160 +} 1.161 + 1.162 +VS_RADIAL_OUTPUT SampleRadialVS(float3 pos : POSITION) 1.163 +{ 1.164 + VS_RADIAL_OUTPUT Output; 1.165 + Output.Position.w = 1.0f; 1.166 + Output.Position.x = pos.x * QuadDesc.z + QuadDesc.x; 1.167 + Output.Position.y = pos.y * QuadDesc.w + QuadDesc.y; 1.168 + Output.Position.z = 0; 1.169 + Output.MaskTexCoord.x = pos.x * MaskTexCoords.z + MaskTexCoords.x; 1.170 + Output.MaskTexCoord.y = pos.y * MaskTexCoords.w + MaskTexCoords.y; 1.171 + 1.172 + // For the radial gradient pixel shader we need to pass in the pixel's 1.173 + // coordinates in user space for the color to be correctly determined. 1.174 + 1.175 + Output.PixelCoord.x = ((Output.Position.x + 1.0f) / 2.0f) * dimensions.x; 1.176 + Output.PixelCoord.y = ((1.0f - Output.Position.y) / 2.0f) * dimensions.y; 1.177 + Output.PixelCoord.xy = mul(float3(Output.PixelCoord.x, Output.PixelCoord.y, 1.0f), DeviceSpaceToUserSpace).xy; 1.178 + return Output; 1.179 +} 1.180 + 1.181 +float Screen(float a, float b) 1.182 +{ 1.183 + return 1 - ((1 - a)*(1 - b)); 1.184 +} 1.185 + 1.186 +static float RedLuminance = 0.3f; 1.187 +static float GreenLuminance = 0.59f; 1.188 +static float BlueLuminance = 0.11f; 1.189 + 1.190 +float Lum(float3 C) 1.191 +{ 1.192 + return RedLuminance * C.r + GreenLuminance * C.g + BlueLuminance * C.b; 1.193 +} 1.194 + 1.195 +float3 ClipColor(float3 C) 1.196 +{ 1.197 + float L = Lum(C); 1.198 + float n = min(min(C.r, C.g), C.b); 1.199 + float x = max(max(C.r, C.g), C.b); 1.200 + 1.201 + if(n < 0) 1.202 + C = L + (((C - L) * L) / (L - n)); 1.203 + 1.204 + if(x > 1) 1.205 + C = L + ((C - L) * (1 - L) / (x - L)); 1.206 + 1.207 + return C; 1.208 +} 1.209 + 1.210 +float3 SetLum(float3 C, float l) 1.211 +{ 1.212 + float d = l - Lum(C); 1.213 + C = C + d; 1.214 + return ClipColor(C); 1.215 +} 1.216 + 1.217 +float Sat(float3 C) 1.218 +{ 1.219 + return max(C.r, max(C.g, C.b)) - min(C.r, min(C.g, C.b)); 1.220 +} 1.221 + 1.222 +void SetSatComponents(inout float minComp, inout float midComp, inout float maxComp, in float satVal) 1.223 +{ 1.224 + midComp -= minComp; 1.225 + maxComp -= minComp; 1.226 + minComp = 0.0; 1.227 + if (maxComp > 0.0) 1.228 + { 1.229 + midComp *= satVal/maxComp; 1.230 + maxComp = satVal; 1.231 + } 1.232 +} 1.233 + 1.234 +float3 SetSat(float3 color, in float satVal) 1.235 +{ 1.236 + if (color.x <= color.y) { 1.237 + if (color.y <= color.z) { 1.238 + // x <= y <= z 1.239 + SetSatComponents(color.x, color.y, color.z, satVal); 1.240 + } 1.241 + else { 1.242 + if (color.x <= color.z) { 1.243 + // x <= z <= y 1.244 + SetSatComponents(color.x, color.z, color.y, satVal); 1.245 + } 1.246 + else { 1.247 + // z <= x <= y 1.248 + SetSatComponents(color.z, color.x, color.y, satVal); 1.249 + } 1.250 + } 1.251 + } 1.252 + else { 1.253 + if (color.x <= color.z) { 1.254 + // y <= x <= z 1.255 + SetSatComponents(color.y, color.x, color.z, satVal); 1.256 + } 1.257 + else { 1.258 + if (color.y <= color.z) { 1.259 + // y <= z <= x 1.260 + SetSatComponents(color.y, color.z, color.x, satVal); 1.261 + } 1.262 + else { 1.263 + // z <= y <= x 1.264 + SetSatComponents(color.z, color.y, color.x, satVal); 1.265 + } 1.266 + } 1.267 + } 1.268 + 1.269 + return color; 1.270 +} 1.271 + 1.272 +float4 SampleBlendTextureSeparablePS_1( VS_OUTPUT In) : SV_Target 1.273 +{ 1.274 + float4 output = tex.Sample(sSampler, In.TexCoord); 1.275 + float4 background = bcktex.Sample(sBckSampler, In.TexCoord); 1.276 + if((output.a == 0) || (background.a == 0)) 1.277 + return output; 1.278 + 1.279 + output.rgb /= output.a; 1.280 + background.rgb /= background.a; 1.281 + 1.282 + float4 retval = output; 1.283 + 1.284 + if(blendop == 1) { // multiply 1.285 + retval.rgb = output.rgb * background.rgb; 1.286 + } else if(blendop == 2) { 1.287 + retval.rgb = output.rgb + background.rgb - output.rgb * background.rgb; 1.288 + } else if(blendop == 3) { 1.289 + if(background.r <= 0.5) 1.290 + retval.r = 2*background.r * output.r; 1.291 + else 1.292 + retval.r = Screen(output.r, 2 * background.r - 1); 1.293 + if(background.g <= 0.5) 1.294 + retval.g = 2 * background.g * output.g; 1.295 + else 1.296 + retval.g = Screen(output.g, 2 * background.g - 1); 1.297 + if(background.b <= 0.5) 1.298 + retval.b = 2 * background.b * output.b; 1.299 + else 1.300 + retval.b = Screen(output.b, 2 * background.b - 1); 1.301 + } else if(blendop == 4) { 1.302 + retval.rgb = min(output.rgb, background.rgb); 1.303 + } else if(blendop == 5) { 1.304 + retval.rgb = max(output.rgb, background.rgb); 1.305 + } else { 1.306 + if(background.r == 0) 1.307 + retval.r = 0; 1.308 + else 1.309 + if(output.r == 1) 1.310 + retval.r = 1; 1.311 + else 1.312 + retval.r = min(1, background.r / (1 - output.r)); 1.313 + if(background.g == 0) 1.314 + retval.g = 0; 1.315 + else 1.316 + if(output.g == 1) 1.317 + retval.g = 1; 1.318 + else 1.319 + retval.g = min(1, background.g / (1 - output.g)); 1.320 + if(background.b == 0) 1.321 + retval.b = 0; 1.322 + else 1.323 + if(output.b == 1) 1.324 + retval.b = 1; 1.325 + else 1.326 + retval.b = min(1, background.b / (1 - output.b)); 1.327 + } 1.328 + 1.329 + output.rgb = ((1 - background.a) * output.rgb + background.a * retval.rgb) * output.a; 1.330 + return output; 1.331 +} 1.332 + 1.333 +float4 SampleBlendTextureSeparablePS_2( VS_OUTPUT In) : SV_Target 1.334 +{ 1.335 + float4 output = tex.Sample(sSampler, In.TexCoord); 1.336 + float4 background = bcktex.Sample(sBckSampler, In.TexCoord); 1.337 + if((output.a == 0) || (background.a == 0)) 1.338 + return output; 1.339 + 1.340 + output.rgb /= output.a; 1.341 + background.rgb /= background.a; 1.342 + 1.343 + float4 retval = output; 1.344 + 1.345 + if(blendop == 7) { 1.346 + if(background.r == 1) 1.347 + retval.r = 1; 1.348 + else 1.349 + if(output.r == 0) 1.350 + retval.r = 0; 1.351 + else 1.352 + retval.r = 1 - min(1, (1 - background.r) / output.r); 1.353 + if(background.g == 1) 1.354 + retval.g = 1; 1.355 + else 1.356 + if(output.g == 0) 1.357 + retval.g = 0; 1.358 + else 1.359 + retval.g = 1 - min(1, (1 - background.g) / output.g); 1.360 + if(background.b == 1) 1.361 + retval.b = 1; 1.362 + else 1.363 + if(output.b == 0) 1.364 + retval.b = 0; 1.365 + else 1.366 + retval.b = 1 - min(1, (1 - background.b) / output.b); 1.367 + } else if(blendop == 8) { 1.368 + if(output.r <= 0.5) 1.369 + retval.r = 2 * output.r * background.r; 1.370 + else 1.371 + retval.r = Screen(background.r, 2 * output.r -1); 1.372 + if(output.g <= 0.5) 1.373 + retval.g = 2 * output.g * background.g; 1.374 + else 1.375 + retval.g = Screen(background.g, 2 * output.g -1); 1.376 + if(output.b <= 0.5) 1.377 + retval.b = 2 * output.b * background.b; 1.378 + else 1.379 + retval.b = Screen(background.b, 2 * output.b -1); 1.380 + } else if(blendop == 9){ 1.381 + float D; 1.382 + if(background.r <= 0.25) 1.383 + D = ((16 * background.r - 12) * background.r + 4) * background.r; 1.384 + else 1.385 + D = sqrt(background.r); 1.386 + if(output.r <= 0.5) 1.387 + retval.r = background.r - (1 - 2 * output.r) * background.r * (1 - background.r); 1.388 + else 1.389 + retval.r = background.r + (2 * output.r - 1) * (D - background.r); 1.390 + 1.391 + if(background.g <= 0.25) 1.392 + D = ((16 * background.g - 12) * background.g + 4) * background.g; 1.393 + else 1.394 + D = sqrt(background.g); 1.395 + if(output.g <= 0.5) 1.396 + retval.g = background.g - (1 - 2 * output.g) * background.g * (1 - background.g); 1.397 + else 1.398 + retval.g = background.g + (2 * output.g - 1) * (D - background.g); 1.399 + 1.400 + if(background.b <= 0.25) 1.401 + D = ((16 * background.b - 12) * background.b + 4) * background.b; 1.402 + else 1.403 + D = sqrt(background.b); 1.404 + 1.405 + if(output.b <= 0.5) 1.406 + retval.b = background.b - (1 - 2 * output.b) * background.b * (1 - background.b); 1.407 + else 1.408 + retval.b = background.b + (2 * output.b - 1) * (D - background.b); 1.409 + } else if(blendop == 10) { 1.410 + retval.rgb = abs(output.rgb - background.rgb); 1.411 + } else { 1.412 + retval.rgb = output.rgb + background.rgb - 2 * output.rgb * background.rgb; 1.413 + } 1.414 + 1.415 + output.rgb = ((1 - background.a) * output.rgb + background.a * retval.rgb) * output.a; 1.416 + return output; 1.417 +} 1.418 + 1.419 +float4 SampleBlendTextureNonSeparablePS( VS_OUTPUT In) : SV_Target 1.420 +{ 1.421 + float4 output = tex.Sample(sSampler, In.TexCoord); 1.422 + float4 background = bcktex.Sample(sBckSampler, In.TexCoord); 1.423 + if((output.a == 0) || (background.a == 0)) 1.424 + return output; 1.425 + 1.426 + output.rgb /= output.a; 1.427 + background.rgb /= background.a; 1.428 + 1.429 + float4 retval = output; 1.430 + 1.431 + if(blendop == 12) { 1.432 + retval.rgb = SetLum(SetSat(output.rgb, Sat(background.rgb)), Lum(background.rgb)); 1.433 + } else if(blendop == 13) { 1.434 + retval.rgb = SetLum(SetSat(background.rgb, Sat(output.rgb)), Lum(background.rgb)); 1.435 + } else if(blendop == 14) { 1.436 + retval.rgb = SetLum(output.rgb, Lum(background.rgb)); 1.437 + } else { 1.438 + retval.rgb = SetLum(background.rgb, Lum(output.rgb)); 1.439 + } 1.440 + 1.441 + output.rgb = ((1 - background.a) * output.rgb + background.a * retval.rgb) * output.a; 1.442 + return output; 1.443 +} 1.444 + 1.445 + 1.446 +float4 SampleTexturePS( VS_OUTPUT In) : SV_Target 1.447 +{ 1.448 + return tex.Sample(sSampler, In.TexCoord); 1.449 +} 1.450 + 1.451 +float4 SampleMaskTexturePS( VS_OUTPUT In) : SV_Target 1.452 +{ 1.453 + return tex.Sample(sSampler, In.TexCoord) * mask.Sample(sMaskSampler, In.MaskTexCoord).a; 1.454 +} 1.455 + 1.456 +float4 SampleRadialGradientPS(VS_RADIAL_OUTPUT In, uniform sampler aSampler) : SV_Target 1.457 +{ 1.458 + // Radial gradient painting is defined as the set of circles whose centers 1.459 + // are described by C(t) = (C2 - C1) * t + C1; with radii 1.460 + // R(t) = (R2 - R1) * t + R1; for R(t) > 0. This shader solves the 1.461 + // quadratic equation that arises when calculating t for pixel (x, y). 1.462 + // 1.463 + // A more extensive derrivation can be found in the pixman radial gradient 1.464 + // code. 1.465 + 1.466 + float2 p = In.PixelCoord; 1.467 + float3 dp = float3(p - center1, radius1); 1.468 + 1.469 + // dpx * dcx + dpy * dcy + r * dr 1.470 + float B = dot(dp, diff); 1.471 + 1.472 + float C = pow(dp.x, 2) + pow(dp.y, 2) - sq_radius1; 1.473 + 1.474 + float det = pow(B, 2) - A * C; 1.475 + 1.476 + if (det < 0) { 1.477 + return float4(0, 0, 0, 0); 1.478 + } 1.479 + 1.480 + float sqrt_det = sqrt(abs(det)); 1.481 + 1.482 + float2 t = (B + float2(sqrt_det, -sqrt_det)) / A; 1.483 + 1.484 + float2 isValid = step(float2(-radius1, -radius1), t * diff.z); 1.485 + 1.486 + if (max(isValid.x, isValid.y) <= 0) { 1.487 + return float4(0, 0, 0, 0); 1.488 + } 1.489 + 1.490 + float upper_t = lerp(t.y, t.x, isValid.x); 1.491 + 1.492 + float4 output = tex.Sample(aSampler, float2(upper_t, 0.5)); 1.493 + // Premultiply 1.494 + output.rgb *= output.a; 1.495 + // Multiply the output color by the input mask for the operation. 1.496 + output *= mask.Sample(sMaskSampler, In.MaskTexCoord).a; 1.497 + return output; 1.498 +}; 1.499 + 1.500 +float4 SampleRadialGradientA0PS( VS_RADIAL_OUTPUT In, uniform sampler aSampler ) : SV_Target 1.501 +{ 1.502 + // This simpler shader is used for the degenerate case where A is 0, 1.503 + // i.e. we're actually solving a linear equation. 1.504 + 1.505 + float2 p = In.PixelCoord; 1.506 + float3 dp = float3(p - center1, radius1); 1.507 + 1.508 + // dpx * dcx + dpy * dcy + r * dr 1.509 + float B = dot(dp, diff); 1.510 + 1.511 + float C = pow(dp.x, 2) + pow(dp.y, 2) - pow(radius1, 2); 1.512 + 1.513 + float t = 0.5 * C / B; 1.514 + 1.515 + if (-radius1 >= t * diff.z) { 1.516 + return float4(0, 0, 0, 0); 1.517 + } 1.518 + 1.519 + float4 output = tex.Sample(aSampler, float2(t, 0.5)); 1.520 + // Premultiply 1.521 + output.rgb *= output.a; 1.522 + // Multiply the output color by the input mask for the operation. 1.523 + output *= mask.Sample(sMaskSampler, In.MaskTexCoord).a; 1.524 + return output; 1.525 +}; 1.526 + 1.527 +float4 SampleShadowHPS( VS_OUTPUT In) : SV_Target 1.528 +{ 1.529 + float outputStrength = 0; 1.530 + 1.531 + outputStrength += BlurWeights[0].x * tex.Sample(sShadowSampler, float2(In.TexCoord.x + BlurOffsetsH[0].x, In.TexCoord.y)).a; 1.532 + outputStrength += BlurWeights[0].y * tex.Sample(sShadowSampler, float2(In.TexCoord.x + BlurOffsetsH[0].y, In.TexCoord.y)).a; 1.533 + outputStrength += BlurWeights[0].z * tex.Sample(sShadowSampler, float2(In.TexCoord.x + BlurOffsetsH[0].z, In.TexCoord.y)).a; 1.534 + outputStrength += BlurWeights[0].w * tex.Sample(sShadowSampler, float2(In.TexCoord.x + BlurOffsetsH[0].w, In.TexCoord.y)).a; 1.535 + outputStrength += BlurWeights[1].x * tex.Sample(sShadowSampler, float2(In.TexCoord.x + BlurOffsetsH[1].x, In.TexCoord.y)).a; 1.536 + outputStrength += BlurWeights[1].y * tex.Sample(sShadowSampler, float2(In.TexCoord.x + BlurOffsetsH[1].y, In.TexCoord.y)).a; 1.537 + outputStrength += BlurWeights[1].z * tex.Sample(sShadowSampler, float2(In.TexCoord.x + BlurOffsetsH[1].z, In.TexCoord.y)).a; 1.538 + outputStrength += BlurWeights[1].w * tex.Sample(sShadowSampler, float2(In.TexCoord.x + BlurOffsetsH[1].w, In.TexCoord.y)).a; 1.539 + outputStrength += BlurWeights[2].x * tex.Sample(sShadowSampler, float2(In.TexCoord.x + BlurOffsetsH[2].x, In.TexCoord.y)).a; 1.540 + 1.541 + return ShadowColor * outputStrength; 1.542 +}; 1.543 + 1.544 +float4 SampleShadowVPS( VS_OUTPUT In) : SV_Target 1.545 +{ 1.546 + float4 outputColor = float4(0, 0, 0, 0); 1.547 + 1.548 + outputColor += BlurWeights[0].x * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[0].x)); 1.549 + outputColor += BlurWeights[0].y * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[0].y)); 1.550 + outputColor += BlurWeights[0].z * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[0].z)); 1.551 + outputColor += BlurWeights[0].w * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[0].w)); 1.552 + outputColor += BlurWeights[1].x * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[1].x)); 1.553 + outputColor += BlurWeights[1].y * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[1].y)); 1.554 + outputColor += BlurWeights[1].z * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[1].z)); 1.555 + outputColor += BlurWeights[1].w * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[1].w)); 1.556 + outputColor += BlurWeights[2].x * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[2].x)); 1.557 + 1.558 + return outputColor; 1.559 +}; 1.560 + 1.561 +float4 SampleMaskShadowVPS( VS_OUTPUT In) : SV_Target 1.562 +{ 1.563 + float4 outputColor = float4(0, 0, 0, 0); 1.564 + 1.565 + outputColor += BlurWeights[0].x * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[0].x)); 1.566 + outputColor += BlurWeights[0].y * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[0].y)); 1.567 + outputColor += BlurWeights[0].z * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[0].z)); 1.568 + outputColor += BlurWeights[0].w * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[0].w)); 1.569 + outputColor += BlurWeights[1].x * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[1].x)); 1.570 + outputColor += BlurWeights[1].y * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[1].y)); 1.571 + outputColor += BlurWeights[1].z * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[1].z)); 1.572 + outputColor += BlurWeights[1].w * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[1].w)); 1.573 + outputColor += BlurWeights[2].x * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[2].x)); 1.574 + 1.575 + return outputColor * mask.Sample(sMaskSampler, In.MaskTexCoord).a; 1.576 +}; 1.577 + 1.578 +PS_TEXT_OUTPUT SampleTextTexturePS( VS_OUTPUT In) : SV_Target 1.579 +{ 1.580 + PS_TEXT_OUTPUT output; 1.581 + output.color = float4(TextColor.r, TextColor.g, TextColor.b, 1.0); 1.582 + output.alpha.rgba = tex.Sample(sSampler, In.TexCoord).bgrg * TextColor.a; 1.583 + return output; 1.584 +}; 1.585 + 1.586 +PS_TEXT_OUTPUT SampleTextTexturePSMasked( VS_OUTPUT In) : SV_Target 1.587 +{ 1.588 + PS_TEXT_OUTPUT output; 1.589 + 1.590 + float maskValue = mask.Sample(sMaskSampler, In.MaskTexCoord).a; 1.591 + 1.592 + output.color = float4(TextColor.r, TextColor.g, TextColor.b, 1.0); 1.593 + output.alpha.rgba = tex.Sample(sSampler, In.TexCoord).bgrg * TextColor.a * maskValue; 1.594 + 1.595 + return output; 1.596 +}; 1.597 + 1.598 +technique10 SampleTexture 1.599 +{ 1.600 + pass P0 1.601 + { 1.602 + SetRasterizerState(TextureRast); 1.603 + SetVertexShader(CompileShader(vs_4_0_level_9_3, SampleTextureVS())); 1.604 + SetGeometryShader(NULL); 1.605 + SetPixelShader(CompileShader(ps_4_0_level_9_3, SampleTexturePS())); 1.606 + } 1.607 +} 1.608 + 1.609 +technique10 SampleTextureForSeparableBlending_1 1.610 +{ 1.611 + pass P0 1.612 + { 1.613 + SetRasterizerState(TextureRast); 1.614 + SetVertexShader(CompileShader(vs_4_0_level_9_3, SampleTextureVS())); 1.615 + SetGeometryShader(NULL); 1.616 + SetPixelShader(CompileShader(ps_4_0_level_9_3, SampleBlendTextureSeparablePS_1())); 1.617 + } 1.618 +} 1.619 + 1.620 +technique10 SampleTextureForSeparableBlending_2 1.621 +{ 1.622 + pass P0 1.623 + { 1.624 + SetRasterizerState(TextureRast); 1.625 + SetVertexShader(CompileShader(vs_4_0_level_9_3, SampleTextureVS())); 1.626 + SetGeometryShader(NULL); 1.627 + SetPixelShader(CompileShader(ps_4_0_level_9_3, SampleBlendTextureSeparablePS_2())); 1.628 + } 1.629 +} 1.630 + 1.631 +technique10 SampleTextureForNonSeparableBlending 1.632 +{ 1.633 + pass P0 1.634 + { 1.635 + SetRasterizerState(TextureRast); 1.636 + SetVertexShader(CompileShader(vs_4_0_level_9_3, SampleTextureVS())); 1.637 + SetGeometryShader(NULL); 1.638 + SetPixelShader(CompileShader(ps_4_0_level_9_3, SampleBlendTextureNonSeparablePS())); 1.639 + } 1.640 +} 1.641 + 1.642 +technique10 SampleRadialGradient 1.643 +{ 1.644 + pass APos 1.645 + { 1.646 + SetRasterizerState(TextureRast); 1.647 + SetVertexShader(CompileShader(vs_4_0_level_9_3, SampleRadialVS())); 1.648 + SetGeometryShader(NULL); 1.649 + SetPixelShader(CompileShader(ps_4_0_level_9_3, SampleRadialGradientPS( sSampler ))); 1.650 + } 1.651 + pass A0 1.652 + { 1.653 + SetRasterizerState(TextureRast); 1.654 + SetVertexShader(CompileShader(vs_4_0_level_9_3, SampleRadialVS())); 1.655 + SetGeometryShader(NULL); 1.656 + SetPixelShader(CompileShader(ps_4_0_level_9_3, SampleRadialGradientA0PS( sSampler ))); 1.657 + } 1.658 + pass APosWrap 1.659 + { 1.660 + SetRasterizerState(TextureRast); 1.661 + SetVertexShader(CompileShader(vs_4_0_level_9_3, SampleRadialVS())); 1.662 + SetGeometryShader(NULL); 1.663 + SetPixelShader(CompileShader(ps_4_0_level_9_3, SampleRadialGradientPS( sWrapSampler ))); 1.664 + } 1.665 + pass A0Wrap 1.666 + { 1.667 + SetRasterizerState(TextureRast); 1.668 + SetVertexShader(CompileShader(vs_4_0_level_9_3, SampleRadialVS())); 1.669 + SetGeometryShader(NULL); 1.670 + SetPixelShader(CompileShader(ps_4_0_level_9_3, SampleRadialGradientA0PS( sWrapSampler ))); 1.671 + } 1.672 + pass APosMirror 1.673 + { 1.674 + SetRasterizerState(TextureRast); 1.675 + SetVertexShader(CompileShader(vs_4_0_level_9_3, SampleRadialVS())); 1.676 + SetGeometryShader(NULL); 1.677 + SetPixelShader(CompileShader(ps_4_0_level_9_3, SampleRadialGradientPS( sMirrorSampler ))); 1.678 + } 1.679 + pass A0Mirror 1.680 + { 1.681 + SetRasterizerState(TextureRast); 1.682 + SetVertexShader(CompileShader(vs_4_0_level_9_3, SampleRadialVS())); 1.683 + SetGeometryShader(NULL); 1.684 + SetPixelShader(CompileShader(ps_4_0_level_9_3, SampleRadialGradientA0PS( sMirrorSampler ))); 1.685 + } 1.686 +} 1.687 + 1.688 +technique10 SampleMaskedTexture 1.689 +{ 1.690 + pass P0 1.691 + { 1.692 + SetRasterizerState(TextureRast); 1.693 + SetVertexShader(CompileShader(vs_4_0_level_9_3, SampleTextureVS())); 1.694 + SetGeometryShader(NULL); 1.695 + SetPixelShader(CompileShader(ps_4_0_level_9_3, SampleMaskTexturePS())); 1.696 + } 1.697 +} 1.698 + 1.699 +technique10 SampleTextureWithShadow 1.700 +{ 1.701 + // Horizontal pass 1.702 + pass P0 1.703 + { 1.704 + SetRasterizerState(TextureRast); 1.705 + SetBlendState(ShadowBlendH, float4(1.0f, 1.0f, 1.0f, 1.0f), 0xffffffff); 1.706 + SetVertexShader(CompileShader(vs_4_0_level_9_3, SampleTextureVS())); 1.707 + SetGeometryShader(NULL); 1.708 + SetPixelShader(CompileShader(ps_4_0_level_9_3, SampleShadowHPS())); 1.709 + } 1.710 + // Vertical pass 1.711 + pass P1 1.712 + { 1.713 + SetRasterizerState(TextureRast); 1.714 + SetBlendState(ShadowBlendV, float4(1.0f, 1.0f, 1.0f, 1.0f), 0xffffffff); 1.715 + SetVertexShader(CompileShader(vs_4_0_level_9_3, SampleTextureVS())); 1.716 + SetGeometryShader(NULL); 1.717 + SetPixelShader(CompileShader(ps_4_0_level_9_3, SampleShadowVPS())); 1.718 + } 1.719 + // Vertical pass - used when using a mask 1.720 + pass P2 1.721 + { 1.722 + SetRasterizerState(TextureRast); 1.723 + SetBlendState(ShadowBlendV, float4(1.0f, 1.0f, 1.0f, 1.0f), 0xffffffff); 1.724 + SetVertexShader(CompileShader(vs_4_0_level_9_3, SampleTextureVS())); 1.725 + SetGeometryShader(NULL); 1.726 + SetPixelShader(CompileShader(ps_4_0_level_9_3, SampleMaskShadowVPS())); 1.727 + } 1.728 +} 1.729 + 1.730 +technique10 SampleTextTexture 1.731 +{ 1.732 + pass Unmasked 1.733 + { 1.734 + SetRasterizerState(TextureRast); 1.735 + SetBlendState(bTextBlend, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF ); 1.736 + SetVertexShader(CompileShader(vs_4_0_level_9_3, SampleTextureVS())); 1.737 + SetGeometryShader(NULL); 1.738 + SetPixelShader(CompileShader(ps_4_0_level_9_3, SampleTextTexturePS())); 1.739 + } 1.740 + pass Masked 1.741 + { 1.742 + SetRasterizerState(TextureRast); 1.743 + SetBlendState(bTextBlend, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF ); 1.744 + SetVertexShader(CompileShader(vs_4_0_level_9_3, SampleTextureVS())); 1.745 + SetGeometryShader(NULL); 1.746 + SetPixelShader(CompileShader(ps_4_0_level_9_3, SampleTextTexturePSMasked())); 1.747 + } 1.748 +} 1.749 +