SpriteText.bsl 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. Parameters =
  2. {
  3. mat4x4 gWorldTransform;
  4. float gInvViewportWidth;
  5. float gInvViewportHeight;
  6. float gViewportYFlip;
  7. color gTint;
  8. Sampler2D gMainTexSamp : alias("gMainTexture");
  9. Texture2D gMainTexture;
  10. };
  11. Blocks =
  12. {
  13. Block GUIParams : auto("GUIParams");
  14. };
  15. Technique =
  16. {
  17. Language = "HLSL11";
  18. Pass =
  19. {
  20. Target =
  21. {
  22. Blend = true;
  23. Color = { SRCA, SRCIA, ADD };
  24. WriteMask = RGB;
  25. };
  26. DepthRead = false;
  27. DepthWrite = false;
  28. Common =
  29. {
  30. cbuffer GUIParams
  31. {
  32. float4x4 gWorldTransform;
  33. float gInvViewportWidth;
  34. float gInvViewportHeight;
  35. float gViewportYFlip;
  36. float4 gTint;
  37. }
  38. };
  39. Vertex =
  40. {
  41. void main(
  42. in float3 inPos : POSITION,
  43. in float2 uv : TEXCOORD0,
  44. out float4 oPosition : SV_Position,
  45. out float2 oUv : TEXCOORD0)
  46. {
  47. float4 tfrmdPos = mul(gWorldTransform, float4(inPos.xy, 0, 1));
  48. float tfrmdX = -1.0f + (tfrmdPos.x * gInvViewportWidth);
  49. float tfrmdY = (1.0f - (tfrmdPos.y * gInvViewportHeight)) * gViewportYFlip;
  50. oPosition = float4(tfrmdX, tfrmdY, 0, 1);
  51. oUv = uv;
  52. }
  53. };
  54. Fragment =
  55. {
  56. SamplerState gMainTexSamp : register(s0);
  57. Texture2D gMainTexture : register(t0);
  58. float4 main(in float4 inPos : SV_Position, float2 uv : TEXCOORD0) : SV_Target
  59. {
  60. float4 color = float4(gTint.rgb, gMainTexture.Sample(gMainTexSamp, uv).r * gTint.a);
  61. return color;
  62. }
  63. };
  64. };
  65. };
  66. Technique =
  67. {
  68. Language = "GLSL";
  69. Pass =
  70. {
  71. Target =
  72. {
  73. Blend = true;
  74. Color = { SRCA, SRCIA, ADD };
  75. WriteMask = RGB;
  76. };
  77. DepthRead = false;
  78. DepthWrite = false;
  79. Common =
  80. {
  81. layout (binding = 0, std140) uniform GUIParams
  82. {
  83. mat4 gWorldTransform;
  84. float gInvViewportWidth;
  85. float gInvViewportHeight;
  86. float gViewportYFlip;
  87. vec4 gTint;
  88. };
  89. };
  90. Vertex =
  91. {
  92. layout (location = 0) in vec3 bs_position;
  93. layout (location = 1) in vec2 bs_texcoord0;
  94. layout (location = 0) out vec2 texcoord0;
  95. out gl_PerVertex
  96. {
  97. vec4 gl_Position;
  98. };
  99. void main()
  100. {
  101. vec4 tfrmdPos = gWorldTransform * vec4(bs_position.xy, 0, 1);
  102. float tfrmdX = -1.0f + (tfrmdPos.x * gInvViewportWidth);
  103. float tfrmdY = (1.0f - (tfrmdPos.y * gInvViewportHeight)) * gViewportYFlip;
  104. gl_Position = vec4(tfrmdX, tfrmdY, 0, 1);
  105. texcoord0 = bs_texcoord0;
  106. }
  107. };
  108. Fragment =
  109. {
  110. layout (binding = 1) uniform sampler2D gMainTexture;
  111. layout (location = 0) in vec2 texcoord0;
  112. layout (location = 0) out vec4 fragColor;
  113. void main()
  114. {
  115. vec4 color = vec4(gTint.rgb, texture(gMainTexture, texcoord0.st).r * gTint.a);
  116. fragColor = color;
  117. }
  118. };
  119. };
  120. };