SpriteText.bsl 2.5 KB

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