SpriteCommon.bslinc 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. mixin SpriteCommon
  2. {
  3. #ifndef ANIMATED
  4. #define ANIMATED 0
  5. #endif
  6. #ifndef TRANSPARENCY
  7. #define TRANSPARENCY 0
  8. #endif
  9. #ifndef UV
  10. #define UV 0
  11. #endif
  12. #if TRANSPARENCY
  13. blend
  14. {
  15. target
  16. {
  17. enabled = true;
  18. #if TRANSPARENCY == 1
  19. color = { srcA, srcIA, add };
  20. #else
  21. color = { one, srcIA, add };
  22. #endif
  23. #if ALPHA
  24. writemask = A;
  25. #else
  26. writemask = RGB;
  27. #endif
  28. };
  29. };
  30. #endif
  31. #if ALPHA
  32. stencil
  33. {
  34. enabled = true;
  35. readmask = 0x1;
  36. writemask = 0x1;
  37. front = { keep, keep, inc, eq };
  38. reference = 0x0;
  39. };
  40. #endif
  41. depth
  42. {
  43. read = false;
  44. write = false;
  45. };
  46. code
  47. {
  48. cbuffer GUIParams
  49. {
  50. float4x4 gWorldTransform;
  51. float gInvViewportWidth;
  52. float gInvViewportHeight;
  53. float gViewportYFlip;
  54. float4 gTint;
  55. float4 gUVSizeOffset;
  56. }
  57. void vsmain(
  58. in float3 inPos : POSITION
  59. #if UV
  60. , in float2 uv : TEXCOORD0
  61. #endif
  62. , out float4 oPosition : SV_Position
  63. #if UV
  64. , out float2 oUv : TEXCOORD0
  65. #endif
  66. )
  67. {
  68. float4 tfrmdPos = mul(gWorldTransform, float4(inPos.xy, 0, 1));
  69. float tfrmdX = -1.0f + (tfrmdPos.x * gInvViewportWidth);
  70. float tfrmdY = (1.0f - (tfrmdPos.y * gInvViewportHeight)) * gViewportYFlip;
  71. oPosition = float4(tfrmdX, tfrmdY, 0, 1);
  72. #if UV
  73. #if ANIMATED
  74. oUv = uv * gUVSizeOffset.xy + gUVSizeOffset.zw;
  75. #else
  76. oUv = uv;
  77. #endif
  78. #endif
  79. }
  80. };
  81. };