ShadersD2D.fx 23 KB

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